@procedures/mcp 0.0.0-stage → 0.1.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/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +359 -2
- package/dist/.tsbuildinfo +1 -0
- package/dist/context/index.d.ts +5 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +5 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/mcp-context.d.ts +57 -0
- package/dist/context/mcp-context.d.ts.map +1 -0
- package/dist/context/mcp-context.js +40 -0
- package/dist/context/mcp-context.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/mapping/index.d.ts +6 -0
- package/dist/mapping/index.d.ts.map +1 -0
- package/dist/mapping/index.js +6 -0
- package/dist/mapping/index.js.map +1 -0
- package/dist/mapping/path-encoder.d.ts +72 -0
- package/dist/mapping/path-encoder.d.ts.map +1 -0
- package/dist/mapping/path-encoder.js +93 -0
- package/dist/mapping/path-encoder.js.map +1 -0
- package/dist/mapping/procedure-to-tool.d.ts +47 -0
- package/dist/mapping/procedure-to-tool.d.ts.map +1 -0
- package/dist/mapping/procedure-to-tool.js +163 -0
- package/dist/mapping/procedure-to-tool.js.map +1 -0
- package/dist/schema/index.d.ts +5 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +5 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/tool-schema.d.ts +77 -0
- package/dist/schema/tool-schema.d.ts.map +1 -0
- package/dist/schema/tool-schema.js +103 -0
- package/dist/schema/tool-schema.js.map +1 -0
- package/dist/schema/zod-to-json-schema.d.ts +58 -0
- package/dist/schema/zod-to-json-schema.d.ts.map +1 -0
- package/dist/schema/zod-to-json-schema.js +79 -0
- package/dist/schema/zod-to-json-schema.js.map +1 -0
- package/dist/types.d.ts +99 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +63 -3
- package/src/context/index.ts +10 -0
- package/src/context/mcp-context.ts +80 -0
- package/src/index.ts +56 -0
- package/src/mapping/index.ts +20 -0
- package/src/mapping/path-encoder.ts +103 -0
- package/src/mapping/procedure-to-tool.ts +208 -0
- package/src/schema/index.ts +15 -0
- package/src/schema/tool-schema.ts +135 -0
- package/src/types.ts +107 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path Encoder
|
|
3
|
+
*
|
|
4
|
+
* Converts procedure paths to/from MCP tool names.
|
|
5
|
+
* MCP tool names should be valid identifiers (alphanumeric with dots/underscores).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Encode a procedure path to an MCP tool name.
|
|
9
|
+
*
|
|
10
|
+
* Strategy: Join path segments with dots.
|
|
11
|
+
* Most procedure paths are already MCP-compatible (lowercase, alphanumeric).
|
|
12
|
+
*
|
|
13
|
+
* @param path - Procedure path array
|
|
14
|
+
* @returns MCP tool name string
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* encodePath(["fs", "read"]) // "fs.read"
|
|
18
|
+
* encodePath(["mongo", "collections", "list"]) // "mongo.collections.list"
|
|
19
|
+
*/
|
|
20
|
+
export function encodePath(path) {
|
|
21
|
+
return path.join(".");
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Decode an MCP tool name back to procedure path.
|
|
25
|
+
*
|
|
26
|
+
* @param toolName - MCP tool name string
|
|
27
|
+
* @returns Procedure path array
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* decodePath("fs.read") // ["fs", "read"]
|
|
31
|
+
* decodePath("mongo.collections.list") // ["mongo", "collections", "list"]
|
|
32
|
+
*/
|
|
33
|
+
export function decodePath(toolName) {
|
|
34
|
+
return toolName.split(".");
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Validate that a path segment is MCP-compatible.
|
|
38
|
+
*
|
|
39
|
+
* Valid segments:
|
|
40
|
+
* - Start with letter or underscore
|
|
41
|
+
* - Contain only letters, numbers, underscores, hyphens
|
|
42
|
+
*
|
|
43
|
+
* @param segment - Path segment to validate
|
|
44
|
+
* @returns True if segment is valid for MCP tool names
|
|
45
|
+
*/
|
|
46
|
+
export function isValidPathSegment(segment) {
|
|
47
|
+
return /^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(segment);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Validate that an entire path is MCP-compatible.
|
|
51
|
+
*
|
|
52
|
+
* @param path - Procedure path to validate
|
|
53
|
+
* @returns True if all segments are valid
|
|
54
|
+
*/
|
|
55
|
+
export function isValidPath(path) {
|
|
56
|
+
return path.length > 0 && path.every(isValidPathSegment);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Sanitize a path segment for MCP compatibility.
|
|
60
|
+
*
|
|
61
|
+
* Replaces invalid characters with underscores.
|
|
62
|
+
*
|
|
63
|
+
* @param segment - Path segment to sanitize
|
|
64
|
+
* @returns Sanitized segment
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* sanitizePathSegment("my-func") // "my-func" (valid)
|
|
68
|
+
* sanitizePathSegment("123abc") // "_123abc" (prefix if starts with number)
|
|
69
|
+
* sanitizePathSegment("my.func") // "my_func" (replace dots)
|
|
70
|
+
*/
|
|
71
|
+
export function sanitizePathSegment(segment) {
|
|
72
|
+
// Replace invalid chars with underscores
|
|
73
|
+
let sanitized = segment.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
74
|
+
// Prefix if starts with number
|
|
75
|
+
if (/^[0-9]/.test(sanitized)) {
|
|
76
|
+
sanitized = "_" + sanitized;
|
|
77
|
+
}
|
|
78
|
+
// Ensure not empty
|
|
79
|
+
if (!sanitized) {
|
|
80
|
+
sanitized = "_";
|
|
81
|
+
}
|
|
82
|
+
return sanitized;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Sanitize an entire path for MCP compatibility.
|
|
86
|
+
*
|
|
87
|
+
* @param path - Procedure path to sanitize
|
|
88
|
+
* @returns Sanitized path
|
|
89
|
+
*/
|
|
90
|
+
export function sanitizePath(path) {
|
|
91
|
+
return path.map(sanitizePathSegment);
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=path-encoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-encoder.js","sourceRoot":"","sources":["../../src/mapping/path-encoder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,UAAU,CAAC,IAAmB;IAC5C,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CAAC,QAAgB;IACzC,OAAO,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAe;IAChD,OAAO,2BAA2B,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACnD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,IAAmB;IAC7C,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAe;IACjD,yCAAyC;IACzC,IAAI,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;IAExD,+BAA+B;IAC/B,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;QAC7B,SAAS,GAAG,GAAG,GAAG,SAAS,CAAC;IAC9B,CAAC;IAED,mBAAmB;IACnB,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,SAAS,GAAG,GAAG,CAAC;IAClB,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,IAAmB;IAC9C,OAAO,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure to MCP Tool Mapper
|
|
3
|
+
*
|
|
4
|
+
* Converts procedures from PROCEDURE_REGISTRY to MCP tool definitions.
|
|
5
|
+
*/
|
|
6
|
+
import type { AnyProcedure, ProcedurePath } from "@procedures/client";
|
|
7
|
+
import type { McpTool, McpToolDefinition, McpToolFilter } from "../types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Convert a single procedure to an MCP tool definition.
|
|
10
|
+
*
|
|
11
|
+
* @param procedure - Procedure to convert
|
|
12
|
+
* @returns MCP tool with procedure metadata
|
|
13
|
+
*/
|
|
14
|
+
export declare function procedureToMcpTool(procedure: AnyProcedure): McpTool;
|
|
15
|
+
/**
|
|
16
|
+
* Convert an MCP tool to the minimal definition format (for ListToolsRequest).
|
|
17
|
+
*
|
|
18
|
+
* @param tool - Full MCP tool with metadata
|
|
19
|
+
* @returns Minimal tool definition for MCP protocol
|
|
20
|
+
*/
|
|
21
|
+
export declare function toToolDefinition(tool: McpTool): McpToolDefinition;
|
|
22
|
+
/**
|
|
23
|
+
* Convert multiple procedures to MCP tools.
|
|
24
|
+
*
|
|
25
|
+
* Filters out procedures without handlers and applies optional filters.
|
|
26
|
+
*
|
|
27
|
+
* @param procedures - Procedures to convert
|
|
28
|
+
* @param filter - Optional filter options
|
|
29
|
+
* @returns Array of MCP tools
|
|
30
|
+
*/
|
|
31
|
+
export declare function proceduresToMcpTools(procedures: AnyProcedure[], filter?: McpToolFilter): McpTool[];
|
|
32
|
+
/**
|
|
33
|
+
* Create a lookup map from tool name to MCP tool.
|
|
34
|
+
*
|
|
35
|
+
* @param tools - Array of MCP tools
|
|
36
|
+
* @returns Map for O(1) lookup by tool name
|
|
37
|
+
*/
|
|
38
|
+
export declare function createToolMap(tools: McpTool[]): Map<string, McpTool>;
|
|
39
|
+
/**
|
|
40
|
+
* Find a tool by procedure path.
|
|
41
|
+
*
|
|
42
|
+
* @param tools - Array or map of MCP tools
|
|
43
|
+
* @param path - Procedure path to find
|
|
44
|
+
* @returns Tool if found, undefined otherwise
|
|
45
|
+
*/
|
|
46
|
+
export declare function findToolByPath(tools: McpTool[] | Map<string, McpTool>, path: ProcedurePath): McpTool | undefined;
|
|
47
|
+
//# sourceMappingURL=procedure-to-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"procedure-to-tool.d.ts","sourceRoot":"","sources":["../../src/mapping/procedure-to-tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AA+B7E;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,YAAY,GAAG,OAAO,CAgCnE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,iBAAiB,CAcjE;AA2CD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,YAAY,EAAE,EAC1B,MAAM,CAAC,EAAE,aAAa,GACrB,OAAO,EAAE,CAKX;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAmBpE;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,EACvC,IAAI,EAAE,aAAa,GAClB,OAAO,GAAG,SAAS,CAUrB"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure to MCP Tool Mapper
|
|
3
|
+
*
|
|
4
|
+
* Converts procedures from PROCEDURE_REGISTRY to MCP tool definitions.
|
|
5
|
+
*/
|
|
6
|
+
import { cachedToolInputSchema, cachedToolOutputSchema } from "../schema/tool-schema.js";
|
|
7
|
+
import { encodePath, sanitizePath } from "./path-encoder.js";
|
|
8
|
+
/**
|
|
9
|
+
* Extract metadata from a procedure.
|
|
10
|
+
*/
|
|
11
|
+
function extractMetadata(procedure) {
|
|
12
|
+
const meta = procedure.metadata;
|
|
13
|
+
return {
|
|
14
|
+
description: meta?.["description"],
|
|
15
|
+
tags: meta?.["tags"],
|
|
16
|
+
internal: meta?.["internal"],
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Convert a single procedure to an MCP tool definition.
|
|
21
|
+
*
|
|
22
|
+
* @param procedure - Procedure to convert
|
|
23
|
+
* @returns MCP tool with procedure metadata
|
|
24
|
+
*/
|
|
25
|
+
export function procedureToMcpTool(procedure) {
|
|
26
|
+
// Sanitize each path segment (replacing chars outside [A-Za-z0-9_-], e.g. a
|
|
27
|
+
// literal "." inside a single segment) before dot-joining. This keeps the
|
|
28
|
+
// dot-joined shape valid segments already have (["shell","run"] -> "shell.run",
|
|
29
|
+
// which the Claude client aliases to "shell_run"), while ensuring two distinct
|
|
30
|
+
// paths that would otherwise encode to the same string no longer collide.
|
|
31
|
+
const toolName = encodePath(sanitizePath(procedure.path));
|
|
32
|
+
const cacheKey = procedure.path.join(".");
|
|
33
|
+
const meta = extractMetadata(procedure);
|
|
34
|
+
const tool = {
|
|
35
|
+
name: toolName,
|
|
36
|
+
description: meta.description ?? `Call ${cacheKey}`,
|
|
37
|
+
inputSchema: cachedToolInputSchema(procedure.input, cacheKey),
|
|
38
|
+
procedurePath: procedure.path,
|
|
39
|
+
};
|
|
40
|
+
// MCP structured output: only an output whose JSON Schema is an object
|
|
41
|
+
const outputSchema = cachedToolOutputSchema(procedure.output);
|
|
42
|
+
if (outputSchema !== undefined) {
|
|
43
|
+
tool.outputSchema = outputSchema;
|
|
44
|
+
}
|
|
45
|
+
// Only add optional properties if they have values
|
|
46
|
+
if (procedure.streaming !== undefined) {
|
|
47
|
+
tool.streaming = procedure.streaming;
|
|
48
|
+
}
|
|
49
|
+
if (meta.tags !== undefined) {
|
|
50
|
+
tool.tags = meta.tags;
|
|
51
|
+
}
|
|
52
|
+
return tool;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Convert an MCP tool to the minimal definition format (for ListToolsRequest).
|
|
56
|
+
*
|
|
57
|
+
* @param tool - Full MCP tool with metadata
|
|
58
|
+
* @returns Minimal tool definition for MCP protocol
|
|
59
|
+
*/
|
|
60
|
+
export function toToolDefinition(tool) {
|
|
61
|
+
const def = {
|
|
62
|
+
name: tool.name,
|
|
63
|
+
inputSchema: tool.inputSchema,
|
|
64
|
+
};
|
|
65
|
+
if (tool.description !== undefined) {
|
|
66
|
+
def.description = tool.description;
|
|
67
|
+
}
|
|
68
|
+
if (tool.outputSchema !== undefined) {
|
|
69
|
+
def.outputSchema = tool.outputSchema;
|
|
70
|
+
}
|
|
71
|
+
return def;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Check if a procedure matches the given filter.
|
|
75
|
+
*/
|
|
76
|
+
function matchesFilter(procedure, filter) {
|
|
77
|
+
if (!filter)
|
|
78
|
+
return true;
|
|
79
|
+
const meta = extractMetadata(procedure);
|
|
80
|
+
// Check internal filter
|
|
81
|
+
if (filter.excludeInternal !== false && meta.internal) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
// Check the include function
|
|
85
|
+
if (filter.include && !filter.include(procedure.path)) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
// Check path prefix
|
|
89
|
+
if (filter.pathPrefix) {
|
|
90
|
+
const matches = filter.pathPrefix.every((segment, i) => procedure.path[i] === segment);
|
|
91
|
+
if (!matches)
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
// Check tag inclusion
|
|
95
|
+
if (filter.includeTags?.length) {
|
|
96
|
+
const hasTags = meta.tags?.some((t) => filter.includeTags.includes(t));
|
|
97
|
+
if (!hasTags)
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
// Check tag exclusion
|
|
101
|
+
if (filter.excludeTags?.length) {
|
|
102
|
+
const hasExcludedTag = meta.tags?.some((t) => filter.excludeTags.includes(t));
|
|
103
|
+
if (hasExcludedTag)
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Convert multiple procedures to MCP tools.
|
|
110
|
+
*
|
|
111
|
+
* Filters out procedures without handlers and applies optional filters.
|
|
112
|
+
*
|
|
113
|
+
* @param procedures - Procedures to convert
|
|
114
|
+
* @param filter - Optional filter options
|
|
115
|
+
* @returns Array of MCP tools
|
|
116
|
+
*/
|
|
117
|
+
export function proceduresToMcpTools(procedures, filter) {
|
|
118
|
+
return procedures
|
|
119
|
+
.filter((p) => p.handler !== undefined)
|
|
120
|
+
.filter((p) => matchesFilter(p, filter))
|
|
121
|
+
.map(procedureToMcpTool);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Create a lookup map from tool name to MCP tool.
|
|
125
|
+
*
|
|
126
|
+
* @param tools - Array of MCP tools
|
|
127
|
+
* @returns Map for O(1) lookup by tool name
|
|
128
|
+
*/
|
|
129
|
+
export function createToolMap(tools) {
|
|
130
|
+
const map = new Map();
|
|
131
|
+
for (const tool of tools) {
|
|
132
|
+
const existing = map.get(tool.name);
|
|
133
|
+
if (existing !== undefined) {
|
|
134
|
+
// Two distinct procedure paths encoded to the same MCP tool name. The
|
|
135
|
+
// Map preserves last-wins semantics (for backward compatibility), but
|
|
136
|
+
// this silently shadowed a tool before — warn on stderr so the collision
|
|
137
|
+
// is visible. stderr is used because stdout is reserved for the MCP
|
|
138
|
+
// stdio protocol stream.
|
|
139
|
+
console.error(`[mcp] Tool-name collision: "${tool.name}" is produced by both ` +
|
|
140
|
+
`[${existing.procedurePath.join(", ")}] and ` +
|
|
141
|
+
`[${tool.procedurePath.join(", ")}]; keeping the latter (last-wins).`);
|
|
142
|
+
}
|
|
143
|
+
map.set(tool.name, tool);
|
|
144
|
+
}
|
|
145
|
+
return map;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Find a tool by procedure path.
|
|
149
|
+
*
|
|
150
|
+
* @param tools - Array or map of MCP tools
|
|
151
|
+
* @param path - Procedure path to find
|
|
152
|
+
* @returns Tool if found, undefined otherwise
|
|
153
|
+
*/
|
|
154
|
+
export function findToolByPath(tools, path) {
|
|
155
|
+
// Must match the sanitization applied in procedureToMcpTool so lookups by
|
|
156
|
+
// path resolve to the same tool name that was stored.
|
|
157
|
+
const toolName = encodePath(sanitizePath(path));
|
|
158
|
+
if (tools instanceof Map) {
|
|
159
|
+
return tools.get(toolName);
|
|
160
|
+
}
|
|
161
|
+
return tools.find((t) => t.name === toolName);
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=procedure-to-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"procedure-to-tool.js","sourceRoot":"","sources":["../../src/mapping/procedure-to-tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACzF,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAiB7D;;GAEG;AACH,SAAS,eAAe,CAAC,SAAuB;IAC9C,MAAM,IAAI,GAAG,SAAS,CAAC,QAA+C,CAAC;IACvE,OAAO;QACL,WAAW,EAAE,IAAI,EAAE,CAAC,aAAa,CAAuB;QACxD,IAAI,EAAE,IAAI,EAAE,CAAC,M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AI,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,oCAAoC,CACxE,CAAC;QACJ,CAAC;QACD,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAC5B,KAAuC,EACvC,IAAmB;IAEnB,0EAA0E;IAC1E,sDAAsD;IACtD,MAAM,QAAQ,GAAG,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;IAEhD,IAAI,KAAK,YAAY,GAAG,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema utilities exports.
|
|
3
|
+
*/
|
|
4
|
+
export { toolInputSchema, cachedToolInputSchema, toolOutputSchema, cachedToolOutputSchema, zodToJsonSchema, cachedZodToJsonSchema, clearSchemaCache, getSchemaCacheSize, type ZodToJsonSchemaOptions, } from "./tool-schema.js";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,gBAAgB,EAChB,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,sBAAsB,GAC5B,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema utilities exports.
|
|
3
|
+
*/
|
|
4
|
+
export { toolInputSchema, cachedToolInputSchema, toolOutputSchema, cachedToolOutputSchema, zodToJsonSchema, cachedZodToJsonSchema, clearSchemaCache, getSchemaCacheSize, } from "./tool-schema.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,gBAAgB,EAChB,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,GAEnB,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The input JSON Schema of an MCP tool.
|
|
3
|
+
*
|
|
4
|
+
* The JSON Schema comes from `jsonSchemaOf()` of the core, which reads any Standard Schema
|
|
5
|
+
* (zod 4 and other libraries). Before, this file converted schemas with the zod 3 library
|
|
6
|
+
* `zod-to-json-schema`, and a schema without zod 3 fields got an empty object schema.
|
|
7
|
+
*/
|
|
8
|
+
import { type ProcedureSchema } from "@procedures/client";
|
|
9
|
+
import type { JsonSchema } from "../types.js";
|
|
10
|
+
/**
|
|
11
|
+
* A schema of a procedure.
|
|
12
|
+
* @deprecated Use `ProcedureSchema` of `@procedures/client`.
|
|
13
|
+
*/
|
|
14
|
+
export interface SchemaLike {
|
|
15
|
+
parse?(data: unknown): unknown;
|
|
16
|
+
safeParse?(data: unknown): {
|
|
17
|
+
success: boolean;
|
|
18
|
+
data?: unknown;
|
|
19
|
+
error?: unknown;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Options for the conversion.
|
|
24
|
+
* @deprecated The options are not used. The core gives draft-07 JSON Schema without definitions.
|
|
25
|
+
*/
|
|
26
|
+
export interface ZodToJsonSchemaOptions {
|
|
27
|
+
/** Name for the schema (not used) */
|
|
28
|
+
name?: string;
|
|
29
|
+
/** Pre-existing definitions (not used) */
|
|
30
|
+
definitions?: Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The input JSON Schema of a tool for a procedure schema.
|
|
34
|
+
*
|
|
35
|
+
* MCP passes the arguments of a tool as an object, so an input that is not an object (a
|
|
36
|
+
* pass-through schema, a schema with no JSON Schema, a number) gives an object schema that
|
|
37
|
+
* accepts any field.
|
|
38
|
+
*/
|
|
39
|
+
export declare function toolInputSchema(schema: ProcedureSchema | unknown): JsonSchema;
|
|
40
|
+
/**
|
|
41
|
+
* The input JSON Schema of a tool.
|
|
42
|
+
* @deprecated Use `toolInputSchema` (the schema need not be zod), or `jsonSchemaOf` of
|
|
43
|
+
* `@procedures/client` for the JSON Schema of any input or output.
|
|
44
|
+
*/
|
|
45
|
+
export declare function zodToJsonSchema(schema: SchemaLike | unknown, _options?: ZodToJsonSchemaOptions): JsonSchema;
|
|
46
|
+
/**
|
|
47
|
+
* The input JSON Schema of a tool, cached by the schema object.
|
|
48
|
+
*
|
|
49
|
+
* @param schema - The input schema of the procedure
|
|
50
|
+
* @param _cacheKey - Not used any more (kept for compatibility): the schema object is the key
|
|
51
|
+
*/
|
|
52
|
+
export declare function cachedToolInputSchema(schema: ProcedureSchema | unknown, _cacheKey?: string): JsonSchema;
|
|
53
|
+
/**
|
|
54
|
+
* The output JSON Schema of a tool (MCP structured output), or `undefined`.
|
|
55
|
+
*
|
|
56
|
+
* MCP needs an object at the root of an output schema, and a client can check each structured
|
|
57
|
+
* result against it. So only an output whose JSON Schema is an object gives one: a pass-through
|
|
58
|
+
* schema, a union (a stream of items) or a number gives none, and the tool gives text only.
|
|
59
|
+
*/
|
|
60
|
+
export declare function toolOutputSchema(schema: ProcedureSchema | unknown): JsonSchema | undefined;
|
|
61
|
+
/** The output JSON Schema of a tool, cached by the schema object. */
|
|
62
|
+
export declare function cachedToolOutputSchema(schema: ProcedureSchema | unknown): JsonSchema | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* The input JSON Schema of a tool, cached.
|
|
65
|
+
* @deprecated Use `cachedToolInputSchema`.
|
|
66
|
+
*/
|
|
67
|
+
export declare function cachedZodToJsonSchema(schema: SchemaLike | unknown, cacheKey?: string): JsonSchema;
|
|
68
|
+
/**
|
|
69
|
+
* Clear the schema cache.
|
|
70
|
+
* Useful when procedures are re-registered with different schemas.
|
|
71
|
+
*/
|
|
72
|
+
export declare function clearSchemaCache(): void;
|
|
73
|
+
/**
|
|
74
|
+
* Get the current schema cache size.
|
|
75
|
+
*/
|
|
76
|
+
export declare function getSchemaCacheSize(): number;
|
|
77
|
+
//# sourceMappingURL=tool-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-schema.d.ts","sourceRoot":"","sources":["../../src/schema/tool-schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAgB,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC;IAC/B,SAAS,CAAC,CAAC,IAAI,EAAE,OAAO,GAAG;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CAClF;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,qCAAqC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACvC;AAKD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,GAAG,UAAU,CAM7E;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,EAAE,QAAQ,CAAC,EAAE,sBAAsB,GAAG,UAAU,CAE3G;AAOD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,UAAU,CAWvG;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,CAG1F;AAMD,qEAAqE;AACrE,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,CAWhG;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,UAAU,CAEjG;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAGvC;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The input JSON Schema of an MCP tool.
|
|
3
|
+
*
|
|
4
|
+
* The JSON Schema comes from `jsonSchemaOf()` of the core, which reads any Standard Schema
|
|
5
|
+
* (zod 4 and other libraries). Before, this file converted schemas with the zod 3 library
|
|
6
|
+
* `zod-to-json-schema`, and a schema without zod 3 fields got an empty object schema.
|
|
7
|
+
*/
|
|
8
|
+
import { jsonSchemaOf } from "@procedures/client";
|
|
9
|
+
/** The input schema of a tool that takes any arguments. */
|
|
10
|
+
const ANY_OBJECT = { type: "object", additionalProperties: true };
|
|
11
|
+
/**
|
|
12
|
+
* The input JSON Schema of a tool for a procedure schema.
|
|
13
|
+
*
|
|
14
|
+
* MCP passes the arguments of a tool as an object, so an input that is not an object (a
|
|
15
|
+
* pass-through schema, a schema with no JSON Schema, a number) gives an object schema that
|
|
16
|
+
* accepts any field.
|
|
17
|
+
*/
|
|
18
|
+
export function toolInputSchema(schema) {
|
|
19
|
+
const json = jsonSchemaOf(schema, { io: "input" });
|
|
20
|
+
if (json && json["type"] === "object") {
|
|
21
|
+
return json;
|
|
22
|
+
}
|
|
23
|
+
return { ...ANY_OBJECT };
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The input JSON Schema of a tool.
|
|
27
|
+
* @deprecated Use `toolInputSchema` (the schema need not be zod), or `jsonSchemaOf` of
|
|
28
|
+
* `@procedures/client` for the JSON Schema of any input or output.
|
|
29
|
+
*/
|
|
30
|
+
export function zodToJsonSchema(schema, _options) {
|
|
31
|
+
return toolInputSchema(schema);
|
|
32
|
+
}
|
|
33
|
+
// Schema cache for performance, keyed by the schema object: a procedure that is registered
|
|
34
|
+
// again with a different schema gets the new JSON Schema (BUGS-2026-07 L30: the cache was keyed
|
|
35
|
+
// by the procedure path and returned the old schema)
|
|
36
|
+
const schemaCache = new Map();
|
|
37
|
+
/**
|
|
38
|
+
* The input JSON Schema of a tool, cached by the schema object.
|
|
39
|
+
*
|
|
40
|
+
* @param schema - The input schema of the procedure
|
|
41
|
+
* @param _cacheKey - Not used any more (kept for compatibility): the schema object is the key
|
|
42
|
+
*/
|
|
43
|
+
export function cachedToolInputSchema(schema, _cacheKey) {
|
|
44
|
+
if (!schema || typeof schema !== "object") {
|
|
45
|
+
return toolInputSchema(schema);
|
|
46
|
+
}
|
|
47
|
+
const cached = schemaCache.get(schema);
|
|
48
|
+
if (cached) {
|
|
49
|
+
return cached;
|
|
50
|
+
}
|
|
51
|
+
const jsonSchema = toolInputSchema(schema);
|
|
52
|
+
schemaCache.set(schema, jsonSchema);
|
|
53
|
+
return jsonSchema;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The output JSON Schema of a tool (MCP structured output), or `undefined`.
|
|
57
|
+
*
|
|
58
|
+
* MCP needs an object at the root of an output schema, and a client can check each structured
|
|
59
|
+
* result against it. So only an output whose JSON Schema is an object gives one: a pass-through
|
|
60
|
+
* schema, a union (a stream of items) or a number gives none, and the tool gives text only.
|
|
61
|
+
*/
|
|
62
|
+
export function toolOutputSchema(schema) {
|
|
63
|
+
const json = jsonSchemaOf(schema, { io: "output" });
|
|
64
|
+
return json && json["type"] === "object" ? json : undefined;
|
|
65
|
+
}
|
|
66
|
+
// The output schemas, cached by the schema object like the input schemas. `null` keeps "no
|
|
67
|
+
// output schema", so the check runs once for each schema.
|
|
68
|
+
const outputSchemaCache = new Map();
|
|
69
|
+
/** The output JSON Schema of a tool, cached by the schema object. */
|
|
70
|
+
export function cachedToolOutputSchema(schema) {
|
|
71
|
+
if (!schema || typeof schema !== "object") {
|
|
72
|
+
return toolOutputSchema(schema);
|
|
73
|
+
}
|
|
74
|
+
const cached = outputSchemaCache.get(schema);
|
|
75
|
+
if (cached !== undefined) {
|
|
76
|
+
return cached ?? undefined;
|
|
77
|
+
}
|
|
78
|
+
const jsonSchema = toolOutputSchema(schema);
|
|
79
|
+
outputSchemaCache.set(schema, jsonSchema ?? null);
|
|
80
|
+
return jsonSchema;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The input JSON Schema of a tool, cached.
|
|
84
|
+
* @deprecated Use `cachedToolInputSchema`.
|
|
85
|
+
*/
|
|
86
|
+
export function cachedZodToJsonSchema(schema, cacheKey) {
|
|
87
|
+
return cachedToolInputSchema(schema, cacheKey);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Clear the schema cache.
|
|
91
|
+
* Useful when procedures are re-registered with different schemas.
|
|
92
|
+
*/
|
|
93
|
+
export function clearSchemaCache() {
|
|
94
|
+
schemaCache.clear();
|
|
95
|
+
outputSchemaCache.clear();
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get the current schema cache size.
|
|
99
|
+
*/
|
|
100
|
+
export function getSchemaCacheSize() {
|
|
101
|
+
return schemaCache.size;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=tool-schema.js.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AW,CAAC,IAAI,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod to JSON Schema Converter
|
|
3
|
+
*
|
|
4
|
+
* Converts Zod schemas to JSON Schema format for MCP tool inputSchema.
|
|
5
|
+
* Uses zod-to-json-schema with caching for performance.
|
|
6
|
+
*/
|
|
7
|
+
import type { JsonSchema } from "../types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Schema interface compatible with Zod.
|
|
10
|
+
* Allows the system to work without direct Zod dependency.
|
|
11
|
+
*/
|
|
12
|
+
export interface SchemaLike {
|
|
13
|
+
parse?(data: unknown): unknown;
|
|
14
|
+
safeParse?(data: unknown): {
|
|
15
|
+
success: boolean;
|
|
16
|
+
data?: unknown;
|
|
17
|
+
error?: unknown;
|
|
18
|
+
};
|
|
19
|
+
_def?: unknown;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Options for Zod to JSON Schema conversion.
|
|
23
|
+
*/
|
|
24
|
+
export interface ZodToJsonSchemaOptions {
|
|
25
|
+
/** Name for the schema (used in definitions) */
|
|
26
|
+
name?: string;
|
|
27
|
+
/** Pre-existing definitions to include */
|
|
28
|
+
definitions?: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Convert a schema to JSON Schema.
|
|
32
|
+
*
|
|
33
|
+
* Uses zod-to-json-schema library for actual Zod schemas,
|
|
34
|
+
* with safe fallbacks for non-Zod implementations.
|
|
35
|
+
*
|
|
36
|
+
* @param schema - Schema to convert (Zod or ZodLike)
|
|
37
|
+
* @param options - Conversion options
|
|
38
|
+
* @returns JSON Schema representation
|
|
39
|
+
*/
|
|
40
|
+
export declare function zodToJsonSchema(schema: SchemaLike | unknown, options?: ZodToJsonSchemaOptions): JsonSchema;
|
|
41
|
+
/**
|
|
42
|
+
* Convert a schema to JSON Schema with caching.
|
|
43
|
+
*
|
|
44
|
+
* @param schema - Schema to convert (Zod or ZodLike)
|
|
45
|
+
* @param _cacheKey - Not used any more (kept for compatibility): the schema object is the key
|
|
46
|
+
* @returns Cached or freshly converted JSON Schema
|
|
47
|
+
*/
|
|
48
|
+
export declare function cachedZodToJsonSchema(schema: SchemaLike | unknown, _cacheKey?: string): JsonSchema;
|
|
49
|
+
/**
|
|
50
|
+
* Clear the schema cache.
|
|
51
|
+
* Useful when procedures are re-registered with different schemas.
|
|
52
|
+
*/
|
|
53
|
+
export declare function clearSchemaCache(): void;
|
|
54
|
+
/**
|
|
55
|
+
* Get the current schema cache size.
|
|
56
|
+
*/
|
|
57
|
+
export declare function getSchemaCacheSize(): number;
|
|
58
|
+
//# sourceMappingURL=zod-to-json-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod-to-json-schema.d.ts","sourceRoot":"","sources":["../../src/schema/zod-to-json-schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC;IAC/B,SAAS,CAAC,CAAC,IAAI,EAAE,OAAO,GAAG;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IACjF,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,gDAAgD;IAChD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACvC;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,UAAU,GAAG,OAAO,EAC5B,OAAO,CAAC,EAAE,sBAAsB,GAC/B,UAAU,CA0BZ;AAOD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,UAAU,GAAG,OAAO,EAC5B,SAAS,CAAC,EAAE,MAAM,GACjB,UAAU,CAaZ;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C"}
|