Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for tools/list #18

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Changes from all commits
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
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