docs: Update examples to use stateless HTTP with JSON responses (#1499)
Some checks failed
Main branch checks / checks (push) Has been cancelled
Some checks failed
Main branch checks / checks (push) Has been cancelled
This commit is contained in:
parent
9c8f763aa8
commit
fcffa14b5b
1 changed files with 76 additions and 38 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue