@outfitter/mcp 0.2.0 → 0.4.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 +179 -5
- package/dist/actions.d.ts +4 -0
- package/dist/actions.js +11 -0
- package/dist/core-tools.d.ts +4 -0
- package/dist/core-tools.js +13 -0
- package/dist/index.d.ts +140 -28
- package/dist/index.js +158 -51
- package/dist/logging.d.ts +2 -0
- package/dist/logging.js +9 -0
- package/dist/schema.d.ts +2 -0
- package/dist/schema.js +7 -0
- package/dist/server.d.ts +4 -0
- package/dist/server.js +18 -0
- package/dist/shared/@outfitter/mcp-2vqyt1fj.d.ts +104 -0
- package/dist/shared/@outfitter/mcp-9m5hs2z0.js +49 -0
- package/dist/shared/@outfitter/mcp-9whem1wr.js +28 -0
- package/dist/shared/@outfitter/mcp-a0cgfsnw.d.ts +8 -0
- package/dist/shared/@outfitter/mcp-cqpyer9m.d.ts +27 -0
- package/dist/shared/@outfitter/mcp-dwd800vf.d.ts +96 -0
- package/dist/shared/@outfitter/mcp-f91wbr49.js +341 -0
- package/dist/shared/@outfitter/mcp-fjtxsa0x.js +36 -0
- package/dist/shared/@outfitter/mcp-h2twz77x.d.ts +699 -0
- package/dist/shared/@outfitter/mcp-jk0ka9hw.d.ts +30 -0
- package/dist/shared/@outfitter/mcp-k8r6kefr.js +538 -0
- package/dist/shared/@outfitter/mcp-mzky3ck8.js +165 -0
- package/dist/shared/@outfitter/mcp-s80bqcsb.d.ts +60 -0
- package/dist/shared/@outfitter/mcp-zv3ej45k.js +143 -0
- package/dist/transport.d.ts +4 -0
- package/dist/transport.js +13 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.js +13 -0
- package/package.json +43 -7
package/dist/index.js
CHANGED
|
@@ -2,7 +2,46 @@
|
|
|
2
2
|
import { DEFAULT_REGISTRY_SURFACES } from "@outfitter/contracts";
|
|
3
3
|
|
|
4
4
|
// src/server.ts
|
|
5
|
+
import { getEnvironment, getEnvironmentDefaults } from "@outfitter/config";
|
|
5
6
|
import { generateRequestId, Result } from "@outfitter/contracts";
|
|
7
|
+
import {
|
|
8
|
+
createOutfitterLoggerFactory,
|
|
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
|
+
}
|
|
6
45
|
|
|
7
46
|
// src/schema.ts
|
|
8
47
|
function zodToJsonSchema(schema) {
|
|
@@ -349,33 +388,116 @@ import {
|
|
|
349
388
|
} from "@outfitter/contracts";
|
|
350
389
|
import { TaggedError } from "@outfitter/contracts";
|
|
351
390
|
var TaggedError2 = TaggedErrorImpl;
|
|
391
|
+
var TOOL_ANNOTATIONS = {
|
|
392
|
+
readOnly: {
|
|
393
|
+
readOnlyHint: true,
|
|
394
|
+
destructiveHint: false,
|
|
395
|
+
idempotentHint: true,
|
|
396
|
+
openWorldHint: false
|
|
397
|
+
},
|
|
398
|
+
write: {
|
|
399
|
+
readOnlyHint: false,
|
|
400
|
+
destructiveHint: false,
|
|
401
|
+
idempotentHint: false,
|
|
402
|
+
openWorldHint: false
|
|
403
|
+
},
|
|
404
|
+
writeIdempotent: {
|
|
405
|
+
readOnlyHint: false,
|
|
406
|
+
destructiveHint: false,
|
|
407
|
+
idempotentHint: true,
|
|
408
|
+
openWorldHint: false
|
|
409
|
+
},
|
|
410
|
+
destructive: {
|
|
411
|
+
readOnlyHint: false,
|
|
412
|
+
destructiveHint: true,
|
|
413
|
+
idempotentHint: true,
|
|
414
|
+
openWorldHint: false
|
|
415
|
+
},
|
|
416
|
+
openWorld: {
|
|
417
|
+
readOnlyHint: false,
|
|
418
|
+
destructiveHint: false,
|
|
419
|
+
idempotentHint: false,
|
|
420
|
+
openWorldHint: true
|
|
421
|
+
}
|
|
422
|
+
};
|
|
352
423
|
var McpErrorBase = TaggedError2("McpError")();
|
|
353
424
|
|
|
354
425
|
class McpError extends McpErrorBase {
|
|
355
426
|
category = "internal";
|
|
356
427
|
}
|
|
428
|
+
function adaptHandler(handler) {
|
|
429
|
+
return handler;
|
|
430
|
+
}
|
|
357
431
|
|
|
358
432
|
// src/server.ts
|
|
359
|
-
|
|
433
|
+
var VALID_MCP_LOG_LEVELS = new Set([
|
|
434
|
+
"debug",
|
|
435
|
+
"info",
|
|
436
|
+
"notice",
|
|
437
|
+
"warning",
|
|
438
|
+
"error",
|
|
439
|
+
"critical",
|
|
440
|
+
"alert",
|
|
441
|
+
"emergency"
|
|
442
|
+
]);
|
|
443
|
+
var DEFAULTS_TO_MCP = {
|
|
444
|
+
debug: "debug",
|
|
445
|
+
info: "info",
|
|
446
|
+
warn: "warning",
|
|
447
|
+
error: "error"
|
|
448
|
+
};
|
|
449
|
+
function createDefaultMcpSink() {
|
|
450
|
+
const formatter = createPrettyFormatter({ colors: false });
|
|
360
451
|
return {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
452
|
+
formatter,
|
|
453
|
+
write(record, formatted) {
|
|
454
|
+
const serialized = formatted ?? formatter.format(record);
|
|
455
|
+
const line = serialized.endsWith(`
|
|
456
|
+
`) ? serialized : `${serialized}
|
|
457
|
+
`;
|
|
458
|
+
if (typeof process !== "undefined" && process.stderr?.write) {
|
|
459
|
+
process.stderr.write(line);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
368
462
|
};
|
|
369
463
|
}
|
|
464
|
+
function resolveDefaultLogLevel(options) {
|
|
465
|
+
const envLogLevel = process.env["OUTFITTER_LOG_LEVEL"];
|
|
466
|
+
if (envLogLevel !== undefined && VALID_MCP_LOG_LEVELS.has(envLogLevel)) {
|
|
467
|
+
return envLogLevel;
|
|
468
|
+
}
|
|
469
|
+
if (options.defaultLogLevel !== undefined && (options.defaultLogLevel === null || VALID_MCP_LOG_LEVELS.has(options.defaultLogLevel))) {
|
|
470
|
+
return options.defaultLogLevel;
|
|
471
|
+
}
|
|
472
|
+
const env = getEnvironment();
|
|
473
|
+
const defaults = getEnvironmentDefaults(env);
|
|
474
|
+
if (defaults.logLevel !== null) {
|
|
475
|
+
const mapped = DEFAULTS_TO_MCP[defaults.logLevel];
|
|
476
|
+
if (mapped !== undefined) {
|
|
477
|
+
return mapped;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
return null;
|
|
481
|
+
}
|
|
370
482
|
function createMcpServer(options) {
|
|
371
483
|
const { name, version, logger: providedLogger } = options;
|
|
372
|
-
|
|
484
|
+
let loggerFactory = null;
|
|
485
|
+
const logger = providedLogger ?? (() => {
|
|
486
|
+
loggerFactory = createOutfitterLoggerFactory({
|
|
487
|
+
defaults: { sinks: [createDefaultMcpSink()] }
|
|
488
|
+
});
|
|
489
|
+
return loggerFactory.createLogger({
|
|
490
|
+
name: "mcp",
|
|
491
|
+
context: { serverName: name, serverVersion: version, surface: "mcp" }
|
|
492
|
+
});
|
|
493
|
+
})();
|
|
373
494
|
const tools = new Map;
|
|
374
495
|
const resources = new Map;
|
|
375
496
|
const resourceTemplates = new Map;
|
|
376
497
|
const prompts = new Map;
|
|
377
498
|
let sdkServer = null;
|
|
378
499
|
const subscriptions = new Set;
|
|
500
|
+
let clientLogLevel = resolveDefaultLogLevel(options);
|
|
379
501
|
function createHandlerContext(toolName, requestId, signal, progressToken) {
|
|
380
502
|
const ctx = {
|
|
381
503
|
requestId,
|
|
@@ -752,10 +874,25 @@ function createMcpServer(options) {
|
|
|
752
874
|
sdkServer?.sendPromptListChanged?.();
|
|
753
875
|
},
|
|
754
876
|
setLogLevel(level) {
|
|
877
|
+
clientLogLevel = level;
|
|
755
878
|
logger.debug("Client log level set", { level });
|
|
756
879
|
},
|
|
880
|
+
sendLogMessage(level, data, loggerName) {
|
|
881
|
+
if (!sdkServer || clientLogLevel === null || !shouldEmitLog(level, clientLogLevel)) {
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
const params = {
|
|
885
|
+
level,
|
|
886
|
+
data
|
|
887
|
+
};
|
|
888
|
+
if (loggerName !== undefined) {
|
|
889
|
+
params.logger = loggerName;
|
|
890
|
+
}
|
|
891
|
+
sdkServer.sendLoggingMessage?.(params);
|
|
892
|
+
},
|
|
757
893
|
bindSdkServer(server2) {
|
|
758
894
|
sdkServer = server2;
|
|
895
|
+
clientLogLevel = resolveDefaultLogLevel(options);
|
|
759
896
|
logger.debug("SDK server bound for notifications");
|
|
760
897
|
},
|
|
761
898
|
async start() {
|
|
@@ -763,6 +900,9 @@ function createMcpServer(options) {
|
|
|
763
900
|
},
|
|
764
901
|
async stop() {
|
|
765
902
|
logger.info("MCP server stopping", { name, version });
|
|
903
|
+
if (loggerFactory !== null) {
|
|
904
|
+
await loggerFactory.flush();
|
|
905
|
+
}
|
|
766
906
|
}
|
|
767
907
|
};
|
|
768
908
|
return server;
|
|
@@ -969,39 +1109,6 @@ function createCoreTools(options = {}) {
|
|
|
969
1109
|
defineQueryTool(options.query)
|
|
970
1110
|
];
|
|
971
1111
|
}
|
|
972
|
-
// src/logging.ts
|
|
973
|
-
var MCP_LEVEL_ORDER = [
|
|
974
|
-
"debug",
|
|
975
|
-
"info",
|
|
976
|
-
"notice",
|
|
977
|
-
"warning",
|
|
978
|
-
"error",
|
|
979
|
-
"critical",
|
|
980
|
-
"alert",
|
|
981
|
-
"emergency"
|
|
982
|
-
];
|
|
983
|
-
function mapLogLevelToMcp(level) {
|
|
984
|
-
switch (level) {
|
|
985
|
-
case "trace":
|
|
986
|
-
case "debug":
|
|
987
|
-
return "debug";
|
|
988
|
-
case "info":
|
|
989
|
-
return "info";
|
|
990
|
-
case "warn":
|
|
991
|
-
return "warning";
|
|
992
|
-
case "error":
|
|
993
|
-
return "error";
|
|
994
|
-
case "fatal":
|
|
995
|
-
return "emergency";
|
|
996
|
-
default: {
|
|
997
|
-
const _exhaustiveCheck = level;
|
|
998
|
-
return _exhaustiveCheck;
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
function shouldEmitLog(messageLevel, threshold) {
|
|
1003
|
-
return MCP_LEVEL_ORDER.indexOf(messageLevel) >= MCP_LEVEL_ORDER.indexOf(threshold);
|
|
1004
|
-
}
|
|
1005
1112
|
// src/transport.ts
|
|
1006
1113
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
1007
1114
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
@@ -1079,16 +1186,12 @@ function toSdkError(error) {
|
|
|
1079
1186
|
}
|
|
1080
1187
|
function createSdkServer(server) {
|
|
1081
1188
|
const capabilities = {
|
|
1082
|
-
tools: { listChanged: true }
|
|
1189
|
+
tools: { listChanged: true },
|
|
1190
|
+
resources: { listChanged: true, subscribe: true },
|
|
1191
|
+
prompts: { listChanged: true },
|
|
1192
|
+
completions: {},
|
|
1193
|
+
logging: {}
|
|
1083
1194
|
};
|
|
1084
|
-
if (server.getResources().length > 0 || server.getResourceTemplates().length > 0) {
|
|
1085
|
-
capabilities["resources"] = { listChanged: true, subscribe: true };
|
|
1086
|
-
}
|
|
1087
|
-
if (server.getPrompts().length > 0) {
|
|
1088
|
-
capabilities["prompts"] = { listChanged: true };
|
|
1089
|
-
}
|
|
1090
|
-
capabilities["completions"] = {};
|
|
1091
|
-
capabilities["logging"] = {};
|
|
1092
1195
|
const sdkServer = new Server({ name: server.name, version: server.version }, { capabilities });
|
|
1093
1196
|
sdkServer.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
1094
1197
|
tools: server.getTools()
|
|
@@ -1170,6 +1273,8 @@ async function connectStdio(server, transport = new StdioServerTransport) {
|
|
|
1170
1273
|
}
|
|
1171
1274
|
export {
|
|
1172
1275
|
zodToJsonSchema,
|
|
1276
|
+
wrapToolResult,
|
|
1277
|
+
wrapToolError,
|
|
1173
1278
|
shouldEmitLog,
|
|
1174
1279
|
mapLogLevelToMcp,
|
|
1175
1280
|
defineTool,
|
|
@@ -1184,5 +1289,7 @@ export {
|
|
|
1184
1289
|
createCoreTools,
|
|
1185
1290
|
connectStdio,
|
|
1186
1291
|
buildMcpTools,
|
|
1292
|
+
adaptHandler,
|
|
1293
|
+
TOOL_ANNOTATIONS,
|
|
1187
1294
|
McpError
|
|
1188
1295
|
};
|
package/dist/logging.js
ADDED
package/dist/schema.d.ts
ADDED
package/dist/schema.js
ADDED
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { createMcpServer, definePrompt, defineResource, defineResourceTemplate, defineTool } from "./shared/@outfitter/mcp-2vqyt1fj";
|
|
2
|
+
import "./shared/@outfitter/mcp-h2twz77x";
|
|
3
|
+
import "./shared/@outfitter/mcp-cqpyer9m";
|
|
4
|
+
export { defineTool, defineResourceTemplate, defineResource, definePrompt, createMcpServer };
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
createMcpServer,
|
|
4
|
+
definePrompt,
|
|
5
|
+
defineResource,
|
|
6
|
+
defineResourceTemplate,
|
|
7
|
+
defineTool
|
|
8
|
+
} from "./shared/@outfitter/mcp-k8r6kefr.js";
|
|
9
|
+
import"./shared/@outfitter/mcp-fjtxsa0x.js";
|
|
10
|
+
import"./shared/@outfitter/mcp-9m5hs2z0.js";
|
|
11
|
+
import"./shared/@outfitter/mcp-f91wbr49.js";
|
|
12
|
+
export {
|
|
13
|
+
defineTool,
|
|
14
|
+
defineResourceTemplate,
|
|
15
|
+
defineResource,
|
|
16
|
+
definePrompt,
|
|
17
|
+
createMcpServer
|
|
18
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { McpServer, McpServerOptions, PromptDefinition, ResourceDefinition, ResourceTemplateDefinition, ToolDefinition } from "./mcp-h2twz77x";
|
|
2
|
+
import { OutfitterError } from "@outfitter/contracts";
|
|
3
|
+
/**
|
|
4
|
+
* Create an MCP server instance.
|
|
5
|
+
*
|
|
6
|
+
* The server provides:
|
|
7
|
+
* - Tool registration with Zod schema validation
|
|
8
|
+
* - Resource registration
|
|
9
|
+
* - Tool invocation with Result-based error handling
|
|
10
|
+
* - Automatic error translation from OutfitterError to McpError
|
|
11
|
+
*
|
|
12
|
+
* @param options - Server configuration options
|
|
13
|
+
* @returns Configured McpServer instance
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const server = createMcpServer({
|
|
18
|
+
* name: "calculator",
|
|
19
|
+
* version: "1.0.0",
|
|
20
|
+
* logger: createLogger({ name: "mcp" }),
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* server.registerTool(defineTool({
|
|
24
|
+
* name: "add",
|
|
25
|
+
* description: "Add two numbers",
|
|
26
|
+
* inputSchema: z.object({ a: z.number(), b: z.number() }),
|
|
27
|
+
* handler: async (input) => Result.ok({ sum: input.a + input.b }),
|
|
28
|
+
* }));
|
|
29
|
+
*
|
|
30
|
+
* const result = await server.invokeTool("add", { a: 2, b: 3 });
|
|
31
|
+
* if (result.isOk()) {
|
|
32
|
+
* console.log(result.value.sum); // 5
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare function createMcpServer(options: McpServerOptions): McpServer;
|
|
37
|
+
/**
|
|
38
|
+
* Define a typed tool.
|
|
39
|
+
*
|
|
40
|
+
* This is a helper function that provides better type inference
|
|
41
|
+
* when creating tool definitions.
|
|
42
|
+
*
|
|
43
|
+
* @param definition - Tool definition object
|
|
44
|
+
* @returns The same tool definition with inferred types
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const echoTool = defineTool({
|
|
49
|
+
* name: "echo",
|
|
50
|
+
* description: "Echo the input message",
|
|
51
|
+
* inputSchema: z.object({ message: z.string() }),
|
|
52
|
+
* handler: async (input, ctx) => {
|
|
53
|
+
* ctx.logger.debug("Echoing message");
|
|
54
|
+
* return Result.ok({ echo: input.message });
|
|
55
|
+
* },
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
declare function defineTool<
|
|
60
|
+
TInput,
|
|
61
|
+
TOutput,
|
|
62
|
+
TError extends OutfitterError = OutfitterError
|
|
63
|
+
>(definition: ToolDefinition<TInput, TOutput, TError>): ToolDefinition<TInput, TOutput, TError>;
|
|
64
|
+
/**
|
|
65
|
+
* Define a resource.
|
|
66
|
+
*
|
|
67
|
+
* This is a helper function for creating resource definitions
|
|
68
|
+
* with consistent typing.
|
|
69
|
+
*
|
|
70
|
+
* @param definition - Resource definition object
|
|
71
|
+
* @returns The same resource definition
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const configResource = defineResource({
|
|
76
|
+
* uri: "file:///etc/app/config.json",
|
|
77
|
+
* name: "Application Config",
|
|
78
|
+
* description: "Main configuration file",
|
|
79
|
+
* mimeType: "application/json",
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
declare function defineResource(definition: ResourceDefinition): ResourceDefinition;
|
|
84
|
+
/**
|
|
85
|
+
* Define a resource template.
|
|
86
|
+
*
|
|
87
|
+
* Helper function for creating resource template definitions
|
|
88
|
+
* with URI pattern matching.
|
|
89
|
+
*
|
|
90
|
+
* @param definition - Resource template definition object
|
|
91
|
+
* @returns The same resource template definition
|
|
92
|
+
*/
|
|
93
|
+
declare function defineResourceTemplate(definition: ResourceTemplateDefinition): ResourceTemplateDefinition;
|
|
94
|
+
/**
|
|
95
|
+
* Define a prompt.
|
|
96
|
+
*
|
|
97
|
+
* Helper function for creating prompt definitions
|
|
98
|
+
* with consistent typing.
|
|
99
|
+
*
|
|
100
|
+
* @param definition - Prompt definition object
|
|
101
|
+
* @returns The same prompt definition
|
|
102
|
+
*/
|
|
103
|
+
declare function definePrompt(definition: PromptDefinition): PromptDefinition;
|
|
104
|
+
export { createMcpServer, defineTool, defineResource, defineResourceTemplate, definePrompt };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/mcp/src/types.ts
|
|
3
|
+
import {
|
|
4
|
+
TaggedError as TaggedErrorImpl
|
|
5
|
+
} from "@outfitter/contracts";
|
|
6
|
+
import { TaggedError } from "@outfitter/contracts";
|
|
7
|
+
var TaggedError2 = TaggedErrorImpl;
|
|
8
|
+
var TOOL_ANNOTATIONS = {
|
|
9
|
+
readOnly: {
|
|
10
|
+
readOnlyHint: true,
|
|
11
|
+
destructiveHint: false,
|
|
12
|
+
idempotentHint: true,
|
|
13
|
+
openWorldHint: false
|
|
14
|
+
},
|
|
15
|
+
write: {
|
|
16
|
+
readOnlyHint: false,
|
|
17
|
+
destructiveHint: false,
|
|
18
|
+
idempotentHint: false,
|
|
19
|
+
openWorldHint: false
|
|
20
|
+
},
|
|
21
|
+
writeIdempotent: {
|
|
22
|
+
readOnlyHint: false,
|
|
23
|
+
destructiveHint: false,
|
|
24
|
+
idempotentHint: true,
|
|
25
|
+
openWorldHint: false
|
|
26
|
+
},
|
|
27
|
+
destructive: {
|
|
28
|
+
readOnlyHint: false,
|
|
29
|
+
destructiveHint: true,
|
|
30
|
+
idempotentHint: true,
|
|
31
|
+
openWorldHint: false
|
|
32
|
+
},
|
|
33
|
+
openWorld: {
|
|
34
|
+
readOnlyHint: false,
|
|
35
|
+
destructiveHint: false,
|
|
36
|
+
idempotentHint: false,
|
|
37
|
+
openWorldHint: true
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var McpErrorBase = TaggedError2("McpError")();
|
|
41
|
+
|
|
42
|
+
class McpError extends McpErrorBase {
|
|
43
|
+
category = "internal";
|
|
44
|
+
}
|
|
45
|
+
function adaptHandler(handler) {
|
|
46
|
+
return handler;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { TOOL_ANNOTATIONS, McpError, adaptHandler, TaggedError };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
defineTool
|
|
4
|
+
} from "./mcp-k8r6kefr.js";
|
|
5
|
+
|
|
6
|
+
// packages/mcp/src/actions.ts
|
|
7
|
+
import { DEFAULT_REGISTRY_SURFACES } from "@outfitter/contracts";
|
|
8
|
+
function isActionRegistry(source) {
|
|
9
|
+
return "list" in source;
|
|
10
|
+
}
|
|
11
|
+
function buildMcpTools(source, options = {}) {
|
|
12
|
+
const actions = isActionRegistry(source) ? source.list() : source;
|
|
13
|
+
const includeSurfaces = options.includeSurfaces ?? [
|
|
14
|
+
"mcp"
|
|
15
|
+
];
|
|
16
|
+
return actions.filter((action) => {
|
|
17
|
+
const surfaces = action.surfaces ?? DEFAULT_REGISTRY_SURFACES;
|
|
18
|
+
return surfaces.some((surface) => includeSurfaces.includes(surface));
|
|
19
|
+
}).map((action) => defineTool({
|
|
20
|
+
name: action.mcp?.tool ?? action.id,
|
|
21
|
+
description: action.mcp?.description ?? action.description ?? action.id,
|
|
22
|
+
inputSchema: action.input,
|
|
23
|
+
handler: async (input, ctx) => action.handler(input, ctx),
|
|
24
|
+
...action.mcp?.deferLoading !== undefined ? { deferLoading: action.mcp.deferLoading } : {}
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { buildMcpTools };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ToolDefinition } from "./mcp-h2twz77x";
|
|
2
|
+
import { ActionRegistry, ActionSurface, AnyActionSpec } from "@outfitter/contracts";
|
|
3
|
+
interface BuildMcpToolsOptions {
|
|
4
|
+
readonly includeSurfaces?: readonly ActionSurface[];
|
|
5
|
+
}
|
|
6
|
+
type ActionSource = ActionRegistry | readonly AnyActionSpec[];
|
|
7
|
+
declare function buildMcpTools(source: ActionSource, options?: BuildMcpToolsOptions): ToolDefinition<unknown, unknown>[];
|
|
8
|
+
export { BuildMcpToolsOptions, buildMcpTools };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @outfitter/mcp - Logging Bridge
|
|
3
|
+
*
|
|
4
|
+
* Maps Outfitter log levels to MCP log levels for
|
|
5
|
+
* server-to-client log message notifications.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* MCP log levels as defined in the MCP specification.
|
|
11
|
+
* Ordered from least to most severe.
|
|
12
|
+
*/
|
|
13
|
+
type McpLogLevel = "debug" | "info" | "notice" | "warning" | "error" | "critical" | "alert" | "emergency";
|
|
14
|
+
/**
|
|
15
|
+
* Outfitter log levels.
|
|
16
|
+
*/
|
|
17
|
+
type OutfitterLogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal";
|
|
18
|
+
/**
|
|
19
|
+
* Map an Outfitter log level to the corresponding MCP log level.
|
|
20
|
+
*/
|
|
21
|
+
declare function mapLogLevelToMcp(level: OutfitterLogLevel): McpLogLevel;
|
|
22
|
+
/**
|
|
23
|
+
* Check whether a message at the given level should be emitted
|
|
24
|
+
* based on the client-requested threshold.
|
|
25
|
+
*/
|
|
26
|
+
declare function shouldEmitLog(messageLevel: McpLogLevel, threshold: McpLogLevel): boolean;
|
|
27
|
+
export { McpLogLevel, mapLogLevelToMcp, shouldEmitLog };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { ToolDefinition } from "./mcp-h2twz77x";
|
|
2
|
+
import { HandlerContext, OutfitterError } from "@outfitter/contracts";
|
|
3
|
+
import { Result } from "@outfitter/contracts";
|
|
4
|
+
type DocsSection = "overview" | "tools" | "examples" | "schemas";
|
|
5
|
+
interface DocsToolInput {
|
|
6
|
+
section?: DocsSection | undefined;
|
|
7
|
+
}
|
|
8
|
+
interface DocsToolEntry {
|
|
9
|
+
name: string;
|
|
10
|
+
summary?: string;
|
|
11
|
+
examples?: Array<{
|
|
12
|
+
input: Record<string, unknown>;
|
|
13
|
+
description?: string;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
interface DocsToolResponse {
|
|
17
|
+
overview?: string;
|
|
18
|
+
tools?: DocsToolEntry[];
|
|
19
|
+
examples?: Array<{
|
|
20
|
+
name?: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
input?: Record<string, unknown>;
|
|
23
|
+
output?: unknown;
|
|
24
|
+
}>;
|
|
25
|
+
schemas?: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
interface DocsToolOptions {
|
|
28
|
+
/** Optional override for the docs tool description. */
|
|
29
|
+
description?: string;
|
|
30
|
+
/** Static docs payload (used when getDocs is not provided). */
|
|
31
|
+
docs?: DocsToolResponse;
|
|
32
|
+
/** Dynamic docs provider. */
|
|
33
|
+
getDocs?: (section?: DocsSection) => DocsToolResponse | Promise<DocsToolResponse>;
|
|
34
|
+
}
|
|
35
|
+
declare function defineDocsTool(options?: DocsToolOptions): ToolDefinition<DocsToolInput, DocsToolResponse>;
|
|
36
|
+
type ConfigAction = "get" | "set" | "list";
|
|
37
|
+
interface ConfigToolInput {
|
|
38
|
+
action: ConfigAction;
|
|
39
|
+
key?: string | undefined;
|
|
40
|
+
value?: unknown | undefined;
|
|
41
|
+
}
|
|
42
|
+
interface ConfigToolResponse {
|
|
43
|
+
action: ConfigAction;
|
|
44
|
+
key?: string;
|
|
45
|
+
value?: unknown;
|
|
46
|
+
found?: boolean;
|
|
47
|
+
config?: Record<string, unknown>;
|
|
48
|
+
}
|
|
49
|
+
interface ConfigStore {
|
|
50
|
+
get(key: string): {
|
|
51
|
+
value: unknown;
|
|
52
|
+
found: boolean;
|
|
53
|
+
} | Promise<{
|
|
54
|
+
value: unknown;
|
|
55
|
+
found: boolean;
|
|
56
|
+
}>;
|
|
57
|
+
set(key: string, value: unknown): void | Promise<void>;
|
|
58
|
+
list(): Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
59
|
+
}
|
|
60
|
+
interface ConfigToolOptions {
|
|
61
|
+
/** Optional override for the config tool description. */
|
|
62
|
+
description?: string;
|
|
63
|
+
/** Initial config values when using the default in-memory store. */
|
|
64
|
+
initial?: Record<string, unknown>;
|
|
65
|
+
/** Custom config store implementation. */
|
|
66
|
+
store?: ConfigStore;
|
|
67
|
+
}
|
|
68
|
+
declare function defineConfigTool(options?: ConfigToolOptions): ToolDefinition<ConfigToolInput, ConfigToolResponse>;
|
|
69
|
+
interface QueryToolInput {
|
|
70
|
+
q?: string | undefined;
|
|
71
|
+
query?: string | undefined;
|
|
72
|
+
limit?: number | undefined;
|
|
73
|
+
cursor?: string | undefined;
|
|
74
|
+
filters?: Record<string, unknown> | undefined;
|
|
75
|
+
}
|
|
76
|
+
interface QueryToolResponse<T = unknown> {
|
|
77
|
+
results: T[];
|
|
78
|
+
nextCursor?: string;
|
|
79
|
+
_meta?: Record<string, unknown>;
|
|
80
|
+
}
|
|
81
|
+
interface QueryToolOptions<T = unknown> {
|
|
82
|
+
/** Optional override for the query tool description. */
|
|
83
|
+
description?: string;
|
|
84
|
+
/** Custom query handler implementation. */
|
|
85
|
+
handler?: (input: NormalizedQueryInput, ctx: HandlerContext) => Promise<Result<QueryToolResponse<T>, OutfitterError>>;
|
|
86
|
+
}
|
|
87
|
+
declare function defineQueryTool<T = unknown>(options?: QueryToolOptions<T>): ToolDefinition<QueryToolInput, QueryToolResponse<T>>;
|
|
88
|
+
interface CoreToolsOptions {
|
|
89
|
+
docs?: DocsToolOptions;
|
|
90
|
+
config?: ConfigToolOptions;
|
|
91
|
+
query?: QueryToolOptions;
|
|
92
|
+
}
|
|
93
|
+
type NormalizedQueryInput = Required<Pick<QueryToolInput, "q">> & Omit<QueryToolInput, "q">;
|
|
94
|
+
type CoreToolDefinition = ToolDefinition<DocsToolInput, DocsToolResponse> | ToolDefinition<ConfigToolInput, ConfigToolResponse> | ToolDefinition<QueryToolInput, QueryToolResponse>;
|
|
95
|
+
declare function createCoreTools(options?: CoreToolsOptions): CoreToolDefinition[];
|
|
96
|
+
export { DocsSection, DocsToolInput, DocsToolEntry, DocsToolResponse, DocsToolOptions, defineDocsTool, ConfigAction, ConfigToolInput, ConfigToolResponse, ConfigStore, ConfigToolOptions, defineConfigTool, QueryToolInput, QueryToolResponse, QueryToolOptions, defineQueryTool, CoreToolsOptions, NormalizedQueryInput, CoreToolDefinition, createCoreTools };
|