Croway opened a new pull request, #30669:
URL: https://github.com/apache/camel/pull/30669

   [CAMEL-27248](https://issues.apache.org/jira/browse/CAMEL-27248), 
[CAMEL-27249](https://issues.apache.org/jira/browse/CAMEL-27249)
   
   ## CAMEL-27248: the path of the `mcpServer` url is ignored
   
   With `transportType=streamableHttp` (camel-openai) or `transportType=sse` 
(camel-openai and camel-spring-ai-chat), `mcpServer.<name>.url` was passed to 
the MCP SDK as the base URI of `HttpClientStreamableHttpTransport` / 
`HttpClientSseClientTransport`. The SDK resolves its endpoint (`/mcp` or `/sse` 
by default) against that base with `URI.resolve` (`Utils.resolveUri`, checked 
in the SDK source at 2.2.0, and 2.1.0 for 4.22.x), and an absolute path 
replaces the path and the query of the base. So `url=http://host:8080/api/mcp` 
sent the requests to `http://host:8080/mcp`, 
`url=http://host:8080/custom/sse?tenant=acme` opened `http://host:8080/sse`, 
and an MCP server on another path (camel-mcp-server with another path, a server 
behind a gateway prefix) could not be reached.
   
   - The url is split into its base (scheme and authority) and its endpoint, 
passed with `endpoint(...)` / `sseEndpoint(...)`, as CAMEL-27246 (#30445) 
already does for the streamableHttp transport of camel-spring-ai-chat. 
camel-spring-ai-chat now uses the same helper for both of its HTTP transports.
   - The endpoint is passed as the absolute URL under the base (which the SDK 
keeps as is), not as a bare path: a path that starts with `//`, such as 
`http://host:8080//other/mcp`, would otherwise be read by the SDK as a 
network-path reference to the host `other`. This also applies to the 
streamableHttp transport of camel-spring-ai-chat added by CAMEL-27246.
   - A url without a path, or with the path `/`, keeps the SDK default (`/mcp`, 
`/sse`). A relative url fails with `mcpServer.<name>.url must be an absolute 
URL, such as http://localhost:8080/sse` instead of an SDK error on connect.
   - The helper is a small private method in each component: the two components 
share no module where it would fit. camel-langchain4j-agent is not affected (it 
passes the url as the endpoint).
   - With sse, only the request that opens the stream uses the url; the 
messages go to the endpoint that the server sends, resolved against the base. 
The MCP SDK servers (Java, TypeScript, Python) and quarkus-mcp-server send an 
absolute path, which works under any base. A base with a path would reject a 
same-origin absolute message URL outside that path (`Utils.resolveUri`), so the 
base is scheme and authority only, as in CAMEL-27246; a path-relative message 
endpoint (`message?sessionId=...`) then resolves under `/`.
   - Docs: `openai-mcp.adoc` and `spring-ai-chat-component.adoc` say that the 
`url` is the URL of the endpoint, path included, and what a url without a path 
uses.
   
   **Behaviour change.** A url whose path is not the endpoint of the server, 
such as `http://host:8080/v1` for a server on `/mcp`, worked by accident 
because its path was ignored, and now fails. Upgrade guide entries are in the 
4.24 guide ("Upgrading Camel 4.23 to 4.24") and, as the fix is backported, in 
the 4.22 guide ("Upgrading from 4.22.2 to 4.22.3"). The urls of the MCP servers 
used by the ITs in the repository (`/mcp`, `/sse`) are not affected.
   
   ## CAMEL-27249: the descriptions lose their `<name>` placeholders
   
   The generated metadata removes everything between angle brackets, so the 
catalog JSON, the option table of the docs and the Javadoc of the endpoint DSL 
read `mcpServer..url= (sse/streamableHttp)`. The placeholders are now written 
as examples: `mcpServer.myServer.transportType=...`, 
`mcpServer.myServer.url=http://localhost:8080/mcp`, 
`mcpServer.myServer.args=arg1,arg2`, and so on.
   
   The other texts of these two components that lost text the same way are 
fixed too: the camel-openai `oauthProfile` option 
(`camel.oauth.<profileName>.client-id`), its `stripThinking` option and 
`CamelOpenAIStripThinking` / `CamelOpenAIThinkingContent` headers 
(`<think>...</think>`), and the camel-spring-ai-chat 
`CamelSpringAiChatAugmentedData` header (`List<...Document>`). Regenerated: 
`openai.json`, `llm.json`, `spring-ai-chat.json`, their copies in 
`camel-catalog`, and `OpenAIEndpointBuilderFactory` / 
`SpringAiChatEndpointBuilderFactory`.
   
   There is no dedicated test: it would only re-assert a description string. 
The regenerated catalog JSON and endpoint DSL in this diff are the evidence.
   
   ## Tests
   
   Both tests use an in-process MCP server: the stateless server of the MCP SDK 
with an `echo` tool, served by the JDK HTTP server over Streamable HTTP and 
over HTTP+SSE. No external service.
   
   - `OpenAIEndpointMcpHttpTransportTest` (new, camel-openai). camel-openai had 
no test that connects a real transport: its MCP tests replace 
`createMcpClient`. One parameterized test creates the client of each case, 
lists the tools and checks the path and query of the requests: streamableHttp 
on `/api/mcp?tenant=acme`, on a url without a path (`/mcp`), and on 
`//mcp.invalid/api/mcp` (stays on the configured server); sse on 
`/custom/sse?tenant=acme` and on `/` (`/sse`). One test covers the relative url 
error.
   - `SpringAiChatMcpHttpTransportTest` (renamed from 
`SpringAiChatMcpStreamableHttpTest` of CAMEL-27246, as it now covers both HTTP 
transports). The fixture also serves HTTP+SSE, and one parameterized test 
checks where sse opens its stream: `/custom/sse`, `/sse` for a url without a 
path, and `//mcp.invalid/custom/sse`. The streamableHttp tests of CAMEL-27246 
are unchanged; they already cover its path, default path, query and errors.
   - The rows with a path fail without the fix (the requests go to `/mcp` or 
`/sse`, without the query), and the `//` rows fail with the endpoint passed as 
a bare path. The rows without a path guard the defaults.
   - `mvn test` in camel-openai (437 tests) and camel-spring-ai-chat (73 
tests), and `-Psourcecheck`. The tests also pass with 
`-Djava.net.preferIPv6Addresses=true`.
   
   _Claude Code on behalf of Croway_
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to