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

   ## Problem
   
   `McpServerBridge.publish` / `publishResource` tracked a spec as published 
before calling the `void` `McpServerEngine.toolAdded` / `resourceAdded`. An 
engine backed by a runtime MCP server (e.g. quarkus-mcp-server, which needs 
unique names) could not refuse a name or uri the application already serves. 
The bridge still tracked it, so:
   
   - a later route with that name or uri was refused as a clash, though nothing 
served it;
   - stopping the route called `toolRemoved` / `resourceRemoved` for something 
the engine never added.
   
   ## Changes
   
   - New `McpServerRefusedException` (`RuntimeCamelException`, `@since 4.24`): 
an engine throws it from `toolAdded` / `resourceAdded` to refuse.
   - `McpServerBridge`: tracks a tool or resource only after the engine call 
returns normally. A refusal logs an ERROR with the reason (and the cause, if 
any), like the bridge's own name clash; the route keeps running. Other engine 
exceptions propagate as before.
   - `McpServerEngine` Javadoc: documents the exception; an engine that throws 
must leave nothing registered, as `toolRemoved` / `resourceRemoved` are called 
only for accepted ones.
   - `mcp-server.adoc` (+ catalog copy): one paragraph for engine authors.
   
   No signature change. Engines that never throw behave as before.
   
   ## Tests
   
   New `McpServerBridgeEngineRefusalTest`:
   
   - refused tool and resource at startup: not published, routes keep running, 
CamelContext starts
   - a later route reusing a refused name / uri is published
   - stopping a refused route calls no `toolRemoved` / `resourceRemoved`
   - another engine exception (`IllegalStateException`) from `toolAdded` / 
`resourceAdded` at bridge start: CamelContext start fails with it
   - a route added later whose tool / resource the engine fails to add (the 
registry only logs it, the route runs): stopping it calls no `toolRemoved` / 
`resourceRemoved`
   
   Results: `camel-mcp-server-api` 36 tests, 0 failures, 0 errors. 
`-Psourcecheck` (formatter, impsort) clean.
   
   Mutation checks, each killed and reverted: `catch (RuntimeException e)` 
instead of the refusal in `publish` or `publishResource`; tracking before the 
engine call; tracking first and untracking only on a refusal (tool and 
resource).
   
   Refs: `CAMEL-26102`. Context: review discussion in 
`apache/camel-quarkus#9368`.
   
   _Claude Code on behalf of jiriOndrusek-agent_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   _Generated with [Claude Code](https://claude.com/claude-code) on behalf of 
@JiriOndrusek_
   


-- 
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