chore: import upstream snapshot with attribution
Deploy Docs / deploy-docs (push) Failing after 1s
Conformance Tests / client-conformance (push) Failing after 3s
Conformance Tests / server-conformance (push) Failing after 1s
GitHub Actions Security Analysis / zizmor (push) Failing after 1s
CI / checks (push) Failing after 59m20s
CI / all-green (push) Has been cancelled
Deploy Docs / deploy-docs (push) Failing after 1s
Conformance Tests / client-conformance (push) Failing after 3s
Conformance Tests / server-conformance (push) Failing after 1s
GitHub Actions Security Analysis / zizmor (push) Failing after 1s
CI / checks (push) Failing after 59m20s
CI / all-green (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
"""Sessionful Streamable HTTP: a tool mutates resources and emits `list_changed` over the standalone GET stream."""
|
||||
|
||||
import itertools
|
||||
|
||||
from mcp.server.mcpserver import Context, MCPServer
|
||||
from mcp.server.mcpserver.resources import TextResource
|
||||
from stories._hosting import run_server_from_args
|
||||
|
||||
|
||||
def build_server() -> MCPServer:
|
||||
mcp = MCPServer("standalone-get-example")
|
||||
counter = itertools.count(1)
|
||||
|
||||
mcp.add_resource(TextResource(uri="note://initial", name="initial", text="initial content"))
|
||||
|
||||
@mcp.tool()
|
||||
async def add_note(content: str, ctx: Context) -> str:
|
||||
"""Register a new resource and announce it via `notifications/resources/list_changed`."""
|
||||
name = f"note-{next(counter)}"
|
||||
mcp.add_resource(TextResource(uri=f"note://{name}", name=name, text=content))
|
||||
# MCPServer does not auto-emit on add_resource; send explicitly. With no
|
||||
# related_request_id this routes to the standalone GET stream.
|
||||
await ctx.session.send_resource_list_changed()
|
||||
return f"registered {name}"
|
||||
|
||||
return mcp
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_server_from_args(build_server)
|
||||
Reference in New Issue
Block a user