docs: Update examples to use stateless HTTP with JSON responses (#1499)
Some checks failed
Main branch checks / checks (push) Has been cancelled

This commit is contained in:
adam jones 2025-11-20 15:06:37 +00:00 • committed by GitHub
commit fcffa14b5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -17,7 +17,7 @@ Here's a simple MCP server that exposes a tool, resource, and prompt:
```python title="server.py"
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("Test Server")
mcp = FastMCP("Test Server", json_response=True)
@mcp.tool()
@ -36,12 +36,22 @@ def get_greeting(name: str) -> str:
def greet_user(name: str, style: str = "friendly") -> str:
"""Generate a greeting prompt"""
return f"Write a {style} greeting for someone named {name}."
if __name__ == "__main__":
mcp.run(transport="streamable-http")
```
Test it with the [MCP Inspector](https://github.com/modelcontextprotocol/inspector):
Run the server:
```bash
uv run mcp dev server.py
uv run --with mcp server.py
```
Then open the [MCP Inspector](https://github.com/modelcontextprotocol/inspector) and connect to `http://localhost:8000/mcp`:
```bash
npx -y @modelcontextprotocol/inspector
```
## Getting Started