@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.
- package/README.md +11 -15
- package/dist/index.cjs +60 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +60 -55
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/components/Server.tsx +71 -66
|
@@ -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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|