@@ -146,7 +146,7 @@ Run from the repository root:
146146from mcp.server.fastmcp import FastMCP
147147
148148# Create an MCP server
149- mcp = FastMCP(" Demo" , json_response = True )
149+ mcp = FastMCP(" Demo" )
150150
151151
152152# Add an addition tool
@@ -178,7 +178,7 @@ def greet_user(name: str, style: str = "friendly") -> str:
178178
179179# Run with streamable HTTP transport
180180if __name__ == " __main__" :
181- mcp.run(transport = " streamable-http" )
181+ mcp.run(transport = " streamable-http" , json_response = True )
182182```
183183
184184_ Full example: [ examples/snippets/servers/fastmcp_quickstart.py] ( https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/servers/fastmcp_quickstart.py ) _
@@ -1026,7 +1026,6 @@ class SimpleTokenVerifier(TokenVerifier):
10261026# Create FastMCP instance as a Resource Server
10271027mcp = FastMCP(
10281028 " Weather Service" ,
1029- json_response = True ,
10301029 # Token verifier for authentication
10311030 token_verifier = SimpleTokenVerifier(),
10321031 # Auth settings for RFC 9728 Protected Resource Metadata
@@ -1050,7 +1049,7 @@ async def get_weather(city: str = "London") -> dict[str, str]:
10501049
10511050
10521051if __name__ == " __main__" :
1053- mcp.run(transport = " streamable-http" )
1052+ mcp.run(transport = " streamable-http" , json_response = True )
10541053```
10551054
10561055_ Full example: [ examples/snippets/servers/oauth_server.py] ( https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/servers/oauth_server.py ) _
@@ -1253,15 +1252,7 @@ Run from the repository root:
12531252
12541253from mcp.server.fastmcp import FastMCP
12551254
1256- # Stateless server with JSON responses (recommended)
1257- mcp = FastMCP(" StatelessServer" , stateless_http = True , json_response = True )
1258-
1259- # Other configuration options:
1260- # Stateless server with SSE streaming responses
1261- # mcp = FastMCP("StatelessServer", stateless_http=True)
1262-
1263- # Stateful server with session persistence
1264- # mcp = FastMCP("StatefulServer")
1255+ mcp = FastMCP(" StatelessServer" )
12651256
12661257
12671258# Add a simple tool to demonstrate the server
@@ -1272,8 +1263,17 @@ def greet(name: str = "World") -> str:
12721263
12731264
12741265# Run server with streamable_http transport
1266+ # Transport-specific options (stateless_http, json_response) are passed to run()
12751267if __name__ == " __main__" :
1276- mcp.run(transport = " streamable-http" )
1268+ # Stateless server with JSON responses (recommended)
1269+ mcp.run(transport = " streamable-http" , stateless_http = True , json_response = True )
1270+
1271+ # Other configuration options:
1272+ # Stateless server with SSE streaming responses
1273+ # mcp.run(transport="streamable-http", stateless_http=True)
1274+
1275+ # Stateful server with session persistence
1276+ # mcp.run(transport="streamable-http")
12771277```
12781278
12791279_ Full example: [ examples/snippets/servers/streamable_config.py] ( https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/servers/streamable_config.py ) _
@@ -1296,7 +1296,7 @@ from starlette.routing import Mount
12961296from mcp.server.fastmcp import FastMCP
12971297
12981298# Create the Echo server
1299- echo_mcp = FastMCP(name = " EchoServer" , stateless_http = True , json_response = True )
1299+ echo_mcp = FastMCP(name = " EchoServer" )
13001300
13011301
13021302@echo_mcp.tool ()
@@ -1306,7 +1306,7 @@ def echo(message: str) -> str:
13061306
13071307
13081308# Create the Math server
1309- math_mcp = FastMCP(name = " MathServer" , stateless_http = True , json_response = True )
1309+ math_mcp = FastMCP(name = " MathServer" )
13101310
13111311
13121312@math_mcp.tool ()
@@ -1327,16 +1327,16 @@ async def lifespan(app: Starlette):
13271327# Create the Starlette app and mount the MCP servers
13281328app = Starlette(
13291329 routes = [
1330- Mount(" /echo" , echo_mcp.streamable_http_app()),
1331- Mount(" /math" , math_mcp.streamable_http_app()),
1330+ Mount(" /echo" , echo_mcp.streamable_http_app(stateless_http = True , json_response = True )),
1331+ Mount(" /math" , math_mcp.streamable_http_app(stateless_http = True , json_response = True )),
13321332 ],
13331333 lifespan = lifespan,
13341334)
13351335
13361336# Note: Clients connect to http://localhost:8000/echo/mcp and http://localhost:8000/math/mcp
13371337# To mount at the root of each path (e.g., /echo instead of /echo/mcp):
1338- # echo_mcp.settings. streamable_http_path = "/"
1339- # math_mcp.settings. streamable_http_path = "/"
1338+ # echo_mcp.streamable_http_app( streamable_http_path= "/", stateless_http=True, json_response=True)
1339+ # math_mcp.streamable_http_app( streamable_http_path= "/", stateless_http=True, json_response=True)
13401340```
13411341
13421342_ Full example: [ examples/snippets/servers/streamable_starlette_mount.py] ( https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/servers/streamable_starlette_mount.py ) _
@@ -1409,7 +1409,7 @@ from starlette.routing import Mount
14091409from mcp.server.fastmcp import FastMCP
14101410
14111411# Create MCP server
1412- mcp = FastMCP(" My App" , json_response = True )
1412+ mcp = FastMCP(" My App" )
14131413
14141414
14151415@mcp.tool ()
@@ -1426,9 +1426,10 @@ async def lifespan(app: Starlette):
14261426
14271427
14281428# Mount the StreamableHTTP server to the existing ASGI server
1429+ # Transport-specific options are passed to streamable_http_app()
14291430app = Starlette(
14301431 routes = [
1431- Mount(" /" , app = mcp.streamable_http_app()),
1432+ Mount(" /" , app = mcp.streamable_http_app(json_response = True )),
14321433 ],
14331434 lifespan = lifespan,
14341435)
@@ -1456,7 +1457,7 @@ from starlette.routing import Host
14561457from mcp.server.fastmcp import FastMCP
14571458
14581459# Create MCP server
1459- mcp = FastMCP(" MCP Host App" , json_response = True )
1460+ mcp = FastMCP(" MCP Host App" )
14601461
14611462
14621463@mcp.tool ()
@@ -1473,9 +1474,10 @@ async def lifespan(app: Starlette):
14731474
14741475
14751476# Mount using Host-based routing
1477+ # Transport-specific options are passed to streamable_http_app()
14761478app = Starlette(
14771479 routes = [
1478- Host(" mcp.acme.corp" , app = mcp.streamable_http_app()),
1480+ Host(" mcp.acme.corp" , app = mcp.streamable_http_app(json_response = True )),
14791481 ],
14801482 lifespan = lifespan,
14811483)
@@ -1503,8 +1505,8 @@ from starlette.routing import Mount
15031505from mcp.server.fastmcp import FastMCP
15041506
15051507# Create multiple MCP servers
1506- api_mcp = FastMCP(" API Server" , json_response = True )
1507- chat_mcp = FastMCP(" Chat Server" , json_response = True )
1508+ api_mcp = FastMCP(" API Server" )
1509+ chat_mcp = FastMCP(" Chat Server" )
15081510
15091511
15101512@api_mcp.tool ()
@@ -1519,12 +1521,6 @@ def send_message(message: str) -> str:
15191521 return f " Message sent: { message} "
15201522
15211523
1522- # Configure servers to mount at the root of each path
1523- # This means endpoints will be at /api and /chat instead of /api/mcp and /chat/mcp
1524- api_mcp.settings.streamable_http_path = " /"
1525- chat_mcp.settings.streamable_http_path = " /"
1526-
1527-
15281524# Create a combined lifespan to manage both session managers
15291525@contextlib.asynccontextmanager
15301526async def lifespan (app : Starlette):
@@ -1534,11 +1530,12 @@ async def lifespan(app: Starlette):
15341530 yield
15351531
15361532
1537- # Mount the servers
1533+ # Mount the servers with transport-specific options passed to streamable_http_app()
1534+ # streamable_http_path="/" means endpoints will be at /api and /chat instead of /api/mcp and /chat/mcp
15381535app = Starlette(
15391536 routes = [
1540- Mount(" /api" , app = api_mcp.streamable_http_app()),
1541- Mount(" /chat" , app = chat_mcp.streamable_http_app()),
1537+ Mount(" /api" , app = api_mcp.streamable_http_app(json_response = True , streamable_http_path = " / " )),
1538+ Mount(" /chat" , app = chat_mcp.streamable_http_app(json_response = True , streamable_http_path = " / " )),
15421539 ],
15431540 lifespan = lifespan,
15441541)
@@ -1552,7 +1549,7 @@ _Full example: [examples/snippets/servers/streamable_http_multiple_servers.py](h
15521549<!-- snippet-source examples/snippets/servers/streamable_http_path_config.py -->
15531550``` python
15541551"""
1555- Example showing path configuration during FastMCP initialization .
1552+ Example showing path configuration when mounting FastMCP .
15561553
15571554Run from the repository root:
15581555 uvicorn examples.snippets.servers.streamable_http_path_config:app --reload
@@ -1563,13 +1560,8 @@ from starlette.routing import Mount
15631560
15641561from mcp.server.fastmcp import FastMCP
15651562
1566- # Configure streamable_http_path during initialization
1567- # This server will mount at the root of wherever it's mounted
1568- mcp_at_root = FastMCP(
1569- " My Server" ,
1570- json_response = True ,
1571- streamable_http_path = " /" ,
1572- )
1563+ # Create a simple FastMCP server
1564+ mcp_at_root = FastMCP(" My Server" )
15731565
15741566
15751567@mcp_at_root.tool ()
@@ -1578,10 +1570,14 @@ def process_data(data: str) -> str:
15781570 return f " Processed: { data} "
15791571
15801572
1581- # Mount at /process - endpoints will be at /process instead of /process/mcp
1573+ # Mount at /process with streamable_http_path="/" so the endpoint is /process (not /process/mcp)
1574+ # Transport-specific options like json_response are passed to streamable_http_app()
15821575app = Starlette(
15831576 routes = [
1584- Mount(" /process" , app = mcp_at_root.streamable_http_app()),
1577+ Mount(
1578+ " /process" ,
1579+ app = mcp_at_root.streamable_http_app(json_response = True , streamable_http_path = " /" ),
1580+ ),
15851581 ]
15861582)
15871583```
0 commit comments