docs: clarify streamable_http_path configuration when mounting servers (#1172)
This commit is contained in:
parent
824ef8a281
commit
ff02c596a4
1 changed files with 302 additions and 0 deletions
29
examples/snippets/servers/streamable_http_path_config.py
Normal file
29
examples/snippets/servers/streamable_http_path_config.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
"""
|
||||
Example showing path configuration during FastMCP initialization.
|
||||
|
||||
Run from the repository root:
|
||||
uvicorn examples.snippets.servers.streamable_http_path_config:app --reload
|
||||
"""
|
||||
|
||||
from starlette.applications import Starlette
|
||||
from starlette.routing import Mount
|
||||
|
||||
from mcp.server.fastmcp import FastMCP
|
||||
|
||||
# Configure streamable_http_path during initialization
|
||||
# This server will mount at the root of wherever it's mounted
|
||||
mcp_at_root = FastMCP("My Server", streamable_http_path="/")
|
||||
|
||||
|
||||
@mcp_at_root.tool()
|
||||
def process_data(data: str) -> str:
|
||||
"""Process some data"""
|
||||
return f"Processed: {data}"
|
||||
|
||||
|
||||
# Mount at /process - endpoints will be at /process instead of /process/mcp
|
||||
app = Starlette(
|
||||
routes=[
|
||||
Mount("/process", app=mcp_at_root.streamable_http_app()),
|
||||
]
|
||||
)
|
||||
Loading…
Reference in a new issue