Repository navigation
FastMCP from OpenAPI - is the httpx.AsyncClient shared?
#3209
import httpx
from fastmcp import FastMCP
# Create an HTTP client for your API
client = httpx.AsyncClient(base_url="https://api.example.com")
# Load your OpenAPI spec
openapi_spec = httpx.get("https://api.example.com/openapi.json").json()
# Create the MCP server
mcp = FastMCP.from_openapi(
openapi_spec=openapi_spec,
client=client,
name="My API Server"
)If the external API returns cookies, for example, are those saved on the shared |
Replies: 2 comments
|
From my testing, it seems like cookies aren't shared. Is there anything else that could be shared between different users? |
|
Yes, it is shared. Every tool generated by I checked this on fastmcp 4.1.0 with an in-process API:
If the upstream API uses cookies for sessions, this leaks state between users. Some options:
As a rule, only put settings on the shared client ( |
Yes, it is shared. Every tool generated by
from_openapisends its requests through the single client you pass in (client.build_request(...)followed byclient.send(...)). Anything stored on that client therefore applies to every MCP session: the cookie jar, default headers, auth, and the connection pool.I checked this on fastmcp 4.1.0 with an in-process API:
POST /logintool, and the API responds withSet-Cookie: session=....Client(mcp), callsGET /whoami.cookie: session=<A's value>.If the upstream API uses cookies for sessions, this leaks state between users. Some options:
Disable the cookie jar if you don't need cookies:
from