@ontrails/mcp 1.0.0-beta.14 → 1.0.0-beta.16
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 +41 -0
- package/README.md +36 -17
- package/package.json +11 -3
- package/src/annotations.ts +4 -1
- package/src/build.ts +689 -127
- package/src/index.ts +14 -4
- package/src/stdio.ts +1 -1
- package/src/surface.ts +215 -0
- package/.turbo/turbo-build.log +0 -1
- package/.turbo/turbo-lint.log +0 -3
- package/.turbo/turbo-typecheck.log +0 -1
- package/dist/annotations.d.ts +0 -19
- package/dist/annotations.d.ts.map +0 -1
- package/dist/annotations.js +0 -31
- package/dist/annotations.js.map +0 -1
- package/dist/blaze.d.ts +0 -41
- package/dist/blaze.d.ts.map +0 -1
- package/dist/blaze.js +0 -108
- package/dist/blaze.js.map +0 -1
- package/dist/build.d.ts +0 -48
- package/dist/build.d.ts.map +0 -1
- package/dist/build.js +0 -229
- package/dist/build.js.map +0 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -13
- package/dist/index.js.map +0 -1
- package/dist/progress.d.ts +0 -13
- package/dist/progress.d.ts.map +0 -1
- package/dist/progress.js +0 -51
- package/dist/progress.js.map +0 -1
- package/dist/stdio.d.ts +0 -12
- package/dist/stdio.d.ts.map +0 -1
- package/dist/stdio.js +0 -15
- package/dist/stdio.js.map +0 -1
- package/dist/tool-name.d.ts +0 -15
- package/dist/tool-name.d.ts.map +0 -1
- package/dist/tool-name.js +0 -19
- package/dist/tool-name.js.map +0 -1
- package/dist/trailhead.d.ts +0 -41
- package/dist/trailhead.d.ts.map +0 -1
- package/dist/trailhead.js +0 -109
- package/dist/trailhead.js.map +0 -1
- package/src/__tests__/annotations.test.ts +0 -63
- package/src/__tests__/build.test.ts +0 -529
- package/src/__tests__/progress.test.ts +0 -136
- package/src/__tests__/tool-name.test.ts +0 -46
- package/src/__tests__/trailhead.test.ts +0 -158
- package/src/trailhead.ts +0 -173
- package/tsconfig.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
package/src/index.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
// Build
|
|
2
2
|
export {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
MCP_TOOL_ERROR_META_KEY,
|
|
4
|
+
MCP_TOOL_EXAMPLES_META_KEY,
|
|
5
|
+
deriveMcpTools,
|
|
6
|
+
type DeriveMcpToolsOptions,
|
|
5
7
|
type McpToolDefinition,
|
|
6
8
|
type McpToolResult,
|
|
9
|
+
type McpToolErrorMeta,
|
|
7
10
|
type McpContent,
|
|
8
11
|
type McpExtra,
|
|
12
|
+
type ResolveMcpPermit,
|
|
13
|
+
type ResolveMcpPermitInput,
|
|
9
14
|
} from './build.js';
|
|
10
15
|
|
|
11
16
|
// Tool naming
|
|
@@ -17,8 +22,13 @@ export { deriveAnnotations, type McpAnnotations } from './annotations.js';
|
|
|
17
22
|
// Progress
|
|
18
23
|
export { createMcpProgressCallback } from './progress.js';
|
|
19
24
|
|
|
20
|
-
//
|
|
21
|
-
export {
|
|
25
|
+
// Surface
|
|
26
|
+
export {
|
|
27
|
+
createServer,
|
|
28
|
+
surface,
|
|
29
|
+
type CreateServerOptions,
|
|
30
|
+
type SurfaceMcpResult,
|
|
31
|
+
} from './surface.js';
|
|
22
32
|
|
|
23
33
|
// Transport
|
|
24
34
|
export { connectStdio } from './stdio.js';
|
package/src/stdio.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Thin wrapper around MCP SDK's StdioServerTransport.
|
|
3
3
|
*
|
|
4
4
|
* Exists as a separate function so it can be swapped for other transports
|
|
5
|
-
* (SSE, streamable HTTP) without changing
|
|
5
|
+
* (SSE, streamable HTTP) without changing surface().
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import type { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
package/src/surface.ts
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Surface helpers for exposing a topo over MCP.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
6
|
+
import {
|
|
7
|
+
CallToolRequestSchema,
|
|
8
|
+
ListToolsRequestSchema,
|
|
9
|
+
} from '@modelcontextprotocol/sdk/types.js';
|
|
10
|
+
import type {
|
|
11
|
+
BaseSurfaceOptions,
|
|
12
|
+
Layer,
|
|
13
|
+
ResourceOverrideMap,
|
|
14
|
+
Topo,
|
|
15
|
+
TrailContextInit,
|
|
16
|
+
} from '@ontrails/core';
|
|
17
|
+
|
|
18
|
+
import type { McpToolDefinition, ResolveMcpPermit } from './build.js';
|
|
19
|
+
import { deriveMcpTools } from './build.js';
|
|
20
|
+
import { connectStdio } from './stdio.js';
|
|
21
|
+
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
// Options
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
|
|
26
|
+
export interface CreateServerOptions extends BaseSurfaceOptions {
|
|
27
|
+
readonly createContext?:
|
|
28
|
+
| (() => TrailContextInit | Promise<TrailContextInit>)
|
|
29
|
+
| undefined;
|
|
30
|
+
readonly description?: string | undefined;
|
|
31
|
+
readonly layers?: readonly Layer[] | undefined;
|
|
32
|
+
readonly name?: string | undefined;
|
|
33
|
+
readonly resources?: ResourceOverrideMap | undefined;
|
|
34
|
+
readonly resolvePermit?: ResolveMcpPermit | undefined;
|
|
35
|
+
readonly version?: string | undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface SurfaceMcpResult {
|
|
39
|
+
readonly close: () => Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
// Internal: create MCP server with tool handlers
|
|
44
|
+
// ---------------------------------------------------------------------------
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Create an MCP Server instance and register all tools.
|
|
48
|
+
*
|
|
49
|
+
* When provided, `info.description` is forwarded to the MCP SDK as the
|
|
50
|
+
* server's `instructions` field — the SDK's documented channel for
|
|
51
|
+
* "optional instructions describing how to use the server and its features."
|
|
52
|
+
*/
|
|
53
|
+
const createMcpServer = (
|
|
54
|
+
tools: McpToolDefinition[],
|
|
55
|
+
info: {
|
|
56
|
+
readonly name: string;
|
|
57
|
+
readonly version: string;
|
|
58
|
+
readonly description?: string | undefined;
|
|
59
|
+
}
|
|
60
|
+
): Server => {
|
|
61
|
+
const server = new Server(
|
|
62
|
+
{ name: info.name, version: info.version },
|
|
63
|
+
{
|
|
64
|
+
capabilities: { tools: {} },
|
|
65
|
+
...(info.description === undefined
|
|
66
|
+
? {}
|
|
67
|
+
: { instructions: info.description }),
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
// Build a lookup map for tool dispatch
|
|
72
|
+
const toolMap = new Map<string, McpToolDefinition>();
|
|
73
|
+
for (const tool of tools) {
|
|
74
|
+
toolMap.set(tool.name, tool);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Register tools/list handler
|
|
78
|
+
// oxlint-disable-next-line require-await -- MCP SDK requires async handler
|
|
79
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
80
|
+
tools: tools.map((t) => ({
|
|
81
|
+
_meta: t._meta,
|
|
82
|
+
annotations: t.annotations,
|
|
83
|
+
description: t.description,
|
|
84
|
+
inputSchema: t.inputSchema,
|
|
85
|
+
name: t.name,
|
|
86
|
+
outputSchema: t.outputSchema,
|
|
87
|
+
})),
|
|
88
|
+
}));
|
|
89
|
+
|
|
90
|
+
// Register tools/call handler
|
|
91
|
+
server.setRequestHandler(
|
|
92
|
+
CallToolRequestSchema,
|
|
93
|
+
async (request, requestExtra) => {
|
|
94
|
+
const tool = toolMap.get(request.params.name);
|
|
95
|
+
if (tool === undefined) {
|
|
96
|
+
return {
|
|
97
|
+
content: [
|
|
98
|
+
{
|
|
99
|
+
text: `Unknown tool: ${request.params.name}`,
|
|
100
|
+
type: 'text' as const,
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
isError: true,
|
|
104
|
+
} as Record<string, unknown>;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const args = (request.params.arguments ?? {}) as Record<string, unknown>;
|
|
108
|
+
const progressToken = request.params._meta?.progressToken;
|
|
109
|
+
const { authInfo } = requestExtra as {
|
|
110
|
+
readonly authInfo?:
|
|
111
|
+
| {
|
|
112
|
+
readonly accessToken?: string | undefined;
|
|
113
|
+
readonly sessionId?: string | undefined;
|
|
114
|
+
readonly token?: string | undefined;
|
|
115
|
+
}
|
|
116
|
+
| undefined;
|
|
117
|
+
};
|
|
118
|
+
const authorizationToken = authInfo?.accessToken ?? authInfo?.token;
|
|
119
|
+
|
|
120
|
+
const sendProgress =
|
|
121
|
+
progressToken === undefined
|
|
122
|
+
? undefined
|
|
123
|
+
: async (current: number, total: number) => {
|
|
124
|
+
await server.notification({
|
|
125
|
+
method: 'notifications/progress',
|
|
126
|
+
params: {
|
|
127
|
+
progress: current,
|
|
128
|
+
progressToken,
|
|
129
|
+
total,
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const extra = {
|
|
135
|
+
abortSignal: requestExtra.signal,
|
|
136
|
+
...(authorizationToken === undefined
|
|
137
|
+
? {}
|
|
138
|
+
: { authorization: `Bearer ${authorizationToken}` }),
|
|
139
|
+
progressToken,
|
|
140
|
+
sendProgress,
|
|
141
|
+
...(authInfo?.sessionId === undefined
|
|
142
|
+
? {}
|
|
143
|
+
: { sessionId: authInfo.sessionId }),
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const result = await tool.handler(args, extra);
|
|
147
|
+
// Spread to satisfy MCP SDK's index-signature requirement
|
|
148
|
+
return { ...result } as Record<string, unknown>;
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
return server;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// ---------------------------------------------------------------------------
|
|
156
|
+
// createServer
|
|
157
|
+
// ---------------------------------------------------------------------------
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Build MCP tools from a topo and create an MCP server.
|
|
161
|
+
*
|
|
162
|
+
* @remarks This is a host materialization boundary. Derivation failures are
|
|
163
|
+
* thrown for server bootstrap code after `deriveMcpTools` has already
|
|
164
|
+
* represented the framework error as a Result.
|
|
165
|
+
*/
|
|
166
|
+
export const createServer = (
|
|
167
|
+
graph: Topo,
|
|
168
|
+
options: CreateServerOptions = {}
|
|
169
|
+
): Server => {
|
|
170
|
+
const toolsResult = deriveMcpTools(graph, {
|
|
171
|
+
configValues: options.configValues,
|
|
172
|
+
createContext: options.createContext,
|
|
173
|
+
exclude: options.exclude,
|
|
174
|
+
include: options.include,
|
|
175
|
+
intent: options.intent,
|
|
176
|
+
layers: options.layers,
|
|
177
|
+
resolvePermit: options.resolvePermit,
|
|
178
|
+
resources: options.resources,
|
|
179
|
+
validate: options.validate,
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
if (toolsResult.isErr()) {
|
|
183
|
+
throw toolsResult.error;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return createMcpServer(toolsResult.value, {
|
|
187
|
+
description: options.description ?? graph.description,
|
|
188
|
+
name: options.name ?? graph.name,
|
|
189
|
+
version: options.version ?? graph.version ?? '0.1.0',
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
// ---------------------------------------------------------------------------
|
|
194
|
+
// surface
|
|
195
|
+
// ---------------------------------------------------------------------------
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Build MCP tools from a topo, create a server, and connect via stdio.
|
|
199
|
+
*
|
|
200
|
+
* @remarks Opens the MCP server on stdio. For custom transports, use
|
|
201
|
+
* `createServer(graph)` with `connectStdio` or your own adapter.
|
|
202
|
+
*/
|
|
203
|
+
export const surface = async (
|
|
204
|
+
graph: Topo,
|
|
205
|
+
options: CreateServerOptions = {}
|
|
206
|
+
): Promise<SurfaceMcpResult> => {
|
|
207
|
+
const server = createServer(graph, options);
|
|
208
|
+
await connectStdio(server);
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
close: async () => {
|
|
212
|
+
await server.close();
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
};
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
$ tsc -b
|
package/.turbo/turbo-lint.log
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
$ tsc --noEmit
|
package/dist/annotations.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Derive MCP tool annotations from trail spec fields.
|
|
3
|
-
*/
|
|
4
|
-
import type { Trail } from '@ontrails/core';
|
|
5
|
-
export interface McpAnnotations {
|
|
6
|
-
readonly readOnlyHint?: boolean | undefined;
|
|
7
|
-
readonly destructiveHint?: boolean | undefined;
|
|
8
|
-
readonly idempotentHint?: boolean | undefined;
|
|
9
|
-
readonly openWorldHint?: boolean | undefined;
|
|
10
|
-
readonly title?: string | undefined;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Map trail spec fields to MCP tool annotations.
|
|
14
|
-
*
|
|
15
|
-
* Only sets hints that are explicitly declared on the trail.
|
|
16
|
-
* Omitted hints let the MCP SDK use its defaults.
|
|
17
|
-
*/
|
|
18
|
-
export declare const deriveAnnotations: (trail: Pick<Trail<unknown, unknown>, "intent" | "idempotent" | "description">) => McpAnnotations;
|
|
19
|
-
//# sourceMappingURL=annotations.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../src/annotations.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAU,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAMpD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5C,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/C,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9C,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC;AAMD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,QAAQ,GAAG,YAAY,GAAG,aAAa,CAAC,KAC5E,cAoBF,CAAC"}
|
package/dist/annotations.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Derive MCP tool annotations from trail spec fields.
|
|
3
|
-
*/
|
|
4
|
-
// ---------------------------------------------------------------------------
|
|
5
|
-
// Derivation
|
|
6
|
-
// ---------------------------------------------------------------------------
|
|
7
|
-
/**
|
|
8
|
-
* Map trail spec fields to MCP tool annotations.
|
|
9
|
-
*
|
|
10
|
-
* Only sets hints that are explicitly declared on the trail.
|
|
11
|
-
* Omitted hints let the MCP SDK use its defaults.
|
|
12
|
-
*/
|
|
13
|
-
export const deriveAnnotations = (trail) => {
|
|
14
|
-
const annotations = {};
|
|
15
|
-
const intentToHint = {
|
|
16
|
-
destroy: 'destructiveHint',
|
|
17
|
-
read: 'readOnlyHint',
|
|
18
|
-
};
|
|
19
|
-
const hint = intentToHint[trail.intent];
|
|
20
|
-
if (hint) {
|
|
21
|
-
annotations[hint] = true;
|
|
22
|
-
}
|
|
23
|
-
if (trail.idempotent === true) {
|
|
24
|
-
annotations['idempotentHint'] = true;
|
|
25
|
-
}
|
|
26
|
-
if (trail.description !== undefined) {
|
|
27
|
-
annotations['title'] = trail.description;
|
|
28
|
-
}
|
|
29
|
-
return annotations;
|
|
30
|
-
};
|
|
31
|
-
//# sourceMappingURL=annotations.js.map
|
package/dist/annotations.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"annotations.js","sourceRoot":"","sources":["../src/annotations.ts"],"names":[],"mappings":"AAAA;;GAEG;AAgBH,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,KAA6E,EAC7D,EAAE;IAClB,MAAM,WAAW,GAA4B,EAAE,CAAC;IAEhD,MAAM,YAAY,GAAoC;QACpD,OAAO,EAAE,iBAAiB;QAC1B,IAAI,EAAE,cAAc;KACrB,CAAC;IAEF,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACxC,IAAI,IAAI,EAAE,CAAC;QACT,WAAW,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC3B,CAAC;IACD,IAAI,KAAK,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;QAC9B,WAAW,CAAC,gBAAgB,CAAC,GAAG,IAAI,CAAC;IACvC,CAAC;IACD,IAAI,KAAK,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;QACpC,WAAW,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,WAAW,CAAC;IAC3C,CAAC;IAED,OAAO,WAA6B,CAAC;AACvC,CAAC,CAAC"}
|
package/dist/blaze.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* blaze() -- the one-liner MCP server launcher.
|
|
3
|
-
*
|
|
4
|
-
* Three lines to expose trails as MCP tools:
|
|
5
|
-
*
|
|
6
|
-
* ```ts
|
|
7
|
-
* const app = topo("myapp", entity);
|
|
8
|
-
* await blaze(app);
|
|
9
|
-
* ```
|
|
10
|
-
*/
|
|
11
|
-
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
12
|
-
import type { Layer, ServiceOverrideMap, Topo, TrailContextInit } from '@ontrails/core';
|
|
13
|
-
import type { McpToolDefinition } from './build.js';
|
|
14
|
-
export interface BlazeMcpOptions {
|
|
15
|
-
/** Config values for services that declare a `config` schema, keyed by service ID. */
|
|
16
|
-
readonly configValues?: Readonly<Record<string, Record<string, unknown>>> | undefined;
|
|
17
|
-
readonly createContext?: (() => TrailContextInit | Promise<TrailContextInit>) | undefined;
|
|
18
|
-
readonly excludeTrails?: readonly string[] | undefined;
|
|
19
|
-
readonly includeTrails?: readonly string[] | undefined;
|
|
20
|
-
readonly layers?: readonly Layer[] | undefined;
|
|
21
|
-
readonly serverInfo?: {
|
|
22
|
-
readonly name?: string | undefined;
|
|
23
|
-
readonly version?: string | undefined;
|
|
24
|
-
} | undefined;
|
|
25
|
-
readonly transport?: 'stdio' | undefined;
|
|
26
|
-
readonly services?: ServiceOverrideMap | undefined;
|
|
27
|
-
/** Set to `false` to skip topo validation at startup. Defaults to `true`. */
|
|
28
|
-
readonly validate?: boolean | undefined;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Create an MCP Server instance and register all tools.
|
|
32
|
-
*/
|
|
33
|
-
export declare const createMcpServer: (tools: McpToolDefinition[], info: {
|
|
34
|
-
readonly name: string;
|
|
35
|
-
readonly version: string;
|
|
36
|
-
}) => Server;
|
|
37
|
-
/**
|
|
38
|
-
* Build MCP tools from an App, create a server, and connect via stdio.
|
|
39
|
-
*/
|
|
40
|
-
export declare const blaze: (app: Topo, options?: BlazeMcpOptions) => Promise<void>;
|
|
41
|
-
//# sourceMappingURL=blaze.d.ts.map
|
package/dist/blaze.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"blaze.d.ts","sourceRoot":"","sources":["../src/blaze.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAKnE,OAAO,KAAK,EACV,KAAK,EACL,kBAAkB,EAClB,IAAI,EAC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,KAAK,IAAI,EACT,UAAS,eAAoB,KAC5B,OAAO,CAAC,IAAI,CA2Bd,CAAC"}
|
package/dist/blaze.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* blaze() -- the one-liner MCP server launcher.
|
|
3
|
-
*
|
|
4
|
-
* Three lines to expose trails as MCP tools:
|
|
5
|
-
*
|
|
6
|
-
* ```ts
|
|
7
|
-
* const app = topo("myapp", entity);
|
|
8
|
-
* await blaze(app);
|
|
9
|
-
* ```
|
|
10
|
-
*/
|
|
11
|
-
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
12
|
-
import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
13
|
-
import { validateTopo } from '@ontrails/core';
|
|
14
|
-
import { buildMcpTools } from './build.js';
|
|
15
|
-
import { connectStdio } from './stdio.js';
|
|
16
|
-
// ---------------------------------------------------------------------------
|
|
17
|
-
// Internal: create MCP server with tool handlers
|
|
18
|
-
// ---------------------------------------------------------------------------
|
|
19
|
-
/**
|
|
20
|
-
* Create an MCP Server instance and register all tools.
|
|
21
|
-
*/
|
|
22
|
-
export const createMcpServer = (tools, info) => {
|
|
23
|
-
const server = new Server({ name: info.name, version: info.version }, { capabilities: { tools: {} } });
|
|
24
|
-
// Build a lookup map for tool dispatch
|
|
25
|
-
const toolMap = new Map();
|
|
26
|
-
for (const tool of tools) {
|
|
27
|
-
toolMap.set(tool.name, tool);
|
|
28
|
-
}
|
|
29
|
-
// Register tools/list handler
|
|
30
|
-
// oxlint-disable-next-line require-await -- MCP SDK requires async handler
|
|
31
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
32
|
-
tools: tools.map((t) => ({
|
|
33
|
-
annotations: t.annotations,
|
|
34
|
-
description: t.description,
|
|
35
|
-
inputSchema: t.inputSchema,
|
|
36
|
-
name: t.name,
|
|
37
|
-
})),
|
|
38
|
-
}));
|
|
39
|
-
// Register tools/call handler
|
|
40
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
41
|
-
const tool = toolMap.get(request.params.name);
|
|
42
|
-
if (tool === undefined) {
|
|
43
|
-
return {
|
|
44
|
-
content: [
|
|
45
|
-
{
|
|
46
|
-
text: `Unknown tool: ${request.params.name}`,
|
|
47
|
-
type: 'text',
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
isError: true,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
const args = (request.params.arguments ?? {});
|
|
54
|
-
const progressToken = request.params._meta?.progressToken;
|
|
55
|
-
const sendProgress = progressToken === undefined
|
|
56
|
-
? undefined
|
|
57
|
-
: async (current, total) => {
|
|
58
|
-
await server.notification({
|
|
59
|
-
method: 'notifications/progress',
|
|
60
|
-
params: {
|
|
61
|
-
progress: current,
|
|
62
|
-
progressToken: progressToken,
|
|
63
|
-
total,
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
const extra = {
|
|
68
|
-
abortSignal: undefined,
|
|
69
|
-
progressToken,
|
|
70
|
-
sendProgress,
|
|
71
|
-
};
|
|
72
|
-
const result = await tool.handler(args, extra);
|
|
73
|
-
// Spread to satisfy MCP SDK's index-signature requirement
|
|
74
|
-
return { ...result };
|
|
75
|
-
});
|
|
76
|
-
return server;
|
|
77
|
-
};
|
|
78
|
-
// ---------------------------------------------------------------------------
|
|
79
|
-
// blaze
|
|
80
|
-
// ---------------------------------------------------------------------------
|
|
81
|
-
/**
|
|
82
|
-
* Build MCP tools from an App, create a server, and connect via stdio.
|
|
83
|
-
*/
|
|
84
|
-
export const blaze = async (app, options = {}) => {
|
|
85
|
-
if (options.validate !== false) {
|
|
86
|
-
const validated = validateTopo(app);
|
|
87
|
-
if (validated.isErr()) {
|
|
88
|
-
throw validated.error;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
const toolsResult = buildMcpTools(app, {
|
|
92
|
-
configValues: options.configValues,
|
|
93
|
-
createContext: options.createContext,
|
|
94
|
-
excludeTrails: options.excludeTrails,
|
|
95
|
-
includeTrails: options.includeTrails,
|
|
96
|
-
layers: options.layers,
|
|
97
|
-
services: options.services,
|
|
98
|
-
});
|
|
99
|
-
if (toolsResult.isErr()) {
|
|
100
|
-
throw toolsResult.error;
|
|
101
|
-
}
|
|
102
|
-
const server = createMcpServer(toolsResult.value, {
|
|
103
|
-
name: options.serverInfo?.name ?? app.name,
|
|
104
|
-
version: options.serverInfo?.version ?? '0.1.0',
|
|
105
|
-
});
|
|
106
|
-
await connectStdio(server);
|
|
107
|
-
};
|
|
108
|
-
//# sourceMappingURL=blaze.js.map
|
package/dist/blaze.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"blaze.js","sourceRoot":"","sources":["../src/blaze.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAO5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AA6B1C,8EAA8E;AAC9E,iDAAiD;AACjD,8EAA8E;AAE9E;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,KAA0B,EAC1B,IAAyD,EACjD,EAAE;IACV,MAAM,MAAM,GAAG,IAAI,MAAM,CACvB,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,EAC1C,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAChC,CAAC;IAEF,uCAAuC;IACvC,MAAM,OAAO,GAAG,IAAI,GAAG,EAA6B,CAAC;IACrD,KAAK,MAAM,IAAI,IAAI,KAAK,EAA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OAAO,CAAC,UAAU,EAAE,IAAI,IAAI,GAAG,CAAC,IAAI;QAC1C,OAAO,EAAE,OAAO,CAAC,UAAU,EAAE,OAAO,IAAI,OAAO;KAChD,CAAC,CAAC;IAEH,MAAM,YAAY,CAAC,MAAM,CAAC,CAAC;AAC7B,CAAC,CAAC"}
|
package/dist/build.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Build MCP tool definitions from a Trails App.
|
|
3
|
-
*
|
|
4
|
-
* Iterates the topo, generates McpToolDefinition[] with handlers that
|
|
5
|
-
* validate input, compose gates, execute the implementation, and map
|
|
6
|
-
* Results to MCP responses.
|
|
7
|
-
*/
|
|
8
|
-
import { Result } from '@ontrails/core';
|
|
9
|
-
import type { Gate, ProvisionOverrideMap, Topo, TrailContextInit } from '@ontrails/core';
|
|
10
|
-
import type { McpAnnotations } from './annotations.js';
|
|
11
|
-
export interface BuildMcpToolsOptions {
|
|
12
|
-
/** Config values for provisions that declare a `config` schema, keyed by provision ID. */
|
|
13
|
-
readonly configValues?: Readonly<Record<string, Record<string, unknown>>> | undefined;
|
|
14
|
-
readonly createContext?: (() => TrailContextInit | Promise<TrailContextInit>) | undefined;
|
|
15
|
-
readonly excludeTrails?: readonly string[] | undefined;
|
|
16
|
-
readonly includeTrails?: readonly string[] | undefined;
|
|
17
|
-
readonly gates?: readonly Gate[] | undefined;
|
|
18
|
-
readonly provisions?: ProvisionOverrideMap | undefined;
|
|
19
|
-
/** Set to `false` to skip topo validation while building tools. */
|
|
20
|
-
readonly validate?: boolean | undefined;
|
|
21
|
-
}
|
|
22
|
-
export interface McpToolDefinition {
|
|
23
|
-
readonly annotations: McpAnnotations | undefined;
|
|
24
|
-
readonly description: string | undefined;
|
|
25
|
-
readonly handler: (args: Record<string, unknown>, extra: McpExtra) => Promise<McpToolResult>;
|
|
26
|
-
readonly inputSchema: Record<string, unknown>;
|
|
27
|
-
readonly name: string;
|
|
28
|
-
/** The trail ID this tool was derived from. */
|
|
29
|
-
readonly trailId: string;
|
|
30
|
-
}
|
|
31
|
-
export interface McpExtra {
|
|
32
|
-
readonly progressToken?: string | number | undefined;
|
|
33
|
-
readonly sendProgress?: ((current: number, total: number) => Promise<void>) | undefined;
|
|
34
|
-
readonly abortSignal?: AbortSignal | undefined;
|
|
35
|
-
}
|
|
36
|
-
export interface McpToolResult {
|
|
37
|
-
readonly content: readonly McpContent[];
|
|
38
|
-
readonly isError?: boolean | undefined;
|
|
39
|
-
}
|
|
40
|
-
export interface McpContent {
|
|
41
|
-
readonly data?: string | undefined;
|
|
42
|
-
readonly mimeType?: string | undefined;
|
|
43
|
-
readonly text?: string | undefined;
|
|
44
|
-
readonly type: 'text' | 'image' | 'resource';
|
|
45
|
-
readonly uri?: string | undefined;
|
|
46
|
-
}
|
|
47
|
-
export declare const buildMcpTools: (app: Topo, options?: BuildMcpToolsOptions) => Result<McpToolDefinition[], Error>;
|
|
48
|
-
//# sourceMappingURL=build.d.ts.map
|
package/dist/build.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,MAAM,EAOP,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAEV,IAAI,EACJ,oBAAoB,EACpB,IAAI,EAEJ,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AASvD,MAAM,WAAW,oBAAoB;IACnC,0FAA0F;IAC1F,QAAQ,CAAC,YAAY,CAAC,EAClB,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,GACjD,SAAS,CAAC;IACd,QAAQ,CAAC,aAAa,CAAC,EACnB,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC,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