Skip to content

Commit 8d281be

Browse files
committed
Rename types for latest SEP-1391 revision
1 parent 7dd550b commit 8d281be

File tree

4 files changed

+114
-99
lines changed

4 files changed

+114
-99
lines changed

src/mcp/client/session.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ async def call_tool(
293293
params=types.CallToolRequestParams(
294294
name=name,
295295
arguments=arguments,
296-
async_properties=async_properties,
296+
operation_params=async_properties,
297297
),
298298
)
299299
),
@@ -307,7 +307,7 @@ async def call_tool(
307307

308308
return result
309309

310-
async def check_tool_async_status(self, token: str) -> types.CheckToolAsyncStatusResult:
310+
async def get_operation_status(self, token: str) -> types.GetOperationStatusResult:
311311
"""Check the status of an async tool operation.
312312
313313
Args:
@@ -318,14 +318,14 @@ async def check_tool_async_status(self, token: str) -> types.CheckToolAsyncStatu
318318
"""
319319
return await self.send_request(
320320
types.ClientRequest(
321-
types.CheckToolAsyncStatusRequest(
322-
params=types.CheckToolAsyncStatusParams(token=token),
321+
types.GetOperationStatusRequest(
322+
params=types.GetOperationStatusParams(token=token),
323323
)
324324
),
325-
types.CheckToolAsyncStatusResult,
325+
types.GetOperationStatusResult,
326326
)
327327

328-
async def get_tool_async_result(self, token: str) -> types.GetToolAsyncPayloadResult:
328+
async def get_operation_result(self, token: str) -> types.GetOperationPayloadResult:
329329
"""Get the result of a completed async tool operation.
330330
331331
Args:
@@ -336,11 +336,11 @@ async def get_tool_async_result(self, token: str) -> types.GetToolAsyncPayloadRe
336336
"""
337337
return await self.send_request(
338338
types.ClientRequest(
339-
types.GetToolAsyncPayloadRequest(
340-
params=types.GetToolAsyncPayloadParams(token=token),
339+
types.GetOperationPayloadRequest(
340+
params=types.GetOperationPayloadParams(token=token),
341341
)
342342
),
343-
types.GetToolAsyncPayloadResult,
343+
types.GetOperationPayloadResult,
344344
)
345345

346346
async def _validate_tool_result(self, name: str, result: types.CallToolResult) -> None:

src/mcp/server/lowlevel/server.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -568,35 +568,35 @@ def _validate_operation_token(self, token: str) -> AsyncOperation:
568568

569569
return operation
570570

571-
def check_tool_async_status(self):
571+
def get_operation_status(self):
572572
"""Register a handler for checking async tool execution status."""
573573

574-
def decorator(func: Callable[[str], Awaitable[types.CheckToolAsyncStatusResult]]):
575-
logger.debug("Registering handler for CheckToolAsyncStatusRequest")
574+
def decorator(func: Callable[[str], Awaitable[types.GetOperationStatusResult]]):
575+
logger.debug("Registering handler for GetOperationStatusRequest")
576576

577-
async def handler(req: types.CheckToolAsyncStatusRequest):
577+
async def handler(req: types.GetOperationStatusRequest):
578578
# Validate token and get operation
579579
operation = self._validate_operation_token(req.params.token)
580580

581581
return types.ServerResult(
582-
types.CheckToolAsyncStatusResult(
582+
types.GetOperationStatusResult(
583583
status=operation.status,
584584
error=operation.error,
585585
)
586586
)
587587

588-
self.request_handlers[types.CheckToolAsyncStatusRequest] = handler
588+
self.request_handlers[types.GetOperationStatusRequest] = handler
589589
return func
590590

591591
return decorator
592592

593-
def get_tool_async_result(self):
593+
def get_operation_result(self):
594594
"""Register a handler for retrieving async tool execution results."""
595595

596-
def decorator(func: Callable[[str], Awaitable[types.GetToolAsyncPayloadResult]]):
597-
logger.debug("Registering handler for GetToolAsyncPayloadRequest")
596+
def decorator(func: Callable[[str], Awaitable[types.GetOperationPayloadResult]]):
597+
logger.debug("Registering handler for GetOperationPayloadRequest")
598598

599-
async def handler(req: types.GetToolAsyncPayloadRequest):
599+
async def handler(req: types.GetOperationPayloadRequest):
600600
# Validate token and get operation
601601
operation = self._validate_operation_token(req.params.token)
602602

@@ -608,9 +608,9 @@ async def handler(req: types.GetToolAsyncPayloadRequest):
608608
if not operation.result:
609609
raise McpError(types.ErrorData(code=-32600, message="No result available for completed operation"))
610610

611-
return types.ServerResult(types.GetToolAsyncPayloadResult(result=operation.result))
611+
return types.ServerResult(types.GetOperationPayloadResult(result=operation.result))
612612

613-
self.request_handlers[types.GetToolAsyncPayloadRequest] = handler
613+
self.request_handlers[types.GetOperationPayloadRequest] = handler
614614
return func
615615

616616
return decorator

src/mcp/types.py

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,14 @@ class Meta(BaseModel):
5353

5454
model_config = ConfigDict(extra="allow")
5555

56+
class Operation(BaseModel):
57+
token: str
58+
"""The token associated with the originating asynchronous tool call."""
59+
model_config = ConfigDict(extra="allow")
60+
5661
meta: Meta | None = Field(alias="_meta", default=None)
62+
operation: Operation | None = Field(alias="_operation", default=None)
63+
"""Async operation parameters, only used when a request is sent during an asynchronous tool call."""
5764

5865

5966
class PaginatedRequestParams(RequestParams):
@@ -68,11 +75,18 @@ class NotificationParams(BaseModel):
6875
class Meta(BaseModel):
6976
model_config = ConfigDict(extra="allow")
7077

78+
class Operation(BaseModel):
79+
token: str
80+
"""The token associated with the originating asynchronous tool call."""
81+
model_config = ConfigDict(extra="allow")
82+
7183
meta: Meta | None = Field(alias="_meta", default=None)
7284
"""
7385
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
7486
for notes on _meta usage.
7587
"""
88+
operation: Operation | None = Field(alias="_operation", default=None)
89+
"""Async operation parameters, only used when a notification is sent during an asynchronous tool call."""
7690

7791

7892
RequestParamsT = TypeVar("RequestParamsT", bound=RequestParams | dict[str, Any] | None)
@@ -106,11 +120,20 @@ class Notification(BaseModel, Generic[NotificationParamsT, MethodT]):
106120
class Result(BaseModel):
107121
"""Base class for JSON-RPC results."""
108122

123+
class Operation(BaseModel):
124+
token: str
125+
"""The token associated with the originating asynchronous tool call."""
126+
model_config = ConfigDict(extra="allow")
127+
109128
meta: dict[str, Any] | None = Field(alias="_meta", default=None)
110129
"""
111130
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
112131
for notes on _meta usage.
113132
"""
133+
operation: Operation | None = Field(alias="_operation", default=None)
134+
"""
135+
Async operation parameters, only used when a result is sent in response to a request with operation parameters.
136+
"""
114137
model_config = ConfigDict(extra="allow")
115138

116139

@@ -896,25 +919,25 @@ class AsyncResultProperties(BaseModel):
896919

897920

898921
# Async status checking types
899-
class CheckToolAsyncStatusParams(RequestParams):
922+
class GetOperationStatusParams(RequestParams):
900923
"""Parameters for checking async tool status."""
901924

902925
token: str
903926
"""Token from the original async tool call."""
904927

905928

906-
class CheckToolAsyncStatusRequest(Request[CheckToolAsyncStatusParams, Literal["tools/async/status"]]):
929+
class GetOperationStatusRequest(Request[GetOperationStatusParams, Literal["tools/async/status"]]):
907930
"""Request to check the status of an async tool call."""
908931

909932
method: Literal["tools/async/status"] = "tools/async/status"
910-
params: CheckToolAsyncStatusParams
933+
params: GetOperationStatusParams
911934

912935

913936
"""Status values for async operations."""
914-
AsyncOperationStatus = Literal["submitted", "working", "completed", "canceled", "failed", "unknown"]
937+
AsyncOperationStatus = Literal["submitted", "working", "input_required", "completed", "canceled", "failed", "unknown"]
915938

916939

917-
class CheckToolAsyncStatusResult(Result):
940+
class GetOperationStatusResult(Result):
918941
"""Result of checking async tool status."""
919942

920943
status: AsyncOperationStatus
@@ -924,21 +947,21 @@ class CheckToolAsyncStatusResult(Result):
924947

925948

926949
# Async payload retrieval types
927-
class GetToolAsyncPayloadParams(RequestParams):
950+
class GetOperationPayloadParams(RequestParams):
928951
"""Parameters for getting async tool payload."""
929952

930953
token: str
931954
"""Token from the original async tool call."""
932955

933956

934-
class GetToolAsyncPayloadRequest(Request[GetToolAsyncPayloadParams, Literal["tools/async/result"]]):
957+
class GetOperationPayloadRequest(Request[GetOperationPayloadParams, Literal["tools/async/result"]]):
935958
"""Request to get the result of a completed async tool call."""
936959

937960
method: Literal["tools/async/result"] = "tools/async/result"
938-
params: GetToolAsyncPayloadParams
961+
params: GetOperationPayloadParams
939962

940963

941-
class GetToolAsyncPayloadResult(Result):
964+
class GetOperationPayloadResult(Result):
942965
"""Result containing the final async tool call result."""
943966

944967
result: "CallToolResult"
@@ -950,7 +973,7 @@ class CallToolRequestParams(RequestParams):
950973

951974
name: str
952975
arguments: dict[str, Any] | None = None
953-
async_properties: AsyncRequestProperties | None = Field(serialization_alias="async", default=None)
976+
operation_params: AsyncRequestProperties | None = Field(serialization_alias="operation", default=None)
954977
"""Optional async execution parameters."""
955978
model_config = ConfigDict(extra="allow")
956979

@@ -969,7 +992,7 @@ class CallToolResult(Result):
969992
structuredContent: dict[str, Any] | None = None
970993
"""An optional JSON object that represents the structured result of the tool call."""
971994
isError: bool = False
972-
async_properties: AsyncResultProperties | None = Field(serialization_alias="async", default=None)
995+
operation_result: AsyncResultProperties | None = Field(serialization_alias="operation", default=None)
973996
"""Optional async execution information. Present when tool is executed asynchronously."""
974997

975998

@@ -1313,8 +1336,8 @@ class ClientRequest(
13131336
| UnsubscribeRequest
13141337
| CallToolRequest
13151338
| ListToolsRequest
1316-
| CheckToolAsyncStatusRequest
1317-
| GetToolAsyncPayloadRequest
1339+
| GetOperationStatusRequest
1340+
| GetOperationPayloadRequest
13181341
]
13191342
):
13201343
pass
@@ -1398,8 +1421,8 @@ class ServerResult(
13981421
| ReadResourceResult
13991422
| CallToolResult
14001423
| ListToolsResult
1401-
| CheckToolAsyncStatusResult
1402-
| GetToolAsyncPayloadResult
1424+
| GetOperationStatusResult
1425+
| GetOperationPayloadResult
14031426
]
14041427
):
14051428
pass

0 commit comments

Comments
 (0)