Skip to content

Commit

Permalink
Merge pull request #18 from modelcontextprotocol/davidsp/list_tools
Browse files Browse the repository at this point in the history
Add support for tools/list
  • Loading branch information
dsp-ant authored Oct 14, 2024
2 parents db5ca59 + 631c589 commit 5c70e16
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion mcp_python/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
ListPromptsResult,
ListResourcesRequest,
ListResourcesResult,
ListToolsRequest,
ListToolsResult,
LoggingLevel,
ProgressNotification,
Prompt,
Expand All @@ -36,6 +38,7 @@
ServerResult,
SetLevelRequest,
SubscribeRequest,
Tool,
UnsubscribeRequest,
)

Expand Down Expand Up @@ -79,7 +82,7 @@ def get_capability(req_type: type) -> dict[str, Any] | None:
return ServerCapabilities(
prompts=get_capability(ListPromptsRequest),
resources=get_capability(ListResourcesRequest),
tools=get_capability(ListPromptsRequest),
tools=get_capability(ListToolsRequest),
logging=get_capability(SetLevelRequest),
)

Expand Down Expand Up @@ -205,6 +208,7 @@ async def handler(req: ReadResourceRequest):

return decorator


def set_logging_level(self):
from mcp_python.types import EmptyResult

Expand Down Expand Up @@ -250,6 +254,19 @@ async def handler(req: UnsubscribeRequest):

return decorator

def list_tools(self):
def decorator(func: Callable[[], Awaitable[list[Tool]]]):
logger.debug("Registering handler for ListToolsRequest")

async def handler(_: Any):
tools = await func()
return ServerResult(ListToolsResult(tools=tools))

self.request_handlers[ListToolsRequest] = handler
return func

return decorator

def call_tool(self):
from mcp_python.types import CallToolResult

Expand Down

0 comments on commit 5c70e16

Please sign in to comment.