docs: restructure into topical sections and add the four most-asked-for pages (#3044)
This commit is contained in:
parent
080f2a869d
commit
220d362112
1 changed files with 2403 additions and 343 deletions
23
docs_src/deploy/tutorial004.py
Normal file
23
docs_src/deploy/tutorial004.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
from mcp.server.mcpserver import Context, MCPServer
|
||||
from mcp.server.subscriptions import SubscriptionBus
|
||||
|
||||
NOTES = {"todo": "buy milk"}
|
||||
|
||||
|
||||
def make_server(bus: SubscriptionBus) -> MCPServer:
|
||||
"""Every replica gets its own server object; all of them hold the same bus."""
|
||||
mcp = MCPServer("Notebook", subscriptions=bus)
|
||||
|
||||
@mcp.resource("note://{name}")
|
||||
def note(name: str) -> str:
|
||||
"""One note, by name."""
|
||||
return NOTES[name]
|
||||
|
||||
@mcp.tool()
|
||||
async def edit_note(name: str, text: str, ctx: Context) -> str:
|
||||
"""Replace a note's text."""
|
||||
NOTES[name] = text
|
||||
await ctx.notify_resource_updated(f"note://{name}")
|
||||
return "saved"
|
||||
|
||||
return mcp
|
||||
Loading…
Reference in a new issue