Spring AI MCP Client Streamable HTTP Transport Does Not Support URL Query Parameters
Description
When using Spring AI MCP Client with streamable-http transport to connect to remote MCP servers that require authentication via URL query parameters (such as Amap/Gaode Maps MCP Server), the query parameters are stripped from the final request URL, causing authentication failures.
Background
Many remote MCP servers use URL query parameters for authentication. For example:
- Amap MCP Server:
https://mcp.amap.com/mcp?key=YOUR_API_KEY
- Other third-party MCP services with API key authentication
The current Spring AI MCP Client implementation splits the URL into url (base URL) and endpoint (path), but query parameters in either field are not preserved in the final HTTP request.
Current Behavior
When configuring:
spring:
ai:
mcp:
client:
streamable-http:
connections:
amap:
url: https://mcp.amap.com/mcp?key=YOUR_API_KEY
# or
url: https://mcp.amap.com
endpoint: /mcp?key=YOUR_API_KEY
The actual HTTP request is sent to https://mcp.amap.com/mcp without the key query parameter, resulting in authentication errors like:
Root Cause
In StreamableHttpWebFluxTransportAutoConfiguration.java:
var webClientBuilder = webClientBuilderTemplate.clone().baseUrl(url);
String streamableHttpEndpoint = Objects.requireNonNullElse(
serverParameters.getValue().endpoint(), "/mcp");
var transportBuilder = WebClientStreamableHttpTransport.builder(webClientBuilder)
.endpoint(streamableHttpEndpoint)
// ...
The WebClient.baseUrl() method parses the URL but only uses scheme, host, and port. When WebClientStreamableHttpTransport later calls .uri(endpoint), it overrides the path and query parameters.
Expected Behavior
The MCP Client should preserve query parameters from either:
- The
url field (e.g., https://mcp.amap.com/mcp?key=xxx)
- The
endpoint field (e.g., /mcp?key=xxx)
Or provide an alternative way to configure query parameters for authentication.
Possible Solutions
- Parse and preserve query parameters from
url or endpoint in WebClientStreamableHttpTransport
- Add a new configuration property for query parameters:
spring:
ai:
mcp:
client:
streamable-http:
connections:
amap:
url: https://mcp.amap.com
endpoint: /mcp
query-params:
key: YOUR_API_KEY
- Support full URL in endpoint without splitting
Workaround
Currently, the only workaround is to implement a custom McpClientTransport that handles query parameters correctly, which requires significant boilerplate code.
Environment
- Spring AI Version: 1.1.2 (also affects 2.0.0)
- Java Version: 21
- Transport: WebFlux Streamable HTTP
Related Issues
- SSE transport supports query parameters in
sse-endpoint field
- Streamable HTTP transport should have feature parity with SSE transport
Additional Context
This issue affects all users trying to connect to remote MCP servers that use URL query parameter authentication, which is a common pattern for third-party API services.
Spring AI MCP Client Streamable HTTP Transport Does Not Support URL Query Parameters
Description
When using Spring AI MCP Client with
streamable-httptransport to connect to remote MCP servers that require authentication via URL query parameters (such as Amap/Gaode Maps MCP Server), the query parameters are stripped from the final request URL, causing authentication failures.Background
Many remote MCP servers use URL query parameters for authentication. For example:
https://mcp.amap.com/mcp?key=YOUR_API_KEYThe current Spring AI MCP Client implementation splits the URL into
url(base URL) andendpoint(path), but query parameters in either field are not preserved in the final HTTP request.Current Behavior
When configuring:
The actual HTTP request is sent to
https://mcp.amap.com/mcpwithout thekeyquery parameter, resulting in authentication errors like:Root Cause
In
StreamableHttpWebFluxTransportAutoConfiguration.java:The
WebClient.baseUrl()method parses the URL but only uses scheme, host, and port. WhenWebClientStreamableHttpTransportlater calls.uri(endpoint), it overrides the path and query parameters.Expected Behavior
The MCP Client should preserve query parameters from either:
urlfield (e.g.,https://mcp.amap.com/mcp?key=xxx)endpointfield (e.g.,/mcp?key=xxx)Or provide an alternative way to configure query parameters for authentication.
Possible Solutions
urlorendpointinWebClientStreamableHttpTransportWorkaround
Currently, the only workaround is to implement a custom
McpClientTransportthat handles query parameters correctly, which requires significant boilerplate code.Environment
Related Issues
sse-endpointfieldAdditional Context
This issue affects all users trying to connect to remote MCP servers that use URL query parameter authentication, which is a common pattern for third-party API services.