Skip to content

add resource templates in example to make example complete #1021

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions examples/servers/simple-resource/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ async def main():
resources = await session.list_resources()
print(resources)

# List available resource templates
resource_templates = await session.list_resource_templates()
print(resource_templates)

# Get a specific resource
resource = await session.read_resource(AnyUrl("file:///greeting.txt"))
print(resource)
Expand Down
12 changes: 12 additions & 0 deletions examples/servers/simple-resource/mcp_simple_resource/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ async def list_resources() -> list[types.Resource]:
for name in SAMPLE_RESOURCES.keys()
]

@app.list_resource_templates()
async def list_resource_templates() -> list[types.ResourceTemplate]:
return [
types.ResourceTemplate(
uriTemplate="file:///{name}.txt",
name="resource template example",
title="resource template example",
description="Get txt file content by name",
mimeType="text/plain",
),
]

@app.read_resource()
async def read_resource(uri: AnyUrl) -> str | bytes:
if uri.path is None:
Expand Down
Loading