pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/modelcontextprotocol/python-sdk/commit/356dfa692bb7cdab71dcdd6d97f524fc77199291

rossorigen="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/global-b40ec823a1a6a1af.css" /> Update simple-resource example to use non-deprecated read_resource re… · modelcontextprotocol/python-sdk@356dfa6 · GitHub
Skip to content

Commit 356dfa6

Browse files
pja-antclaude
andauthored
Update simple-resource example to use non-deprecated read_resource return type (#1331)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1644b82 commit 356dfa6

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

  • examples/servers/simple-resource/mcp_simple_resource

examples/servers/simple-resource/mcp_simple_resource/server.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import click
33
import mcp.types as types
44
from mcp.server.lowlevel import Server
5+
from mcp.server.lowlevel.helper_types import ReadResourceContents
56
from pydantic import AnyUrl, FileUrl
67
from starlette.requests import Request
78

@@ -46,15 +47,15 @@ async def list_resources() -> list[types.Resource]:
4647
]
4748

4849
@app.read_resource()
49-
async def read_resource(uri: AnyUrl) -> str | bytes:
50+
async def read_resource(uri: AnyUrl):
5051
if uri.path is None:
5152
raise ValueError(f"Invalid resource path: {uri}")
5253
name = uri.path.replace(".txt", "").lstrip("/")
5354

5455
if name not in SAMPLE_RESOURCES:
5556
raise ValueError(f"Unknown resource: {uri}")
5657

57-
return SAMPLE_RESOURCES[name]["content"]
58+
return [ReadResourceContents(content=SAMPLE_RESOURCES[name]["content"], mime_type="text/plain")]
5859

5960
if transport == "sse":
6061
from mcp.server.sse import SseServerTransport

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy