@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
|
@@ -1,70 +1,33 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
import {
|
|
3
|
+
VALID_MCP_LOG_LEVELS,
|
|
4
|
+
createDefaultMcpSink,
|
|
5
|
+
resolveDefaultLogLevel
|
|
6
|
+
} from "./mcp-n9vzcp37.js";
|
|
7
|
+
import {
|
|
8
|
+
matchUriTemplate
|
|
9
|
+
} from "./mcp-zt2s3r38.js";
|
|
10
|
+
import {
|
|
11
|
+
createMcpProgressCallback
|
|
12
|
+
} from "./mcp-q70dtfj6.js";
|
|
2
13
|
import {
|
|
3
14
|
shouldEmitLog
|
|
4
15
|
} from "./mcp-fjtxsa0x.js";
|
|
5
|
-
import {
|
|
6
|
-
zodToJsonSchema
|
|
7
|
-
} from "./mcp-zy7b487d.js";
|
|
8
16
|
import {
|
|
9
17
|
McpError
|
|
10
|
-
} from "./mcp-
|
|
18
|
+
} from "./mcp-s2vnhzav.js";
|
|
19
|
+
import {
|
|
20
|
+
zodToJsonSchema
|
|
21
|
+
} from "./mcp-hw5wz4gb.js";
|
|
11
22
|
|
|
12
23
|
// packages/mcp/src/server.ts
|
|
13
|
-
import { getEnvironment, getEnvironmentDefaults } from "@outfitter/config";
|
|
14
|
-
import { generateRequestId, Result } from "@outfitter/contracts";
|
|
15
24
|
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"notice",
|
|
23
|
-
"warning",
|
|
24
|
-
"error",
|
|
25
|
-
"critical",
|
|
26
|
-
"alert",
|
|
27
|
-
"emergency"
|
|
28
|
-
]);
|
|
29
|
-
var DEFAULTS_TO_MCP = {
|
|
30
|
-
debug: "debug",
|
|
31
|
-
info: "info",
|
|
32
|
-
warn: "warning",
|
|
33
|
-
error: "error"
|
|
34
|
-
};
|
|
35
|
-
function createDefaultMcpSink() {
|
|
36
|
-
const formatter = createPrettyFormatter({ colors: false });
|
|
37
|
-
return {
|
|
38
|
-
formatter,
|
|
39
|
-
write(record, formatted) {
|
|
40
|
-
const serialized = formatted ?? formatter.format(record);
|
|
41
|
-
const line = serialized.endsWith(`
|
|
42
|
-
`) ? serialized : `${serialized}
|
|
43
|
-
`;
|
|
44
|
-
if (typeof process !== "undefined" && process.stderr?.write) {
|
|
45
|
-
process.stderr.write(line);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
function resolveDefaultLogLevel(options) {
|
|
51
|
-
const envLogLevel = process.env["OUTFITTER_LOG_LEVEL"];
|
|
52
|
-
if (envLogLevel !== undefined && VALID_MCP_LOG_LEVELS.has(envLogLevel)) {
|
|
53
|
-
return envLogLevel;
|
|
54
|
-
}
|
|
55
|
-
if (options.defaultLogLevel !== undefined && (options.defaultLogLevel === null || VALID_MCP_LOG_LEVELS.has(options.defaultLogLevel))) {
|
|
56
|
-
return options.defaultLogLevel;
|
|
57
|
-
}
|
|
58
|
-
const env = getEnvironment();
|
|
59
|
-
const defaults = getEnvironmentDefaults(env);
|
|
60
|
-
if (defaults.logLevel !== null) {
|
|
61
|
-
const mapped = DEFAULTS_TO_MCP[defaults.logLevel];
|
|
62
|
-
if (mapped !== undefined) {
|
|
63
|
-
return mapped;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
25
|
+
formatZodIssues,
|
|
26
|
+
generateRequestId,
|
|
27
|
+
Result,
|
|
28
|
+
ValidationError
|
|
29
|
+
} from "@outfitter/contracts";
|
|
30
|
+
import { createOutfitterLoggerFactory } from "@outfitter/logging";
|
|
68
31
|
function createMcpServer(options) {
|
|
69
32
|
const { name, version, logger: providedLogger } = options;
|
|
70
33
|
let loggerFactory = null;
|
|
@@ -84,10 +47,10 @@ function createMcpServer(options) {
|
|
|
84
47
|
let sdkServer = null;
|
|
85
48
|
const subscriptions = new Set;
|
|
86
49
|
let clientLogLevel = resolveDefaultLogLevel(options);
|
|
87
|
-
function createHandlerContext(
|
|
50
|
+
function createHandlerContext(label, requestId, signal, progressToken, loggerMeta) {
|
|
88
51
|
const ctx = {
|
|
89
52
|
requestId,
|
|
90
|
-
logger: logger.child({ tool:
|
|
53
|
+
logger: logger.child(loggerMeta ?? { tool: label, requestId }),
|
|
91
54
|
cwd: process.cwd(),
|
|
92
55
|
env: process.env
|
|
93
56
|
};
|
|
@@ -95,19 +58,27 @@ function createMcpServer(options) {
|
|
|
95
58
|
ctx.signal = signal;
|
|
96
59
|
}
|
|
97
60
|
if (progressToken !== undefined && sdkServer) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
...total !== undefined ? { total } : {},
|
|
106
|
-
...message ? { message } : {}
|
|
107
|
-
}
|
|
61
|
+
const sender = (notification) => {
|
|
62
|
+
const maybePromise = sdkServer?.notification?.(notification);
|
|
63
|
+
if (typeof maybePromise === "object" && maybePromise !== null && "then" in maybePromise) {
|
|
64
|
+
maybePromise.catch((error) => {
|
|
65
|
+
logger.warn("Failed to send MCP progress notification", {
|
|
66
|
+
error: error instanceof Error ? error.message : String(error)
|
|
67
|
+
});
|
|
108
68
|
});
|
|
109
69
|
}
|
|
110
70
|
};
|
|
71
|
+
const streamProgress = createMcpProgressCallback(progressToken, sender);
|
|
72
|
+
const progress = streamProgress;
|
|
73
|
+
progress.report = (value, total, message) => {
|
|
74
|
+
streamProgress({
|
|
75
|
+
type: "progress",
|
|
76
|
+
current: value,
|
|
77
|
+
total: total ?? value,
|
|
78
|
+
...message !== undefined ? { message } : {}
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
ctx.progress = progress;
|
|
111
82
|
}
|
|
112
83
|
return ctx;
|
|
113
84
|
}
|
|
@@ -125,13 +96,17 @@ function createMcpServer(options) {
|
|
|
125
96
|
cancelled: -32603
|
|
126
97
|
};
|
|
127
98
|
const code = codeMap[error.category] ?? -32603;
|
|
99
|
+
const context = {
|
|
100
|
+
originalTag: error._tag,
|
|
101
|
+
category: error.category
|
|
102
|
+
};
|
|
103
|
+
if (error._tag === "ValidationError" && "field" in error && typeof error.field === "string") {
|
|
104
|
+
context["field"] = error.field;
|
|
105
|
+
}
|
|
128
106
|
return new McpError({
|
|
129
107
|
message: error.message,
|
|
130
108
|
code,
|
|
131
|
-
context
|
|
132
|
-
originalTag: error._tag,
|
|
133
|
-
category: error.category
|
|
134
|
-
}
|
|
109
|
+
context
|
|
135
110
|
});
|
|
136
111
|
}
|
|
137
112
|
const server = {
|
|
@@ -322,12 +297,10 @@ function createMcpServer(options) {
|
|
|
322
297
|
}));
|
|
323
298
|
}
|
|
324
299
|
const requestId = generateRequestId();
|
|
325
|
-
const ctx = {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
env: process.env
|
|
330
|
-
};
|
|
300
|
+
const ctx = createHandlerContext(uri, requestId, undefined, undefined, {
|
|
301
|
+
resource: uri,
|
|
302
|
+
requestId
|
|
303
|
+
});
|
|
331
304
|
try {
|
|
332
305
|
const result = await resource.handler(uri, ctx);
|
|
333
306
|
if (result.isErr()) {
|
|
@@ -346,18 +319,15 @@ function createMcpServer(options) {
|
|
|
346
319
|
const variables = matchUriTemplate(template.uriTemplate, uri);
|
|
347
320
|
if (variables) {
|
|
348
321
|
const templateRequestId = generateRequestId();
|
|
349
|
-
const templateCtx = {
|
|
350
|
-
requestId: templateRequestId,
|
|
351
|
-
logger: logger.child({
|
|
352
|
-
resource: uri,
|
|
353
|
-
requestId: templateRequestId
|
|
354
|
-
}),
|
|
355
|
-
cwd: process.cwd(),
|
|
356
|
-
env: process.env
|
|
357
|
-
};
|
|
322
|
+
const templateCtx = createHandlerContext(uri, templateRequestId, undefined, undefined, { resource: uri, requestId: templateRequestId });
|
|
358
323
|
try {
|
|
359
324
|
const result = await template.handler(uri, variables, templateCtx);
|
|
360
325
|
if (result.isErr()) {
|
|
326
|
+
logger.warn("Resource template handler returned error", {
|
|
327
|
+
uri,
|
|
328
|
+
requestId: templateRequestId,
|
|
329
|
+
error: result.error._tag
|
|
330
|
+
});
|
|
361
331
|
return Result.err(translateError(result.error));
|
|
362
332
|
}
|
|
363
333
|
return Result.ok(result.value);
|
|
@@ -390,7 +360,7 @@ function createMcpServer(options) {
|
|
|
390
360
|
}
|
|
391
361
|
const parseResult = tool.zodSchema.safeParse(input);
|
|
392
362
|
if (!parseResult.success) {
|
|
393
|
-
const errorMessages = parseResult.error.issues
|
|
363
|
+
const errorMessages = formatZodIssues(parseResult.error.issues);
|
|
394
364
|
logger.warn("Input validation failed", {
|
|
395
365
|
tool: toolName,
|
|
396
366
|
requestId,
|
|
@@ -460,6 +430,10 @@ function createMcpServer(options) {
|
|
|
460
430
|
sdkServer?.sendPromptListChanged?.();
|
|
461
431
|
},
|
|
462
432
|
setLogLevel(level) {
|
|
433
|
+
if (!VALID_MCP_LOG_LEVELS.has(level)) {
|
|
434
|
+
logger.warn("Ignoring invalid client log level", { level });
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
463
437
|
clientLogLevel = level;
|
|
464
438
|
logger.debug("Client log level set", { level });
|
|
465
439
|
},
|
|
@@ -496,39 +470,25 @@ function createMcpServer(options) {
|
|
|
496
470
|
function defineTool(definition) {
|
|
497
471
|
return definition;
|
|
498
472
|
}
|
|
499
|
-
function escapeRegex(str) {
|
|
500
|
-
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
501
|
-
}
|
|
502
|
-
function matchUriTemplate(template, uri) {
|
|
503
|
-
const paramNames = [];
|
|
504
|
-
const parts = template.split(/(\{[^}]+\})/);
|
|
505
|
-
const regexSource = parts.map((part) => {
|
|
506
|
-
const paramMatch = part.match(/^\{([^}]+)\}$/);
|
|
507
|
-
if (paramMatch?.[1]) {
|
|
508
|
-
paramNames.push(paramMatch[1]);
|
|
509
|
-
return "([^/]+)";
|
|
510
|
-
}
|
|
511
|
-
return escapeRegex(part);
|
|
512
|
-
}).join("");
|
|
513
|
-
const regex = new RegExp(`^${regexSource}$`);
|
|
514
|
-
const match = uri.match(regex);
|
|
515
|
-
if (!match) {
|
|
516
|
-
return null;
|
|
517
|
-
}
|
|
518
|
-
const variables = {};
|
|
519
|
-
for (let i = 0;i < paramNames.length; i++) {
|
|
520
|
-
const name = paramNames[i];
|
|
521
|
-
const value = match[i + 1];
|
|
522
|
-
if (name !== undefined && value !== undefined) {
|
|
523
|
-
variables[name] = value;
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
return variables;
|
|
527
|
-
}
|
|
528
473
|
function defineResource(definition) {
|
|
529
474
|
return definition;
|
|
530
475
|
}
|
|
531
476
|
function defineResourceTemplate(definition) {
|
|
477
|
+
if ("paramSchema" in definition && definition.paramSchema !== undefined) {
|
|
478
|
+
const { paramSchema, handler: typedHandler, ...rest } = definition;
|
|
479
|
+
const wrappedHandler = async (uri, variables, ctx) => {
|
|
480
|
+
const parseResult = paramSchema.safeParse(variables);
|
|
481
|
+
if (!parseResult.success) {
|
|
482
|
+
const errorMessages = formatZodIssues(parseResult.error.issues);
|
|
483
|
+
return Result.err(new ValidationError({
|
|
484
|
+
message: `Invalid resource parameters: ${errorMessages}`,
|
|
485
|
+
field: "params"
|
|
486
|
+
}));
|
|
487
|
+
}
|
|
488
|
+
return typedHandler(uri, parseResult.data, ctx);
|
|
489
|
+
};
|
|
490
|
+
return { ...rest, handler: wrappedHandler };
|
|
491
|
+
}
|
|
532
492
|
return definition;
|
|
533
493
|
}
|
|
534
494
|
function definePrompt(definition) {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/mcp/src/internal/uri-template.ts
|
|
3
|
+
function escapeRegex(str) {
|
|
4
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
5
|
+
}
|
|
6
|
+
function matchUriTemplate(template, uri) {
|
|
7
|
+
const paramNames = [];
|
|
8
|
+
const parts = template.split(/(\{[^}]+\})/);
|
|
9
|
+
const regexSource = parts.map((part) => {
|
|
10
|
+
const paramMatch = part.match(/^\{([^}]+)\}$/);
|
|
11
|
+
if (paramMatch?.[1]) {
|
|
12
|
+
paramNames.push(paramMatch[1]);
|
|
13
|
+
return "([^/]+)";
|
|
14
|
+
}
|
|
15
|
+
return escapeRegex(part);
|
|
16
|
+
}).join("");
|
|
17
|
+
const regex = new RegExp(`^${regexSource}$`);
|
|
18
|
+
const match = uri.match(regex);
|
|
19
|
+
if (!match) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const variables = {};
|
|
23
|
+
for (let i = 0;i < paramNames.length; i++) {
|
|
24
|
+
const name = paramNames[i];
|
|
25
|
+
const value = match[i + 1];
|
|
26
|
+
if (name !== undefined && value !== undefined) {
|
|
27
|
+
variables[name] = value;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return variables;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { matchUriTemplate };
|
package/dist/transport.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import { McpToolResponse, connectStdio, createSdkServer, wrapToolError, wrapToolResult } from "./shared/@outfitter/mcp-
|
|
2
|
-
import "./shared/@outfitter/mcp-
|
|
1
|
+
import { McpToolResponse, connectStdio, createSdkServer, wrapToolError, wrapToolResult } from "./shared/@outfitter/mcp-yf0w5cgh.js";
|
|
2
|
+
import "./shared/@outfitter/mcp-qmdmgxa1.js";
|
|
3
|
+
import "./shared/@outfitter/mcp-7btcghjj.js";
|
|
4
|
+
import "./shared/@outfitter/mcp-knc1gq0g.js";
|
|
5
|
+
import "./shared/@outfitter/mcp-9ry52yg3.js";
|
|
6
|
+
import "./shared/@outfitter/mcp-dgwj3jna.js";
|
|
7
|
+
import "./shared/@outfitter/mcp-q5hr7227.js";
|
|
3
8
|
import "./shared/@outfitter/mcp-cqpyer9m.js";
|
|
4
9
|
export { wrapToolResult, wrapToolError, createSdkServer, connectStdio, McpToolResponse };
|
package/dist/transport.js
CHANGED
|
@@ -1,10 +1,166 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
// packages/mcp/src/transport.ts
|
|
3
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
4
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
2
5
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
CallToolRequestSchema,
|
|
7
|
+
CompleteRequestSchema,
|
|
8
|
+
GetPromptRequestSchema,
|
|
9
|
+
ListPromptsRequestSchema,
|
|
10
|
+
ListResourcesRequestSchema,
|
|
11
|
+
ListResourceTemplatesRequestSchema,
|
|
12
|
+
ListToolsRequestSchema,
|
|
13
|
+
ReadResourceRequestSchema,
|
|
14
|
+
McpError as SdkMcpError,
|
|
15
|
+
SetLevelRequestSchema,
|
|
16
|
+
SubscribeRequestSchema,
|
|
17
|
+
UnsubscribeRequestSchema
|
|
18
|
+
} from "@modelcontextprotocol/sdk/types.js";
|
|
19
|
+
import { safeStringify } from "@outfitter/contracts";
|
|
20
|
+
function isMcpToolResponse(value) {
|
|
21
|
+
if (!value || typeof value !== "object") {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const content = value.content;
|
|
25
|
+
return Array.isArray(content);
|
|
26
|
+
}
|
|
27
|
+
function toTextPayload(value) {
|
|
28
|
+
if (typeof value === "string") {
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
return safeStringify(value);
|
|
32
|
+
}
|
|
33
|
+
function serializeError(error) {
|
|
34
|
+
if (error && typeof error === "object") {
|
|
35
|
+
const record = error;
|
|
36
|
+
return {
|
|
37
|
+
_tag: record._tag ?? "McpError",
|
|
38
|
+
message: record.message ?? "Unknown error",
|
|
39
|
+
code: record.code,
|
|
40
|
+
context: record.context
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
_tag: "McpError",
|
|
45
|
+
message: String(error)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function wrapToolResult(value) {
|
|
49
|
+
if (isMcpToolResponse(value)) {
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
const structuredContent = value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
53
|
+
return {
|
|
54
|
+
content: [
|
|
55
|
+
{
|
|
56
|
+
type: "text",
|
|
57
|
+
text: toTextPayload(value)
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
...structuredContent ? { structuredContent } : {}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function wrapToolError(error) {
|
|
64
|
+
return {
|
|
65
|
+
content: [
|
|
66
|
+
{
|
|
67
|
+
type: "text",
|
|
68
|
+
text: toTextPayload(serializeError(error))
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
isError: true
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function toSdkError(error) {
|
|
75
|
+
return new SdkMcpError(error.code, error.message, error.context);
|
|
76
|
+
}
|
|
77
|
+
function createSdkServer(server) {
|
|
78
|
+
const capabilities = {
|
|
79
|
+
tools: { listChanged: true },
|
|
80
|
+
resources: { listChanged: true, subscribe: true },
|
|
81
|
+
prompts: { listChanged: true },
|
|
82
|
+
completions: {},
|
|
83
|
+
logging: {}
|
|
84
|
+
};
|
|
85
|
+
const sdkServer = new Server({ name: server.name, version: server.version }, { capabilities });
|
|
86
|
+
sdkServer.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
87
|
+
tools: server.getTools()
|
|
88
|
+
}));
|
|
89
|
+
sdkServer.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
90
|
+
const { name, arguments: args } = request.params;
|
|
91
|
+
const progressToken = request.params._meta?.progressToken;
|
|
92
|
+
const options = progressToken !== undefined ? { progressToken } : undefined;
|
|
93
|
+
const result = await server.invokeTool(name, args ?? {}, options);
|
|
94
|
+
if (result.isErr()) {
|
|
95
|
+
return wrapToolError(result.error);
|
|
96
|
+
}
|
|
97
|
+
return wrapToolResult(result.value);
|
|
98
|
+
});
|
|
99
|
+
sdkServer.setRequestHandler(ListResourcesRequestSchema, async () => ({
|
|
100
|
+
resources: server.getResources().map((r) => ({
|
|
101
|
+
uri: r.uri,
|
|
102
|
+
name: r.name,
|
|
103
|
+
...r.description ? { description: r.description } : {},
|
|
104
|
+
...r.mimeType ? { mimeType: r.mimeType } : {}
|
|
105
|
+
}))
|
|
106
|
+
}));
|
|
107
|
+
sdkServer.setRequestHandler(ListResourceTemplatesRequestSchema, async () => ({
|
|
108
|
+
resourceTemplates: server.getResourceTemplates().map((t) => ({
|
|
109
|
+
uriTemplate: t.uriTemplate,
|
|
110
|
+
name: t.name,
|
|
111
|
+
...t.description ? { description: t.description } : {},
|
|
112
|
+
...t.mimeType ? { mimeType: t.mimeType } : {}
|
|
113
|
+
}))
|
|
114
|
+
}));
|
|
115
|
+
sdkServer.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
116
|
+
const { uri } = request.params;
|
|
117
|
+
const result = await server.readResource(uri);
|
|
118
|
+
if (result.isErr()) {
|
|
119
|
+
throw toSdkError(result.error);
|
|
120
|
+
}
|
|
121
|
+
return { contents: result.value };
|
|
122
|
+
});
|
|
123
|
+
sdkServer.setRequestHandler(SubscribeRequestSchema, async (request) => {
|
|
124
|
+
server.subscribe(request.params.uri);
|
|
125
|
+
return {};
|
|
126
|
+
});
|
|
127
|
+
sdkServer.setRequestHandler(UnsubscribeRequestSchema, async (request) => {
|
|
128
|
+
server.unsubscribe(request.params.uri);
|
|
129
|
+
return {};
|
|
130
|
+
});
|
|
131
|
+
sdkServer.setRequestHandler(ListPromptsRequestSchema, async () => ({
|
|
132
|
+
prompts: server.getPrompts()
|
|
133
|
+
}));
|
|
134
|
+
sdkServer.setRequestHandler(GetPromptRequestSchema, async (request) => {
|
|
135
|
+
const { name, arguments: args } = request.params;
|
|
136
|
+
const result = await server.getPrompt(name, args ?? {});
|
|
137
|
+
if (result.isErr()) {
|
|
138
|
+
throw toSdkError(result.error);
|
|
139
|
+
}
|
|
140
|
+
return { ...result.value };
|
|
141
|
+
});
|
|
142
|
+
sdkServer.setRequestHandler(CompleteRequestSchema, async (request) => {
|
|
143
|
+
const { ref, argument } = request.params;
|
|
144
|
+
const completionRef = ref.type === "ref/prompt" ? { type: "ref/prompt", name: ref.name } : { type: "ref/resource", uri: ref.uri };
|
|
145
|
+
const result = await server.complete(completionRef, argument.name, argument.value);
|
|
146
|
+
if (result.isErr()) {
|
|
147
|
+
throw toSdkError(result.error);
|
|
148
|
+
}
|
|
149
|
+
return { completion: result.value };
|
|
150
|
+
});
|
|
151
|
+
sdkServer.setRequestHandler(SetLevelRequestSchema, async (request) => {
|
|
152
|
+
const level = request.params.level;
|
|
153
|
+
server.setLogLevel?.(level);
|
|
154
|
+
return {};
|
|
155
|
+
});
|
|
156
|
+
server.bindSdkServer?.(sdkServer);
|
|
157
|
+
return sdkServer;
|
|
158
|
+
}
|
|
159
|
+
async function connectStdio(server, transport = new StdioServerTransport) {
|
|
160
|
+
const sdkServer = createSdkServer(server);
|
|
161
|
+
await sdkServer.connect(transport);
|
|
162
|
+
return sdkServer;
|
|
163
|
+
}
|
|
8
164
|
export {
|
|
9
165
|
wrapToolResult,
|
|
10
166
|
wrapToolError,
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./shared/@outfitter/mcp-qmdmgxa1.js";
|
|
2
|
+
import { InvokeToolOptions, McpError, McpHandlerContext, McpServer, McpServerOptions, ProgressReporter, Result, TaggedError, adaptHandler } from "./shared/@outfitter/mcp-7btcghjj.js";
|
|
3
|
+
import { SerializedTool, TOOL_ANNOTATIONS, ToolAnnotations, ToolDefinition } from "./shared/@outfitter/mcp-knc1gq0g.js";
|
|
4
|
+
import { BlobResourceContent, ResourceContent, ResourceDefinition, ResourceReadHandler, ResourceTemplateDefinition, ResourceTemplateReadHandler, TextResourceContent, TypedResourceTemplateDefinition, TypedResourceTemplateReadHandler } from "./shared/@outfitter/mcp-9ry52yg3.js";
|
|
5
|
+
import { CompletionHandler, CompletionRef, CompletionResult, PromptArgument, PromptDefinition, PromptHandler, PromptMessage, PromptMessageContent, PromptResult } from "./shared/@outfitter/mcp-dgwj3jna.js";
|
|
6
|
+
import { ContentAnnotations } from "./shared/@outfitter/mcp-q5hr7227.js";
|
|
2
7
|
import "./shared/@outfitter/mcp-cqpyer9m.js";
|
|
3
|
-
export { adaptHandler, ToolDefinition, ToolAnnotations, TextResourceContent, TaggedError, TOOL_ANNOTATIONS, SerializedTool, Result, ResourceTemplateReadHandler, ResourceTemplateDefinition, ResourceReadHandler, ResourceDefinition, ResourceContent, PromptResult, PromptMessageContent, PromptMessage, PromptHandler, PromptDefinition, PromptArgument, ProgressReporter, McpServerOptions, McpServer, McpHandlerContext, McpError, InvokeToolOptions, ContentAnnotations, CompletionResult, CompletionRef, CompletionHandler, BlobResourceContent };
|
|
8
|
+
export { adaptHandler, TypedResourceTemplateReadHandler, TypedResourceTemplateDefinition, ToolDefinition, ToolAnnotations, TextResourceContent, TaggedError, TOOL_ANNOTATIONS, SerializedTool, Result, ResourceTemplateReadHandler, ResourceTemplateDefinition, ResourceReadHandler, ResourceDefinition, ResourceContent, PromptResult, PromptMessageContent, PromptMessage, PromptHandler, PromptDefinition, PromptArgument, ProgressReporter, McpServerOptions, McpServer, McpHandlerContext, McpError, InvokeToolOptions, ContentAnnotations, CompletionResult, CompletionRef, CompletionHandler, BlobResourceContent };
|
package/dist/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@outfitter/mcp",
|
|
3
3
|
"description": "MCP server framework with typed tools for Outfitter",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
@@ -34,6 +34,12 @@
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"./package.json": "./package.json",
|
|
37
|
+
"./progress": {
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./dist/progress.d.ts",
|
|
40
|
+
"default": "./dist/progress.js"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
37
43
|
"./schema": {
|
|
38
44
|
"import": {
|
|
39
45
|
"types": "./dist/schema.d.ts",
|
|
@@ -59,11 +65,27 @@
|
|
|
59
65
|
}
|
|
60
66
|
}
|
|
61
67
|
},
|
|
68
|
+
"keywords": [
|
|
69
|
+
"mcp",
|
|
70
|
+
"model-context-protocol",
|
|
71
|
+
"outfitter",
|
|
72
|
+
"tools",
|
|
73
|
+
"typescript"
|
|
74
|
+
],
|
|
75
|
+
"license": "MIT",
|
|
76
|
+
"repository": {
|
|
77
|
+
"type": "git",
|
|
78
|
+
"url": "https://github.com/outfitter-dev/outfitter.git",
|
|
79
|
+
"directory": "packages/mcp"
|
|
80
|
+
},
|
|
62
81
|
"sideEffects": false,
|
|
82
|
+
"publishConfig": {
|
|
83
|
+
"access": "public"
|
|
84
|
+
},
|
|
63
85
|
"scripts": {
|
|
64
|
-
"build": "bunup --filter @outfitter/mcp",
|
|
65
|
-
"lint": "
|
|
66
|
-
"lint:fix": "
|
|
86
|
+
"build": "cd ../.. && bash ./scripts/run-bunup-with-lock.sh bunup --filter @outfitter/mcp",
|
|
87
|
+
"lint": "oxlint ./src",
|
|
88
|
+
"lint:fix": "oxlint --fix ./src",
|
|
67
89
|
"test": "bun test",
|
|
68
90
|
"typecheck": "tsc --noEmit",
|
|
69
91
|
"clean": "rm -rf dist",
|
|
@@ -73,32 +95,16 @@
|
|
|
73
95
|
"@modelcontextprotocol/sdk": "^1.12.1",
|
|
74
96
|
"zod": "^4.3.5"
|
|
75
97
|
},
|
|
98
|
+
"devDependencies": {
|
|
99
|
+
"@outfitter/config": "0.4.0",
|
|
100
|
+
"@outfitter/contracts": "0.5.0",
|
|
101
|
+
"@outfitter/logging": "0.4.3",
|
|
102
|
+
"@types/bun": "^1.3.9",
|
|
103
|
+
"typescript": "^5.9.3"
|
|
104
|
+
},
|
|
76
105
|
"peerDependencies": {
|
|
77
106
|
"@outfitter/config": ">=0.3.0",
|
|
78
107
|
"@outfitter/contracts": ">=0.2.0",
|
|
79
108
|
"@outfitter/logging": ">=0.3.0"
|
|
80
|
-
},
|
|
81
|
-
"devDependencies": {
|
|
82
|
-
"@outfitter/config": "0.3.3",
|
|
83
|
-
"@outfitter/contracts": "0.4.1",
|
|
84
|
-
"@outfitter/logging": "0.4.1",
|
|
85
|
-
"@types/bun": "latest",
|
|
86
|
-
"typescript": "^5.8.0"
|
|
87
|
-
},
|
|
88
|
-
"keywords": [
|
|
89
|
-
"outfitter",
|
|
90
|
-
"mcp",
|
|
91
|
-
"model-context-protocol",
|
|
92
|
-
"tools",
|
|
93
|
-
"typescript"
|
|
94
|
-
],
|
|
95
|
-
"license": "MIT",
|
|
96
|
-
"repository": {
|
|
97
|
-
"type": "git",
|
|
98
|
-
"url": "https://github.com/outfitter-dev/outfitter.git",
|
|
99
|
-
"directory": "packages/mcp"
|
|
100
|
-
},
|
|
101
|
-
"publishConfig": {
|
|
102
|
-
"access": "public"
|
|
103
109
|
}
|
|
104
110
|
}
|