Agent / foldkit-agent-mcp
agent-mcp
Exposing a Foldkit app to desktop or IDE assistants over the Model Context Protocol (MCP) usually means building and maintaining a parallel tool server whose schemas, permissions, and handlers drift from your UI. You want MCP clients to discover and invoke the exact capabilities your application already enforces.
foldkit-agent-mcp serves any bound foldkit-agent runtime over MCP (2025-06-18) via stdio or Streamable HTTP. Your AssistantAgent contract stays the authority for input schemas, availability, authorization, and completion, while this adapter maps capabilities to tools/list, tools/call, and resources/read. See agent contracts in action in the live Todo agent demo.
Install
pnpm add foldkit-agent foldkit-agent-mcpfoldkit, effect, and foldkit-agent are peer dependencies.
A first MCP server
Bind an agent contract to a Foldkit host and serve it over stdio (start with the Agent contract guide for full contract options):
import { Schema } from 'effect'
import { defineMessageUnion } from 'foldkit/message'
import { Agent } from 'foldkit-agent'
import { AgentMcp } from 'foldkit-agent-mcp'
const Model = Schema.Struct({ todos: Schema.Array(Schema.String) })
const Message = defineMessageUnion({ RequestedCreateTodo: { title: Schema.String } })
const TodoAgent = Agent.forModel<typeof Model.Type>()
const AppAgent = TodoAgent.make({
messages: TodoAgent.expose(Message, { RequestedCreateTodo: 'Create a todo' }),
})
type AppModel = typeof Model.Type
const { host } = Agent.headless({
init: (): { model: AppModel; commands: [] } => ({ model: { todos: [] }, commands: [] }),
update: (model: AppModel) => ({ model, commands: [] }),
})
const agentRuntime = TodoAgent.bind({ definition: AppAgent, host })
const server = AgentMcp.stdio({ agent: agentRuntime })AgentMcp.stdio attaches to stdin/stdout immediately and exposes requested_create_todo over JSON-RPC to any connected MCP client. Retain server and call server.close() on shutdown, and route your own application logs to stderr so stdout stays clean for MCP messages (the adapter sends its own diagnostics to stderr by default).
For embedding or tests without stdio, use AgentMcp.handler:
const served = AgentMcp.handler({ agent: agentRuntime })
await served.handle({ jsonrpc: '2.0', id: 1, method: 'tools/list' })