Add story-style examples suite (27 stories + harness + CI) (#2957)
This commit is contained in:
parent
9dc8c5f02d
commit
4caa41f6d5
1 changed files with 6801 additions and 26 deletions
27
examples/stories/json_response/server.py
Normal file
27
examples/stories/json_response/server.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
"""Serve over Streamable HTTP with JSON responses (no SSE stream); HTTP-only, so this exports ``build_app()``.
|
||||
|
||||
The 2026-07-28 path is stateless and JSON-only by construction today; the
|
||||
``json_response=True`` flag also forces JSON for the legacy (2025-era) branch on
|
||||
the same endpoint. Mid-call notifications are dropped.
|
||||
"""
|
||||
|
||||
from starlette.applications import Starlette
|
||||
|
||||
from mcp.server.mcpserver import Context, MCPServer
|
||||
from stories._hosting import NO_DNS_REBIND, run_app_from_args
|
||||
|
||||
|
||||
def build_app() -> Starlette:
|
||||
mcp = MCPServer("json-response-example")
|
||||
|
||||
@mcp.tool()
|
||||
async def greet(name: str, ctx: Context) -> str:
|
||||
"""Report progress mid-call, then return a greeting."""
|
||||
await ctx.report_progress(0.5, total=1.0, message="halfway")
|
||||
return f"Hello, {name}!"
|
||||
|
||||
return mcp.streamable_http_app(json_response=True, transport_security=NO_DNS_REBIND)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_app_from_args(build_app)
|
||||
Loading…
Reference in a new issue