File tree Expand file tree Collapse file tree 1 file changed +3
-2
lines changed
examples/servers/simple-resource/mcp_simple_resource Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Original file line number Diff line number Diff line change 2
2
import click
3
3
import mcp .types as types
4
4
from mcp .server .lowlevel import Server
5
+ from mcp .server .lowlevel .helper_types import ReadResourceContents
5
6
from pydantic import AnyUrl , FileUrl
6
7
from starlette .requests import Request
7
8
@@ -46,15 +47,15 @@ async def list_resources() -> list[types.Resource]:
46
47
]
47
48
48
49
@app .read_resource ()
49
- async def read_resource (uri : AnyUrl ) -> str | bytes :
50
+ async def read_resource (uri : AnyUrl ):
50
51
if uri .path is None :
51
52
raise ValueError (f"Invalid resource path: { uri } " )
52
53
name = uri .path .replace (".txt" , "" ).lstrip ("/" )
53
54
54
55
if name not in SAMPLE_RESOURCES :
55
56
raise ValueError (f"Unknown resource: { uri } " )
56
57
57
- return SAMPLE_RESOURCES [name ]["content" ]
58
+ return [ ReadResourceContents ( content = SAMPLE_RESOURCES [name ]["content" ], mime_type = "text/plain" ) ]
58
59
59
60
if transport == "sse" :
60
61
from mcp .server .sse import SseServerTransport
You can’t perform that action at this time.
0 commit comments