@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.
Files changed (51) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +36 -17
  3. package/package.json +11 -3
  4. package/src/annotations.ts +4 -1
  5. package/src/build.ts +689 -127
  6. package/src/index.ts +14 -4
  7. package/src/stdio.ts +1 -1
  8. package/src/surface.ts +215 -0
  9. package/.turbo/turbo-build.log +0 -1
  10. package/.turbo/turbo-lint.log +0 -3
  11. package/.turbo/turbo-typecheck.log +0 -1
  12. package/dist/annotations.d.ts +0 -19
  13. package/dist/annotations.d.ts.map +0 -1
  14. package/dist/annotations.js +0 -31
  15. package/dist/annotations.js.map +0 -1
  16. package/dist/blaze.d.ts +0 -41
  17. package/dist/blaze.d.ts.map +0 -1
  18. package/dist/blaze.js +0 -108
  19. package/dist/blaze.js.map +0 -1
  20. package/dist/build.d.ts +0 -48
  21. package/dist/build.d.ts.map +0 -1
  22. package/dist/build.js +0 -229
  23. package/dist/build.js.map +0 -1
  24. package/dist/index.d.ts +0 -7
  25. package/dist/index.d.ts.map +0 -1
  26. package/dist/index.js +0 -13
  27. package/dist/index.js.map +0 -1
  28. package/dist/progress.d.ts +0 -13
  29. package/dist/progress.d.ts.map +0 -1
  30. package/dist/progress.js +0 -51
  31. package/dist/progress.js.map +0 -1
  32. package/dist/stdio.d.ts +0 -12
  33. package/dist/stdio.d.ts.map +0 -1
  34. package/dist/stdio.js +0 -15
  35. package/dist/stdio.js.map +0 -1
  36. package/dist/tool-name.d.ts +0 -15
  37. package/dist/tool-name.d.ts.map +0 -1
  38. package/dist/tool-name.js +0 -19
  39. package/dist/tool-name.js.map +0 -1
  40. package/dist/trailhead.d.ts +0 -41
  41. package/dist/trailhead.d.ts.map +0 -1
  42. package/dist/trailhead.js +0 -109
  43. package/dist/trailhead.js.map +0 -1
  44. package/src/__tests__/annotations.test.ts +0 -63
  45. package/src/__tests__/build.test.ts +0 -529
  46. package/src/__tests__/progress.test.ts +0 -136
  47. package/src/__tests__/tool-name.test.ts +0 -46
  48. package/src/__tests__/trailhead.test.ts +0 -158
  49. package/src/trailhead.ts +0 -173
  50. package/tsconfig.json +0 -9
  51. package/tsconfig.tsbuildinfo +0 -1
package/dist/build.js DELETED
@@ -1,229 +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, TRAILHEAD_KEY, ValidationError, executeTrail, isBlobRef, validateEstablishedTopo, zodToJsonSchema, } from '@ontrails/core';
9
- import { deriveAnnotations } from './annotations.js';
10
- import { createMcpProgressCallback } from './progress.js';
11
- import { deriveToolName } from './tool-name.js';
12
- // ---------------------------------------------------------------------------
13
- // Internal helpers (defined before use)
14
- // ---------------------------------------------------------------------------
15
- /** Concatenate an array of Uint8Array chunks into a single Uint8Array. */
16
- const concatChunks = (chunks, totalLength) => {
17
- const result = new Uint8Array(totalLength);
18
- let offset = 0;
19
- for (const chunk of chunks) {
20
- result.set(chunk, offset);
21
- offset += chunk.length;
22
- }
23
- return result;
24
- };
25
- /** Collect a ReadableStream into a single Uint8Array. */
26
- const collectStream = async (stream) => {
27
- const reader = stream.getReader();
28
- const chunks = [];
29
- let totalLength = 0;
30
- for (;;) {
31
- const { done, value } = await reader.read();
32
- if (done) {
33
- break;
34
- }
35
- chunks.push(value);
36
- totalLength += value.length;
37
- }
38
- return concatChunks(chunks, totalLength);
39
- };
40
- /** Resolve BlobRef data to Uint8Array (handles ReadableStream). */
41
- const resolveBlobData = (blob) => {
42
- if (blob.data instanceof ReadableStream) {
43
- return collectStream(blob.data);
44
- }
45
- return blob.data;
46
- };
47
- const uint8ArrayToBase64 = (bytes) => {
48
- // Use btoa with manual conversion for runtime-agnostic base64
49
- let binary = '';
50
- for (const byte of bytes) {
51
- binary += String.fromCodePoint(byte);
52
- }
53
- return btoa(binary);
54
- };
55
- const blobToContent = async (blob) => {
56
- const bytes = await resolveBlobData(blob);
57
- if (blob.mimeType.startsWith('image/')) {
58
- return {
59
- data: uint8ArrayToBase64(bytes),
60
- mimeType: blob.mimeType,
61
- type: 'image',
62
- };
63
- }
64
- return {
65
- mimeType: blob.mimeType,
66
- type: 'resource',
67
- uri: `blob://${blob.name}`,
68
- };
69
- };
70
- /** Separate blob fields from non-blob fields in an object. */
71
- const separateBlobFields = async (obj) => {
72
- const blobContents = [];
73
- const textFields = {};
74
- let hasBlobFields = false;
75
- for (const [key, val] of Object.entries(obj)) {
76
- if (isBlobRef(val)) {
77
- hasBlobFields = true;
78
- blobContents.push(await blobToContent(val));
79
- }
80
- else {
81
- textFields[key] = val;
82
- }
83
- }
84
- return { blobContents, hasBlobFields, textFields };
85
- };
86
- /** Serialize a mixed blob/text object to MCP content. */
87
- const serializeMixedObject = async (obj) => {
88
- const { blobContents, hasBlobFields, textFields } = await separateBlobFields(obj);
89
- if (!hasBlobFields) {
90
- return undefined;
91
- }
92
- if (Object.keys(textFields).length > 0) {
93
- blobContents.unshift({ text: JSON.stringify(textFields), type: 'text' });
94
- }
95
- return blobContents;
96
- };
97
- const serializeOutput = async (value) => {
98
- if (isBlobRef(value)) {
99
- return [await blobToContent(value)];
100
- }
101
- if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
102
- const mixed = await serializeMixedObject(value);
103
- if (mixed) {
104
- return mixed;
105
- }
106
- }
107
- return [{ text: JSON.stringify(value), type: 'text' }];
108
- };
109
- // ---------------------------------------------------------------------------
110
- // Handler factory
111
- // ---------------------------------------------------------------------------
112
- /** Create an error result for MCP responses. */
113
- const mcpError = (message) => ({
114
- content: [{ text: message, type: 'text' }],
115
- isError: true,
116
- });
117
- /** Add the MCP trailhead marker while preserving any existing context extras. */
118
- const withMcpTrailhead = (progressCb) => ({
119
- ...(progressCb === undefined ? {} : { progress: progressCb }),
120
- extensions: {
121
- [TRAILHEAD_KEY]: 'mcp',
122
- },
123
- });
124
- const createHandler = (t, gates, options) => async (args, extra) => {
125
- const progressCb = createMcpProgressCallback(extra);
126
- const result = await executeTrail(t, args, {
127
- abortSignal: extra.abortSignal,
128
- configValues: options.configValues,
129
- createContext: options.createContext,
130
- ctx: withMcpTrailhead(progressCb),
131
- gates,
132
- provisions: options.provisions,
133
- });
134
- if (result.isOk()) {
135
- return { content: await serializeOutput(result.value) };
136
- }
137
- return mcpError(result.error.message);
138
- };
139
- // ---------------------------------------------------------------------------
140
- // Builder
141
- // ---------------------------------------------------------------------------
142
- /**
143
- * Build MCP tool definitions from an App's topology.
144
- *
145
- * Each trail in the topo becomes an McpToolDefinition with:
146
- * - A derived tool name (app-prefixed, underscore-delimited)
147
- * - JSON Schema input from zodToJsonSchema
148
- * - MCP annotations from trail meta
149
- * - A handler that validates, composes gates, executes, and maps results
150
- */
151
- /** Check if a trail should be included based on meta and filters. */
152
- const shouldInclude = (trail, options) => {
153
- if (trail.meta?.['internal'] === true) {
154
- return false;
155
- }
156
- if (options.includeTrails !== undefined && options.includeTrails.length > 0) {
157
- return options.includeTrails.includes(trail.id);
158
- }
159
- if (options.excludeTrails !== undefined &&
160
- options.excludeTrails.includes(trail.id)) {
161
- return false;
162
- }
163
- return true;
164
- };
165
- /** Build a description with optional example input appended. */
166
- const buildDescription = (trail) => {
167
- let { description } = trail;
168
- if (description !== undefined &&
169
- trail.examples !== undefined &&
170
- trail.examples.length > 0) {
171
- const [firstExample] = trail.examples;
172
- if (firstExample !== undefined) {
173
- description = `${description}\n\nExample input: ${JSON.stringify(firstExample.input)}`;
174
- }
175
- }
176
- return description;
177
- };
178
- /** Build a single MCP tool definition from a trail. */
179
- const buildToolDefinition = (app, trail, gates, options) => {
180
- const rawAnnotations = deriveAnnotations(trail);
181
- const annotations = Object.keys(rawAnnotations).length > 0 ? rawAnnotations : undefined;
182
- return {
183
- annotations,
184
- description: buildDescription(trail),
185
- handler: createHandler(trail, gates, options),
186
- inputSchema: zodToJsonSchema(trail.input),
187
- name: deriveToolName(app.name, trail.id),
188
- trailId: trail.id,
189
- };
190
- };
191
- /** Register a trail as an MCP tool, checking for name collisions. */
192
- const registerTool = (app, trailItem, gates, options, nameToTrailId, tools) => {
193
- const toolName = deriveToolName(app.name, trailItem.id);
194
- const existingId = nameToTrailId.get(toolName);
195
- if (existingId !== undefined) {
196
- return Result.err(new ValidationError(`MCP tool-name collision: trails "${existingId}" and "${trailItem.id}" both derive the tool name "${toolName}"`));
197
- }
198
- nameToTrailId.set(toolName, trailItem.id);
199
- tools.push(buildToolDefinition(app, trailItem, gates, options));
200
- return Result.ok();
201
- };
202
- /** Filter topo items to eligible trails. */
203
- const eligibleTrails = (app, options) => app.list().filter((trail) => shouldInclude(trail, options));
204
- const validateToolBuild = (app, options) => {
205
- if (options.validate === false) {
206
- return Result.ok();
207
- }
208
- const validated = validateEstablishedTopo(app);
209
- return validated.isErr() ? Result.err(validated.error) : Result.ok();
210
- };
211
- const registerTools = (app, options, gates) => {
212
- const tools = [];
213
- const nameToTrailId = new Map();
214
- for (const trailItem of eligibleTrails(app, options)) {
215
- const registered = registerTool(app, trailItem, gates, options, nameToTrailId, tools);
216
- if (registered.isErr()) {
217
- return registered;
218
- }
219
- }
220
- return Result.ok(tools);
221
- };
222
- export const buildMcpTools = (app, options = {}) => {
223
- const validation = validateToolBuild(app, options);
224
- if (validation.isErr()) {
225
- return validation;
226
- }
227
- return registerTools(app, options, options.gates ?? []);
228
- };
229
- //# sourceMappingURL=build.js.map
package/dist/build.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,MAAM,EACN,aAAa,EACb,eAAe,EACf,YAAY,EACZ,SAAS,EACT,uBAAuB,EACvB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAWxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAk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AS,EACT,UAAgC,EAAE,EACE,EAAE;IACtC,MAAM,UAAU,GAAG,iBAAiB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACnD,IAAI,UAAU,CAAC,KAAK,EAAE,EAAE,CAAC;QACvB,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,OAAO,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;AAC1D,CAAC,CAAC"}
package/dist/index.d.ts DELETED
@@ -1,7 +0,0 @@
1
- export { buildMcpTools, type BuildMcpToolsOptions, type McpToolDefinition, type McpToolResult, type McpContent, type McpExtra, } from './build.js';
2
- export { deriveToolName } from './tool-name.js';
3
- export { deriveAnnotations, type McpAnnotations } from './annotations.js';
4
- export { createMcpProgressCallback } from './progress.js';
5
- export { trailhead, type TrailheadMcpOptions } from './trailhead.js';
6
- export { connectStdio } from './stdio.js';
7
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,QAAQ,GACd,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGhD,OAAO,EAAE,iBAAiB,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAG1E,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAG1D,OAAO,EAAE,SAAS,EAAE,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAGrE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js DELETED
@@ -1,13 +0,0 @@
1
- // Build
2
- export { buildMcpTools, } from './build.js';
3
- // Tool naming
4
- export { deriveToolName } from './tool-name.js';
5
- // Annotations
6
- export { deriveAnnotations } from './annotations.js';
7
- // Progress
8
- export { createMcpProgressCallback } from './progress.js';
9
- // Trailhead
10
- export { trailhead } from './trailhead.js';
11
- // Transport
12
- export { connectStdio } from './stdio.js';
13
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,QAAQ;AACR,OAAO,EACL,aAAa,GAMd,MAAM,YAAY,CAAC;AAEpB,cAAc;AACd,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,cAAc;AACd,OAAO,EAAE,iBAAiB,EAAuB,MAAM,kBAAkB,CAAC;AAE1E,WAAW;AACX,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAE1D,YAAY;AACZ,OAAO,EAAE,SAAS,EAA4B,MAAM,gBAAgB,CAAC;AAErE,YAAY;AACZ,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
@@ -1,13 +0,0 @@
1
- /**
2
- * Bridge Trails ProgressCallback to MCP sendProgress notifications.
3
- */
4
- import type { ProgressCallback } from '@ontrails/core';
5
- import type { McpExtra } from './build.js';
6
- /**
7
- * Create a ProgressCallback that bridges to MCP's sendProgress.
8
- *
9
- * Returns `undefined` if the MCP client did not provide a progressToken
10
- * (meaning no progress reporting was requested).
11
- */
12
- export declare const createMcpProgressCallback: (extra: McpExtra) => ProgressCallback | undefined;
13
- //# sourceMappingURL=progress.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../src/progress.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAiB,MAAM,gBAAgB,CAAC;AAEtE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AA6C3C;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,GACpC,OAAO,QAAQ,KACd,gBAAgB,GAAG,SAarB,CAAC"}
package/dist/progress.js DELETED
@@ -1,51 +0,0 @@
1
- /**
2
- * Bridge Trails ProgressCallback to MCP sendProgress notifications.
3
- */
4
- /** Fire-and-forget a progress send, swallowing transport errors. */
5
- const fireSend = async (send, current, total) => {
6
- try {
7
- await send(current, total);
8
- }
9
- catch {
10
- /* Transport errors are expected and safe to ignore */
11
- }
12
- };
13
- const handleProgress = (event, send) => {
14
- if (event.current !== undefined && event.total !== undefined) {
15
- fireSend(send, event.current, event.total);
16
- }
17
- else if (event.current !== undefined) {
18
- fireSend(send, event.current, 0);
19
- }
20
- };
21
- const progressHandlers = {
22
- complete: (_event, send) => fireSend(send, 1, 1),
23
- error: () => {
24
- /* No progress notification for errors */
25
- },
26
- progress: handleProgress,
27
- start: (_event, send) => fireSend(send, 0, 1),
28
- };
29
- // ---------------------------------------------------------------------------
30
- // Factory
31
- // ---------------------------------------------------------------------------
32
- /**
33
- * Create a ProgressCallback that bridges to MCP's sendProgress.
34
- *
35
- * Returns `undefined` if the MCP client did not provide a progressToken
36
- * (meaning no progress reporting was requested).
37
- */
38
- export const createMcpProgressCallback = (extra) => {
39
- if (extra.progressToken === undefined || extra.progressToken === null) {
40
- return undefined;
41
- }
42
- if (typeof extra.sendProgress !== 'function') {
43
- return undefined;
44
- }
45
- const send = extra.sendProgress;
46
- return (event) => {
47
- const handler = progressHandlers[event.type];
48
- handler?.(event, send);
49
- };
50
- };
51
- //# sourceMappingURL=progress.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"progress.js","sourceRoot":"","sources":["../src/progress.ts"],"names":[],"mappings":"AAAA;;GAEG;AAYH,oEAAoE;AACpE,MAAM,QAAQ,GAAG,KAAK,EACpB,IAAY,EACZ,OAAe,EACf,KAAa,EACE,EAAE;IACjB,IAAI,CAAC;QACH,MAAM,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,sDAAsD;IACxD,CAAC;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KAAK,CAAC,IAAI,CAAC,CAAC;QAC7C,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACzB,CAAC,CAAC;AACJ,CAAC,CAAC"}
package/dist/stdio.d.ts DELETED
@@ -1,12 +0,0 @@
1
- /**
2
- * Thin wrapper around MCP SDK's StdioServerTransport.
3
- *
4
- * Exists as a separate function so it can be swapped for other transports
5
- * (SSE, streamable HTTP) without changing trailhead().
6
- */
7
- import type { Server } from '@modelcontextprotocol/sdk/server/index.js';
8
- /**
9
- * Connect an MCP server to stdio transport.
10
- */
11
- export declare const connectStdio: (server: Server) => Promise<void>;
12
- //# sourceMappingURL=stdio.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../src/stdio.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAGxE;;GAEG;AACH,eAAO,MAAM,YAAY,GAAU,QAAQ,MAAM,KAAG,OAAO,CAAC,IAAI,CAG/D,CAAC"}
package/dist/stdio.js DELETED
@@ -1,15 +0,0 @@
1
- /**
2
- * Thin wrapper around MCP SDK's StdioServerTransport.
3
- *
4
- * Exists as a separate function so it can be swapped for other transports
5
- * (SSE, streamable HTTP) without changing trailhead().
6
- */
7
- import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
8
- /**
9
- * Connect an MCP server to stdio transport.
10
- */
11
- export const connectStdio = async (server) => {
12
- const transport = new StdioServerTransport();
13
- await server.connect(transport);
14
- };
15
- //# sourceMappingURL=stdio.js.map
package/dist/stdio.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"stdio.js","sourceRoot":"","sources":["../src/stdio.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEjF;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,MAAc,EAAiB,EAAE;IAClE,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC,CAAC"}
@@ -1,15 +0,0 @@
1
- /**
2
- * Derive MCP-safe tool names from app name + trail ID.
3
- *
4
- * MCP tool names must be [a-z0-9_]+. We prefix with the app name,
5
- * replace dots and hyphens with underscores, and lowercase everything.
6
- */
7
- /**
8
- * Convert app name + trail ID to an MCP-safe tool name.
9
- *
10
- * @example
11
- * deriveToolName("myapp", "entity.show") // "myapp_entity_show"
12
- * deriveToolName("dispatch", "patch.search") // "dispatch_patch_search"
13
- */
14
- export declare const deriveToolName: (appName: string, trailId: string) => string;
15
- //# sourceMappingURL=tool-name.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tool-name.d.ts","sourceRoot":"","sources":["../src/tool-name.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,EAAE,SAAS,MAAM,KAAG,MAIjE,CAAC"}
package/dist/tool-name.js DELETED
@@ -1,19 +0,0 @@
1
- /**
2
- * Derive MCP-safe tool names from app name + trail ID.
3
- *
4
- * MCP tool names must be [a-z0-9_]+. We prefix with the app name,
5
- * replace dots and hyphens with underscores, and lowercase everything.
6
- */
7
- /**
8
- * Convert app name + trail ID to an MCP-safe tool name.
9
- *
10
- * @example
11
- * deriveToolName("myapp", "entity.show") // "myapp_entity_show"
12
- * deriveToolName("dispatch", "patch.search") // "dispatch_patch_search"
13
- */
14
- export const deriveToolName = (appName, trailId) => {
15
- const prefix = appName.toLowerCase().replaceAll(/[.-]/g, '_');
16
- const suffix = trailId.toLowerCase().replaceAll(/[.-]/g, '_');
17
- return `${prefix}_${suffix}`;
18
- };
19
- //# sourceMappingURL=tool-name.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tool-name.js","sourceRoot":"","sources":["../src/tool-name.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAe,EAAE,OAAe,EAAU,EAAE;IACzE,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IAC9D,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IAC9D,OAAO,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC;AAC/B,CAAC,CAAC"}
@@ -1,41 +0,0 @@
1
- /**
2
- * trailhead() -- 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 trailhead(app);
9
- * ```
10
- */
11
- import { Server } from '@modelcontextprotocol/sdk/server/index.js';
12
- import type { Gate, ProvisionOverrideMap, Topo, TrailContextInit } from '@ontrails/core';
13
- import type { McpToolDefinition } from './build.js';
14
- export interface TrailheadMcpOptions {
15
- /** Config values for provisions that declare a `config` schema, keyed by provision 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 gates?: readonly Gate[] | undefined;
21
- readonly provisions?: ProvisionOverrideMap | undefined;
22
- readonly serverInfo?: {
23
- readonly name?: string | undefined;
24
- readonly version?: string | undefined;
25
- } | undefined;
26
- readonly transport?: 'stdio' | 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 trailhead: (app: Topo, options?: TrailheadMcpOptions) => Promise<void>;
41
- //# sourceMappingURL=trailhead.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"trailhead.d.ts","sourceRoot":"","sources":["../src/trailhead.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAKnE,OAAO,KAAK,EACV,IAAI,EACJ,oBAAoB,EACpB,IAAI,EACJ,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAQpD,MAAM,WAAW,mBAAmB;IAClC,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,GACpD,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,KAAK,CAAC,EAAE,SAAS,IAAI,EAAE,GAAG,SAAS,CAAC;IAC7C,QAAQ,CAAC,UAAU,CAAC,EAAE,oBAAoB,GAAG,SAAS,CAAC;IACvD,QAAQ,CAAC,UAAU,CAAC,EAChB;QACE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QACnC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;KACvC,GACD,SAAS,CAAC;IACd,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACzC,6EAA6E;IAC7E,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACzC;AAMD;;GAEG;AACH,eAAO,MAAM,eAAe,GAC1B,OAAO,iBAAiB,EAAE,EAC1B,MAAM;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,KACxD,MAmEF,CAAC;AAMF;;GAEG;AACH,eAAO,MAAM,SAAS,GACpB,KAAK,IAAI,EACT,UAAS,mBAAwB,KAChC,OAAO,CAAC,IAAI,CA4Bd,CAAC"}
package/dist/trailhead.js DELETED
@@ -1,109 +0,0 @@
1
- /**
2
- * trailhead() -- 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 trailhead(app);
9
- * ```
10
- */
11
- import { Server } from '@modelcontextprotocol/sdk/server/index.js';
12
- import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
13
- import { validateEstablishedTopo } 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
- // trailhead
80
- // ---------------------------------------------------------------------------
81
- /**
82
- * Build MCP tools from an App, create a server, and connect via stdio.
83
- */
84
- export const trailhead = async (app, options = {}) => {
85
- if (options.validate !== false) {
86
- const validated = validateEstablishedTopo(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
- gates: options.gates,
96
- includeTrails: options.includeTrails,
97
- provisions: options.provisions,
98
- validate: options.validate,
99
- });
100
- if (toolsResult.isErr()) {
101
- throw toolsResult.error;
102
- }
103
- const server = createMcpServer(toolsResult.value, {
104
- name: options.serverInfo?.name ?? app.name,
105
- version: options.serverInfo?.version ?? '0.1.0',
106
- });
107
- await connectStdio(server);
108
- };
109
- //# sourceMappingURL=trailhead.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"trailhead.js","sourceRoot":"","sources":["../src/trailhead.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,MAAM,EAA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