@kubb/plugin-mcp 5.0.0-beta.36 → 5.0.0-beta.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -58,68 +58,57 @@ type Props = {
58
58
  const keysPrinter = functionPrinter({ mode: 'keys' })
59
59
 
60
60
  export function Server({ name, serverName, serverVersion, paramsCasing, operations }: Props): KubbReactNode {
61
- return (
62
- <File.Source name={name} isExportable isIndexable>
63
- <Const name={'server'} export>
64
- {`
65
- new McpServer({
66
- name: '${serverName}',
67
- version: '${serverVersion}',
68
- })
69
- `}
70
- </Const>
71
-
72
- {operations
73
- .map(({ tool, mcp, zod, node }) => {
74
- const { path: pathParams } = getOperationParameters(node, { paramsCasing })
75
-
76
- const pathEntries: Array<{ key: string; value: string }> = []
77
- const otherEntries: Array<{ key: string; value: string }> = []
78
-
79
- for (const p of pathParams) {
80
- const zodParam = zod.pathParams.find((zp) => zp.name === p.name)
81
- pathEntries.push({ key: p.name, value: zodParam ? zodParam.schemaName : zodExprFromSchemaNode(p.schema) })
82
- }
83
-
84
- if (zod.requestName) {
85
- otherEntries.push({ key: 'data', value: zod.requestName })
86
- }
87
-
88
- if (zod.queryParams) {
89
- otherEntries.push({ key: 'params', value: zodGroupExpr(zod.queryParams) })
90
- }
91
-
92
- if (zod.headerParams) {
93
- otherEntries.push({ key: 'headers', value: zodGroupExpr(zod.headerParams) })
94
- }
95
-
96
- otherEntries.sort((a, b) => a.key.localeCompare(b.key))
97
- const entries = [...pathEntries, ...otherEntries]
98
-
99
- const paramsNode = entries.length
100
- ? ast.createFunctionParameters({
101
- params: [
102
- ast.createParameterGroup({
103
- properties: entries.map((e) => ast.createFunctionParameter({ name: e.key, optional: false })),
104
- }),
105
- ],
106
- })
107
- : null
108
-
109
- const destructured = paramsNode ? (keysPrinter.print(paramsNode) ?? '') : ''
110
- const inputSchema = entries.length ? `{ ${entries.map((e) => `${e.key}: ${e.value}`).join(', ')} }` : null
111
- const outputSchema = zod.responseName
112
-
113
- const config = [
114
- tool.title ? `title: ${JSON.stringify(tool.title)}` : null,
115
- `description: ${JSON.stringify(tool.description)}`,
116
- outputSchema ? `outputSchema: { data: ${outputSchema} }` : null,
117
- ]
118
- .filter(Boolean)
119
- .join(',\n ')
120
-
121
- if (inputSchema) {
122
- return `
61
+ const registrations = operations
62
+ .map(({ tool, mcp, zod, node }) => {
63
+ const { path: pathParams } = getOperationParameters(node, { paramsCasing })
64
+
65
+ const pathEntries: Array<{ key: string; value: string }> = []
66
+ const otherEntries: Array<{ key: string; value: string }> = []
67
+
68
+ for (const p of pathParams) {
69
+ const zodParam = zod.pathParams.find((zp) => zp.name === p.name)
70
+ pathEntries.push({ key: p.name, value: zodParam ? zodParam.schemaName : zodExprFromSchemaNode(p.schema) })
71
+ }
72
+
73
+ if (zod.requestName) {
74
+ otherEntries.push({ key: 'data', value: zod.requestName })
75
+ }
76
+
77
+ if (zod.queryParams) {
78
+ otherEntries.push({ key: 'params', value: zodGroupExpr(zod.queryParams) })
79
+ }
80
+
81
+ if (zod.headerParams) {
82
+ otherEntries.push({ key: 'headers', value: zodGroupExpr(zod.headerParams) })
83
+ }
84
+
85
+ otherEntries.sort((a, b) => a.key.localeCompare(b.key))
86
+ const entries = [...pathEntries, ...otherEntries]
87
+
88
+ const paramsNode = entries.length
89
+ ? ast.createFunctionParameters({
90
+ params: [
91
+ ast.createParameterGroup({
92
+ properties: entries.map((e) => ast.createFunctionParameter({ name: e.key, optional: false })),
93
+ }),
94
+ ],
95
+ })
96
+ : null
97
+
98
+ const destructured = paramsNode ? (keysPrinter.print(paramsNode) ?? '') : ''
99
+ const inputSchema = entries.length ? `{ ${entries.map((e) => `${e.key}: ${e.value}`).join(', ')} }` : null
100
+ const outputSchema = zod.responseName
101
+
102
+ const config = [
103
+ tool.title ? `title: ${JSON.stringify(tool.title)}` : null,
104
+ `description: ${JSON.stringify(tool.description)}`,
105
+ outputSchema ? `outputSchema: { data: ${outputSchema} }` : null,
106
+ ]
107
+ .filter(Boolean)
108
+ .join(',\n ')
109
+
110
+ if (inputSchema) {
111
+ return `
123
112
  server.registerTool(${JSON.stringify(tool.name)}, {
124
113
  ${config},
125
114
  inputSchema: ${inputSchema},
@@ -127,17 +116,33 @@ server.registerTool(${JSON.stringify(tool.name)}, {
127
116
  return ${mcp.name}(${destructured}, request)
128
117
  })
129
118
  `
130
- }
119
+ }
131
120
 
132
- return `
121
+ return `
133
122
  server.registerTool(${JSON.stringify(tool.name)}, {
134
123
  ${config},
135
124
  }, async (request) => {
136
125
  return ${mcp.name}(request)
137
126
  })
138
127
  `
139
- })
140
- .filter(Boolean)}
128
+ })
129
+ .filter(Boolean)
130
+ .join('\n')
131
+
132
+ return (
133
+ <File.Source name={name} isExportable isIndexable>
134
+ <Function name="getServer" export>
135
+ {`const server = new McpServer({
136
+ name: '${serverName}',
137
+ version: '${serverVersion}',
138
+ })
139
+ ${registrations}
140
+ return server`}
141
+ </Function>
142
+
143
+ <Const name={'server'} export>
144
+ {'getServer()'}
145
+ </Const>
141
146
 
142
147
  <Function name="startServer" async export>
143
148
  {`try {