You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(mcp): simplify generated code via runtime invoker adapters
- Introduced `McpOperation` to cleanly encapsulate static routing metadata and runtime arguments.
- Refactored `McpInvoker` to act as a factory, providing strongly-typed adapters (`asToolHandler`, `asCompletionHandler`, etc.) for both stateful and stateless servers.
- Updated APT generator (`McpRouter`, `McpRoute`) to output clean method references instead of complex, boilerplate-heavy lambda chains.
Copy file name to clipboardExpand all lines: docs/asciidoc/modules/mcp.adoc
+65-7Lines changed: 65 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -189,7 +189,7 @@ public class UserService {
189
189
<1> Forces array schema generation for `User`, overriding generic `Object` erasure and the global/config flag.
190
190
<2> Explicitly disables schema generation for this specific tool.
191
191
192
-
=== Custom Invokers & Telemetry
192
+
=== Custom Invokers
193
193
194
194
You can inject custom logic (like SLF4J MDC context propagation, tracing, or custom error handling) around every tool, prompt, or resource execution by providing an `McpInvoker`.
195
195
@@ -204,16 +204,21 @@ Invokers are chained. You can register multiple invokers and they will wrap the
<1> Extract rich contextual data from the `McpOperation` record.
232
-
<2> Proceed with the execution chain.
233
-
<3> Register the invoker. Jooby will safely map any business exceptions thrown by your action into valid MCP JSON-RPC errors.
237
+
<2> Proceed to the next interceptor in the chain or execute the final target handler.
238
+
<3> Register the invoker. Jooby will safely map any business exceptions thrown by your chain into valid MCP JSON-RPC errors.
239
+
240
+
==== Context Augmentation
241
+
242
+
You can use an `McpInvoker` to resolve contextual data (such as an authenticated user, a tenant ID, etc.) and inject it directly into the `McpOperation`.
243
+
244
+
This allows your tool methods to simply declare the custom type in their method signature, keeping your business logic clean and completely decoupled from transport-layer extraction.
Once the invoker is registered, you can seamlessly declare the augmented argument in your MCP controllers. The Jooby Annotation Processor will automatically map the injected argument to your method parameter.
273
+
274
+
.Tool Implementation
275
+
[source, java]
276
+
----
277
+
import io.jooby.annotation.mcp.McpTool;
278
+
279
+
public class BillingService {
280
+
281
+
/**
282
+
* @param user The authenticated user (injected by UserContextInvoker).
283
+
* Note: Because it is a complex type not present in the JSON request,
284
+
* it is safely ignored by the JSON schema generator.
285
+
*/
286
+
@McpTool(description = "Retrieves the billing history for the current user")
287
+
public InvoiceHistory getMyInvoices(User user, int limit) {
0 commit comments