Title: feat: Support separate endpoint path router in WebFluxStreamableServerTransportProvider · Issue #621 · modelcontextprotocol/java-sdk · GitHub
Open Graph Title: feat: Support separate endpoint path router in WebFluxStreamableServerTransportProvider · Issue #621 · modelcontextprotocol/java-sdk
X Title: feat: Support separate endpoint path router in WebFluxStreamableServerTransportProvider · Issue #621 · modelcontextprotocol/java-sdk
Description: Please do a quick search on GitHub issues first, the feature you are about to request might have already been requested. #79 #80 #425 #432 Expected Behavior The user can customize the endpoint routing functions. We hope to wrap HTTP-APIs...
Open Graph Description: Please do a quick search on GitHub issues first, the feature you are about to request might have already been requested. #79 #80 #425 #432 Expected Behavior The user can customize the endpoint rout...
X Description: Please do a quick search on GitHub issues first, the feature you are about to request might have already been requested. #79 #80 #425 #432 Expected Behavior The user can customize the endpoint rout...
Opengraph URL: https://github.com/modelcontextprotocol/java-sdk/issues/621
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"feat: Support separate endpoint path router in WebFluxStreamableServerTransportProvider","articleBody":"Please do a quick search on GitHub issues first, the feature you are about to request might have already been requested.\n#79 \n#80 \n#425 \n#432 \n\n**Expected Behavior**\n\nThe user can customize the endpoint routing functions.\nWe hope to wrap HTTP-APIs to MCP-Server-Tools.\n\n- Uses Spring WebFlux's RouterFunction for endpoint handling (GET, POST, DELETE)\n\nWe hope to support the follow MCP-Servers in one application process:\n- `/mcp`\n- `/mcp/mcp-server-app-name-A` -\u003e some MCP-Tools\n- `/mcp/mcp-server-app-name-B` -\u003e some MCP-Tools\n- `/mcp/mcp-server-app-name-C` -\u003e some MCP-Tools\n\n\u003c!--- Tell us how it should work. Add a code example to explain what you think the feature should look like. This is optional, but it would help up understand your expectations. --\u003e\n\n**Current Behavior**\n\nThe `RouterFunction` is private initialization in `WebFluxStreamableServerTransportProvider`, and its constructor is private.\n\n```java\npublic class WebFluxStreamableServerTransportProvider implements McpStreamableServerTransportProvider {\n\n\tprivate final String mcpEndpoint;\n\n\tprivate final RouterFunction\u003c?\u003e routerFunction;\n\n\tprivate WebFluxStreamableServerTransportProvider(ObjectMapper objectMapper, String mcpEndpoint,\n\t\t\tMcpTransportContextExtractor\u003cServerRequest\u003e contextExtractor, boolean disallowDelete,\n\t\t\tDuration keepAliveInterval) {\n\t\t\n\t\tthis.mcpEndpoint = mcpEndpoint;\n\t\t\n\t\tthis.routerFunction = RouterFunctions.route()\n\t\t\t.GET(this.mcpEndpoint, this::handleGet)\n\t\t\t.POST(this.mcpEndpoint, this::handlePost)\n\t\t\t.DELETE(this.mcpEndpoint, this::handleDelete)\n\t\t\t.build();\n\t}\n\n\tpublic RouterFunction\u003c?\u003e getRouterFunction() {\n\t\treturn this.routerFunction;\n\t}\n\n}\n```\n\n```java\npublic abstract class RouterFunctions {\n\n\tpublic static Builder route() {\n\t\treturn new RouterFunctionBuilder();\n\t}\n\n}\n```\n\n```java\nclass RouterFunctionBuilder implements RouterFunctions.Builder {\n\n\tprivate final List\u003cRouterFunction\u003cServerResponse\u003e\u003e routerFunctions = new ArrayList\u003c\u003e();\n\n\n\t@Override\n\tpublic RouterFunctions.Builder add(RouterFunction\u003cServerResponse\u003e routerFunction) {\n\t\tAssert.notNull(routerFunction, \"RouterFunction must not be null\");\n\t\tthis.routerFunctions.add(routerFunction);\n\t\treturn this;\n\t}\n\n\t@Override\n\tpublic RouterFunction\u003cServerResponse\u003e build() {\n\t\tif (this.routerFunctions.isEmpty()) {\n\t\t\tthrow new IllegalStateException(\"No routes registered. Register a route with GET(), POST(), etc.\");\n\t\t}\n\t\tRouterFunction\u003cServerResponse\u003e result = new BuiltRouterFunction(this.routerFunctions);\n\n\t\tif (this.filterFunctions.isEmpty() \u0026\u0026 this.errorHandlers.isEmpty()) {\n\t\t\treturn result;\n\t\t}\n\t\telse {\n\t\t\tHandlerFilterFunction\u003cServerResponse, ServerResponse\u003e filter =\n\t\t\t\t\tStream.concat(this.filterFunctions.stream(), this.errorHandlers.stream())\n\t\t\t\t\t\t\t.reduce(HandlerFilterFunction::andThen)\n\t\t\t\t\t\t\t.orElseThrow(IllegalStateException::new);\n\n\t\t\treturn result.filter(filter);\n\t\t}\n\t}\n\n\n\t/**\n\t * Router function returned by {@link #build()} that simply iterates over the registered routes.\n\t */\n\tprivate static class BuiltRouterFunction extends RouterFunctions.AbstractRouterFunction\u003cServerResponse\u003e {\n\n\t\tprivate final List\u003cRouterFunction\u003cServerResponse\u003e\u003e routerFunctions;\n\n\t\tpublic BuiltRouterFunction(List\u003cRouterFunction\u003cServerResponse\u003e\u003e routerFunctions) {\n\t\t\tAssert.notEmpty(routerFunctions, \"RouterFunctions must not be empty\");\n\t\t\tthis.routerFunctions = new ArrayList\u003c\u003e(routerFunctions);\n\t\t}\n\n\t\t@Override\n\t\tpublic Mono\u003cHandlerFunction\u003cServerResponse\u003e\u003e route(ServerRequest request) {\n\t\t\treturn Flux.fromIterable(this.routerFunctions)\n\t\t\t\t\t.concatMap(routerFunction -\u003e routerFunction.route(request))\n\t\t\t\t\t.next();\n\t\t}\n\n\t\t@Override\n\t\tpublic void accept(RouterFunctions.Visitor visitor) {\n\t\t\tthis.routerFunctions.forEach(routerFunction -\u003e routerFunction.accept(visitor));\n\t\t}\n\t}\n\n}\n```\n\n\u003c!--- Explain the difference from current behavior and why do you need this feature (aka why it is not possible to implement the desired functionality with the current version) --\u003e\n\n**Context**\n\nAPI is MCP, allowing AI to connect to the real world with lower cost, speed, and security. The existing APIs can be instantly converted into a Remote MCP Server, laying out the shortest connection path between AI and the real world.\n\nWe need to start multiple `WebFluxStreamableServerTransportProvider`, `McpAsyncServer` instances in one application process. Please to see the follow code in `McpServerConfiguration`, that is reference to `McpServerStreamableHttpWebFluxAutoConfiguration`.\n\nIt can support the follow MCP-Servers:\n- `/mcp`\n- `/mcp/mcp-server-app-name-A` -\u003e some MCP-Tools\n- `/mcp/mcp-server-app-name-B` -\u003e some MCP-Tools\n\nBut the `RouterFunction` can not dynamic update when the database update for some new app-name MCP-Server.\n\n- `/mcp/mcp-server-app-name-C`\n\n```java\n@Slf4j\n@EnableConfigurationProperties({ McpServerStreamableHttpProperties.class })\n@Configuration(proxyBeanMethods = false)\npublic class McpServerConfiguration {\n\n public McpServerConfiguration() {\n log.info(\"create McpServerConfiguration\");\n }\n\n @Bean\n public Map\u003cString, List\u003cMcpTool\u003e\u003e mcpToolListMap() {\n List\u003cString\u003e yamlFiles = List.of(\n \"mcp-server-user-apis.yml\",\n \"mcp-server-travel-apis.yml\"\n );\n\n return yamlFiles.stream()\n .map(YamlUtil::load)\n .collect(Collectors.toMap(\n mcpServerRule -\u003e mcpServerRule.getServer().getName(),\n McpServerRule::getTools\n ));\n }\n\n @Bean\n @ConditionalOnProperty(prefix = McpServerProperties.CONFIG_PREFIX, name = \"type\", havingValue = \"ASYNC\")\n @Conditional({ McpServerAutoConfiguration.EnabledStreamableServerCondition.class })\n public Map\u003cString, WebFluxStreamableServerTransportProvider\u003e transportProviderMap(\n Map\u003cString, List\u003cMcpTool\u003e\u003e mcpToolListMap) {\n log.info(\"init transportProviderMap\");\n\n Map\u003cString, WebFluxStreamableServerTransportProvider\u003e transportProviderMap =\n new ConcurrentHashMap\u003c\u003e(mcpToolListMap.size());\n transportProviderMap.putAll(McpServerTransportManager.transportProviderMap(mcpToolListMap.keySet()));\n return transportProviderMap;\n }\n\n /**\n * @see McpServerAutoConfiguration#capabilitiesBuilder()\n */\n @Bean\n public McpSchema.ServerCapabilities.Builder capabilitiesBuilder() {\n log.info(\"init capabilitiesBuilder\");\n\n return McpSchema.ServerCapabilities.builder()\n .tools(true);\n }\n\n @Bean\n @ConditionalOnProperty(prefix = McpServerProperties.CONFIG_PREFIX, name = \"type\", havingValue = \"ASYNC\")\n public Map\u003cString, McpAsyncServer\u003e mcpAsyncServerMap(\n Map\u003cString, List\u003cMcpTool\u003e\u003e mcpToolListMap,\n Map\u003cString, WebFluxStreamableServerTransportProvider\u003e transportProviderMap,\n McpSchema.ServerCapabilities.Builder capabilitiesBuilder) {\n log.info(\"init mcpAsyncServerMap\");\n\n return McpServerManager.mcpAsyncServerMap(mcpToolListMap, transportProviderMap, capabilitiesBuilder);\n }\n\n /**\n * @see McpServerStreamableHttpWebFluxAutoConfiguration#webFluxStreamableServerTransportProvider\n */\n @Bean\n @ConditionalOnProperty(prefix = McpServerProperties.CONFIG_PREFIX, name = \"type\", havingValue = \"ASYNC\")\n @Conditional({ McpServerAutoConfiguration.EnabledStreamableServerCondition.class })\n public WebFluxStreamableServerTransportProvider webFluxStreamableServerTransportProvider(\n ObjectProvider\u003cObjectMapper\u003e objectMapperProvider, McpServerStreamableHttpProperties serverProperties) {\n log.info(\"init webFluxStreamableServerTransportProvider\");\n\n ObjectMapper objectMapper = objectMapperProvider.getIfAvailable(ObjectMapper::new);\n\n return WebFluxStreamableServerTransportProvider.builder()\n .objectMapper(objectMapper)\n .messageEndpoint(serverProperties.getMcpEndpoint())\n .keepAliveInterval(serverProperties.getKeepAliveInterval())\n .disallowDelete(serverProperties.isDisallowDelete())\n .build();\n }\n\n /**\n * @see McpServerStreamableHttpWebFluxAutoConfiguration#webFluxStreamableServerRouterFunction\n */\n // Router function for streamable http transport used by Spring WebFlux to start an\n // HTTP server.\n @Bean\n @ConditionalOnProperty(prefix = McpServerProperties.CONFIG_PREFIX, name = \"type\", havingValue = \"ASYNC\")\n @Conditional({ McpServerAutoConfiguration.EnabledStreamableServerCondition.class })\n public RouterFunction\u003c?\u003e webFluxStreamableServerRouterFunction(\n WebFluxStreamableServerTransportProvider webFluxProvider,\n Map\u003cString, WebFluxStreamableServerTransportProvider\u003e transportProviderMap) {\n log.info(\"init webFluxStreamableServerRouterFunction\");\n\n RouterFunctions.Builder routerFunctionBuilder = RouterFunctions.route();\n routerFunctionBuilder.add((RouterFunction\u003cServerResponse\u003e) webFluxProvider.getRouterFunction());\n\n for (WebFluxStreamableServerTransportProvider transportProvider : transportProviderMap.values()) {\n routerFunctionBuilder.add((RouterFunction\u003cServerResponse\u003e) transportProvider.getRouterFunction());\n }\n\n return routerFunctionBuilder.build();\n }\n\n}\n```\n\n\u003c!--- \nHow has this issue affected you?\nWhat are you trying to accomplish?\nWhat other alternatives have you considered?\nAre you aware of any workarounds?\n--\u003e\n","author":{"url":"https://github.com/lihuagang03","@type":"Person","name":"lihuagang03"},"datePublished":"2025-10-14T03:08:15.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/621/java-sdk/issues/621"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f1248d26-4273-cbba-5232-c003ea75f5fa |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E59C:1C1025:1B9D661:2518283:6A5BB177 |
| html-safe-nonce | e8e35a1890a514b95de82fc736a7fa0d9de6c3635a037e7d46800172dd0d4c14 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNTlDOjFDMTAyNToxQjlENjYxOjI1MTgyODM6NkE1QkIxNzciLCJ2aXNpdG9yX2lkIjoiODE0MjAxNTY4NDI5OTk2MDY5NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 0d7f85a02281b5587db50f4c6065f045b7fe1e1d4f04a70f4a265892a31a219a |
| hovercard-subject-tag | issue:3512182926 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/java-sdk/621/issue_layout |
| twitter:image | https://opengraph.githubassets.com/54dfa4d3948c70da12bd78ccdfbaff8cd617cd5a21d2eebdbfff93438186bc75/modelcontextprotocol/java-sdk/issues/621 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/54dfa4d3948c70da12bd78ccdfbaff8cd617cd5a21d2eebdbfff93438186bc75/modelcontextprotocol/java-sdk/issues/621 |
| og:image:alt | Please do a quick search on GitHub issues first, the feature you are about to request might have already been requested. #79 #80 #425 #432 Expected Behavior The user can customize the endpoint rout... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | lihuagang03 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| go-import | github.com/modelcontextprotocol/java-sdk git https://github.com/modelcontextprotocol/java-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 919609219 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/java-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 919609219 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/java-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width