Mcp Tools

MCP tools of a project

A REST API handler annotated @KlokMcpTool is also a tool of the service's MCP server. klok-quarkus-extension registers it at startup and fails the build on a broken one: its page MCP tools has the rules. The plugin reads the same facts from the sources, without compiling or running anything, in two places:

  • klokMcpTools lists what the service exposes to an agent;
  • the documentation payload carries each tool as the route's mcpTool, which KlokDocumentationEgress turns into the project's MCP tools page and the tenant skill's mcp-tool facts.

klokMcpTools

./gradlew klokMcpTools

For a project with a read tool and a write tool:

[KlokPlugin - MCP tools] MCP tools of acme-orders: 2 tool(s), 1 on

  TOOL          STATE                                            ACCESS  OPERATION             ROUTE                 DESCRIPTION
  order_create  off (set ACM001A3_OrderCreate.mcp.enabled=true)  writes  POST /api/orders      ACM001A3_OrderCreate  Create an order ...
  order_get     on                                               reads   GET /api/orders/{id}  ACM001A2_OrderGet     Read one order by its id ...
Column Means
TOOL the name the model sees
STATE on or off: <RouteId>.mcp.enabled in application.properties, else on for a tool that only reads and off for one that writes
ACCESS reads, or writes for @KlokMcpTool(write = true)
OPERATION the verb and full path of the REST operation the tool calls; (no REST API uses it) when no KlokRestApi of the project names the handler, which the extension's build check refuses
ROUTE the handler's route id

The task writes the same list to build/klok-mcp-tools/mcp-tools.json. A tool that a model can see is a tool it can call with the caller's rights, so this is the list to read in a review and before switching a tool that writes on.

How the scan reads a tool

  • The handler is a concrete class extending KlokRestApiHandlerRoute, directly or through base classes of the project, annotated dev.klok.framework.patterns.routecapability.KlokMcpTool. name, description and write are read from the annotation; a description written as a concatenation of string literals is folded into one text.
  • The operation comes from the op(path, Handler.class, description, query...) or operation(...) call in the get(), post(), put() or delete() method of a KlokRestApi. Its full path is overrideContextPath() (default /api), resourceName() and the operation's path, when they return literals.
  • The arguments are the path parameters (required), the query parameters (optional) and, for POST and PUT, body, typed by the handler's first type argument. The reply type is its second.
  • enabledByDefault in the payload is the default (!write). The listing also shows what application.properties sets, which is one environment's choice.