Skip to content

HttpServletStreamableServerTransportProvider seems not to work on subpath contextPath #442

@fabb

Description

@fabb

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

  1. Create a Jetty server
  2. Add a ServletContextHandler with a subpath "/mcp" as contextPath
  3. Configure the HttpServletStreamableServerTransportProvider with mcpEndpoint "/" (or "/mcp", does not make a difference)
  4. 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), "/*");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions