Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions src/mcp/server/lowlevel/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ async def main():
UnstructuredContent: TypeAlias = Iterable[types.ContentBlock]
CombinationContent: TypeAlias = tuple[UnstructuredContent, StructuredContent]

# type alias for call_tool handler function signature
CallToolHandler: TypeAlias = Callable[
[str, dict[str, Any]],
Awaitable[
UnstructuredContent | StructuredContent | CombinationContent | types.CallToolResult | types.CreateTaskResult
],
]

# This will be properly typed in each Server instance's context
request_ctx: contextvars.ContextVar[RequestContext[ServerSession, Any, Any]] = contextvars.ContextVar("request_ctx")

Expand Down Expand Up @@ -497,18 +505,7 @@ def call_tool(self, *, validate_input: bool = True):
If outputSchema is defined, validates structuredContent or errors if missing.
"""

def decorator(
func: Callable[
...,
Awaitable[
UnstructuredContent
| StructuredContent
| CombinationContent
| types.CallToolResult
| types.CreateTaskResult
],
],
):
def decorator(func: CallToolHandler) -> CallToolHandler:
logger.debug("Registering handler for CallToolRequest")

async def handler(req: types.CallToolRequest):
Expand Down