@outfitter/mcp 0.4.2 → 0.5.0
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 +130 -28
- package/dist/actions.d.ts +7 -2
- package/dist/actions.js +52 -5
- package/dist/core-tools.d.ts +7 -2
- package/dist/core-tools.js +140 -6
- package/dist/index.d.ts +14 -953
- package/dist/index.js +8 -959
- package/dist/internal/content-types.d.ts +2 -0
- package/dist/internal/content-types.js +1 -0
- package/dist/internal/log-config.d.ts +24 -0
- package/dist/internal/log-config.js +13 -0
- package/dist/internal/prompt-types.d.ts +3 -0
- package/dist/internal/prompt-types.js +1 -0
- package/dist/internal/resource-types.d.ts +4 -0
- package/dist/internal/resource-types.js +1 -0
- package/dist/internal/server-types.d.ts +7 -0
- package/dist/internal/server-types.js +20 -0
- package/dist/internal/tool-types.d.ts +2 -0
- package/dist/{shared/@outfitter/mcp-9m5hs2z0.js → internal/tool-types.js} +4 -16
- package/dist/internal/uri-template.d.ts +8 -0
- package/dist/internal/uri-template.js +7 -0
- package/dist/progress.d.ts +2 -0
- package/dist/progress.js +7 -0
- package/dist/schema.js +1 -1
- package/dist/server.d.ts +7 -2
- package/dist/server.js +6 -3
- package/dist/shared/@outfitter/{mcp-5b5726ga.d.ts → mcp-3hxaatj9.d.ts} +37 -6
- package/dist/shared/@outfitter/{mcp-zb3p61y9.d.ts → mcp-4s22693j.d.ts} +1 -1
- package/dist/shared/@outfitter/mcp-7btcghjj.d.ts +304 -0
- package/dist/shared/@outfitter/mcp-9ry52yg3.d.ts +187 -0
- package/dist/shared/@outfitter/mcp-dgwj3jna.d.ts +103 -0
- package/dist/shared/@outfitter/{mcp-5jcgb033.d.ts → mcp-f67dnr72.d.ts} +1 -1
- package/dist/shared/@outfitter/mcp-hw5wz4gb.js +1 -0
- package/dist/shared/@outfitter/mcp-knc1gq0g.d.ts +130 -0
- package/dist/shared/@outfitter/mcp-n9vzcp37.js +55 -0
- package/dist/shared/@outfitter/mcp-q5hr7227.d.ts +24 -0
- package/dist/shared/@outfitter/mcp-q70dtfj6.js +53 -0
- package/dist/shared/@outfitter/mcp-r27vbpc1.d.ts +45 -0
- package/dist/shared/@outfitter/mcp-s2vnhzav.js +2 -0
- package/dist/shared/@outfitter/{mcp-s3gfhcdk.d.ts → mcp-yf0w5cgh.d.ts} +1 -1
- package/dist/shared/@outfitter/{mcp-hh12tqfg.js → mcp-yf1n85e9.js} +79 -119
- package/dist/shared/@outfitter/mcp-zt2s3r38.js +33 -0
- package/dist/transport.d.ts +7 -2
- package/dist/transport.js +161 -5
- package/dist/types.d.ts +7 -2
- package/dist/types.js +1 -1
- package/package.json +33 -27
- package/dist/shared/@outfitter/mcp-fks4zt1z.d.ts +0 -699
- package/dist/shared/@outfitter/mcp-mzky3ck8.js +0 -165
- package/dist/shared/@outfitter/mcp-zmc7ht6z.js +0 -28
- package/dist/shared/@outfitter/mcp-zv3ej45k.js +0 -143
- package/dist/shared/@outfitter/mcp-zy7b487d.js +0 -5
package/dist/index.js
CHANGED
|
@@ -1,959 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
createPrettyFormatter
|
|
10
|
-
} from "@outfitter/logging";
|
|
11
|
-
|
|
12
|
-
// src/logging.ts
|
|
13
|
-
var MCP_LEVEL_ORDER = [
|
|
14
|
-
"debug",
|
|
15
|
-
"info",
|
|
16
|
-
"notice",
|
|
17
|
-
"warning",
|
|
18
|
-
"error",
|
|
19
|
-
"critical",
|
|
20
|
-
"alert",
|
|
21
|
-
"emergency"
|
|
22
|
-
];
|
|
23
|
-
function mapLogLevelToMcp(level) {
|
|
24
|
-
switch (level) {
|
|
25
|
-
case "trace":
|
|
26
|
-
case "debug":
|
|
27
|
-
return "debug";
|
|
28
|
-
case "info":
|
|
29
|
-
return "info";
|
|
30
|
-
case "warn":
|
|
31
|
-
return "warning";
|
|
32
|
-
case "error":
|
|
33
|
-
return "error";
|
|
34
|
-
case "fatal":
|
|
35
|
-
return "emergency";
|
|
36
|
-
default: {
|
|
37
|
-
const _exhaustiveCheck = level;
|
|
38
|
-
return _exhaustiveCheck;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function shouldEmitLog(messageLevel, threshold) {
|
|
43
|
-
return MCP_LEVEL_ORDER.indexOf(messageLevel) >= MCP_LEVEL_ORDER.indexOf(threshold);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// src/schema.ts
|
|
47
|
-
import { zodToJsonSchema } from "@outfitter/contracts/schema";
|
|
48
|
-
|
|
49
|
-
// src/types.ts
|
|
50
|
-
import {
|
|
51
|
-
TaggedError as TaggedErrorImpl
|
|
52
|
-
} from "@outfitter/contracts";
|
|
53
|
-
import { TaggedError } from "@outfitter/contracts";
|
|
54
|
-
var TaggedError2 = TaggedErrorImpl;
|
|
55
|
-
var TOOL_ANNOTATIONS = {
|
|
56
|
-
readOnly: {
|
|
57
|
-
readOnlyHint: true,
|
|
58
|
-
destructiveHint: false,
|
|
59
|
-
idempotentHint: true,
|
|
60
|
-
openWorldHint: false
|
|
61
|
-
},
|
|
62
|
-
write: {
|
|
63
|
-
readOnlyHint: false,
|
|
64
|
-
destructiveHint: false,
|
|
65
|
-
idempotentHint: false,
|
|
66
|
-
openWorldHint: false
|
|
67
|
-
},
|
|
68
|
-
writeIdempotent: {
|
|
69
|
-
readOnlyHint: false,
|
|
70
|
-
destructiveHint: false,
|
|
71
|
-
idempotentHint: true,
|
|
72
|
-
openWorldHint: false
|
|
73
|
-
},
|
|
74
|
-
destructive: {
|
|
75
|
-
readOnlyHint: false,
|
|
76
|
-
destructiveHint: true,
|
|
77
|
-
idempotentHint: true,
|
|
78
|
-
openWorldHint: false
|
|
79
|
-
},
|
|
80
|
-
openWorld: {
|
|
81
|
-
readOnlyHint: false,
|
|
82
|
-
destructiveHint: false,
|
|
83
|
-
idempotentHint: false,
|
|
84
|
-
openWorldHint: true
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
var McpErrorBase = TaggedError2("McpError")();
|
|
88
|
-
|
|
89
|
-
class McpError extends McpErrorBase {
|
|
90
|
-
category = "internal";
|
|
91
|
-
}
|
|
92
|
-
function adaptHandler(handler) {
|
|
93
|
-
return handler;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// src/server.ts
|
|
97
|
-
var VALID_MCP_LOG_LEVELS = new Set([
|
|
98
|
-
"debug",
|
|
99
|
-
"info",
|
|
100
|
-
"notice",
|
|
101
|
-
"warning",
|
|
102
|
-
"error",
|
|
103
|
-
"critical",
|
|
104
|
-
"alert",
|
|
105
|
-
"emergency"
|
|
106
|
-
]);
|
|
107
|
-
var DEFAULTS_TO_MCP = {
|
|
108
|
-
debug: "debug",
|
|
109
|
-
info: "info",
|
|
110
|
-
warn: "warning",
|
|
111
|
-
error: "error"
|
|
112
|
-
};
|
|
113
|
-
function createDefaultMcpSink() {
|
|
114
|
-
const formatter = createPrettyFormatter({ colors: false });
|
|
115
|
-
return {
|
|
116
|
-
formatter,
|
|
117
|
-
write(record, formatted) {
|
|
118
|
-
const serialized = formatted ?? formatter.format(record);
|
|
119
|
-
const line = serialized.endsWith(`
|
|
120
|
-
`) ? serialized : `${serialized}
|
|
121
|
-
`;
|
|
122
|
-
if (typeof process !== "undefined" && process.stderr?.write) {
|
|
123
|
-
process.stderr.write(line);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
function resolveDefaultLogLevel(options) {
|
|
129
|
-
const envLogLevel = process.env["OUTFITTER_LOG_LEVEL"];
|
|
130
|
-
if (envLogLevel !== undefined && VALID_MCP_LOG_LEVELS.has(envLogLevel)) {
|
|
131
|
-
return envLogLevel;
|
|
132
|
-
}
|
|
133
|
-
if (options.defaultLogLevel !== undefined && (options.defaultLogLevel === null || VALID_MCP_LOG_LEVELS.has(options.defaultLogLevel))) {
|
|
134
|
-
return options.defaultLogLevel;
|
|
135
|
-
}
|
|
136
|
-
const env = getEnvironment();
|
|
137
|
-
const defaults = getEnvironmentDefaults(env);
|
|
138
|
-
if (defaults.logLevel !== null) {
|
|
139
|
-
const mapped = DEFAULTS_TO_MCP[defaults.logLevel];
|
|
140
|
-
if (mapped !== undefined) {
|
|
141
|
-
return mapped;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
function createMcpServer(options) {
|
|
147
|
-
const { name, version, logger: providedLogger } = options;
|
|
148
|
-
let loggerFactory = null;
|
|
149
|
-
const logger = providedLogger ?? (() => {
|
|
150
|
-
loggerFactory = createOutfitterLoggerFactory({
|
|
151
|
-
defaults: { sinks: [createDefaultMcpSink()] }
|
|
152
|
-
});
|
|
153
|
-
return loggerFactory.createLogger({
|
|
154
|
-
name: "mcp",
|
|
155
|
-
context: { serverName: name, serverVersion: version, surface: "mcp" }
|
|
156
|
-
});
|
|
157
|
-
})();
|
|
158
|
-
const tools = new Map;
|
|
159
|
-
const resources = new Map;
|
|
160
|
-
const resourceTemplates = new Map;
|
|
161
|
-
const prompts = new Map;
|
|
162
|
-
let sdkServer = null;
|
|
163
|
-
const subscriptions = new Set;
|
|
164
|
-
let clientLogLevel = resolveDefaultLogLevel(options);
|
|
165
|
-
function createHandlerContext(toolName, requestId, signal, progressToken) {
|
|
166
|
-
const ctx = {
|
|
167
|
-
requestId,
|
|
168
|
-
logger: logger.child({ tool: toolName, requestId }),
|
|
169
|
-
cwd: process.cwd(),
|
|
170
|
-
env: process.env
|
|
171
|
-
};
|
|
172
|
-
if (signal !== undefined) {
|
|
173
|
-
ctx.signal = signal;
|
|
174
|
-
}
|
|
175
|
-
if (progressToken !== undefined && sdkServer) {
|
|
176
|
-
ctx.progress = {
|
|
177
|
-
report(progress, total, message) {
|
|
178
|
-
sdkServer?.notification?.({
|
|
179
|
-
method: "notifications/progress",
|
|
180
|
-
params: {
|
|
181
|
-
progressToken,
|
|
182
|
-
progress,
|
|
183
|
-
...total !== undefined ? { total } : {},
|
|
184
|
-
...message ? { message } : {}
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
return ctx;
|
|
191
|
-
}
|
|
192
|
-
function translateError(error) {
|
|
193
|
-
const codeMap = {
|
|
194
|
-
validation: -32602,
|
|
195
|
-
not_found: -32601,
|
|
196
|
-
permission: -32600,
|
|
197
|
-
internal: -32603,
|
|
198
|
-
timeout: -32603,
|
|
199
|
-
network: -32603,
|
|
200
|
-
rate_limit: -32603,
|
|
201
|
-
auth: -32600,
|
|
202
|
-
conflict: -32603,
|
|
203
|
-
cancelled: -32603
|
|
204
|
-
};
|
|
205
|
-
const code = codeMap[error.category] ?? -32603;
|
|
206
|
-
return new McpError({
|
|
207
|
-
message: error.message,
|
|
208
|
-
code,
|
|
209
|
-
context: {
|
|
210
|
-
originalTag: error._tag,
|
|
211
|
-
category: error.category
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
const server = {
|
|
216
|
-
name,
|
|
217
|
-
version,
|
|
218
|
-
registerTool(tool) {
|
|
219
|
-
logger.debug("Registering tool", { name: tool.name });
|
|
220
|
-
const description = tool.description?.trim() ?? "";
|
|
221
|
-
if (description.length < 8) {
|
|
222
|
-
logger.warn("Tool description may be too short for search discovery", {
|
|
223
|
-
name: tool.name,
|
|
224
|
-
description
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
const jsonSchema = zodToJsonSchema(tool.inputSchema);
|
|
228
|
-
const handler = (input, ctx) => tool.handler(input, ctx);
|
|
229
|
-
const deferLoading = tool.deferLoading ?? true;
|
|
230
|
-
const stored = {
|
|
231
|
-
name: tool.name,
|
|
232
|
-
description,
|
|
233
|
-
inputSchema: jsonSchema,
|
|
234
|
-
deferLoading,
|
|
235
|
-
handler,
|
|
236
|
-
zodSchema: tool.inputSchema
|
|
237
|
-
};
|
|
238
|
-
if (tool.annotations !== undefined) {
|
|
239
|
-
stored.annotations = tool.annotations;
|
|
240
|
-
}
|
|
241
|
-
tools.set(tool.name, stored);
|
|
242
|
-
logger.info("Tool registered", { name: tool.name });
|
|
243
|
-
if (sdkServer) {
|
|
244
|
-
sdkServer.sendToolListChanged?.();
|
|
245
|
-
}
|
|
246
|
-
},
|
|
247
|
-
registerResource(resource) {
|
|
248
|
-
logger.debug("Registering resource", {
|
|
249
|
-
uri: resource.uri,
|
|
250
|
-
name: resource.name
|
|
251
|
-
});
|
|
252
|
-
resources.set(resource.uri, resource);
|
|
253
|
-
logger.info("Resource registered", { uri: resource.uri });
|
|
254
|
-
if (sdkServer) {
|
|
255
|
-
sdkServer.sendResourceListChanged?.();
|
|
256
|
-
}
|
|
257
|
-
},
|
|
258
|
-
registerResourceTemplate(template) {
|
|
259
|
-
logger.debug("Registering resource template", {
|
|
260
|
-
uriTemplate: template.uriTemplate,
|
|
261
|
-
name: template.name
|
|
262
|
-
});
|
|
263
|
-
resourceTemplates.set(template.uriTemplate, template);
|
|
264
|
-
logger.info("Resource template registered", {
|
|
265
|
-
uriTemplate: template.uriTemplate
|
|
266
|
-
});
|
|
267
|
-
if (sdkServer) {
|
|
268
|
-
sdkServer.sendResourceListChanged?.();
|
|
269
|
-
}
|
|
270
|
-
},
|
|
271
|
-
getTools() {
|
|
272
|
-
return Array.from(tools.values()).map((tool) => ({
|
|
273
|
-
name: tool.name,
|
|
274
|
-
description: tool.description,
|
|
275
|
-
inputSchema: tool.inputSchema,
|
|
276
|
-
defer_loading: tool.deferLoading,
|
|
277
|
-
...tool.annotations ? { annotations: tool.annotations } : {}
|
|
278
|
-
}));
|
|
279
|
-
},
|
|
280
|
-
getResources() {
|
|
281
|
-
return Array.from(resources.values());
|
|
282
|
-
},
|
|
283
|
-
getResourceTemplates() {
|
|
284
|
-
return Array.from(resourceTemplates.values());
|
|
285
|
-
},
|
|
286
|
-
async complete(ref, argumentName, value) {
|
|
287
|
-
if (ref.type === "ref/prompt") {
|
|
288
|
-
const prompt = prompts.get(ref.name);
|
|
289
|
-
if (!prompt) {
|
|
290
|
-
return Result.err(new McpError({
|
|
291
|
-
message: `Prompt not found: ${ref.name}`,
|
|
292
|
-
code: -32601,
|
|
293
|
-
context: { prompt: ref.name }
|
|
294
|
-
}));
|
|
295
|
-
}
|
|
296
|
-
const arg = prompt.arguments.find((a) => a.name === argumentName);
|
|
297
|
-
if (!arg?.complete) {
|
|
298
|
-
return Result.ok({ values: [] });
|
|
299
|
-
}
|
|
300
|
-
try {
|
|
301
|
-
const result = await arg.complete(value);
|
|
302
|
-
return Result.ok(result);
|
|
303
|
-
} catch (error) {
|
|
304
|
-
return Result.err(new McpError({
|
|
305
|
-
message: error instanceof Error ? error.message : "Unknown error",
|
|
306
|
-
code: -32603,
|
|
307
|
-
context: {
|
|
308
|
-
prompt: ref.name,
|
|
309
|
-
argument: argumentName,
|
|
310
|
-
thrown: true
|
|
311
|
-
}
|
|
312
|
-
}));
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
if (ref.type === "ref/resource") {
|
|
316
|
-
const template = resourceTemplates.get(ref.uri);
|
|
317
|
-
if (!template) {
|
|
318
|
-
return Result.err(new McpError({
|
|
319
|
-
message: `Resource template not found: ${ref.uri}`,
|
|
320
|
-
code: -32601,
|
|
321
|
-
context: { uri: ref.uri }
|
|
322
|
-
}));
|
|
323
|
-
}
|
|
324
|
-
const handler = template.complete?.[argumentName];
|
|
325
|
-
if (!handler) {
|
|
326
|
-
return Result.ok({ values: [] });
|
|
327
|
-
}
|
|
328
|
-
try {
|
|
329
|
-
const result = await handler(value);
|
|
330
|
-
return Result.ok(result);
|
|
331
|
-
} catch (error) {
|
|
332
|
-
return Result.err(new McpError({
|
|
333
|
-
message: error instanceof Error ? error.message : "Unknown error",
|
|
334
|
-
code: -32603,
|
|
335
|
-
context: { uri: ref.uri, argument: argumentName, thrown: true }
|
|
336
|
-
}));
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
return Result.err(new McpError({
|
|
340
|
-
message: "Invalid completion reference type",
|
|
341
|
-
code: -32602,
|
|
342
|
-
context: { ref }
|
|
343
|
-
}));
|
|
344
|
-
},
|
|
345
|
-
registerPrompt(prompt) {
|
|
346
|
-
logger.debug("Registering prompt", { name: prompt.name });
|
|
347
|
-
prompts.set(prompt.name, prompt);
|
|
348
|
-
logger.info("Prompt registered", { name: prompt.name });
|
|
349
|
-
if (sdkServer) {
|
|
350
|
-
sdkServer.sendPromptListChanged?.();
|
|
351
|
-
}
|
|
352
|
-
},
|
|
353
|
-
getPrompts() {
|
|
354
|
-
return Array.from(prompts.values()).map((p) => ({
|
|
355
|
-
name: p.name,
|
|
356
|
-
...p.description ? { description: p.description } : {},
|
|
357
|
-
arguments: p.arguments
|
|
358
|
-
}));
|
|
359
|
-
},
|
|
360
|
-
async getPrompt(promptName, args) {
|
|
361
|
-
const prompt = prompts.get(promptName);
|
|
362
|
-
if (!prompt) {
|
|
363
|
-
return Result.err(new McpError({
|
|
364
|
-
message: `Prompt not found: ${promptName}`,
|
|
365
|
-
code: -32601,
|
|
366
|
-
context: { prompt: promptName }
|
|
367
|
-
}));
|
|
368
|
-
}
|
|
369
|
-
for (const arg of prompt.arguments) {
|
|
370
|
-
if (arg.required && (args[arg.name] === undefined || args[arg.name] === "")) {
|
|
371
|
-
return Result.err(new McpError({
|
|
372
|
-
message: `Missing required argument: ${arg.name}`,
|
|
373
|
-
code: -32602,
|
|
374
|
-
context: { prompt: promptName, argument: arg.name }
|
|
375
|
-
}));
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
try {
|
|
379
|
-
const result = await prompt.handler(args);
|
|
380
|
-
if (result.isErr()) {
|
|
381
|
-
return Result.err(translateError(result.error));
|
|
382
|
-
}
|
|
383
|
-
return Result.ok(result.value);
|
|
384
|
-
} catch (error) {
|
|
385
|
-
return Result.err(new McpError({
|
|
386
|
-
message: error instanceof Error ? error.message : "Unknown error",
|
|
387
|
-
code: -32603,
|
|
388
|
-
context: { prompt: promptName, thrown: true }
|
|
389
|
-
}));
|
|
390
|
-
}
|
|
391
|
-
},
|
|
392
|
-
async readResource(uri) {
|
|
393
|
-
const resource = resources.get(uri);
|
|
394
|
-
if (resource) {
|
|
395
|
-
if (!resource.handler) {
|
|
396
|
-
return Result.err(new McpError({
|
|
397
|
-
message: `Resource not readable: ${uri}`,
|
|
398
|
-
code: -32002,
|
|
399
|
-
context: { uri }
|
|
400
|
-
}));
|
|
401
|
-
}
|
|
402
|
-
const requestId = generateRequestId();
|
|
403
|
-
const ctx = {
|
|
404
|
-
requestId,
|
|
405
|
-
logger: logger.child({ resource: uri, requestId }),
|
|
406
|
-
cwd: process.cwd(),
|
|
407
|
-
env: process.env
|
|
408
|
-
};
|
|
409
|
-
try {
|
|
410
|
-
const result = await resource.handler(uri, ctx);
|
|
411
|
-
if (result.isErr()) {
|
|
412
|
-
return Result.err(translateError(result.error));
|
|
413
|
-
}
|
|
414
|
-
return Result.ok(result.value);
|
|
415
|
-
} catch (error) {
|
|
416
|
-
return Result.err(new McpError({
|
|
417
|
-
message: error instanceof Error ? error.message : "Unknown error",
|
|
418
|
-
code: -32603,
|
|
419
|
-
context: { uri, thrown: true }
|
|
420
|
-
}));
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
for (const template of resourceTemplates.values()) {
|
|
424
|
-
const variables = matchUriTemplate(template.uriTemplate, uri);
|
|
425
|
-
if (variables) {
|
|
426
|
-
const templateRequestId = generateRequestId();
|
|
427
|
-
const templateCtx = {
|
|
428
|
-
requestId: templateRequestId,
|
|
429
|
-
logger: logger.child({
|
|
430
|
-
resource: uri,
|
|
431
|
-
requestId: templateRequestId
|
|
432
|
-
}),
|
|
433
|
-
cwd: process.cwd(),
|
|
434
|
-
env: process.env
|
|
435
|
-
};
|
|
436
|
-
try {
|
|
437
|
-
const result = await template.handler(uri, variables, templateCtx);
|
|
438
|
-
if (result.isErr()) {
|
|
439
|
-
return Result.err(translateError(result.error));
|
|
440
|
-
}
|
|
441
|
-
return Result.ok(result.value);
|
|
442
|
-
} catch (error) {
|
|
443
|
-
return Result.err(new McpError({
|
|
444
|
-
message: error instanceof Error ? error.message : "Unknown error",
|
|
445
|
-
code: -32603,
|
|
446
|
-
context: { uri, thrown: true }
|
|
447
|
-
}));
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
return Result.err(new McpError({
|
|
452
|
-
message: `Resource not found: ${uri}`,
|
|
453
|
-
code: -32002,
|
|
454
|
-
context: { uri }
|
|
455
|
-
}));
|
|
456
|
-
},
|
|
457
|
-
async invokeTool(toolName, input, invokeOptions) {
|
|
458
|
-
const requestId = invokeOptions?.requestId ?? generateRequestId();
|
|
459
|
-
logger.debug("Invoking tool", { tool: toolName, requestId });
|
|
460
|
-
const tool = tools.get(toolName);
|
|
461
|
-
if (!tool) {
|
|
462
|
-
logger.warn("Tool not found", { tool: toolName, requestId });
|
|
463
|
-
return Result.err(new McpError({
|
|
464
|
-
message: `Tool not found: ${toolName}`,
|
|
465
|
-
code: -32601,
|
|
466
|
-
context: { tool: toolName }
|
|
467
|
-
}));
|
|
468
|
-
}
|
|
469
|
-
const parseResult = tool.zodSchema.safeParse(input);
|
|
470
|
-
if (!parseResult.success) {
|
|
471
|
-
const errorMessages = parseResult.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join("; ");
|
|
472
|
-
logger.warn("Input validation failed", {
|
|
473
|
-
tool: toolName,
|
|
474
|
-
requestId,
|
|
475
|
-
errors: errorMessages
|
|
476
|
-
});
|
|
477
|
-
return Result.err(new McpError({
|
|
478
|
-
message: `Invalid input: ${errorMessages}`,
|
|
479
|
-
code: -32602,
|
|
480
|
-
context: {
|
|
481
|
-
tool: toolName,
|
|
482
|
-
validationErrors: parseResult.error.issues
|
|
483
|
-
}
|
|
484
|
-
}));
|
|
485
|
-
}
|
|
486
|
-
const ctx = createHandlerContext(toolName, requestId, invokeOptions?.signal, invokeOptions?.progressToken);
|
|
487
|
-
try {
|
|
488
|
-
const result = await tool.handler(parseResult.data, ctx);
|
|
489
|
-
if (result.isErr()) {
|
|
490
|
-
logger.debug("Tool returned error", {
|
|
491
|
-
tool: toolName,
|
|
492
|
-
requestId,
|
|
493
|
-
error: result.error._tag
|
|
494
|
-
});
|
|
495
|
-
return Result.err(translateError(result.error));
|
|
496
|
-
}
|
|
497
|
-
logger.debug("Tool completed successfully", {
|
|
498
|
-
tool: toolName,
|
|
499
|
-
requestId
|
|
500
|
-
});
|
|
501
|
-
return Result.ok(result.value);
|
|
502
|
-
} catch (error) {
|
|
503
|
-
logger.error("Tool threw exception", {
|
|
504
|
-
tool: toolName,
|
|
505
|
-
requestId,
|
|
506
|
-
error: error instanceof Error ? error.message : String(error)
|
|
507
|
-
});
|
|
508
|
-
return Result.err(new McpError({
|
|
509
|
-
message: error instanceof Error ? error.message : "Unknown error",
|
|
510
|
-
code: -32603,
|
|
511
|
-
context: {
|
|
512
|
-
tool: toolName,
|
|
513
|
-
thrown: true
|
|
514
|
-
}
|
|
515
|
-
}));
|
|
516
|
-
}
|
|
517
|
-
},
|
|
518
|
-
subscribe(uri) {
|
|
519
|
-
subscriptions.add(uri);
|
|
520
|
-
logger.debug("Resource subscription added", { uri });
|
|
521
|
-
},
|
|
522
|
-
unsubscribe(uri) {
|
|
523
|
-
subscriptions.delete(uri);
|
|
524
|
-
logger.debug("Resource subscription removed", { uri });
|
|
525
|
-
},
|
|
526
|
-
notifyResourceUpdated(uri) {
|
|
527
|
-
if (subscriptions.has(uri)) {
|
|
528
|
-
sdkServer?.sendResourceUpdated?.({ uri });
|
|
529
|
-
}
|
|
530
|
-
},
|
|
531
|
-
notifyToolsChanged() {
|
|
532
|
-
sdkServer?.sendToolListChanged?.();
|
|
533
|
-
},
|
|
534
|
-
notifyResourcesChanged() {
|
|
535
|
-
sdkServer?.sendResourceListChanged?.();
|
|
536
|
-
},
|
|
537
|
-
notifyPromptsChanged() {
|
|
538
|
-
sdkServer?.sendPromptListChanged?.();
|
|
539
|
-
},
|
|
540
|
-
setLogLevel(level) {
|
|
541
|
-
clientLogLevel = level;
|
|
542
|
-
logger.debug("Client log level set", { level });
|
|
543
|
-
},
|
|
544
|
-
sendLogMessage(level, data, loggerName) {
|
|
545
|
-
if (!sdkServer || clientLogLevel === null || !shouldEmitLog(level, clientLogLevel)) {
|
|
546
|
-
return;
|
|
547
|
-
}
|
|
548
|
-
const params = {
|
|
549
|
-
level,
|
|
550
|
-
data
|
|
551
|
-
};
|
|
552
|
-
if (loggerName !== undefined) {
|
|
553
|
-
params.logger = loggerName;
|
|
554
|
-
}
|
|
555
|
-
sdkServer.sendLoggingMessage?.(params);
|
|
556
|
-
},
|
|
557
|
-
bindSdkServer(server2) {
|
|
558
|
-
sdkServer = server2;
|
|
559
|
-
clientLogLevel = resolveDefaultLogLevel(options);
|
|
560
|
-
logger.debug("SDK server bound for notifications");
|
|
561
|
-
},
|
|
562
|
-
async start() {
|
|
563
|
-
logger.info("MCP server starting", { name, version, tools: tools.size });
|
|
564
|
-
},
|
|
565
|
-
async stop() {
|
|
566
|
-
logger.info("MCP server stopping", { name, version });
|
|
567
|
-
if (loggerFactory !== null) {
|
|
568
|
-
await loggerFactory.flush();
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
};
|
|
572
|
-
return server;
|
|
573
|
-
}
|
|
574
|
-
function defineTool(definition) {
|
|
575
|
-
return definition;
|
|
576
|
-
}
|
|
577
|
-
function escapeRegex(str) {
|
|
578
|
-
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
579
|
-
}
|
|
580
|
-
function matchUriTemplate(template, uri) {
|
|
581
|
-
const paramNames = [];
|
|
582
|
-
const parts = template.split(/(\{[^}]+\})/);
|
|
583
|
-
const regexSource = parts.map((part) => {
|
|
584
|
-
const paramMatch = part.match(/^\{([^}]+)\}$/);
|
|
585
|
-
if (paramMatch?.[1]) {
|
|
586
|
-
paramNames.push(paramMatch[1]);
|
|
587
|
-
return "([^/]+)";
|
|
588
|
-
}
|
|
589
|
-
return escapeRegex(part);
|
|
590
|
-
}).join("");
|
|
591
|
-
const regex = new RegExp(`^${regexSource}$`);
|
|
592
|
-
const match = uri.match(regex);
|
|
593
|
-
if (!match) {
|
|
594
|
-
return null;
|
|
595
|
-
}
|
|
596
|
-
const variables = {};
|
|
597
|
-
for (let i = 0;i < paramNames.length; i++) {
|
|
598
|
-
const name = paramNames[i];
|
|
599
|
-
const value = match[i + 1];
|
|
600
|
-
if (name !== undefined && value !== undefined) {
|
|
601
|
-
variables[name] = value;
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
return variables;
|
|
605
|
-
}
|
|
606
|
-
function defineResource(definition) {
|
|
607
|
-
return definition;
|
|
608
|
-
}
|
|
609
|
-
function defineResourceTemplate(definition) {
|
|
610
|
-
return definition;
|
|
611
|
-
}
|
|
612
|
-
function definePrompt(definition) {
|
|
613
|
-
return definition;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
// src/actions.ts
|
|
617
|
-
function isActionRegistry(source) {
|
|
618
|
-
return "list" in source;
|
|
619
|
-
}
|
|
620
|
-
function buildMcpTools(source, options = {}) {
|
|
621
|
-
const actions = isActionRegistry(source) ? source.list() : source;
|
|
622
|
-
const includeSurfaces = options.includeSurfaces ?? [
|
|
623
|
-
"mcp"
|
|
624
|
-
];
|
|
625
|
-
return actions.filter((action) => {
|
|
626
|
-
const surfaces = action.surfaces ?? DEFAULT_REGISTRY_SURFACES;
|
|
627
|
-
return surfaces.some((surface) => includeSurfaces.includes(surface));
|
|
628
|
-
}).map((action) => defineTool({
|
|
629
|
-
name: action.mcp?.tool ?? action.id,
|
|
630
|
-
description: action.mcp?.description ?? action.description ?? action.id,
|
|
631
|
-
inputSchema: action.input,
|
|
632
|
-
handler: async (input, ctx) => action.handler(input, ctx),
|
|
633
|
-
...action.mcp?.deferLoading !== undefined ? { deferLoading: action.mcp.deferLoading } : {}
|
|
634
|
-
}));
|
|
635
|
-
}
|
|
636
|
-
// src/core-tools.ts
|
|
637
|
-
import { Result as Result2, ValidationError } from "@outfitter/contracts";
|
|
638
|
-
import { z } from "zod";
|
|
639
|
-
var DEFAULT_DOCS = {
|
|
640
|
-
overview: "No documentation configured yet.",
|
|
641
|
-
tools: [],
|
|
642
|
-
examples: [],
|
|
643
|
-
schemas: {}
|
|
644
|
-
};
|
|
645
|
-
var docsSchema = z.object({
|
|
646
|
-
section: z.enum(["overview", "tools", "examples", "schemas"]).optional()
|
|
647
|
-
});
|
|
648
|
-
function pickDocsSection(payload, section) {
|
|
649
|
-
if (!section) {
|
|
650
|
-
return payload;
|
|
651
|
-
}
|
|
652
|
-
return {
|
|
653
|
-
[section]: payload[section]
|
|
654
|
-
};
|
|
655
|
-
}
|
|
656
|
-
function defineDocsTool(options = {}) {
|
|
657
|
-
return {
|
|
658
|
-
name: "docs",
|
|
659
|
-
description: options.description ?? "Documentation, usage patterns, and examples for this MCP server.",
|
|
660
|
-
deferLoading: false,
|
|
661
|
-
inputSchema: docsSchema,
|
|
662
|
-
handler: async (input) => {
|
|
663
|
-
const payload = options.getDocs ? await options.getDocs(input.section) : options.docs ?? DEFAULT_DOCS;
|
|
664
|
-
return Result2.ok(pickDocsSection(payload, input.section));
|
|
665
|
-
}
|
|
666
|
-
};
|
|
667
|
-
}
|
|
668
|
-
var configSchema = z.object({
|
|
669
|
-
action: z.enum(["get", "set", "list"]),
|
|
670
|
-
key: z.string().optional(),
|
|
671
|
-
value: z.unknown().optional()
|
|
672
|
-
});
|
|
673
|
-
function createInMemoryStore(initial = {}) {
|
|
674
|
-
const store = new Map(Object.entries(initial));
|
|
675
|
-
return {
|
|
676
|
-
get(key) {
|
|
677
|
-
return { value: store.get(key), found: store.has(key) };
|
|
678
|
-
},
|
|
679
|
-
set(key, value) {
|
|
680
|
-
store.set(key, value);
|
|
681
|
-
},
|
|
682
|
-
list() {
|
|
683
|
-
return Object.fromEntries(store.entries());
|
|
684
|
-
}
|
|
685
|
-
};
|
|
686
|
-
}
|
|
687
|
-
function defineConfigTool(options = {}) {
|
|
688
|
-
const store = options.store ?? createInMemoryStore(options.initial);
|
|
689
|
-
return {
|
|
690
|
-
name: "config",
|
|
691
|
-
description: options.description ?? "Read or modify server configuration values.",
|
|
692
|
-
deferLoading: false,
|
|
693
|
-
inputSchema: configSchema,
|
|
694
|
-
handler: async (input) => {
|
|
695
|
-
switch (input.action) {
|
|
696
|
-
case "list": {
|
|
697
|
-
const config = await store.list();
|
|
698
|
-
return Result2.ok({ action: "list", config });
|
|
699
|
-
}
|
|
700
|
-
case "get": {
|
|
701
|
-
if (!input.key) {
|
|
702
|
-
return Result2.err(new ValidationError({
|
|
703
|
-
message: "Config key is required for action 'get'.",
|
|
704
|
-
field: "key"
|
|
705
|
-
}));
|
|
706
|
-
}
|
|
707
|
-
const { value, found } = await store.get(input.key);
|
|
708
|
-
return Result2.ok({ action: "get", key: input.key, value, found });
|
|
709
|
-
}
|
|
710
|
-
case "set": {
|
|
711
|
-
if (!input.key) {
|
|
712
|
-
return Result2.err(new ValidationError({
|
|
713
|
-
message: "Config key is required for action 'set'.",
|
|
714
|
-
field: "key"
|
|
715
|
-
}));
|
|
716
|
-
}
|
|
717
|
-
await store.set(input.key, input.value);
|
|
718
|
-
return Result2.ok({
|
|
719
|
-
action: "set",
|
|
720
|
-
key: input.key,
|
|
721
|
-
value: input.value
|
|
722
|
-
});
|
|
723
|
-
}
|
|
724
|
-
default:
|
|
725
|
-
return Result2.err(new ValidationError({
|
|
726
|
-
message: `Unknown action: ${input.action}`,
|
|
727
|
-
field: "action"
|
|
728
|
-
}));
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
};
|
|
732
|
-
}
|
|
733
|
-
var querySchema = z.object({
|
|
734
|
-
q: z.string().min(1).describe("Search query. Supports natural language or filter syntax.").optional(),
|
|
735
|
-
query: z.string().min(1).describe("Alias for q. Supports natural language or filter syntax.").optional(),
|
|
736
|
-
limit: z.number().int().positive().optional(),
|
|
737
|
-
cursor: z.string().optional(),
|
|
738
|
-
filters: z.record(z.string(), z.unknown()).optional()
|
|
739
|
-
}).refine((value) => {
|
|
740
|
-
const queryValue = (value.q ?? value.query)?.trim();
|
|
741
|
-
return typeof queryValue === "string" && queryValue.length > 0;
|
|
742
|
-
}, {
|
|
743
|
-
message: "Query is required.",
|
|
744
|
-
path: ["q"]
|
|
745
|
-
});
|
|
746
|
-
function defineQueryTool(options = {}) {
|
|
747
|
-
return {
|
|
748
|
-
name: "query",
|
|
749
|
-
description: options.description ?? "Search and discover resources with filters and pagination.",
|
|
750
|
-
deferLoading: false,
|
|
751
|
-
inputSchema: querySchema,
|
|
752
|
-
handler: (input, ctx) => {
|
|
753
|
-
const normalized = {
|
|
754
|
-
...input,
|
|
755
|
-
q: (input.q ?? input.query ?? "").trim()
|
|
756
|
-
};
|
|
757
|
-
if (options.handler) {
|
|
758
|
-
return options.handler(normalized, ctx);
|
|
759
|
-
}
|
|
760
|
-
return Promise.resolve(Result2.ok({
|
|
761
|
-
results: [],
|
|
762
|
-
_meta: {
|
|
763
|
-
note: "No query handler configured."
|
|
764
|
-
}
|
|
765
|
-
}));
|
|
766
|
-
}
|
|
767
|
-
};
|
|
768
|
-
}
|
|
769
|
-
function createCoreTools(options = {}) {
|
|
770
|
-
return [
|
|
771
|
-
defineDocsTool(options.docs),
|
|
772
|
-
defineConfigTool(options.config),
|
|
773
|
-
defineQueryTool(options.query)
|
|
774
|
-
];
|
|
775
|
-
}
|
|
776
|
-
// src/transport.ts
|
|
777
|
-
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
778
|
-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
779
|
-
import {
|
|
780
|
-
CallToolRequestSchema,
|
|
781
|
-
CompleteRequestSchema,
|
|
782
|
-
GetPromptRequestSchema,
|
|
783
|
-
ListPromptsRequestSchema,
|
|
784
|
-
ListResourcesRequestSchema,
|
|
785
|
-
ListResourceTemplatesRequestSchema,
|
|
786
|
-
ListToolsRequestSchema,
|
|
787
|
-
ReadResourceRequestSchema,
|
|
788
|
-
McpError as SdkMcpError,
|
|
789
|
-
SetLevelRequestSchema,
|
|
790
|
-
SubscribeRequestSchema,
|
|
791
|
-
UnsubscribeRequestSchema
|
|
792
|
-
} from "@modelcontextprotocol/sdk/types.js";
|
|
793
|
-
import { safeStringify } from "@outfitter/contracts";
|
|
794
|
-
function isMcpToolResponse(value) {
|
|
795
|
-
if (!value || typeof value !== "object") {
|
|
796
|
-
return false;
|
|
797
|
-
}
|
|
798
|
-
const content = value.content;
|
|
799
|
-
return Array.isArray(content);
|
|
800
|
-
}
|
|
801
|
-
function toTextPayload(value) {
|
|
802
|
-
if (typeof value === "string") {
|
|
803
|
-
return value;
|
|
804
|
-
}
|
|
805
|
-
return safeStringify(value);
|
|
806
|
-
}
|
|
807
|
-
function serializeError(error) {
|
|
808
|
-
if (error && typeof error === "object") {
|
|
809
|
-
const record = error;
|
|
810
|
-
return {
|
|
811
|
-
_tag: record._tag ?? "McpError",
|
|
812
|
-
message: record.message ?? "Unknown error",
|
|
813
|
-
code: record.code,
|
|
814
|
-
context: record.context
|
|
815
|
-
};
|
|
816
|
-
}
|
|
817
|
-
return {
|
|
818
|
-
_tag: "McpError",
|
|
819
|
-
message: String(error)
|
|
820
|
-
};
|
|
821
|
-
}
|
|
822
|
-
function wrapToolResult(value) {
|
|
823
|
-
if (isMcpToolResponse(value)) {
|
|
824
|
-
return value;
|
|
825
|
-
}
|
|
826
|
-
const structuredContent = value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
827
|
-
return {
|
|
828
|
-
content: [
|
|
829
|
-
{
|
|
830
|
-
type: "text",
|
|
831
|
-
text: toTextPayload(value)
|
|
832
|
-
}
|
|
833
|
-
],
|
|
834
|
-
...structuredContent ? { structuredContent } : {}
|
|
835
|
-
};
|
|
836
|
-
}
|
|
837
|
-
function wrapToolError(error) {
|
|
838
|
-
return {
|
|
839
|
-
content: [
|
|
840
|
-
{
|
|
841
|
-
type: "text",
|
|
842
|
-
text: toTextPayload(serializeError(error))
|
|
843
|
-
}
|
|
844
|
-
],
|
|
845
|
-
isError: true
|
|
846
|
-
};
|
|
847
|
-
}
|
|
848
|
-
function toSdkError(error) {
|
|
849
|
-
return new SdkMcpError(error.code, error.message, error.context);
|
|
850
|
-
}
|
|
851
|
-
function createSdkServer(server) {
|
|
852
|
-
const capabilities = {
|
|
853
|
-
tools: { listChanged: true },
|
|
854
|
-
resources: { listChanged: true, subscribe: true },
|
|
855
|
-
prompts: { listChanged: true },
|
|
856
|
-
completions: {},
|
|
857
|
-
logging: {}
|
|
858
|
-
};
|
|
859
|
-
const sdkServer = new Server({ name: server.name, version: server.version }, { capabilities });
|
|
860
|
-
sdkServer.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
861
|
-
tools: server.getTools()
|
|
862
|
-
}));
|
|
863
|
-
sdkServer.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
864
|
-
const { name, arguments: args } = request.params;
|
|
865
|
-
const progressToken = request.params._meta?.progressToken;
|
|
866
|
-
const options = progressToken !== undefined ? { progressToken } : undefined;
|
|
867
|
-
const result = await server.invokeTool(name, args ?? {}, options);
|
|
868
|
-
if (result.isErr()) {
|
|
869
|
-
return wrapToolError(result.error);
|
|
870
|
-
}
|
|
871
|
-
return wrapToolResult(result.value);
|
|
872
|
-
});
|
|
873
|
-
sdkServer.setRequestHandler(ListResourcesRequestSchema, async () => ({
|
|
874
|
-
resources: server.getResources().map((r) => ({
|
|
875
|
-
uri: r.uri,
|
|
876
|
-
name: r.name,
|
|
877
|
-
...r.description ? { description: r.description } : {},
|
|
878
|
-
...r.mimeType ? { mimeType: r.mimeType } : {}
|
|
879
|
-
}))
|
|
880
|
-
}));
|
|
881
|
-
sdkServer.setRequestHandler(ListResourceTemplatesRequestSchema, async () => ({
|
|
882
|
-
resourceTemplates: server.getResourceTemplates().map((t) => ({
|
|
883
|
-
uriTemplate: t.uriTemplate,
|
|
884
|
-
name: t.name,
|
|
885
|
-
...t.description ? { description: t.description } : {},
|
|
886
|
-
...t.mimeType ? { mimeType: t.mimeType } : {}
|
|
887
|
-
}))
|
|
888
|
-
}));
|
|
889
|
-
sdkServer.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
890
|
-
const { uri } = request.params;
|
|
891
|
-
const result = await server.readResource(uri);
|
|
892
|
-
if (result.isErr()) {
|
|
893
|
-
throw toSdkError(result.error);
|
|
894
|
-
}
|
|
895
|
-
return { contents: result.value };
|
|
896
|
-
});
|
|
897
|
-
sdkServer.setRequestHandler(SubscribeRequestSchema, async (request) => {
|
|
898
|
-
server.subscribe(request.params.uri);
|
|
899
|
-
return {};
|
|
900
|
-
});
|
|
901
|
-
sdkServer.setRequestHandler(UnsubscribeRequestSchema, async (request) => {
|
|
902
|
-
server.unsubscribe(request.params.uri);
|
|
903
|
-
return {};
|
|
904
|
-
});
|
|
905
|
-
sdkServer.setRequestHandler(ListPromptsRequestSchema, async () => ({
|
|
906
|
-
prompts: server.getPrompts()
|
|
907
|
-
}));
|
|
908
|
-
sdkServer.setRequestHandler(GetPromptRequestSchema, async (request) => {
|
|
909
|
-
const { name, arguments: args } = request.params;
|
|
910
|
-
const result = await server.getPrompt(name, args ?? {});
|
|
911
|
-
if (result.isErr()) {
|
|
912
|
-
throw toSdkError(result.error);
|
|
913
|
-
}
|
|
914
|
-
return { ...result.value };
|
|
915
|
-
});
|
|
916
|
-
sdkServer.setRequestHandler(CompleteRequestSchema, async (request) => {
|
|
917
|
-
const { ref, argument } = request.params;
|
|
918
|
-
const completionRef = ref.type === "ref/prompt" ? { type: "ref/prompt", name: ref.name } : { type: "ref/resource", uri: ref.uri };
|
|
919
|
-
const result = await server.complete(completionRef, argument.name, argument.value);
|
|
920
|
-
if (result.isErr()) {
|
|
921
|
-
throw toSdkError(result.error);
|
|
922
|
-
}
|
|
923
|
-
return { completion: result.value };
|
|
924
|
-
});
|
|
925
|
-
sdkServer.setRequestHandler(SetLevelRequestSchema, async (request) => {
|
|
926
|
-
const level = request.params.level;
|
|
927
|
-
server.setLogLevel?.(level);
|
|
928
|
-
return {};
|
|
929
|
-
});
|
|
930
|
-
server.bindSdkServer?.(sdkServer);
|
|
931
|
-
return sdkServer;
|
|
932
|
-
}
|
|
933
|
-
async function connectStdio(server, transport = new StdioServerTransport) {
|
|
934
|
-
const sdkServer = createSdkServer(server);
|
|
935
|
-
await sdkServer.connect(transport);
|
|
936
|
-
return sdkServer;
|
|
937
|
-
}
|
|
938
|
-
export {
|
|
939
|
-
zodToJsonSchema,
|
|
940
|
-
wrapToolResult,
|
|
941
|
-
wrapToolError,
|
|
942
|
-
shouldEmitLog,
|
|
943
|
-
mapLogLevelToMcp,
|
|
944
|
-
defineTool,
|
|
945
|
-
defineResourceTemplate,
|
|
946
|
-
defineResource,
|
|
947
|
-
defineQueryTool,
|
|
948
|
-
definePrompt,
|
|
949
|
-
defineDocsTool,
|
|
950
|
-
defineConfigTool,
|
|
951
|
-
createSdkServer,
|
|
952
|
-
createMcpServer,
|
|
953
|
-
createCoreTools,
|
|
954
|
-
connectStdio,
|
|
955
|
-
buildMcpTools,
|
|
956
|
-
adaptHandler,
|
|
957
|
-
TOOL_ANNOTATIONS,
|
|
958
|
-
McpError
|
|
959
|
-
};
|
|
1
|
+
export { buildMcpTools } from "./actions.js";
|
|
2
|
+
export { createCoreTools, defineConfigTool, defineDocsTool, defineQueryTool } from "./core-tools.js";
|
|
3
|
+
export { mapLogLevelToMcp, shouldEmitLog } from "./logging.js";
|
|
4
|
+
export { createMcpProgressCallback } from "./progress.js";
|
|
5
|
+
export { zodToJsonSchema } from "./schema.js";
|
|
6
|
+
export { createMcpServer, definePrompt, defineResource, defineResourceTemplate, defineTool } from "./server.js";
|
|
7
|
+
export { connectStdio, createSdkServer, wrapToolError, wrapToolResult } from "./transport.js";
|
|
8
|
+
export { adaptHandler, McpError, TOOL_ANNOTATIONS } from "./types.js";
|