File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ " trpc-to-mcp " : patch
3+ ---
4+
5+ fix: transformer function being undefined and not receiving output
Original file line number Diff line number Diff line change @@ -15,7 +15,6 @@ import type {
1515} from "@trpc/server/unstable-core-do-not-import" ;
1616
1717import { extractToolsFromProcedures , type McpTool } from "./tools" ;
18- import type { McpMeta } from "./types" ;
1918
2019export function setRequestHandler < TRecord extends RouterRecord > (
2120 server : Server ,
@@ -42,12 +41,10 @@ export function setRequestHandler<TRecord extends RouterRecord>(
4241 trpcCaller ,
4342 ) ;
4443
45- const meta = procedure . meta as McpMeta | undefined ;
46- const transformMcpProcedure = meta ?. mcp ?. transformMcpProcedure ;
47-
48- if ( typeof transformMcpProcedure === "function" ) {
44+ if ( typeof tool . transformMcpProcedure === "function" ) {
4945 // @ts -expect-error path in router
50- const result = await transformMcpProcedure ( procedure ( args ) ) ;
46+ const output = await procedure ( args ) ;
47+ const result = await tool . transformMcpProcedure ( output ) ;
5148
5249 return {
5350 content : result ,
Original file line number Diff line number Diff line change @@ -7,13 +7,14 @@ import type {
77} from "@trpc/server/unstable-core-do-not-import" ;
88import { z } from "zod/v4" ;
99
10- import type { McpMeta } from "./types" ;
10+ import type { McpMeta , TransformMcpProcedureFunction } from "./types" ;
1111
1212export type McpTool = {
1313 name : string ;
1414 description : string ;
1515 pathInRouter : string [ ] ;
1616 inputSchema ?: z . core . JSONSchema . JSONSchema ;
17+ transformMcpProcedure ?: TransformMcpProcedureFunction ;
1718} ;
1819
1920export function mergeInputs ( inputs : z . ZodObject [ ] ) {
@@ -44,6 +45,7 @@ export function extractToolsFromProcedures<
4445 name : meta ?. mcp ?. name ?? name . replace ( / \. / g, "_" ) ,
4546 description : meta ?. mcp ?. description ?? "" ,
4647 pathInRouter,
48+ transformMcpProcedure : meta ?. mcp ?. transformMcpProcedure ,
4749 } ;
4850
4951 if ( schema ) {
Original file line number Diff line number Diff line change @@ -10,8 +10,10 @@ export type McpMeta = {
1010 enabled ?: boolean ;
1111 description ?: string ;
1212 name ?: string ;
13- transformMcpProcedure ?: (
14- output : inferProcedureOutput < AnyProcedure > ,
15- ) => MaybePromise < ContentBlock [ ] > ;
13+ transformMcpProcedure ?: TransformMcpProcedureFunction ;
1614 } ;
1715} ;
16+
17+ export type TransformMcpProcedureFunction = (
18+ output : inferProcedureOutput < AnyProcedure > ,
19+ ) => MaybePromise < ContentBlock [ ] > ;
You can’t perform that action at this time.
0 commit comments