@ontrails/mcp 1.0.0-beta.4 → 1.0.0-beta.41
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 +391 -12
- package/README.md +69 -17
- package/package.json +11 -3
- package/src/annotations.ts +24 -1
- package/src/build.ts +1335 -136
- package/src/index.ts +32 -4
- package/src/progress.ts +22 -0
- package/src/resources.ts +336 -0
- package/src/stdio.ts +9 -1
- package/src/surface.ts +295 -0
- package/src/tool-name.ts +6 -7
- 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 -36
- package/dist/blaze.d.ts.map +0 -1
- package/dist/blaze.js +0 -96
- package/dist/blaze.js.map +0 -1
- package/dist/build.d.ts +0 -40
- package/dist/build.d.ts.map +0 -1
- package/dist/build.js +0 -227
- 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/src/__tests__/annotations.test.ts +0 -63
- package/src/__tests__/blaze.test.ts +0 -105
- package/src/__tests__/build.test.ts +0 -453
- package/src/__tests__/progress.test.ts +0 -136
- package/src/__tests__/tool-name.test.ts +0 -46
- package/src/blaze.ts +0 -146
- package/tsconfig.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
package/src/surface.ts
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
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
|
+
ErrorCode,
|
|
9
|
+
ListResourcesRequestSchema,
|
|
10
|
+
ListToolsRequestSchema,
|
|
11
|
+
McpError,
|
|
12
|
+
ReadResourceRequestSchema,
|
|
13
|
+
} from '@modelcontextprotocol/sdk/types.js';
|
|
14
|
+
import type {
|
|
15
|
+
BaseSurfaceOptions,
|
|
16
|
+
Layer,
|
|
17
|
+
OverlayEnvelopeLike,
|
|
18
|
+
ResourceOverrideMap,
|
|
19
|
+
Topo,
|
|
20
|
+
TrailContextInit,
|
|
21
|
+
} from '@ontrails/core';
|
|
22
|
+
|
|
23
|
+
import type {
|
|
24
|
+
McpSurfaceTrailheadMap,
|
|
25
|
+
McpToolDefinition,
|
|
26
|
+
ResolveMcpPermit,
|
|
27
|
+
} from './build.js';
|
|
28
|
+
import { deriveMcpTools } from './build.js';
|
|
29
|
+
import { buildMcpResources } from './resources.js';
|
|
30
|
+
import type { BuiltMcpResources, McpResourcesConfig } from './resources.js';
|
|
31
|
+
import { connectStdio } from './stdio.js';
|
|
32
|
+
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// Options
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
|
|
37
|
+
export interface CreateServerOptions extends BaseSurfaceOptions {
|
|
38
|
+
readonly createContext?:
|
|
39
|
+
| (() => TrailContextInit | Promise<TrailContextInit>)
|
|
40
|
+
| undefined;
|
|
41
|
+
readonly description?: string | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* App-authored overlay envelopes (the same collection compile embeds in
|
|
44
|
+
* `trails.lock`). The `surfaces` overlay's `mcp` bindings are the authored,
|
|
45
|
+
* lockable default: list bindings become grouped trailhead tools and scalar
|
|
46
|
+
* bindings become tool synonyms.
|
|
47
|
+
*/
|
|
48
|
+
readonly overlays?: readonly OverlayEnvelopeLike[] | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Call-site trailhead map. Override-in-context by design: when both this
|
|
51
|
+
* map and overlay `mcp` list bindings are present, the call-site map wins
|
|
52
|
+
* at runtime.
|
|
53
|
+
*/
|
|
54
|
+
readonly trailheads?: McpSurfaceTrailheadMap | undefined;
|
|
55
|
+
readonly layers?: readonly Layer[] | undefined;
|
|
56
|
+
readonly mcpResources?: McpResourcesConfig | false | undefined;
|
|
57
|
+
readonly name?: string | undefined;
|
|
58
|
+
readonly resources?: ResourceOverrideMap | undefined;
|
|
59
|
+
readonly resolvePermit?: ResolveMcpPermit | undefined;
|
|
60
|
+
readonly version?: string | undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface SurfaceMcpResult {
|
|
64
|
+
readonly close: () => Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
// Internal: create MCP server with tool handlers
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Create an MCP Server instance and register all tools.
|
|
73
|
+
*
|
|
74
|
+
* When provided, `info.description` is forwarded to the MCP SDK as the
|
|
75
|
+
* server's `instructions` field — the SDK's documented channel for
|
|
76
|
+
* "optional instructions describing how to use the server and its features."
|
|
77
|
+
*/
|
|
78
|
+
const createMcpServer = (
|
|
79
|
+
tools: McpToolDefinition[],
|
|
80
|
+
info: {
|
|
81
|
+
readonly name: string;
|
|
82
|
+
readonly version: string;
|
|
83
|
+
readonly description?: string | undefined;
|
|
84
|
+
},
|
|
85
|
+
mcpResources?: BuiltMcpResources | undefined
|
|
86
|
+
): Server => {
|
|
87
|
+
const server = new Server(
|
|
88
|
+
{ name: info.name, version: info.version },
|
|
89
|
+
{
|
|
90
|
+
capabilities: {
|
|
91
|
+
...(mcpResources === undefined ? {} : { resources: {} }),
|
|
92
|
+
tools: {},
|
|
93
|
+
},
|
|
94
|
+
...(info.description === undefined
|
|
95
|
+
? {}
|
|
96
|
+
: { instructions: info.description }),
|
|
97
|
+
}
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
// Build a lookup map for tool dispatch
|
|
101
|
+
const toolMap = new Map<string, McpToolDefinition>();
|
|
102
|
+
for (const tool of tools) {
|
|
103
|
+
toolMap.set(tool.name, tool);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Register tools/list handler
|
|
107
|
+
// oxlint-disable-next-line require-await -- MCP SDK requires async handler
|
|
108
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
109
|
+
tools: tools.map((t) => ({
|
|
110
|
+
_meta: t._meta,
|
|
111
|
+
annotations: t.annotations,
|
|
112
|
+
description: t.description,
|
|
113
|
+
inputSchema: t.inputSchema,
|
|
114
|
+
name: t.name,
|
|
115
|
+
outputSchema: t.outputSchema,
|
|
116
|
+
})),
|
|
117
|
+
}));
|
|
118
|
+
|
|
119
|
+
// Register tools/call handler
|
|
120
|
+
server.setRequestHandler(
|
|
121
|
+
CallToolRequestSchema,
|
|
122
|
+
async (request, requestExtra) => {
|
|
123
|
+
const tool = toolMap.get(request.params.name);
|
|
124
|
+
if (tool === undefined) {
|
|
125
|
+
return {
|
|
126
|
+
content: [
|
|
127
|
+
{
|
|
128
|
+
text: `Unknown tool: ${request.params.name}`,
|
|
129
|
+
type: 'text' as const,
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
isError: true,
|
|
133
|
+
} as Record<string, unknown>;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const args = (request.params.arguments ?? {}) as Record<string, unknown>;
|
|
137
|
+
const progressToken = request.params._meta?.progressToken;
|
|
138
|
+
const { authInfo } = requestExtra as {
|
|
139
|
+
readonly authInfo?:
|
|
140
|
+
| {
|
|
141
|
+
readonly accessToken?: string | undefined;
|
|
142
|
+
readonly sessionId?: string | undefined;
|
|
143
|
+
readonly token?: string | undefined;
|
|
144
|
+
}
|
|
145
|
+
| undefined;
|
|
146
|
+
};
|
|
147
|
+
const authorizationToken = authInfo?.accessToken ?? authInfo?.token;
|
|
148
|
+
|
|
149
|
+
const sendProgress =
|
|
150
|
+
progressToken === undefined
|
|
151
|
+
? undefined
|
|
152
|
+
: async (current: number, total: number) => {
|
|
153
|
+
await server.notification({
|
|
154
|
+
method: 'notifications/progress',
|
|
155
|
+
params: {
|
|
156
|
+
progress: current,
|
|
157
|
+
progressToken,
|
|
158
|
+
total,
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const extra = {
|
|
164
|
+
abortSignal: requestExtra.signal,
|
|
165
|
+
...(authorizationToken === undefined
|
|
166
|
+
? {}
|
|
167
|
+
: { authorization: `Bearer ${authorizationToken}` }),
|
|
168
|
+
progressToken,
|
|
169
|
+
sendProgress,
|
|
170
|
+
...(authInfo?.sessionId === undefined
|
|
171
|
+
? {}
|
|
172
|
+
: { sessionId: authInfo.sessionId }),
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const result = await tool.handler(args, extra);
|
|
176
|
+
// Spread to satisfy MCP SDK's index-signature requirement
|
|
177
|
+
return { ...result } as Record<string, unknown>;
|
|
178
|
+
}
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
if (mcpResources !== undefined) {
|
|
182
|
+
// oxlint-disable-next-line require-await -- MCP SDK requires async handler
|
|
183
|
+
server.setRequestHandler(ListResourcesRequestSchema, async () => ({
|
|
184
|
+
resources: mcpResources.list.map((resource) => ({
|
|
185
|
+
description: resource.description,
|
|
186
|
+
mimeType: resource.mimeType,
|
|
187
|
+
name: resource.name,
|
|
188
|
+
uri: resource.uri,
|
|
189
|
+
})),
|
|
190
|
+
}));
|
|
191
|
+
|
|
192
|
+
server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
193
|
+
const content = mcpResources.read(request.params.uri);
|
|
194
|
+
if (content === undefined) {
|
|
195
|
+
throw new McpError(
|
|
196
|
+
ErrorCode.InvalidParams,
|
|
197
|
+
`Resource ${request.params.uri} not found`
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
contents: [content],
|
|
202
|
+
};
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return server;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// ---------------------------------------------------------------------------
|
|
210
|
+
// createServer
|
|
211
|
+
// ---------------------------------------------------------------------------
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Build MCP tools from a topo and create an MCP server.
|
|
215
|
+
*
|
|
216
|
+
* @remarks This is a host materialization boundary. Derivation failures are
|
|
217
|
+
* thrown for server bootstrap code after `deriveMcpTools` has already
|
|
218
|
+
* represented the framework error as a Result.
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```ts
|
|
222
|
+
* import { connectStdio, createServer } from '@ontrails/mcp';
|
|
223
|
+
*
|
|
224
|
+
* const server = createServer(graph, { name: 'demo' });
|
|
225
|
+
* await connectStdio(server);
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
export const createServer = (
|
|
229
|
+
graph: Topo,
|
|
230
|
+
options: CreateServerOptions = {}
|
|
231
|
+
): Server => {
|
|
232
|
+
const toolsResult = deriveMcpTools(graph, {
|
|
233
|
+
configValues: options.configValues,
|
|
234
|
+
createContext: options.createContext,
|
|
235
|
+
exclude: options.exclude,
|
|
236
|
+
include: options.include,
|
|
237
|
+
intent: options.intent,
|
|
238
|
+
layers: options.layers,
|
|
239
|
+
overlays: options.overlays,
|
|
240
|
+
resolvePermit: options.resolvePermit,
|
|
241
|
+
resources: options.resources,
|
|
242
|
+
trailheads: options.trailheads,
|
|
243
|
+
validate: options.validate,
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
if (toolsResult.isErr()) {
|
|
247
|
+
throw toolsResult.error;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const mcpResources =
|
|
251
|
+
options.mcpResources === false
|
|
252
|
+
? undefined
|
|
253
|
+
: buildMcpResources(graph, toolsResult.value, options.mcpResources);
|
|
254
|
+
|
|
255
|
+
return createMcpServer(
|
|
256
|
+
toolsResult.value,
|
|
257
|
+
{
|
|
258
|
+
description: options.description ?? graph.description,
|
|
259
|
+
name: options.name ?? graph.name,
|
|
260
|
+
version: options.version ?? graph.version ?? '0.1.0',
|
|
261
|
+
},
|
|
262
|
+
mcpResources
|
|
263
|
+
);
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
// ---------------------------------------------------------------------------
|
|
267
|
+
// surface
|
|
268
|
+
// ---------------------------------------------------------------------------
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Build MCP tools from a topo, create a server, and connect via stdio.
|
|
272
|
+
*
|
|
273
|
+
* @remarks Opens the MCP server on stdio. For custom transports, use
|
|
274
|
+
* `createServer(graph)` with `connectStdio` or your own adapter.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```ts
|
|
278
|
+
* import { surface } from '@ontrails/mcp';
|
|
279
|
+
*
|
|
280
|
+
* await surface(graph, { name: 'demo' });
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
export const surface = async (
|
|
284
|
+
graph: Topo,
|
|
285
|
+
options: CreateServerOptions = {}
|
|
286
|
+
): Promise<SurfaceMcpResult> => {
|
|
287
|
+
const server = createServer(graph, options);
|
|
288
|
+
await connectStdio(server);
|
|
289
|
+
|
|
290
|
+
return {
|
|
291
|
+
close: async () => {
|
|
292
|
+
await server.close();
|
|
293
|
+
},
|
|
294
|
+
};
|
|
295
|
+
};
|
package/src/tool-name.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Derive MCP-safe tool names from app name + trail ID.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* The derivation itself lives in `@ontrails/core` (`deriveMcpToolName`) so
|
|
5
|
+
* governance readers such as Warden's `surface-overlay-coherence` rule check
|
|
6
|
+
* collisions against the exact projection the MCP surface renders.
|
|
6
7
|
*/
|
|
7
8
|
|
|
9
|
+
import { deriveMcpToolName } from '@ontrails/core';
|
|
10
|
+
|
|
8
11
|
/**
|
|
9
12
|
* Convert app name + trail ID to an MCP-safe tool name.
|
|
10
13
|
*
|
|
@@ -12,8 +15,4 @@
|
|
|
12
15
|
* deriveToolName("myapp", "entity.show") // "myapp_entity_show"
|
|
13
16
|
* deriveToolName("dispatch", "patch.search") // "dispatch_patch_search"
|
|
14
17
|
*/
|
|
15
|
-
export const deriveToolName =
|
|
16
|
-
const prefix = appName.toLowerCase().replaceAll(/[.-]/g, '_');
|
|
17
|
-
const suffix = trailId.toLowerCase().replaceAll(/[.-]/g, '_');
|
|
18
|
-
return `${prefix}_${suffix}`;
|
|
19
|
-
};
|
|
18
|
+
export const deriveToolName = deriveMcpToolName;
|
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,36 +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, Topo, TrailContext } from '@ontrails/core';
|
|
13
|
-
import type { McpToolDefinition } from './build.js';
|
|
14
|
-
export interface BlazeMcpOptions {
|
|
15
|
-
readonly createContext?: (() => TrailContext | Promise<TrailContext>) | undefined;
|
|
16
|
-
readonly excludeTrails?: readonly string[] | undefined;
|
|
17
|
-
readonly includeTrails?: readonly string[] | undefined;
|
|
18
|
-
readonly layers?: readonly Layer[] | undefined;
|
|
19
|
-
readonly serverInfo?: {
|
|
20
|
-
readonly name?: string | undefined;
|
|
21
|
-
readonly version?: string | undefined;
|
|
22
|
-
} | undefined;
|
|
23
|
-
readonly transport?: 'stdio' | undefined;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Create an MCP Server instance and register all tools.
|
|
27
|
-
*/
|
|
28
|
-
export declare const createMcpServer: (tools: McpToolDefinition[], info: {
|
|
29
|
-
readonly name: string;
|
|
30
|
-
readonly version: string;
|
|
31
|
-
}) => Server;
|
|
32
|
-
/**
|
|
33
|
-
* Build MCP tools from an App, create a server, and connect via stdio.
|
|
34
|
-
*/
|
|
35
|
-
export declare const blaze: (app: Topo, options?: BlazeMcpOptions) => Promise<void>;
|
|
36
|
-
//# sourceMappingURL=blaze.d.ts.map
|
package/dist/blaze.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
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
|
|
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 { buildMcpTools } from './build.js';
|
|
14
|
-
import { connectStdio } from './stdio.js';
|
|
15
|
-
// ---------------------------------------------------------------------------
|
|
16
|
-
// Internal: create MCP server with tool handlers
|
|
17
|
-
// ---------------------------------------------------------------------------
|
|
18
|
-
/**
|
|
19
|
-
* Create an MCP Server instance and register all tools.
|
|
20
|
-
*/
|
|
21
|
-
export const createMcpServer = (tools, info) => {
|
|
22
|
-
const server = new Server({ name: info.name, version: info.version }, { capabilities: { tools: {} } });
|
|
23
|
-
// Build a lookup map for tool dispatch
|
|
24
|
-
const toolMap = new Map();
|
|
25
|
-
for (const tool of tools) {
|
|
26
|
-
toolMap.set(tool.name, tool);
|
|
27
|
-
}
|
|
28
|
-
// Register tools/list handler
|
|
29
|
-
// oxlint-disable-next-line require-await -- MCP SDK requires async handler
|
|
30
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
31
|
-
tools: tools.map((t) => ({
|
|
32
|
-
annotations: t.annotations,
|
|
33
|
-
description: t.description,
|
|
34
|
-
inputSchema: t.inputSchema,
|
|
35
|
-
name: t.name,
|
|
36
|
-
})),
|
|
37
|
-
}));
|
|
38
|
-
// Register tools/call handler
|
|
39
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
40
|
-
const tool = toolMap.get(request.params.name);
|
|
41
|
-
if (tool === undefined) {
|
|
42
|
-
return {
|
|
43
|
-
content: [
|
|
44
|
-
{
|
|
45
|
-
text: `Unknown tool: ${request.params.name}`,
|
|
46
|
-
type: 'text',
|
|
47
|
-
},
|
|
48
|
-
],
|
|
49
|
-
isError: true,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
const args = (request.params.arguments ?? {});
|
|
53
|
-
const progressToken = request.params._meta?.progressToken;
|
|
54
|
-
const sendProgress = progressToken === undefined
|
|
55
|
-
? undefined
|
|
56
|
-
: async (current, total) => {
|
|
57
|
-
await server.notification({
|
|
58
|
-
method: 'notifications/progress',
|
|
59
|
-
params: {
|
|
60
|
-
progress: current,
|
|
61
|
-
progressToken: progressToken,
|
|
62
|
-
total,
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
const extra = {
|
|
67
|
-
progressToken,
|
|
68
|
-
sendProgress,
|
|
69
|
-
signal: undefined,
|
|
70
|
-
};
|
|
71
|
-
const result = await tool.handler(args, extra);
|
|
72
|
-
// Spread to satisfy MCP SDK's index-signature requirement
|
|
73
|
-
return { ...result };
|
|
74
|
-
});
|
|
75
|
-
return server;
|
|
76
|
-
};
|
|
77
|
-
// ---------------------------------------------------------------------------
|
|
78
|
-
// blaze
|
|
79
|
-
// ---------------------------------------------------------------------------
|
|
80
|
-
/**
|
|
81
|
-
* Build MCP tools from an App, create a server, and connect via stdio.
|
|
82
|
-
*/
|
|
83
|
-
export const blaze = async (app, options = {}) => {
|
|
84
|
-
const tools = buildMcpTools(app, {
|
|
85
|
-
createContext: options.createContext,
|
|
86
|
-
excludeTrails: options.excludeTrails,
|
|
87
|
-
includeTrails: options.includeTrails,
|
|
88
|
-
layers: options.layers,
|
|
89
|
-
});
|
|
90
|
-
const server = createMcpServer(tools, {
|
|
91
|
-
name: options.serverInfo?.name ?? app.name,
|
|
92
|
-
version: options.serverInfo?.version ?? '0.1.0',
|
|
93
|
-
});
|
|
94
|
-
await connectStdio(server);
|
|
95
|
-
};
|
|
96
|
-
//# sourceMappingURL=blaze.js.map
|
package/dist/blaze.js.map
DEL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9E;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,EACxB,GAAS,EACT,UAA2B,EAAE,EACd,EAAE;IACjB,MAAM,KAAK,GAAG,aAAa,CAAC,GAAG,EAAE;QAC/B,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,eAAe,CAAC,KAAK,EAAE;QACpC,IAAI,EAAE,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,40 +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 layers, execute the implementation, and map
|
|
6
|
-
* Results to MCP responses.
|
|
7
|
-
*/
|
|
8
|
-
import type { Layer, Topo, TrailContext } from '@ontrails/core';
|
|
9
|
-
import type { McpAnnotations } from './annotations.js';
|
|
10
|
-
export interface BuildMcpToolsOptions {
|
|
11
|
-
readonly createContext?: (() => TrailContext | Promise<TrailContext>) | undefined;
|
|
12
|
-
readonly excludeTrails?: readonly string[] | undefined;
|
|
13
|
-
readonly includeTrails?: readonly string[] | undefined;
|
|
14
|
-
readonly layers?: readonly Layer[] | undefined;
|
|
15
|
-
}
|
|
16
|
-
export interface McpToolDefinition {
|
|
17
|
-
readonly annotations: McpAnnotations | undefined;
|
|
18
|
-
readonly description: string | undefined;
|
|
19
|
-
readonly handler: (args: Record<string, unknown>, extra: McpExtra) => Promise<McpToolResult>;
|
|
20
|
-
readonly inputSchema: Record<string, unknown>;
|
|
21
|
-
readonly name: string;
|
|
22
|
-
}
|
|
23
|
-
export interface McpExtra {
|
|
24
|
-
readonly progressToken?: string | number | undefined;
|
|
25
|
-
readonly sendProgress?: ((current: number, total: number) => Promise<void>) | undefined;
|
|
26
|
-
readonly signal?: AbortSignal | undefined;
|
|
27
|
-
}
|
|
28
|
-
export interface McpToolResult {
|
|
29
|
-
readonly content: readonly McpContent[];
|
|
30
|
-
readonly isError?: boolean | undefined;
|
|
31
|
-
}
|
|
32
|
-
export interface McpContent {
|
|
33
|
-
readonly data?: string | undefined;
|
|
34
|
-
readonly mimeType?: string | undefined;
|
|
35
|
-
readonly text?: string | undefined;
|
|
36
|
-
readonly type: 'text' | 'image' | 'resource';
|
|
37
|
-
readonly uri?: string | undefined;
|
|
38
|
-
}
|
|
39
|
-
export declare const buildMcpTools: (app: Topo, options?: BuildMcpToolsOptions) => McpToolDefinition[];
|
|
40
|
-
//# 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;AASH,OAAO,KAAK,EAAW,KAAK,EAAE,IAAI,EAAS,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEhF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AASvD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,aAAa,CAAC,EACnB,CAAC,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,GAC5C,SAAS,CAAC;IACd,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IACvD,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IACvD,QAAQ,CAAC,MAAM,CA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