MCP
Overview
Serve your application to AI assistants with the Model Context Protocol.
The Model Context Protocol (MCP) is an open standard that lets AI assistants (Claude, IDE agents, your own agents) use tools and data that you provide, in one common way. Instead of each assistant needing custom code for your app, your app serves MCP once and every compatible assistant can use it.
| MCP offers | Meaning | Kest |
|---|---|---|
| Tools | actions the assistant can call | @McpTool |
| Resources | data it can read | @McpResource |
| Prompts | ready-made questions | @McpPrompt |
@Injectable class Inventory {
@McpTool("find_product", "Looks a product up by SKU", readOnly = true) fun find(sku: String): Product? = ...
@McpResource("inventory://low-stock", "Low stock") fun lowStock() = ...
@McpPrompt("restock_plan", "Drafts a plan") fun plan(category: String) = "Plan a restock for $category."
}
Kest.run<AppModule> { import(McpModule.forRoot { name = "inventory"; bearerToken = System.getenv("MCP_TOKEN") }) }
startHttp(NettyHttpAdapter(8080)) { useMiddleware(mcp.middleware("/mcp")) }Parameter names and types become the tool's input schema. A tool that throws is reported to the model as isError, not as a protocol error, so it can recover.
MCP or the ai package?
| You want | Use |
|---|---|
| other assistants (Claude, an IDE) to use your app | an MCP server (this section) |
| your application to call a model and let it use your methods | AI and @AiTool |
The same method can be both @McpTool and @AiTool.
Read MCP server for a full walk-through, Primitives, Transports and Testing.
Tools without annotations: tool("echo", "Repeats text", mapOf("text" to "string")) { args -> args["text"] }. Supported: initialize, ping, tools, resources (fixed URIs), prompts, batches. Not supported: stdio transport, server-sent streaming, resource templates and subscriptions, OAuth.