Skip to content

Wrong data path when MCP server mounted as ASGI SSE app under some subpath #464

@piotrekkr

Description

@piotrekkr

Describe the bug

When I setup MCP server as a SSE app under some subpath in existing ASGI app, in response to /my/sub/path/sse, I receive wrong endpoint path in data: (missing /my/sub/path prefix). For example if SSE app is mounted under /mcp/test and I call /mcp/test/sse in response I receive:

$ curl -i localhost:8080/mcp/test/sse      
...

event: endpoint
data: /messages/?session_id=e01cc317d1cd48fdb305a8074cee2134

Then MCP client tries to call http://localhost:8080/messages/?session_id=e01cc317d1cd48fdb305a8074cee2134 which does not exist. I believe this is not an issue if MPC server is mounted under root path /, but with subpath it is returning wrong data path.

Side note: There is example of this process in this repo readme but what is the point of mounting app into existing asgi server under /? It will override all routes of existing app, no?

To Reproduce

from fastapi import FastAPI
from mcp.server import FastMCP

# Create a server instance
server = FastMCP("quoting-mcp")

app = FastAPI()
app.mount('/mcp/test', server.sse_app())

call http://localhost:8080:/mcp/test/sse

Expected behavior

$ curl -i localhost:8080/mcp/test/sse      
...

event: endpoint
data: /mcp/test/messages/?session_id=e01cc317d1cd48fdb305a8074cee2134

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds reproneeds additional information to be able to reproduce bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions