Skip to content

Commit 587dbb7

Browse files
committed
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.
1 parent ab2f502 commit 587dbb7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Diff for: src/mcp/server/__init__.py

+19
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ async def handle_call_tool(
3030
) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
3131
# Implementation
3232
33+
@server.list_resource_templates()
34+
async def handle_list_resource_templates() -> list[types.ResourceTemplate]:
35+
# Implementation
36+
3337
3. Define notification handlers if needed:
3438
@server.progress_notification()
3539
async def handle_progress(
@@ -227,6 +231,21 @@ async def handler(_: Any):
227231

228232
return decorator
229233

234+
def list_resource_templates(self):
235+
def decorator(func: Callable[[], Awaitable[list[types.ResourceTemplate]]]):
236+
logger.debug("Registering handler for ListResourceTemplatesRequest")
237+
238+
async def handler(_: Any):
239+
templates = await func()
240+
return types.ServerResult(
241+
types.ListResourceTemplatesResult(resourceTemplates=templates)
242+
)
243+
244+
self.request_handlers[types.ListResourceTemplatesRequest] = handler
245+
return func
246+
247+
return decorator
248+
230249
def read_resource(self):
231250
def decorator(func: Callable[[AnyUrl], Awaitable[str | bytes]]):
232251
logger.debug("Registering handler for ReadResourceRequest")

0 commit comments

Comments
 (0)