@procedures/mcp-server 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 +366 -2
- package/dist/.tsbuildinfo +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/module.d.ts +11 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +16 -0
- package/dist/module.js.map +1 -0
- package/dist/procedures/mcp/index.d.ts +6 -0
- package/dist/procedures/mcp/index.d.ts.map +1 -0
- package/dist/procedures/mcp/index.js +6 -0
- package/dist/procedures/mcp/index.js.map +1 -0
- package/dist/procedures/mcp/list-tools.d.ts +8 -0
- package/dist/procedures/mcp/list-tools.d.ts.map +1 -0
- package/dist/procedures/mcp/list-tools.js +60 -0
- package/dist/procedures/mcp/list-tools.js.map +1 -0
- package/dist/procedures/mcp/serve.d.ts +38 -0
- package/dist/procedures/mcp/serve.d.ts.map +1 -0
- package/dist/procedures/mcp/serve.js +123 -0
- package/dist/procedures/mcp/serve.js.map +1 -0
- package/dist/register.d.ts +11 -0
- package/dist/register.d.ts.map +1 -0
- package/dist/register.js +21 -0
- package/dist/register.js.map +1 -0
- package/dist/surface.d.ts +36 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +74 -0
- package/dist/surface.js.map +1 -0
- package/dist/transport/index.d.ts +7 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +7 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/mcp-transport.d.ts +94 -0
- package/dist/transport/mcp-transport.d.ts.map +1 -0
- package/dist/transport/mcp-transport.js +368 -0
- package/dist/transport/mcp-transport.js.map +1 -0
- package/dist/transport/sse.d.ts +20 -0
- package/dist/transport/sse.d.ts.map +1 -0
- package/dist/transport/sse.js +23 -0
- package/dist/transport/sse.js.map +1 -0
- package/dist/transport/stdio.d.ts +16 -0
- package/dist/transport/stdio.d.ts.map +1 -0
- package/dist/transport/stdio.js +18 -0
- package/dist/transport/stdio.js.map +1 -0
- package/dist/types.d.ts +55 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +81 -3
- package/src/index.ts +48 -0
- package/src/module.ts +18 -0
- package/src/procedures/mcp/index.ts +6 -0
- package/src/procedures/mcp/list-tools.ts +84 -0
- package/src/procedures/mcp/serve.ts +170 -0
- package/src/register.ts +24 -0
- package/src/surface.ts +85 -0
- package/src/transport/index.ts +7 -0
- package/src/transport/mcp-transport.ts +418 -0
- package/src/transport/sse.ts +29 -0
- package/src/transport/stdio.ts +19 -0
- package/src/types.ts +64 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-tools.js","sourceRoot":"","sources":["../../../src/procedures/mcp/list-tools.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAqB,MAAM,oBAAoB,CAAC;AAC5F,OAAO,EAAE,oBAAoB,EAAsB,MAAM,iBAAiB,CAAC;AAE3E,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,8CAA8C;IAC9C,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,yCAAyC,CAAC;IAC/F,yCAAyC;IACzC,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,oCAAoC,CAAC;IAC1F,kDAAkD;IAClD,eAAe,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC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,UAAU,EAAE,MAAM,CAAC,CAAC;QAE1D,MAAM,KAAK,GAAkB,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACnD,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,IAAI,EAAE,IAAI,CAAC,aAAa;YACxB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC,CAAC,CAAC;QAEJ,OAAO;YACL,KAAK;YACL,KAAK,EAAE,KAAK,CAAC,MAAM;SACpB,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mcp.serve Procedure
|
|
3
|
+
*
|
|
4
|
+
* Start MCP server to expose procedures as tools.
|
|
5
|
+
*
|
|
6
|
+
* Which procedures are tools is a security decision. Before, `mcp.serve` exposed every
|
|
7
|
+
* procedure of the registry, `shell.exec` too (deep dive, architecture review 3.2). Now the tools
|
|
8
|
+
* come from `namespaces`/`exclude`, or from the `mcpNamespaces`/`mcpExclude` of the bundles
|
|
9
|
+
* (default: `@procedures/bundle-mcp`, resolved from the current folder). Without a list,
|
|
10
|
+
* nothing is exposed. The nested calls follow the call policy (`strictCalls`), and each tool call
|
|
11
|
+
* has a time limit.
|
|
12
|
+
*/
|
|
13
|
+
import { ProcedureServer, type AnyProcedure, type ProcedurePath } from "@procedures/client";
|
|
14
|
+
/** The default bundle of the tool surface. */
|
|
15
|
+
export declare const DEFAULT_SERVE_BUNDLE = "@procedures/bundle-mcp";
|
|
16
|
+
/** The options of `prepareServe`: the tool surface and the rules of the server. */
|
|
17
|
+
export interface ServeOptions {
|
|
18
|
+
autoRegister?: boolean | undefined;
|
|
19
|
+
namespaces?: readonly string[] | undefined;
|
|
20
|
+
exclude?: readonly string[] | undefined;
|
|
21
|
+
bundles?: readonly string[] | undefined;
|
|
22
|
+
strictCalls?: boolean | undefined;
|
|
23
|
+
toolTimeoutMs?: number | undefined;
|
|
24
|
+
}
|
|
25
|
+
/** The server of `mcp.serve`, before its transport starts. */
|
|
26
|
+
export interface ServeSetup {
|
|
27
|
+
server: ProcedureServer;
|
|
28
|
+
expose: (path: ProcedurePath) => boolean;
|
|
29
|
+
/** Why the server has no tools, when it has none. */
|
|
30
|
+
warning?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* This function builds the procedure server of `mcp.serve`: its expose rule, its call policy and
|
|
34
|
+
* its interceptors. The bundles resolve from `from` (default: the current folder).
|
|
35
|
+
*/
|
|
36
|
+
export declare function prepareServe(input: ServeOptions, from?: string): Promise<ServeSetup>;
|
|
37
|
+
export declare const mcpServeProcedure: AnyProcedure;
|
|
38
|
+
//# sourceMappingURL=serve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../../src/procedures/mcp/serve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAEL,eAAe,EAGf,KAAK,YAAY,EACjB,KAAK,aAAa,EACnB,MAAM,oBAAoB,CAAC;AAK5B,8CAA8C;AAC9C,eAAO,MAAM,oBAAoB,2BAA2B,CAAC;AA+C7D,mFAAmF;AACnF,MAAM,WAAW,YAAY;IAC3B,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACnC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IAC3C,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IACxC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IACxC,WAAW,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAClC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACpC;AAED,8DAA8D;AAC9D,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,eAAe,CAAC;IACxB,MAAM,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,OAAO,CAAC;IACzC,qDAAqD;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,GAAE,MAAsB,GAAG,OAAO,CAAC,UAAU,CAAC,CA6BzG;AAED,eAAO,MAAM,iBAAiB,EAAE,YA0C9B,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mcp.serve Procedure
|
|
3
|
+
*
|
|
4
|
+
* Start MCP server to expose procedures as tools.
|
|
5
|
+
*
|
|
6
|
+
* Which procedures are tools is a security decision. Before, `mcp.serve` exposed every
|
|
7
|
+
* procedure of the registry, `shell.exec` too (deep dive, architecture review 3.2). Now the tools
|
|
8
|
+
* come from `namespaces`/`exclude`, or from the `mcpNamespaces`/`mcpExclude` of the bundles
|
|
9
|
+
* (default: `@procedures/bundle-mcp`, resolved from the current folder). Without a list,
|
|
10
|
+
* nothing is exposed. The nested calls follow the call policy (`strictCalls`), and each tool call
|
|
11
|
+
* has a time limit.
|
|
12
|
+
*/
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
import { defineProcedure, ProcedureServer, PROCEDURE_REGISTRY, timeoutInterceptor, } from "@procedures/client";
|
|
15
|
+
import { McpServerTransport } from "../../transport/mcp-transport.js";
|
|
16
|
+
import { exposeRule, importBundles, mergeSurfaces } from "../../surface.js";
|
|
17
|
+
/** The default bundle of the tool surface. */
|
|
18
|
+
export const DEFAULT_SERVE_BUNDLE = "@procedures/bundle-mcp";
|
|
19
|
+
const McpServeInputSchema = z.object({
|
|
20
|
+
/**
|
|
21
|
+
* Transport type (default: "stdio"). Only stdio is implemented: the SSE transport needs an
|
|
22
|
+
* HTTP server integration, and accepting "sse" here only led to an error (BUGS-2026-07 L28).
|
|
23
|
+
*/
|
|
24
|
+
transport: z.enum(["stdio"]).default("stdio").describe("Transport type (default: \"stdio\"). Only stdio is implemented: the SSE transport needs an HTTP server integration, and accepting \"sse\" here only led to an error (BUGS-2026-07 L28)."),
|
|
25
|
+
/** Server name for MCP (default: "procedure-server") */
|
|
26
|
+
name: z.string().optional().describe("Server name for MCP (default: \"procedure-server\")"),
|
|
27
|
+
/** Server version for MCP (default: "1.0.0") */
|
|
28
|
+
version: z.string().optional().describe("Server version for MCP (default: \"1.0.0\")"),
|
|
29
|
+
/** Whether to auto-register all procedures (default: true) */
|
|
30
|
+
autoRegister: z.boolean().default(true).describe("Whether to auto-register all procedures (default: true)"),
|
|
31
|
+
/** Enable debug logging */
|
|
32
|
+
debug: z.boolean().default(false).describe("Enable debug logging"),
|
|
33
|
+
/** The namespaces (first path segments) of the tools. With this list, the bundles give no tools. */
|
|
34
|
+
namespaces: z.array(z.string()).optional().describe("The namespaces (first path segments) of the tools. With this list, the bundles give no tools."),
|
|
35
|
+
/** Procedure keys of the tool namespaces that are not tools. */
|
|
36
|
+
exclude: z.array(z.string()).optional().describe("Procedure keys of the tool namespaces that are not tools."),
|
|
37
|
+
/** The bundles whose mcpNamespaces and mcpExclude give the tools, when `namespaces` is not given. */
|
|
38
|
+
bundles: z.array(z.string()).optional().describe("The bundles whose mcpNamespaces and mcpExclude give the tools, when `namespaces` is not given."),
|
|
39
|
+
/** True (the default): a procedure of code without metadata.calls can call only tools. */
|
|
40
|
+
strictCalls: z.boolean().default(true).describe("True (the default): a procedure of code without metadata.calls can call only tools."),
|
|
41
|
+
/** The time limit of each tool call, in milliseconds (default: 600000). 0: no limit. */
|
|
42
|
+
toolTimeoutMs: z.number().int().min(0).default(600_000).describe("The time limit of each tool call, in milliseconds (default: 600000). 0: no limit."),
|
|
43
|
+
});
|
|
44
|
+
const McpServeOutputSchema = {
|
|
45
|
+
parse: (data) => data,
|
|
46
|
+
safeParse: (data) => ({ success: true, data: data }),
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* This function builds the procedure server of `mcp.serve`: its expose rule, its call policy and
|
|
50
|
+
* its interceptors. The bundles resolve from `from` (default: the current folder).
|
|
51
|
+
*/
|
|
52
|
+
export async function prepareServe(input, from = process.cwd()) {
|
|
53
|
+
let expose = () => false;
|
|
54
|
+
let warning;
|
|
55
|
+
if (input.namespaces) {
|
|
56
|
+
expose = exposeRule({ namespaces: input.namespaces, exclude: input.exclude });
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const bundles = input.bundles ?? [DEFAULT_SERVE_BUNDLE];
|
|
60
|
+
try {
|
|
61
|
+
const surface = mergeSurfaces(await importBundles(bundles, from));
|
|
62
|
+
if (surface) {
|
|
63
|
+
expose = exposeRule({ namespaces: surface.namespaces, exclude: [...(surface.exclude ?? []), ...(input.exclude ?? [])] });
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
warning = `The bundles ${bundles.join(", ")} give no mcpNamespaces, so no procedure is a tool. Give namespaces.`;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
warning =
|
|
71
|
+
`The bundles ${bundles.join(", ")} cannot be loaded from ${from} (${error.message}), ` +
|
|
72
|
+
`so no procedure is a tool. Give namespaces, or run in a project that has the bundles.`;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const server = new ProcedureServer({
|
|
76
|
+
autoRegister: input.autoRegister ?? true,
|
|
77
|
+
registry: PROCEDURE_REGISTRY,
|
|
78
|
+
expose,
|
|
79
|
+
strictCalls: input.strictCalls ?? true,
|
|
80
|
+
interceptors: [timeoutInterceptor({ ms: input.toolTimeoutMs ?? 600_000 })],
|
|
81
|
+
});
|
|
82
|
+
return warning === undefined ? { server, expose } : { server, expose, warning };
|
|
83
|
+
}
|
|
84
|
+
export const mcpServeProcedure = defineProcedure({
|
|
85
|
+
path: ["mcp", "serve"],
|
|
86
|
+
input: McpServeInputSchema,
|
|
87
|
+
output: McpServeOutputSchema,
|
|
88
|
+
metadata: {
|
|
89
|
+
description: "Start MCP server to expose procedures as tools",
|
|
90
|
+
tags: ["mcp", "server"],
|
|
91
|
+
},
|
|
92
|
+
handler: async (input) => {
|
|
93
|
+
const serverName = input.name ?? "procedure-server";
|
|
94
|
+
const serverVersion = input.version ?? "1.0.0";
|
|
95
|
+
const { server, expose, warning } = await prepareServe(input);
|
|
96
|
+
// Build transport options
|
|
97
|
+
const options = {
|
|
98
|
+
transport: input.transport,
|
|
99
|
+
serverInfo: {
|
|
100
|
+
name: serverName,
|
|
101
|
+
version: serverVersion,
|
|
102
|
+
},
|
|
103
|
+
debug: input.debug,
|
|
104
|
+
toolFilter: { include: expose },
|
|
105
|
+
};
|
|
106
|
+
// Create MCP transport
|
|
107
|
+
const mcpTransport = new McpServerTransport(server, options);
|
|
108
|
+
// Add transport and start
|
|
109
|
+
server.addTransport(mcpTransport);
|
|
110
|
+
await server.start();
|
|
111
|
+
const state = mcpTransport.getState();
|
|
112
|
+
if (warning)
|
|
113
|
+
console.error(`[mcp.serve] ${warning}`);
|
|
114
|
+
return {
|
|
115
|
+
success: true,
|
|
116
|
+
transport: input.transport,
|
|
117
|
+
toolCount: state.toolCount,
|
|
118
|
+
serverName,
|
|
119
|
+
...(warning ? { warning } : {}),
|
|
120
|
+
};
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
//# sourceMappingURL=serve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../../../src/procedures/mcp/serve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,kBAAkB,GAGnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAEtE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAE5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AE,OAAO,EAAE,GAAG,MAAM,YAAY,CAAC,KAAK,CAAC,CAAC;QAE9D,0BAA0B;QAC1B,MAAM,OAAO,GAA8B;YACzC,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,UAAU,EAAE;gBACV,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,aAAa;aACvB;YACD,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,UAAU,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE;SAChC,CAAC;QAEF,uBAAuB;QACvB,MAAM,YAAY,GAAG,IAAI,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAE7D,0BAA0B;QAC1B,MAAM,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QAClC,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QAErB,MAAM,KAAK,GAAG,YAAY,CAAC,QAAQ,EAAE,CAAC;QACtC,IAAI,OAAO;YAAE,OAAO,CAAC,KAAK,CAAC,eAAe,OAAO,EAAE,CAAC,CAAC;QAErD,OAAO;YACL,OAAO,EAAE,IAAI;YACb,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,UAAU;YACV,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChC,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing this file registers the MCP procedures in the global registry (DECISIONS-2026-10,
|
|
3
|
+
* "Every package root registers its procedures"). The procedures as data are in `module.ts`,
|
|
4
|
+
* which registers nothing: a host with its own registry uses that one.
|
|
5
|
+
*/
|
|
6
|
+
export * from "./module.js";
|
|
7
|
+
/**
|
|
8
|
+
* Register all MCP procedures.
|
|
9
|
+
*/
|
|
10
|
+
export declare function registerMcpProcedures(): void;
|
|
11
|
+
//# sourceMappingURL=register.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,cAAc,aAAa,CAAC;AAE5B;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAM5C"}
|
package/dist/register.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing this file registers the MCP procedures in the global registry (DECISIONS-2026-10,
|
|
3
|
+
* "Every package root registers its procedures"). The procedures as data are in `module.ts`,
|
|
4
|
+
* which registers nothing: a host with its own registry uses that one.
|
|
5
|
+
*/
|
|
6
|
+
import { PROCEDURE_REGISTRY } from "@procedures/client";
|
|
7
|
+
import { mcpModule } from "./module.js";
|
|
8
|
+
export * from "./module.js";
|
|
9
|
+
/**
|
|
10
|
+
* Register all MCP procedures.
|
|
11
|
+
*/
|
|
12
|
+
export function registerMcpProcedures() {
|
|
13
|
+
for (const proc of mcpModule.procedures) {
|
|
14
|
+
if (!PROCEDURE_REGISTRY.has(proc.path)) {
|
|
15
|
+
PROCEDURE_REGISTRY.register(proc);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
// Auto-register when this module is imported
|
|
20
|
+
registerMcpProcedures();
|
|
21
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,cAAc,aAAa,CAAC;AAE5B;;GAEG;AACH,MAAM,UAAU,qBAAqB;IACnC,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,UAAU,EAAE,CAAC;QACxC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACvC,kBAAkB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;AACH,CAAC;AAED,6CAA6C;AAC7C,qBAAqB,EAAE,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tool surface of an MCP server: which procedures are tools.
|
|
3
|
+
*
|
|
4
|
+
* A bundle (for example `@procedures/bundle-mcp`) registers procedures when it is imported.
|
|
5
|
+
* Its `register.js` exports `mcpNamespaces` (the first path segments of the tools) and
|
|
6
|
+
* `mcpExclude` (procedure keys of those namespaces that are not tools). The dev-tools server
|
|
7
|
+
* (`impl-mcp-dev`) and `mcp.serve` build their expose rule from these lists.
|
|
8
|
+
*/
|
|
9
|
+
import { type ProcedurePath, type ToolSurface } from "@procedures/client";
|
|
10
|
+
/** The tools of a server: the namespaces, less the excluded procedure keys (the core type). */
|
|
11
|
+
export type { ToolSurface };
|
|
12
|
+
/** The exports of a bundle's `register.js` that describe its tools. */
|
|
13
|
+
export interface BundleSurfaceModule {
|
|
14
|
+
mcpNamespaces?: readonly string[];
|
|
15
|
+
mcpExclude?: readonly string[];
|
|
16
|
+
}
|
|
17
|
+
/** The expose rule of a tool surface: `surfaceRule()` of the core host policy (roadmap 2.3). */
|
|
18
|
+
export declare function exposeRule(surface: ToolSurface): (path: ProcedurePath) => boolean;
|
|
19
|
+
/**
|
|
20
|
+
* The union of the surfaces of some bundles. Undefined when no bundle has `mcpNamespaces`: such
|
|
21
|
+
* bundles say nothing about their tools.
|
|
22
|
+
*/
|
|
23
|
+
export declare function mergeSurfaces(modules: readonly BundleSurfaceModule[]): ToolSurface | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* The file URL of a bundle's `register.js`, found in the `node_modules` folders from `from`
|
|
26
|
+
* upward. The bundle's `exports` map gives the file. (`require.resolve` cannot do it: a bundle
|
|
27
|
+
* exports `register.js` for `import` only.)
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolveBundleRegister(bundle: string, from: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* This function imports the `register.js` of each bundle, which registers its procedures, and
|
|
32
|
+
* returns the modules. With `from`, a bundle resolves from that folder (a project), not from
|
|
33
|
+
* this package.
|
|
34
|
+
*/
|
|
35
|
+
export declare function importBundles(bundles: readonly string[], from?: string): Promise<BundleSurfaceModule[]>;
|
|
36
|
+
//# sourceMappingURL=surface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"surface.d.ts","sourceRoot":"","sources":["../src/surface.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,EAAe,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEvF,+FAA+F;AAC/F,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B,uEAAuE;AACvE,MAAM,WAAW,mBAAmB;IAClC,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAChC;AAED,gGAAgG;AAChG,wBAAgB,UAAU,CAAC,OAAO,EAAE,WAAW,GAAG,CAAC,IAAI,EAAE,aAAa,KAAK,OAAO,CAEjF;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,SAAS,mBAAmB,EAAE,GAAG,WAAW,GAAG,SAAS,CAW9F;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAoB1E;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAO7G"}
|
package/dist/surface.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tool surface of an MCP server: which procedures are tools.
|
|
3
|
+
*
|
|
4
|
+
* A bundle (for example `@procedures/bundle-mcp`) registers procedures when it is imported.
|
|
5
|
+
* Its `register.js` exports `mcpNamespaces` (the first path segments of the tools) and
|
|
6
|
+
* `mcpExclude` (procedure keys of those namespaces that are not tools). The dev-tools server
|
|
7
|
+
* (`impl-mcp-dev`) and `mcp.serve` build their expose rule from these lists.
|
|
8
|
+
*/
|
|
9
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
10
|
+
import { dirname, join, resolve } from "node:path";
|
|
11
|
+
import { pathToFileURL } from "node:url";
|
|
12
|
+
import { surfaceRule } from "@procedures/client";
|
|
13
|
+
/** The expose rule of a tool surface: `surfaceRule()` of the core host policy (roadmap 2.3). */
|
|
14
|
+
export function exposeRule(surface) {
|
|
15
|
+
return surfaceRule(surface);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The union of the surfaces of some bundles. Undefined when no bundle has `mcpNamespaces`: such
|
|
19
|
+
* bundles say nothing about their tools.
|
|
20
|
+
*/
|
|
21
|
+
export function mergeSurfaces(modules) {
|
|
22
|
+
let namespaces;
|
|
23
|
+
const exclude = new Set();
|
|
24
|
+
for (const module of modules) {
|
|
25
|
+
if (Array.isArray(module.mcpNamespaces)) {
|
|
26
|
+
namespaces ??= new Set();
|
|
27
|
+
for (const namespace of module.mcpNamespaces)
|
|
28
|
+
namespaces.add(namespace);
|
|
29
|
+
}
|
|
30
|
+
for (const key of module.mcpExclude ?? [])
|
|
31
|
+
exclude.add(key);
|
|
32
|
+
}
|
|
33
|
+
return namespaces ? { namespaces: [...namespaces].sort(), exclude: [...exclude].sort() } : undefined;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The file URL of a bundle's `register.js`, found in the `node_modules` folders from `from`
|
|
37
|
+
* upward. The bundle's `exports` map gives the file. (`require.resolve` cannot do it: a bundle
|
|
38
|
+
* exports `register.js` for `import` only.)
|
|
39
|
+
*/
|
|
40
|
+
export function resolveBundleRegister(bundle, from) {
|
|
41
|
+
let dir = resolve(from);
|
|
42
|
+
for (;;) {
|
|
43
|
+
const folder = join(dir, "node_modules", ...bundle.split("/"));
|
|
44
|
+
const manifestPath = join(folder, "package.json");
|
|
45
|
+
if (existsSync(manifestPath)) {
|
|
46
|
+
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
47
|
+
const entry = manifest.exports?.["./register.js"];
|
|
48
|
+
const target = typeof entry === "string"
|
|
49
|
+
? entry
|
|
50
|
+
: (entry?.import ??
|
|
51
|
+
entry?.default ??
|
|
52
|
+
"./dist/register.js");
|
|
53
|
+
return pathToFileURL(join(folder, target)).href;
|
|
54
|
+
}
|
|
55
|
+
const parent = dirname(dir);
|
|
56
|
+
if (parent === dir)
|
|
57
|
+
throw new Error(`Cannot find ${bundle} from ${from}`);
|
|
58
|
+
dir = parent;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* This function imports the `register.js` of each bundle, which registers its procedures, and
|
|
63
|
+
* returns the modules. With `from`, a bundle resolves from that folder (a project), not from
|
|
64
|
+
* this package.
|
|
65
|
+
*/
|
|
66
|
+
export async function importBundles(bundles, from) {
|
|
67
|
+
const modules = [];
|
|
68
|
+
for (const bundle of bundles) {
|
|
69
|
+
const target = from ? resolveBundleRegister(bundle, from) : `${bundle}/register.js`;
|
|
70
|
+
modules.push((await import(target)));
|
|
71
|
+
}
|
|
72
|
+
return modules;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=surface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"surface.js","sourceRoot":"","sources":["../src/surface.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OA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MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Server Transport
|
|
3
|
+
*
|
|
4
|
+
* Implements ServerTransport interface for MCP protocol.
|
|
5
|
+
* Maps PROCEDURE_REGISTRY to MCP tools.
|
|
6
|
+
*/
|
|
7
|
+
import type { ServerTransport, Server } from "@procedures/client";
|
|
8
|
+
import { type McpTool } from "@procedures/mcp";
|
|
9
|
+
import type { McpServerTransportOptions, McpServerTransportState } from "../types.js";
|
|
10
|
+
/**
|
|
11
|
+
* MCP Server Transport
|
|
12
|
+
*
|
|
13
|
+
* Implements the ServerTransport interface for MCP (Model Context Protocol).
|
|
14
|
+
* Maps procedures from PROCEDURE_REGISTRY to MCP tools, handling:
|
|
15
|
+
* - ListToolsRequest: Returns all registered procedures as tools
|
|
16
|
+
* - CallToolRequest: Executes the corresponding procedure
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const server = new ProcedureServer({ autoRegister: true });
|
|
21
|
+
* const mcpTransport = new McpServerTransport(server, {
|
|
22
|
+
* transport: "stdio",
|
|
23
|
+
* serverInfo: { name: "my-server", version: "1.0.0" }
|
|
24
|
+
* });
|
|
25
|
+
* server.addTransport(mcpTransport);
|
|
26
|
+
* await server.start();
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare class McpServerTransport implements ServerTransport {
|
|
30
|
+
readonly name = "mcp";
|
|
31
|
+
private mcpServer;
|
|
32
|
+
private server;
|
|
33
|
+
private registry;
|
|
34
|
+
private options;
|
|
35
|
+
private running;
|
|
36
|
+
private tools;
|
|
37
|
+
private registerListener;
|
|
38
|
+
private unregisterListener;
|
|
39
|
+
/** A pending list_changed notification: a burst of registrations sends one */
|
|
40
|
+
private listChangedTimer;
|
|
41
|
+
constructor(server: Server, options?: McpServerTransportOptions);
|
|
42
|
+
/**
|
|
43
|
+
* Setup MCP request handlers.
|
|
44
|
+
*/
|
|
45
|
+
private setupHandlers;
|
|
46
|
+
/**
|
|
47
|
+
* Setup registry event listeners for dynamic tool updates.
|
|
48
|
+
*/
|
|
49
|
+
/**
|
|
50
|
+
* The result of a streaming procedure. An MCP tool result is one message, so the transport
|
|
51
|
+
* reads the whole stream. Each item becomes a text block (the last MAX_STREAM_BLOCKS items),
|
|
52
|
+
* and a progress notification when the caller sent a progress token, so a client can show
|
|
53
|
+
* the items while the stream runs.
|
|
54
|
+
*/
|
|
55
|
+
private streamResult;
|
|
56
|
+
private setupRegistryListeners;
|
|
57
|
+
/**
|
|
58
|
+
* Remove the registry event listeners, if attached.
|
|
59
|
+
*/
|
|
60
|
+
private removeRegistryListeners;
|
|
61
|
+
/**
|
|
62
|
+
* Refresh the tool list from the registry.
|
|
63
|
+
*/
|
|
64
|
+
private refreshTools;
|
|
65
|
+
/** The tool names and descriptions: a change of this text is a change of the tool list. */
|
|
66
|
+
private toolSignature;
|
|
67
|
+
/** Send one notifications/tools/list_changed for a burst of registry events. */
|
|
68
|
+
private scheduleListChanged;
|
|
69
|
+
/**
|
|
70
|
+
* Log a debug message if debug mode is enabled.
|
|
71
|
+
*/
|
|
72
|
+
private log;
|
|
73
|
+
/**
|
|
74
|
+
* Start the MCP transport.
|
|
75
|
+
*/
|
|
76
|
+
start(): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Stop the MCP transport.
|
|
79
|
+
*/
|
|
80
|
+
stop(): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Check if the transport is running.
|
|
83
|
+
*/
|
|
84
|
+
isRunning(): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Get current transport state.
|
|
87
|
+
*/
|
|
88
|
+
getState(): McpServerTransportState;
|
|
89
|
+
/**
|
|
90
|
+
* Get the list of available tools.
|
|
91
|
+
*/
|
|
92
|
+
getTools(): McpTool[];
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=mcp-transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-transport.d.ts","sourceRoot":"","sources":["../../src/transport/mcp-transport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,EAAqB,MAAM,oBAAoB,CAAC;AAErF,OAAO,EAIL,KAAK,OAAO,EACb,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAiCtF;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,kBAAmB,YAAW,eAAe;IACxD,QAAQ,CAAC,IAAI,SAAS;IAEtB,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAoB;IACpC,OAAO,CAAC,OAAO,CACa;IAC5B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,KAAK,CAAmC;IAChD,OAAO,CAAC,gBAAgB,CAA6C;IACrE,OAAO,CAAC,kBAAkB,CAA6C;IACvE,8EAA8E;IAC9E,OAAO,CAAC,gBAAgB,CAA4C;IAEpE,YAAY,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,yBAA8B,EA8BlE;IAED;;OAEG;IACH,OAAO,CAAC,aAAa;IAsFrB;;OAEG;IACH;;;;;OAKG;YACW,YAAY;IAoC1B,OAAO,CAAC,s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