Skip to content

Commit 2932236

Browse files
committed
docs: return dicts from resources instead of json.dumps
MCPServer handles serialization, so resources can return dicts directly instead of calling json.dumps manually.
1 parent 3da0ebc commit 2932236

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

docs/concepts.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,21 @@ LLM's context without performing computation or causing side effects.
3131
Resources can be static (fixed URI) or use URI templates for dynamic content:
3232

3333
```python
34-
import json
35-
3634
from mcp.server.mcpserver import MCPServer
3735

3836
mcp = MCPServer("Demo")
3937

4038

4139
@mcp.resource("config://app")
42-
def get_config() -> str:
40+
def get_config() -> dict:
4341
"""Expose application configuration."""
44-
return json.dumps({"theme": "dark", "version": "2.0"})
42+
return {"theme": "dark", "version": "2.0"}
4543

4644

4745
@mcp.resource("users://{user_id}/profile")
48-
def get_profile(user_id: str) -> str:
46+
def get_profile(user_id: str) -> dict:
4947
"""Get a user profile by ID."""
50-
return json.dumps({"user_id": user_id, "name": "Alice"})
48+
return {"user_id": user_id, "name": "Alice"}
5149
```
5250

5351
<!-- TODO: See [Resources](server/resources.md) for full documentation. -->

0 commit comments

Comments
 (0)