@smartbear/mcp 0.12.1 → 0.13.1
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 +30 -6
- package/dist/bugsnag/client/api/CurrentUser.js +50 -26
- package/dist/bugsnag/client/api/Error.js +156 -93
- package/dist/bugsnag/client/api/Project.js +398 -276
- package/dist/bugsnag/client/api/api.js +4087 -3837
- package/dist/bugsnag/client/api/base.js +155 -173
- package/dist/bugsnag/client/api/configuration.js +28 -25
- package/dist/bugsnag/client/filters.js +11 -20
- package/dist/bugsnag/client.js +1398 -1281
- package/dist/bugsnag/input-schemas.js +39 -57
- package/dist/collaborator/client.js +335 -371
- package/dist/common/bugsnag.js +5 -3
- package/dist/common/cache.js +50 -57
- package/dist/common/client-registry.js +106 -119
- package/dist/common/info.js +7 -3
- package/dist/common/register-clients.js +0 -16
- package/dist/common/server.js +270 -228
- package/dist/common/tools.js +19 -0
- package/dist/common/transport-http.js +252 -343
- package/dist/common/transport-stdio.js +40 -37
- package/dist/common/zod-utils.js +20 -0
- package/dist/index.js +18 -23
- package/dist/package.json.js +11 -0
- package/dist/pactflow/client/ai.js +142 -169
- package/dist/pactflow/client/base.js +41 -51
- package/dist/pactflow/client/prompt-utils.js +93 -84
- package/dist/pactflow/client/prompts.js +95 -92
- package/dist/pactflow/client/tools.js +94 -83
- package/dist/pactflow/client/utils.js +60 -64
- package/dist/pactflow/client.js +399 -320
- package/dist/qmetry/client/api/client-api.js +43 -41
- package/dist/qmetry/client/api/error-handler.js +264 -310
- package/dist/qmetry/client/auto-resolve.js +78 -99
- package/dist/qmetry/client/automation.js +139 -162
- package/dist/qmetry/client/handlers.js +49 -46
- package/dist/qmetry/client/issues.js +133 -115
- package/dist/qmetry/client/project.js +153 -174
- package/dist/qmetry/client/requirement.js +82 -70
- package/dist/qmetry/client/testcase.js +240 -208
- package/dist/qmetry/client/testsuite.js +332 -293
- package/dist/qmetry/client/tools/automation-tools.js +291 -288
- package/dist/qmetry/client/tools/index.js +16 -13
- package/dist/qmetry/client/tools/issue-tools.js +534 -543
- package/dist/qmetry/client/tools/project-tools.js +635 -656
- package/dist/qmetry/client/tools/requirement-tools.js +525 -528
- package/dist/qmetry/client/tools/testcase-tools.js +773 -786
- package/dist/qmetry/client/tools/testsuite-tools.js +1069 -1083
- package/dist/qmetry/client/utils.js +8 -14
- package/dist/qmetry/client.js +111 -109
- package/dist/qmetry/config/constants.js +48 -44
- package/dist/qmetry/config/rest-endpoints.js +51 -48
- package/dist/qmetry/types/automation.js +7 -7
- package/dist/qmetry/types/common.js +763 -1049
- package/dist/qmetry/types/issues.js +26 -19
- package/dist/qmetry/types/project.js +32 -25
- package/dist/qmetry/types/requirements.js +26 -21
- package/dist/qmetry/types/testcase.js +55 -44
- package/dist/qmetry/types/testsuite.js +66 -52
- package/dist/reflect/client.js +284 -226
- package/dist/swagger/client/api.js +645 -662
- package/dist/swagger/client/configuration.js +31 -33
- package/dist/swagger/client/portal-types.js +204 -244
- package/dist/swagger/client/registry-types.js +62 -96
- package/dist/swagger/client/tools.js +148 -158
- package/dist/swagger/client/user-management-types.js +11 -22
- package/dist/swagger/client.js +143 -135
- package/dist/swagger/config-utils.js +10 -16
- package/dist/zephyr/client.js +43 -42
- package/dist/zephyr/common/api-client.js +35 -30
- package/dist/zephyr/common/auth-service.js +16 -13
- package/dist/zephyr/common/rest-api-schemas.js +3173 -5146
- package/dist/zephyr/tool/environment/get-environments.js +66 -66
- package/dist/zephyr/tool/priority/get-priorities.js +41 -41
- package/dist/zephyr/tool/project/get-project.js +37 -37
- package/dist/zephyr/tool/project/get-projects.js +46 -46
- package/dist/zephyr/tool/status/get-statuses.js +47 -47
- package/dist/zephyr/tool/test-case/get-test-case.js +37 -37
- package/dist/zephyr/tool/test-case/get-test-cases.js +62 -62
- package/dist/zephyr/tool/test-cycle/get-test-cycle.js +37 -37
- package/dist/zephyr/tool/test-cycle/get-test-cycles.js +70 -70
- package/dist/zephyr/tool/test-execution/get-test-execution.js +37 -37
- package/dist/zephyr/tool/test-execution/get-test-executions.js +43 -43
- package/package.json +5 -5
- package/dist/bugsnag/client/api/index.js +0 -6
- package/dist/common/types.js +0 -6
- package/dist/qmetry/client/tools/types.js +0 -1
- package/dist/swagger/client/index.js +0 -6
- package/dist/tests/unit/bugsnag/utils/factories.js +0 -86
- package/dist/zephyr/tool/zephyr-tool.js +0 -1
package/dist/common/server.js
CHANGED
|
@@ -1,239 +1,281 @@
|
|
|
1
|
-
import { McpServer, ResourceTemplate
|
|
2
|
-
import {
|
|
3
|
-
import Bugsnag from "
|
|
1
|
+
import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { ZodObject, ZodIntersection, ZodOptional, ZodDefault, ZodRecord, ZodString, ZodNumber, ZodBoolean, ZodArray, ZodEnum, ZodLiteral, ZodUnion, ZodAny } from "zod";
|
|
3
|
+
import Bugsnag from "./bugsnag.js";
|
|
4
4
|
import { CacheService } from "./cache.js";
|
|
5
|
-
import {
|
|
6
|
-
import { ToolError } from "./
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}, (params, options) => {
|
|
70
|
-
return this.server.elicitInput(params, options);
|
|
71
|
-
});
|
|
72
|
-
if (client.registerResources) {
|
|
73
|
-
client.registerResources((name, path, cb) => {
|
|
74
|
-
const url = `${client.toolPrefix}://${name}/${path}`;
|
|
75
|
-
return super.registerResource(name, new ResourceTemplate(url, {
|
|
76
|
-
list: undefined,
|
|
77
|
-
}), {}, async (url, variables, extra) => {
|
|
78
|
-
try {
|
|
79
|
-
return await cb(url, variables, extra);
|
|
80
|
-
}
|
|
81
|
-
catch (e) {
|
|
82
|
-
Bugsnag.notify(e, (event) => {
|
|
83
|
-
event.addMetadata("app", { resource: name, url: url });
|
|
84
|
-
event.unhandled = true;
|
|
85
|
-
});
|
|
86
|
-
throw e;
|
|
5
|
+
import { MCP_SERVER_VERSION, MCP_SERVER_NAME } from "./info.js";
|
|
6
|
+
import { ToolError } from "./tools.js";
|
|
7
|
+
import { unwrapZodType } from "./zod-utils.js";
|
|
8
|
+
class SmartBearMcpServer extends McpServer {
|
|
9
|
+
cache;
|
|
10
|
+
constructor() {
|
|
11
|
+
super(
|
|
12
|
+
{
|
|
13
|
+
name: MCP_SERVER_NAME,
|
|
14
|
+
version: MCP_SERVER_VERSION
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
capabilities: {
|
|
18
|
+
resources: { listChanged: true },
|
|
19
|
+
// Server supports dynamic resource lists
|
|
20
|
+
tools: { listChanged: true },
|
|
21
|
+
// Server supports dynamic tool lists
|
|
22
|
+
logging: {},
|
|
23
|
+
// Server supports logging messages
|
|
24
|
+
prompts: {}
|
|
25
|
+
// Server supports sending prompts to Host
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
this.cache = new CacheService();
|
|
30
|
+
}
|
|
31
|
+
getCache() {
|
|
32
|
+
return this.cache;
|
|
33
|
+
}
|
|
34
|
+
async addClient(client) {
|
|
35
|
+
await client.registerTools(
|
|
36
|
+
(params, cb) => {
|
|
37
|
+
const toolName = `${client.toolPrefix}_${params.title.replace(/\s+/g, "_").toLowerCase()}`;
|
|
38
|
+
const toolTitle = `${client.name}: ${params.title}`;
|
|
39
|
+
return super.registerTool(
|
|
40
|
+
toolName,
|
|
41
|
+
{
|
|
42
|
+
title: toolTitle,
|
|
43
|
+
description: this.getDescription(params),
|
|
44
|
+
inputSchema: this.getInputSchema(params),
|
|
45
|
+
outputSchema: this.getOutputSchema(params),
|
|
46
|
+
annotations: this.getAnnotations(toolTitle, params)
|
|
47
|
+
},
|
|
48
|
+
async (args, extra) => {
|
|
49
|
+
try {
|
|
50
|
+
if (!client.isConfigured()) {
|
|
51
|
+
throw new ToolError(
|
|
52
|
+
`The tool is not configured - configuration options for ${client.name} are missing or invalid.`
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
const result = await cb(args, extra);
|
|
56
|
+
if (result) {
|
|
57
|
+
this.validateCallbackResult(result, params);
|
|
58
|
+
this.addStructuredContentAsText(result);
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
} catch (e) {
|
|
62
|
+
if (e instanceof ToolError) {
|
|
63
|
+
return {
|
|
64
|
+
isError: true,
|
|
65
|
+
content: [
|
|
66
|
+
{
|
|
67
|
+
type: "text",
|
|
68
|
+
text: `Error executing ${toolTitle}: ${e.message}`
|
|
87
69
|
}
|
|
70
|
+
]
|
|
71
|
+
};
|
|
72
|
+
} else {
|
|
73
|
+
Bugsnag.notify(e, (event) => {
|
|
74
|
+
event.addMetadata("app", { tool: toolName });
|
|
75
|
+
event.unhandled = true;
|
|
88
76
|
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
77
|
+
}
|
|
78
|
+
throw e;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
},
|
|
83
|
+
(params, options) => {
|
|
84
|
+
return this.server.elicitInput(params, options);
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
if (client.registerResources) {
|
|
88
|
+
client.registerResources((name, path, cb) => {
|
|
89
|
+
const url = `${client.toolPrefix}://${name}/${path}`;
|
|
90
|
+
return super.registerResource(
|
|
91
|
+
name,
|
|
92
|
+
new ResourceTemplate(url, {
|
|
93
|
+
list: void 0
|
|
94
|
+
}),
|
|
95
|
+
{},
|
|
96
|
+
async (url2, variables, extra) => {
|
|
97
|
+
try {
|
|
98
|
+
return await cb(url2, variables, extra);
|
|
99
|
+
} catch (e) {
|
|
100
|
+
Bugsnag.notify(e, (event) => {
|
|
101
|
+
event.addMetadata("app", { resource: name, url: url2 });
|
|
102
|
+
event.unhandled = true;
|
|
103
|
+
});
|
|
104
|
+
throw e;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
});
|
|
96
109
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (params.outputSchema && !result.structuredContent) {
|
|
102
|
-
throw new Error(`The result of the tool '${params.title}' must include 'structuredContent'`);
|
|
103
|
-
}
|
|
110
|
+
if (client.registerPrompts) {
|
|
111
|
+
client.registerPrompts((name, config, cb) => {
|
|
112
|
+
return super.registerPrompt(name, config, cb);
|
|
113
|
+
});
|
|
104
114
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
type: "text",
|
|
110
|
-
text: JSON.stringify(result.structuredContent),
|
|
111
|
-
},
|
|
112
|
-
];
|
|
113
|
-
}
|
|
115
|
+
}
|
|
116
|
+
validateCallbackResult(result, params) {
|
|
117
|
+
if (result.isError) {
|
|
118
|
+
return;
|
|
114
119
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
destructiveHint: params.destructive ?? false,
|
|
120
|
-
idempotentHint: params.idempotent ?? true,
|
|
121
|
-
openWorldHint: params.openWorld ?? false,
|
|
122
|
-
};
|
|
123
|
-
return annotations;
|
|
124
|
-
}
|
|
125
|
-
getInputSchema(params) {
|
|
126
|
-
const args = {};
|
|
127
|
-
for (const param of params.parameters ?? []) {
|
|
128
|
-
args[param.name] = param.type;
|
|
129
|
-
if (param.description) {
|
|
130
|
-
args[param.name] = args[param.name].describe(param.description);
|
|
131
|
-
}
|
|
132
|
-
if (!param.required) {
|
|
133
|
-
args[param.name] = args[param.name].optional();
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return { ...args, ...this.schemaToRawShape(params.inputSchema) };
|
|
120
|
+
if (params.outputSchema && !result.structuredContent) {
|
|
121
|
+
throw new Error(
|
|
122
|
+
`The result of the tool '${params.title}' must include 'structuredContent'`
|
|
123
|
+
);
|
|
137
124
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const rightShape = this.schemaToRawShape(schema._def.right);
|
|
146
|
-
return { ...leftShape, ...rightShape };
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return undefined;
|
|
150
|
-
}
|
|
151
|
-
getOutputSchema(params) {
|
|
152
|
-
return this.schemaToRawShape(params.outputSchema);
|
|
153
|
-
}
|
|
154
|
-
getDescription(params) {
|
|
155
|
-
const { summary, useCases, examples, parameters, inputSchema, hints, outputDescription, } = params;
|
|
156
|
-
let description = summary;
|
|
157
|
-
// Parameters if available otherwise use inputSchema
|
|
158
|
-
if ((parameters ?? []).length > 0) {
|
|
159
|
-
description += `\n\n**Parameters:**\n${parameters
|
|
160
|
-
?.map((p) => `- ${p.name} (${this.getReadableTypeName(p.type)})${p.required ? " *required*" : ""}` +
|
|
161
|
-
`${p.description ? `: ${p.description}` : ""}` +
|
|
162
|
-
`${p.examples ? ` (e.g. ${p.examples.join(", ")})` : ""}` +
|
|
163
|
-
`${p.constraints ? `\n - ${p.constraints.join("\n - ")}` : ""}`)
|
|
164
|
-
.join("\n")}`;
|
|
125
|
+
}
|
|
126
|
+
addStructuredContentAsText(result) {
|
|
127
|
+
if (result.structuredContent && !result.content?.length) {
|
|
128
|
+
result.content = [
|
|
129
|
+
{
|
|
130
|
+
type: "text",
|
|
131
|
+
text: JSON.stringify(result.structuredContent)
|
|
165
132
|
}
|
|
166
|
-
|
|
167
|
-
description += "\n\n**Parameters:**\n";
|
|
168
|
-
description += Object.keys(inputSchema.shape)
|
|
169
|
-
.map((key) => this.formatParameterDescription(key, inputSchema.shape[key]))
|
|
170
|
-
.join("\n");
|
|
171
|
-
}
|
|
172
|
-
if (outputDescription) {
|
|
173
|
-
description += `\n\n**Output Description:** ${outputDescription}`;
|
|
174
|
-
}
|
|
175
|
-
// Use Cases
|
|
176
|
-
if (useCases && useCases.length > 0) {
|
|
177
|
-
description += `\n\n**Use Cases:** ${useCases.map((uc, i) => `${i + 1}. ${uc}`).join(" ")}`;
|
|
178
|
-
}
|
|
179
|
-
// Examples
|
|
180
|
-
if (examples && examples.length > 0) {
|
|
181
|
-
description +=
|
|
182
|
-
`\n\n**Examples:**\n` +
|
|
183
|
-
examples
|
|
184
|
-
.map((ex, idx) => `${idx + 1}. ${ex.description}\n\`\`\`json\n${JSON.stringify(ex.parameters, null, 2)}\n\`\`\`${ex.expectedOutput ? `\nExpected Output: ${ex.expectedOutput}` : ""}`)
|
|
185
|
-
.join("\n\n");
|
|
186
|
-
}
|
|
187
|
-
// Hints
|
|
188
|
-
if (hints && hints.length > 0) {
|
|
189
|
-
description += `\n\n**Hints:** ${hints.map((hint, i) => `${i + 1}. ${hint}`).join(" ")}`;
|
|
190
|
-
}
|
|
191
|
-
return description.trim();
|
|
133
|
+
];
|
|
192
134
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
135
|
+
}
|
|
136
|
+
getAnnotations(toolTitle, params) {
|
|
137
|
+
const annotations = {
|
|
138
|
+
title: toolTitle,
|
|
139
|
+
readOnlyHint: params.readOnly ?? true,
|
|
140
|
+
destructiveHint: params.destructive ?? false,
|
|
141
|
+
idempotentHint: params.idempotent ?? true,
|
|
142
|
+
openWorldHint: params.openWorld ?? false
|
|
143
|
+
};
|
|
144
|
+
return annotations;
|
|
145
|
+
}
|
|
146
|
+
getInputSchema(params) {
|
|
147
|
+
const args = {};
|
|
148
|
+
for (const param of params.parameters ?? []) {
|
|
149
|
+
args[param.name] = param.type;
|
|
150
|
+
if (param.description) {
|
|
151
|
+
args[param.name] = args[param.name].describe(param.description);
|
|
152
|
+
}
|
|
153
|
+
if (!param.required) {
|
|
154
|
+
args[param.name] = args[param.name].optional();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return { ...args, ...this.schemaToRawShape(params.inputSchema) };
|
|
158
|
+
}
|
|
159
|
+
schemaToRawShape(schema) {
|
|
160
|
+
if (schema) {
|
|
161
|
+
if (schema instanceof ZodObject) {
|
|
162
|
+
return schema.shape;
|
|
163
|
+
}
|
|
164
|
+
if (schema instanceof ZodIntersection) {
|
|
165
|
+
const leftShape = this.schemaToRawShape(
|
|
166
|
+
schema.def.left
|
|
167
|
+
);
|
|
168
|
+
const rightShape = this.schemaToRawShape(
|
|
169
|
+
schema.def.right
|
|
170
|
+
);
|
|
171
|
+
return { ...leftShape, ...rightShape };
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return void 0;
|
|
175
|
+
}
|
|
176
|
+
getOutputSchema(params) {
|
|
177
|
+
return this.schemaToRawShape(params.outputSchema);
|
|
178
|
+
}
|
|
179
|
+
getDescription(params) {
|
|
180
|
+
const {
|
|
181
|
+
summary,
|
|
182
|
+
useCases,
|
|
183
|
+
examples,
|
|
184
|
+
parameters,
|
|
185
|
+
inputSchema,
|
|
186
|
+
hints,
|
|
187
|
+
outputDescription
|
|
188
|
+
} = params;
|
|
189
|
+
let description = summary;
|
|
190
|
+
if ((parameters ?? []).length > 0) {
|
|
191
|
+
description += `
|
|
192
|
+
|
|
193
|
+
**Parameters:**
|
|
194
|
+
${parameters?.map(
|
|
195
|
+
(p) => `- ${p.name} (${this.getReadableTypeName(p.type)})${p.required ? " *required*" : ""}${p.description ? `: ${p.description}` : ""}${p.examples ? ` (e.g. ${p.examples.join(", ")})` : ""}${p.constraints ? `
|
|
196
|
+
- ${p.constraints.join("\n - ")}` : ""}`
|
|
197
|
+
).join("\n")}`;
|
|
198
|
+
}
|
|
199
|
+
if (inputSchema && inputSchema instanceof ZodObject) {
|
|
200
|
+
description += "\n\n**Parameters:**\n";
|
|
201
|
+
description += Object.keys(inputSchema.shape).map(
|
|
202
|
+
(key) => this.formatParameterDescription(key, inputSchema.shape[key])
|
|
203
|
+
).join("\n");
|
|
204
|
+
}
|
|
205
|
+
if (outputDescription) {
|
|
206
|
+
description += `
|
|
207
|
+
|
|
208
|
+
**Output Description:** ${outputDescription}`;
|
|
209
|
+
}
|
|
210
|
+
if (useCases && useCases.length > 0) {
|
|
211
|
+
description += `
|
|
212
|
+
|
|
213
|
+
**Use Cases:** ${useCases.map((uc, i) => `${i + 1}. ${uc}`).join(" ")}`;
|
|
214
|
+
}
|
|
215
|
+
if (examples && examples.length > 0) {
|
|
216
|
+
description += `
|
|
217
|
+
|
|
218
|
+
**Examples:**
|
|
219
|
+
` + examples.map(
|
|
220
|
+
(ex, idx) => `${idx + 1}. ${ex.description}
|
|
221
|
+
\`\`\`json
|
|
222
|
+
${JSON.stringify(ex.parameters, null, 2)}
|
|
223
|
+
\`\`\`${ex.expectedOutput ? `
|
|
224
|
+
Expected Output: ${ex.expectedOutput}` : ""}`
|
|
225
|
+
).join("\n\n");
|
|
226
|
+
}
|
|
227
|
+
if (hints && hints.length > 0) {
|
|
228
|
+
description += `
|
|
229
|
+
|
|
230
|
+
**Hints:** ${hints.map((hint, i) => `${i + 1}. ${hint}`).join(" ")}`;
|
|
231
|
+
}
|
|
232
|
+
return description.trim();
|
|
233
|
+
}
|
|
234
|
+
formatParameterDescription(key, field, description = null, isOptional = false, defaultValue = null) {
|
|
235
|
+
description = description ?? (field.description || null);
|
|
236
|
+
if (field instanceof ZodOptional) {
|
|
237
|
+
field = field.unwrap();
|
|
238
|
+
return this.formatParameterDescription(
|
|
239
|
+
key,
|
|
240
|
+
field,
|
|
241
|
+
description,
|
|
242
|
+
true,
|
|
243
|
+
defaultValue
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
if (field instanceof ZodDefault) {
|
|
247
|
+
defaultValue = JSON.stringify(
|
|
248
|
+
field.def.defaultValue
|
|
249
|
+
);
|
|
250
|
+
field = field.unwrap();
|
|
251
|
+
return this.formatParameterDescription(
|
|
252
|
+
key,
|
|
253
|
+
field,
|
|
254
|
+
description,
|
|
255
|
+
true,
|
|
256
|
+
defaultValue
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
return `- ${key} (${this.getReadableTypeName(field)})${isOptional ? "" : " *required*"}${description ? `: ${description}` : ""}${defaultValue ? ` (default: ${defaultValue})` : ""}`;
|
|
260
|
+
}
|
|
261
|
+
getReadableTypeName(zodType) {
|
|
262
|
+
zodType = unwrapZodType(zodType);
|
|
263
|
+
if (zodType instanceof ZodRecord) {
|
|
264
|
+
const record = zodType;
|
|
265
|
+
return `record<${this.getReadableTypeName(record.def.keyType)}, ${this.getReadableTypeName(record.def.valueType)}>`;
|
|
238
266
|
}
|
|
267
|
+
if (zodType instanceof ZodString) return "string";
|
|
268
|
+
if (zodType instanceof ZodNumber) return "number";
|
|
269
|
+
if (zodType instanceof ZodBoolean) return "boolean";
|
|
270
|
+
if (zodType instanceof ZodArray) return "array";
|
|
271
|
+
if (zodType instanceof ZodObject) return "object";
|
|
272
|
+
if (zodType instanceof ZodEnum) return "enum";
|
|
273
|
+
if (zodType instanceof ZodLiteral) return "literal";
|
|
274
|
+
if (zodType instanceof ZodUnion) return "union";
|
|
275
|
+
if (zodType instanceof ZodAny) return "any";
|
|
276
|
+
return "any";
|
|
277
|
+
}
|
|
239
278
|
}
|
|
279
|
+
export {
|
|
280
|
+
SmartBearMcpServer
|
|
281
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class ToolError extends Error {
|
|
2
|
+
// can be used to set misc properties like response status code, etc.
|
|
3
|
+
metadata;
|
|
4
|
+
constructor(cause, options, metadata) {
|
|
5
|
+
super(cause, options);
|
|
6
|
+
this.metadata = metadata;
|
|
7
|
+
Object.setPrototypeOf(this, ToolError.prototype);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
class Tool {
|
|
11
|
+
client;
|
|
12
|
+
constructor(client) {
|
|
13
|
+
this.client = client;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
Tool,
|
|
18
|
+
ToolError
|
|
19
|
+
};
|