Skip to content

Commit 6e63dcb

Browse files
authored
Merge pull request #54 from Lab11HQ/chore/rename-request-context
2 parents 22b7575 + 67b3ca1 commit 6e63dcb

37 files changed

+135
-137
lines changed

src/conduit/client/coordinator.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from collections.abc import Coroutine
1111
from typing import Any, Awaitable, Callable, TypeVar
1212

13-
from conduit.client.request_context import RequestContext
13+
from conduit.client.message_context import MessageContext
1414
from conduit.client.server_manager import ServerManager
1515
from conduit.protocol.base import (
1616
INTERNAL_ERROR,
@@ -35,9 +35,9 @@
3535
TResult = TypeVar("TResult", bound=Result)
3636
TNotification = TypeVar("TNotification", bound=Notification)
3737

38-
RequestHandler = Callable[[RequestContext, TRequest], Awaitable[TResult | Error]]
38+
RequestHandler = Callable[[MessageContext, TRequest], Awaitable[TResult | Error]]
3939
NotificationHandler = Callable[
40-
[RequestContext, TNotification], Coroutine[Any, Any, None]
40+
[MessageContext, TNotification], Coroutine[Any, Any, None]
4141
]
4242

4343

@@ -137,14 +137,14 @@ def _on_message_loop_done(self, task: asyncio.Task[None]) -> None:
137137
# Build context
138138
# ================================
139139

140-
def _build_context(self, server_id: str) -> RequestContext:
140+
def _build_context(self, server_id: str) -> MessageContext:
141141
"""Builds context for a request.
142142
143143
Args:
144144
server_id: ID of the server making the request
145145
146146
Returns:
147-
RequestContext: Context with server state and helpers
147+
MessageContext: Context with server state and helpers
148148
149149
Raises:
150150
ValueError: If the server is not registered with the client
@@ -153,7 +153,7 @@ def _build_context(self, server_id: str) -> RequestContext:
153153
if server_state is None:
154154
raise ValueError(f"Server {server_id} not registered")
155155

156-
return RequestContext(
156+
return MessageContext(
157157
server_id=server_id,
158158
server_state=server_state,
159159
server_manager=self.server_manager,
@@ -250,7 +250,7 @@ async def _route_request(
250250
async def _execute_request_handler(
251251
self,
252252
handler: RequestHandler,
253-
context: RequestContext,
253+
context: MessageContext,
254254
request_id: str | int,
255255
request: Request,
256256
) -> None:
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212

1313
@dataclass
14-
class RequestContext:
15-
"""Rich context for handling server -> client requests.
14+
class MessageContext:
15+
"""Rich context for handling server -> client messages.
1616
1717
Provides immediate access to server state, capabilities, and helper methods.
1818
"""
@@ -60,6 +60,6 @@ def get_server_display_name(self) -> str:
6060
def __str__(self) -> str:
6161
"""String representation for logging."""
6262
return (
63-
f"RequestContext(server={self.get_server_display_name()},"
63+
f"MessageContext(server={self.get_server_display_name()},"
6464
f"id={self.server_id})"
6565
)

src/conduit/client/protocol/elicitation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
from typing import Awaitable, Callable
33

4-
from conduit.client.request_context import RequestContext
4+
from conduit.client.message_context import MessageContext
55
from conduit.protocol.elicitation import ElicitRequest, ElicitResult
66

77

@@ -19,7 +19,7 @@ def __init__(self):
1919
self.logger = logging.getLogger("conduit.client.protocol.elicitation")
2020

2121
async def handle_elicitation(
22-
self, context: RequestContext, request: ElicitRequest
22+
self, context: MessageContext, request: ElicitRequest
2323
) -> ElicitResult:
2424
"""Elicit a response from the user.
2525

src/conduit/client/protocol/roots.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
from copy import deepcopy
33

4-
from conduit.client.request_context import RequestContext
4+
from conduit.client.message_context import MessageContext
55
from conduit.protocol.roots import ListRootsRequest, ListRootsResult, Root
66

77

@@ -78,7 +78,7 @@ def cleanup_server(self, server_id: str) -> None:
7878
# ================================
7979

8080
async def handle_list_roots(
81-
self, context: RequestContext, request: ListRootsRequest
81+
self, context: MessageContext, request: ListRootsRequest
8282
) -> ListRootsResult:
8383
"""List the roots available to the server making the request."""
8484
roots = self.get_server_roots(context.server_id)

src/conduit/client/protocol/sampling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
from typing import Awaitable, Callable
33

4-
from conduit.client.request_context import RequestContext
4+
from conduit.client.message_context import MessageContext
55
from conduit.protocol.sampling import CreateMessageRequest, CreateMessageResult
66

77

@@ -19,7 +19,7 @@ def __init__(self):
1919
self.logger = logging.getLogger("conduit.client.protocol.sampling")
2020

2121
async def handle_create_message(
22-
self, context: RequestContext, request: CreateMessageRequest
22+
self, context: MessageContext, request: CreateMessageRequest
2323
) -> CreateMessageResult:
2424
"""Sample the host LLM for the server.
2525

src/conduit/client/session.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515
from conduit.client.callbacks import CallbackManager
1616
from conduit.client.coordinator import MessageCoordinator
17+
from conduit.client.message_context import MessageContext
1718
from conduit.client.protocol.elicitation import (
1819
ElicitationManager,
1920
ElicitationNotConfiguredError,
2021
)
2122
from conduit.client.protocol.roots import RootsManager
2223
from conduit.client.protocol.sampling import SamplingManager, SamplingNotConfiguredError
23-
from conduit.client.request_context import RequestContext
2424
from conduit.client.server_manager import ServerManager
2525
from conduit.protocol.base import (
2626
INTERNAL_ERROR,
@@ -293,7 +293,7 @@ def _validate_protocol_version(self, result: InitializeResult) -> None:
293293
# ================================
294294

295295
async def _handle_ping(
296-
self, context: RequestContext, request: PingRequest
296+
self, context: MessageContext, request: PingRequest
297297
) -> EmptyResult:
298298
"""Returns an empty result."""
299299

@@ -304,7 +304,7 @@ async def _handle_ping(
304304
# ================================
305305

306306
async def _handle_list_roots(
307-
self, context: RequestContext, request: ListRootsRequest
307+
self, context: MessageContext, request: ListRootsRequest
308308
) -> ListRootsResult | Error:
309309
"""Returns the roots available to the server.
310310
@@ -324,7 +324,7 @@ async def _handle_list_roots(
324324
# ================================
325325

326326
async def _handle_sampling(
327-
self, context: RequestContext, request: CreateMessageRequest
327+
self, context: MessageContext, request: CreateMessageRequest
328328
) -> CreateMessageResult | Error:
329329
"""Creates a message using the configured sampling handler.
330330
@@ -354,7 +354,7 @@ async def _handle_sampling(
354354
# ================================
355355

356356
async def _handle_elicitation(
357-
self, context: RequestContext, request: ElicitRequest
357+
self, context: MessageContext, request: ElicitRequest
358358
) -> ElicitResult | Error:
359359
"""Returns an elicitation result using the configured elicitation handler.
360360
@@ -384,7 +384,7 @@ async def _handle_elicitation(
384384
# ================================
385385

386386
async def _handle_cancelled(
387-
self, context: RequestContext, notification: CancelledNotification
387+
self, context: MessageContext, notification: CancelledNotification
388388
) -> None:
389389
"""Cancels a request from the server and calls the registered callback."""
390390
request_exists = (
@@ -400,13 +400,13 @@ async def _handle_cancelled(
400400
await self.callbacks.call_cancelled(context.server_id, notification)
401401

402402
async def _handle_progress(
403-
self, context: RequestContext, notification: ProgressNotification
403+
self, context: MessageContext, notification: ProgressNotification
404404
) -> None:
405405
"""Calls the registered callback for progress updates."""
406406
await self.callbacks.call_progress(context.server_id, notification)
407407

408408
async def _handle_prompts_list_changed(
409-
self, context: RequestContext, notification: PromptListChangedNotification
409+
self, context: MessageContext, notification: PromptListChangedNotification
410410
) -> None:
411411
"""Fetches the updated prompts list and calls the registered callback.
412412
@@ -433,7 +433,7 @@ async def _handle_prompts_list_changed(
433433
)
434434

435435
async def _handle_resources_list_changed(
436-
self, context: RequestContext, notification: ResourceListChangedNotification
436+
self, context: MessageContext, notification: ResourceListChangedNotification
437437
) -> None:
438438
"""Fetches the updated resources/templates and calls the registered callback.
439439
@@ -479,7 +479,7 @@ async def _handle_resources_list_changed(
479479
)
480480

481481
async def _handle_resources_updated(
482-
self, context: RequestContext, notification: ResourceUpdatedNotification
482+
self, context: MessageContext, notification: ResourceUpdatedNotification
483483
) -> None:
484484
"""Reads the updated resource content and calls the registered callback.
485485
@@ -502,7 +502,7 @@ async def _handle_resources_updated(
502502
)
503503

504504
async def _handle_tools_list_changed(
505-
self, context: RequestContext, notification: ToolListChangedNotification
505+
self, context: MessageContext, notification: ToolListChangedNotification
506506
) -> None:
507507
"""Fetches the updated tools list and calls the registered callback.
508508
@@ -529,7 +529,7 @@ async def _handle_tools_list_changed(
529529
)
530530

531531
async def _handle_logging_message(
532-
self, context: RequestContext, notification: LoggingMessageNotification
532+
self, context: MessageContext, notification: LoggingMessageNotification
533533
) -> None:
534534
"""Calls the registered callback for logging messages."""
535535
await self.callbacks.call_logging_message(context.server_id, notification)

src/conduit/server/coordinator.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@
2626
JSONRPCResponse,
2727
)
2828
from conduit.server.client_manager import ClientManager
29-
from conduit.server.request_context import RequestContext
29+
from conduit.server.message_context import MessageContext
3030
from conduit.shared.message_parser import MessageParser
3131
from conduit.transport.server import ClientMessage, ServerTransport, TransportContext
3232

3333
TRequest = TypeVar("TRequest", bound=Request)
3434
TResult = TypeVar("TResult", bound=Result)
3535
TNotification = TypeVar("TNotification", bound=Notification)
3636

37-
RequestHandler = Callable[[RequestContext, TRequest], Awaitable[TResult | Error]]
37+
RequestHandler = Callable[[MessageContext, TRequest], Awaitable[TResult | Error]]
3838
NotificationHandler = Callable[
39-
[RequestContext, TNotification], Coroutine[Any, Any, None]
39+
[MessageContext, TNotification], Coroutine[Any, Any, None]
4040
]
4141

4242

@@ -140,14 +140,14 @@ def _on_message_loop_done(self, task: asyncio.Task[None]) -> None:
140140

141141
def _build_context(
142142
self, client_id: str, originating_request_id: str | int | None = None
143-
) -> RequestContext:
144-
"""Builds context for a request.
143+
) -> MessageContext:
144+
"""Builds context for handling a message.
145145
146146
Args:
147147
client_id: ID of the client making the request
148148
149149
Returns:
150-
RequestContext: Rich context with client state and helpers
150+
MessageContext: Rich context with client state and helpers
151151
152152
Raises:
153153
ValueError: If client is not registered
@@ -156,7 +156,7 @@ def _build_context(
156156
if client_state is None:
157157
raise ValueError(f"Client {client_id} not registered")
158158

159-
return RequestContext(
159+
return MessageContext(
160160
client_id=client_id,
161161
client_state=client_state,
162162
client_manager=self.client_manager,
@@ -256,7 +256,7 @@ async def _route_request(
256256
async def _execute_request_handler(
257257
self,
258258
handler: RequestHandler,
259-
context: RequestContext,
259+
context: MessageContext,
260260
request_id: str | int,
261261
request: Request,
262262
) -> None:
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818

1919

2020
@dataclass
21-
class RequestContext:
22-
"""Rich context for handling client -> server requests.
21+
class MessageContext:
22+
"""Rich context for handling client -> server messages.
2323
2424
Provides immediate access to client state, capabilities, and helper methods
2525
instead of requiring handlers to work with bare client_id strings.
2626
2727
This context is built once at the coordinator level and threaded through
28-
the request pipeline, giving handlers everything they need to make
28+
the message pipeline, giving handlers everything they need to make
2929
informed decisions about client capabilities and state.
3030
"""
3131

@@ -104,6 +104,6 @@ def get_client_display_name(self) -> str:
104104
def __str__(self) -> str:
105105
"""String representation for logging."""
106106
return (
107-
f"RequestContext(client={self.get_client_display_name()},"
107+
f"MessageContext(client={self.get_client_display_name()},"
108108
f"id={self.client_id})"
109109
)

src/conduit/server/protocol/completions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from conduit.protocol.completions import CompleteRequest, CompleteResult
55

66
if TYPE_CHECKING:
7-
from conduit.server.request_context import RequestContext
7+
from conduit.server.message_context import MessageContext
88

99

1010
class CompletionNotConfiguredError(Exception):
@@ -14,13 +14,13 @@ class CompletionNotConfiguredError(Exception):
1414
class CompletionManager:
1515
def __init__(self):
1616
self.completion_handler: (
17-
Callable[["RequestContext", CompleteRequest], Awaitable[CompleteResult]]
17+
Callable[["MessageContext", CompleteRequest], Awaitable[CompleteResult]]
1818
| None
1919
) = None
2020
self.logger = logging.getLogger("conduit.server.protocol.completions")
2121

2222
async def handle_complete(
23-
self, context: "RequestContext", request: CompleteRequest
23+
self, context: "MessageContext", request: CompleteRequest
2424
) -> CompleteResult:
2525
"""Generate a completion for a given argument.
2626

src/conduit/server/protocol/logging.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from conduit.protocol.logging import LoggingLevel, SetLevelRequest
66

77
if TYPE_CHECKING:
8-
from conduit.server.request_context import RequestContext
8+
from conduit.server.message_context import MessageContext
99

1010

1111
class LoggingManager:
@@ -55,7 +55,7 @@ def cleanup_client(self, client_id: str) -> None:
5555
self._client_log_levels.pop(client_id, None)
5656

5757
async def handle_set_level(
58-
self, context: "RequestContext", request: SetLevelRequest
58+
self, context: "MessageContext", request: SetLevelRequest
5959
) -> EmptyResult:
6060
"""Set the MCP protocol logging level for a specific client.
6161

0 commit comments

Comments
 (0)