An MCP tool is something a language model decides to call on its own, so expose only the procedures you want a model to use. A model picks a tool based on its name, description, and input schema. Give each exposed procedure a clear name, a description of what it does and when to use it, and a .describe() on each input field.
Install
pnpm add trpc-to-mcp @modelcontextprotocol/server
@trpc/server 11 and @modelcontextprotocol/server 2 are peer dependencies. Install mcp-handler 2 only if you use the mcp-handler adapter. Node.js 20 or later is required.
Usage
Add McpMeta to your tRPC instance.
import { initTRPC } from "@trpc/server";
import { type McpMeta } from "trpc-to-mcp";
const t = initTRPC.context<Context>().meta<McpMeta>().create();
Enable mcp on the procedures you want as tools.
import { z } from "zod";
export const appRouter = t.router({
hello: t.procedure
.meta({
mcp: {
enabled: true,
description: "Say hello to someone",
// Optional. Defaults to the procedure path with dots replaced by
// underscores, e.g. "hello" or "user_byId".
name: "say_hello",
},
})
.input(z.object({ name: z.string().describe("Who to greet") }))
.query(({ input }) => `Hello ${input.name}`),
});
Inputs must be object schemas from a validator that implements Standard JSON Schema, such as zod 4.2 or later, ArkType, or Valibot with toStandardJsonSchema(). Chained .input() calls are merged into one tool input schema. Subscriptions can't be tools.
tRPC validates input on every call, so your zod transforms and refinements run as usual. Errors thrown by a procedure, including TRPCError, come back to the client as a tool result with isError: true.
meta.mcp also takes title and annotations. Queries get readOnlyHint: true unless you set it yourself.
Serve your tools
createMcpServer returns an McpServer with your tools registered. You can register more tools, prompts, and resources on it.
Over stdio:
import { serveStdio } from "@modelcontextprotocol/server/stdio";
import { createMcpServer } from "trpc-to-mcp";
serveStdio(() =>
createMcpServer({ name: "my-app", version: "1.0.0" }, appRouter, { db }),
);
Over HTTP, with the SDK's createMcpHandler on any runtime with web-standard Request and Response:
To add tools to an McpServer you created yourself, call registerTrpcTools(server, appRouter, ctx).
Context
The third argument is the tRPC context. Pass a value, or a function that creates the context on each tool call. The function receives the MCP request context, so it can read the HTTP request and the auth info from your auth middleware.
Tool calls run through your tRPC middlewares, so auth checks in a protectedProcedure apply to MCP clients too.
Transform outputs
By default a tool returns the procedure output as JSON text. To return something easier for a model to read, wrap the procedure with transformMcpProcedure and return MCP content blocks. The output argument is typed from the procedure.
The content types are text, image, audio, resource, and resource_link. The procedure still returns its normal output to tRPC clients.
Structured output
If a procedure has an .output() validator that describes an object, the tool advertises it as an outputSchema and returns the output as structuredContent next to the text content.
mcp-handler turns an MCP server into a (Request) => Promise<Response> handler for Next.js, Nuxt, SvelteKit, Hono, and other frameworks. Install mcp-handler 2, then:
// app/api/mcp/route.ts
import { trpcToMcpHandler } from "trpc-to-mcp/adapters/vercel-mcp-adapter";
const handler = trpcToMcpHandler(appRouter, createContext, {
// mcp-handler options
serverOptions: {
serverInfo: { name: "my-app", version: "1.0.0" },
verboseLogs: process.env.NODE_ENV === "development",
},
// Register extra tools, prompts, or resources
callback: (server) => {},
});
export { handler as GET, handler as POST };
mcp-handler serves requests without sessions, so there is no Redis setup and no basePath. Mount the handler at any route.
Use with better-auth
The @better-auth/mcp plugin makes your better-auth app an OAuth authorization server for MCP clients. Put your handler behind requireMcpAuth, and read the user ID from the access token claims.
Creates an McpServer with the router's tools registered.
registerTrpcTools(server, router, ctx)
trpc-to-mcp
Registers the router's tools on an existing McpServer.
extractToolsFromProcedures(router)
trpc-to-mcp
Returns the tool definitions without a server.
transformMcpProcedure(procedure, transform)
trpc-to-mcp
Sets the MCP content a procedure's tool returns.
trpcToMcpHandler(router, ctx, options?)
trpc-to-mcp/adapters/vercel-mcp-adapter
Creates an mcp-handler request handler.
McpMeta, McpContext, McpTool
trpc-to-mcp
Types for procedure meta, the context argument, and tool definitions.
Upgrading from 1.x
Replace @modelcontextprotocol/sdk with @modelcontextprotocol/server 2, and upgrade mcp-handler to 2 if you use the adapter. Node.js 20 or later is required.
In trpcToMcpHandler, remove config. Move verboseLogs into serverOptions, and mount the handler at the route you want.
Use zod 4.2 or later, or another validator with Standard JSON Schema support. zod is no longer a peer dependency.
Replace setRequestHandler(server.server, tools, caller) with registerTrpcTools(server, appRouter, ctx). mergeInputs is removed.
In McpTool, pathInRouter is now path, a dotted string, and transformMcpProcedure is now transform.
Set output transforms with the transformMcpProcedure() helper. meta.mcp.transformMcpProcedure is removed.
An enabled subscription, or an enabled procedure whose input is not an object, now throws when the server starts.
pnpm install
pnpm test # vitest
pnpm lint # oxlint with type-aware rules
pnpm typecheck # tsc
pnpm format # oxfmt
pnpm build # tsdown
CI runs format:check, lint, typecheck, test, and build on every push.
To release, add a changeset with pnpm changeset in your pull request. After it merges, the publish workflow opens a "Version Packages" pull request that bumps the version and updates CHANGELOG.md. Merging that pull request publishes to npm with trusted publishing and creates a GitHub release. No npm token is stored in the repository.
Result
Now you can chill and add MCP to your VC-backed startup so your investors won't worry, and profit
Noch keine Tool-Liste. Remote-Server erhalten eine nach dem ersten Health-Check.
FAQ
Fragen
Wie installiere ich Trpc To?
Kopieren Sie auf dieser Seite die stdio-Konfiguration für Cursor, Claude Desktop, Claude Code oder VS Code. Sie nutzt die Installation des Herausgebers, keinen PlugMCP-Proxy.
Benötigt Trpc To einen API-Schlüssel?
In diesem Eintrag ist keine erforderliche Umgebungsvariable aufgeführt.
Welchen Transport verwendet Trpc To?
Trpc To läuft lokal über stdio.
Wann wurde Trpc To zuletzt geprüft?
Zuletzt geprüft: 2026-11-16. Turn tRPC procedures into MCP tools