mirror of
https://github.com/aljazceru/mcp-python-sdk.git
synced 2025-12-19 23:04:25 +01:00
Add handler for resource templates
We missed to have a handler for resource templates. We add this now. One caveat is still that the `uriTemplate` in `ResourceTemplate` is not a pydantic type.
This commit is contained in:
@@ -30,6 +30,10 @@ Usage:
|
|||||||
) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
|
) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
|
||||||
# Implementation
|
# Implementation
|
||||||
|
|
||||||
|
@server.list_resource_templates()
|
||||||
|
async def handle_list_resource_templates() -> list[types.ResourceTemplate]:
|
||||||
|
# Implementation
|
||||||
|
|
||||||
3. Define notification handlers if needed:
|
3. Define notification handlers if needed:
|
||||||
@server.progress_notification()
|
@server.progress_notification()
|
||||||
async def handle_progress(
|
async def handle_progress(
|
||||||
@@ -227,6 +231,21 @@ class Server:
|
|||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
def list_resource_templates(self):
|
||||||
|
def decorator(func: Callable[[], Awaitable[list[types.ResourceTemplate]]]):
|
||||||
|
logger.debug("Registering handler for ListResourceTemplatesRequest")
|
||||||
|
|
||||||
|
async def handler(_: Any):
|
||||||
|
templates = await func()
|
||||||
|
return types.ServerResult(
|
||||||
|
types.ListResourceTemplatesResult(resourceTemplates=templates)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.request_handlers[types.ListResourceTemplatesRequest] = handler
|
||||||
|
return func
|
||||||
|
|
||||||
|
return decorator
|
||||||
|
|
||||||
def read_resource(self):
|
def read_resource(self):
|
||||||
def decorator(func: Callable[[AnyUrl], Awaitable[str | bytes]]):
|
def decorator(func: Callable[[AnyUrl], Awaitable[str | bytes]]):
|
||||||
logger.debug("Registering handler for ReadResourceRequest")
|
logger.debug("Registering handler for ReadResourceRequest")
|
||||||
|
|||||||
Reference in New Issue
Block a user