-
Notifications
You must be signed in to change notification settings - Fork 575
Description
Bug description
I want to run the HttpServletStreamableServerTransportProvider
on a subpath of my jetty server, and have unrelated servlets on different contextPaths. Giving the ServletContextHandler
of the MCP server a contextPath
of a subpath (e.g. /mcp
), makes the MCP server unreachable from the MCP Inspector.
Environment
- Version 0.11.0
- openjdk 24.0.1, the code runs as an extension in Bitwig Studio
Steps to reproduce
- Create a Jetty server
- Add a
ServletContextHandler
with a subpath"/mcp"
ascontextPath
- Configure the
HttpServletStreamableServerTransportProvider
withmcpEndpoint
"/"
(or"/mcp"
, does not make a difference) - Add a servlet with this transport provider instance
Expected behavior
With the MCP Inspector (npx @modelcontextprotocol/inspector
) it should be possible to connect to http://localhost:12345/mcp via Streamable HTTP.
When setting the contextPath
to "/"
and the transport's mcpEndpoint
to "/mcp"
, the MCP Inspector can connect correctly and everything works. But I want to bind a different handler on "/"
for serving a website.
Minimal Complete Reproducible example
var jettyServer = new Server();
ServerConnector connector = new ServerConnector(jettyServer);
connector.setHost("localhost");
connector.setPort("12345");
jettyServer.addConnector(connector);
var contextHandler = new ServletContextHandler();
contextHandler.setContextPath("/mcp"); // using "/" would work correctly in combination with `.mcpEndpoint("/mcp")` - but I need a subpath as contextPath since I want to add another handler on the root path for serving a website
jettyServer.setHandler(contextHandler);
jettyServer.start();
var objectMapper = new ObjectMapper();
var transportProvider = HttpServletStreamableServerTransportProvider
.builder()
.objectMapper(objectMapper)
.mcpEndpoint("/")
.build();
var mcpServer = McpServer.sync(this.transportProvider)
.serverInfo("MyServer", "0.0.1")
// ... register tools
.build();
contextHandler.addServlet(new ServletHolder(transportProvider), "/*");