@ontrails/mcp 1.0.0-beta.2 → 1.0.0-beta.21
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 +300 -5
- package/README.md +70 -21
- package/package.json +11 -3
- package/src/annotations.ts +32 -9
- package/src/build.ts +1236 -137
- package/src/index.ts +31 -4
- package/src/progress.ts +22 -0
- package/src/resources.ts +228 -0
- package/src/stdio.ts +9 -1
- package/src/surface.ts +279 -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 -29
- 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 -190
- 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 -70
- package/src/__tests__/blaze.test.ts +0 -105
- package/src/__tests__/build.test.ts +0 -377
- 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/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
|
-
{"version":3,"file":"blaze.d.ts","sourceRoot":"","sources":["../src/blaze.ts"],"names":[],"mappings":"AAAA;;;;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
* 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
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"blaze.js","sourceRoot":"","sources":["../src/blaze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E,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;AAQH,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAS,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEvE,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,CAAC,EAAE,SAAS,KAAK,EAAE,GAAG,SAAS,CAAC;CAChD;AAED,MAAM,WAAW,iBAAiB;I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UAAS,oBAAyB,KACjC,iBAAiB,EAiBnB,CAAC"}
|
package/dist/build.js
DELETED
|
@@ -1,190 +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 { composeLayers, createTrailContext, validateInput, zodToJsonSchema, } from '@ontrails/core';
|
|
9
|
-
import { deriveAnnotations } from './annotations.js';
|
|
10
|
-
import { createMcpProgressCallback } from './progress.js';
|
|
11
|
-
import { deriveToolName } from './tool-name.js';
|
|
12
|
-
const isBlobRef = (value) => {
|
|
13
|
-
if (typeof value !== 'object' || value === null) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
const obj = value;
|
|
17
|
-
return (obj['kind'] === 'blob' &&
|
|
18
|
-
obj['data'] instanceof Uint8Array &&
|
|
19
|
-
typeof obj['mimeType'] === 'string');
|
|
20
|
-
};
|
|
21
|
-
const uint8ArrayToBase64 = (bytes) => {
|
|
22
|
-
// Use btoa with manual conversion for runtime-agnostic base64
|
|
23
|
-
let binary = '';
|
|
24
|
-
for (const byte of bytes) {
|
|
25
|
-
binary += String.fromCodePoint(byte);
|
|
26
|
-
}
|
|
27
|
-
return btoa(binary);
|
|
28
|
-
};
|
|
29
|
-
const blobToContent = (blob) => {
|
|
30
|
-
if (blob.mimeType.startsWith('image/')) {
|
|
31
|
-
return {
|
|
32
|
-
data: uint8ArrayToBase64(blob.data),
|
|
33
|
-
mimeType: blob.mimeType,
|
|
34
|
-
type: 'image',
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
mimeType: blob.mimeType,
|
|
39
|
-
type: 'resource',
|
|
40
|
-
uri: `blob://${blob.name ?? 'unnamed'}`,
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
/** Separate blob fields from non-blob fields in an object. */
|
|
44
|
-
const separateBlobFields = (obj) => {
|
|
45
|
-
const blobContents = [];
|
|
46
|
-
const textFields = {};
|
|
47
|
-
let hasBlobFields = false;
|
|
48
|
-
for (const [key, val] of Object.entries(obj)) {
|
|
49
|
-
if (isBlobRef(val)) {
|
|
50
|
-
hasBlobFields = true;
|
|
51
|
-
blobContents.push(blobToContent(val));
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
textFields[key] = val;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return { blobContents, hasBlobFields, textFields };
|
|
58
|
-
};
|
|
59
|
-
/** Serialize a mixed blob/text object to MCP content. */
|
|
60
|
-
const serializeMixedObject = (obj) => {
|
|
61
|
-
const { blobContents, hasBlobFields, textFields } = separateBlobFields(obj);
|
|
62
|
-
if (!hasBlobFields) {
|
|
63
|
-
return undefined;
|
|
64
|
-
}
|
|
65
|
-
if (Object.keys(textFields).length > 0) {
|
|
66
|
-
blobContents.unshift({ text: JSON.stringify(textFields), type: 'text' });
|
|
67
|
-
}
|
|
68
|
-
return blobContents;
|
|
69
|
-
};
|
|
70
|
-
const serializeOutput = (value) => {
|
|
71
|
-
if (isBlobRef(value)) {
|
|
72
|
-
return [blobToContent(value)];
|
|
73
|
-
}
|
|
74
|
-
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
75
|
-
const mixed = serializeMixedObject(value);
|
|
76
|
-
if (mixed) {
|
|
77
|
-
return mixed;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return [{ text: JSON.stringify(value), type: 'text' }];
|
|
81
|
-
};
|
|
82
|
-
// ---------------------------------------------------------------------------
|
|
83
|
-
// Handler factory
|
|
84
|
-
// ---------------------------------------------------------------------------
|
|
85
|
-
/** Create an error result for MCP responses. */
|
|
86
|
-
const mcpError = (message) => ({
|
|
87
|
-
content: [{ text: message, type: 'text' }],
|
|
88
|
-
isError: true,
|
|
89
|
-
});
|
|
90
|
-
/** Build a TrailContext from options and MCP extra. */
|
|
91
|
-
const buildTrailContext = async (options, extra) => {
|
|
92
|
-
const baseContext = options.createContext !== undefined && options.createContext !== null
|
|
93
|
-
? await options.createContext()
|
|
94
|
-
: createTrailContext();
|
|
95
|
-
const signal = extra.signal ?? baseContext.signal;
|
|
96
|
-
const progressCb = createMcpProgressCallback(extra);
|
|
97
|
-
return {
|
|
98
|
-
...baseContext,
|
|
99
|
-
signal,
|
|
100
|
-
...(progressCb === undefined ? {} : { progress: progressCb }),
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
/** Execute a trail and map the result to an MCP response. */
|
|
104
|
-
const executeAndMap = async (trail, validatedInput, ctx, layers) => {
|
|
105
|
-
const impl = composeLayers([...layers], trail, trail.implementation);
|
|
106
|
-
try {
|
|
107
|
-
const result = await impl(validatedInput, ctx);
|
|
108
|
-
if (result.isOk()) {
|
|
109
|
-
return { content: serializeOutput(result.value) };
|
|
110
|
-
}
|
|
111
|
-
return mcpError(result.error.message);
|
|
112
|
-
}
|
|
113
|
-
catch (error) {
|
|
114
|
-
return mcpError(error instanceof Error ? error.message : String(error));
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
const createHandler = (trail, layers, options) => async (args, extra) => {
|
|
118
|
-
const validated = validateInput(trail.input, args);
|
|
119
|
-
if (validated.isErr()) {
|
|
120
|
-
return mcpError(validated.error.message);
|
|
121
|
-
}
|
|
122
|
-
const ctx = await buildTrailContext(options, extra);
|
|
123
|
-
return executeAndMap(trail, validated.value, ctx, layers);
|
|
124
|
-
};
|
|
125
|
-
// ---------------------------------------------------------------------------
|
|
126
|
-
// Builder
|
|
127
|
-
// ---------------------------------------------------------------------------
|
|
128
|
-
/**
|
|
129
|
-
* Build MCP tool definitions from an App's topology.
|
|
130
|
-
*
|
|
131
|
-
* Each trail in the topo becomes an McpToolDefinition with:
|
|
132
|
-
* - A derived tool name (app-prefixed, underscore-delimited)
|
|
133
|
-
* - JSON Schema input from zodToJsonSchema
|
|
134
|
-
* - MCP annotations from trail markers
|
|
135
|
-
* - A handler that validates, composes layers, executes, and maps results
|
|
136
|
-
*/
|
|
137
|
-
/** Check if a trail should be included based on markers and filters. */
|
|
138
|
-
const shouldInclude = (trail, options) => {
|
|
139
|
-
if (trail.markers?.['internal'] === true) {
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
if (options.includeTrails !== undefined && options.includeTrails.length > 0) {
|
|
143
|
-
return options.includeTrails.includes(trail.id);
|
|
144
|
-
}
|
|
145
|
-
if (options.excludeTrails !== undefined &&
|
|
146
|
-
options.excludeTrails.includes(trail.id)) {
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
return true;
|
|
150
|
-
};
|
|
151
|
-
/** Build a description with optional example input appended. */
|
|
152
|
-
const buildDescription = (trail) => {
|
|
153
|
-
let { description } = trail;
|
|
154
|
-
if (description !== undefined &&
|
|
155
|
-
trail.examples !== undefined &&
|
|
156
|
-
trail.examples.length > 0) {
|
|
157
|
-
const [firstExample] = trail.examples;
|
|
158
|
-
if (firstExample !== undefined) {
|
|
159
|
-
description = `${description}\n\nExample input: ${JSON.stringify(firstExample.input)}`;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return description;
|
|
163
|
-
};
|
|
164
|
-
/** Build a single MCP tool definition from a trail. */
|
|
165
|
-
const buildToolDefinition = (app, trail, layers, options) => {
|
|
166
|
-
const rawAnnotations = deriveAnnotations(trail);
|
|
167
|
-
const annotations = Object.keys(rawAnnotations).length > 0 ? rawAnnotations : undefined;
|
|
168
|
-
return {
|
|
169
|
-
annotations,
|
|
170
|
-
description: buildDescription(trail),
|
|
171
|
-
handler: createHandler(trail, layers, options),
|
|
172
|
-
inputSchema: zodToJsonSchema(trail.input),
|
|
173
|
-
name: deriveToolName(app.name, trail.id),
|
|
174
|
-
};
|
|
175
|
-
};
|
|
176
|
-
export const buildMcpTools = (app, options = {}) => {
|
|
177
|
-
const layers = options.layers ?? [];
|
|
178
|
-
const tools = [];
|
|
179
|
-
for (const item of app.list()) {
|
|
180
|
-
if (item.kind !== 'trail' && item.kind !== 'hike') {
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
if (!shouldInclude(item, options)) {
|
|
184
|
-
continue;
|
|
185
|
-
}
|
|
186
|
-
tools.push(buildToolDefinition(app, item, layers, options));
|
|
187
|
-
}
|
|
188
|
-
return tools;
|
|
189
|
-
};
|
|
190
|
-
//# 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,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAIxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AA0DhD,MAAM,SAAS,GAAG,CAAC,KAAc,EAAoB,EAAE;IACrD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,GAAG,GAAG,KAAgC,CAAC;IAC7C,OAAO,CACL,GAAG,CAAC,MAAM,CAAC,KAAK,MAAM;QACtB,GAAG,CAAC,MAAM,CAAC,YAAY,UAAU;QACjC,OAAO,GAAG,CAAC,UAAU,CAAC,KAAK,QAAQ,CACpC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,KAAiB,EAAU,EAAE;IACvD,8DAA8D;IAC9D,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,IAAI,MAAM,CAAC,aAAa,CAAC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C,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;QAC9B,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAClD,SAAS;QACX,CAAC;QACD,IAAI,CAAC,aAAa,CAAC,IAA+B,EAAE,OAAO,CAAC,EAAE,CAAC;YAC7D,SAAS;QACX,CAAC;QACD,KAAK,CAAC,IAAI,CACR,mBAAmB,CAAC,GAAG,EAAE,IAA+B,EAAE,MAAM,EAAE,OAAO,CAAC,CAC3E,CAAC;IACJ,CAAC;IAED,OAAO,KAAK,CAAC;AACf,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 { blaze, type BlazeMcpOptions } from './blaze.js';
|
|
6
|
-
export { connectStdio } from './stdio.js';
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -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,KAAK,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAGzD,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
|
-
// Blaze
|
|
10
|
-
export { blaze } from './blaze.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,QAAQ;AACR,OAAO,EAAE,KAAK,EAAwB,MAAM,YAAY,CAAC;AAEzD,YAAY;AACZ,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/progress.d.ts
DELETED
|
@@ -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
|
package/dist/progress.d.ts.map
DELETED
|
@@ -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
|
package/dist/progress.js.map
DELETED
|
@@ -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;AACH,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,KAAoB,EAAE,IAAY,EAAQ,EAAE;IAClE,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAC7D,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,OAA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K's StdioServerTransport.
|
|
3
|
-
*
|
|
4
|
-
* Exists as a separate function so it can be swapped for other transports
|
|
5
|
-
* (SSE, streamable HTTP) without changing blaze().
|
|
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
|
package/dist/stdio.d.ts.map
DELETED
|
@@ -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 blaze().
|
|
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"}
|
package/dist/tool-name.d.ts
DELETED
|
@@ -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
|
package/dist/tool-name.d.ts.map
DELETED
|
@@ -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
|
package/dist/tool-name.js.map
DELETED
|
@@ -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,70 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test';
|
|
2
|
-
|
|
3
|
-
import { deriveAnnotations } from '../annotations.js';
|
|
4
|
-
|
|
5
|
-
describe('deriveAnnotations', () => {
|
|
6
|
-
test('readOnly trail produces readOnlyHint', () => {
|
|
7
|
-
const annotations = deriveAnnotations({ readOnly: true });
|
|
8
|
-
expect(annotations.readOnlyHint).toBe(true);
|
|
9
|
-
expect(annotations.destructiveHint).toBeUndefined();
|
|
10
|
-
expect(annotations.idempotentHint).toBeUndefined();
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
test('destructive trail produces destructiveHint', () => {
|
|
14
|
-
const annotations = deriveAnnotations({ destructive: true });
|
|
15
|
-
expect(annotations.destructiveHint).toBe(true);
|
|
16
|
-
expect(annotations.readOnlyHint).toBeUndefined();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test('idempotent trail produces idempotentHint', () => {
|
|
20
|
-
const annotations = deriveAnnotations({ idempotent: true });
|
|
21
|
-
expect(annotations.idempotentHint).toBe(true);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('multiple markers combine correctly', () => {
|
|
25
|
-
const annotations = deriveAnnotations({
|
|
26
|
-
idempotent: true,
|
|
27
|
-
readOnly: true,
|
|
28
|
-
});
|
|
29
|
-
expect(annotations.readOnlyHint).toBe(true);
|
|
30
|
-
expect(annotations.idempotentHint).toBe(true);
|
|
31
|
-
expect(annotations.destructiveHint).toBeUndefined();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test('no markers produces empty annotations', () => {
|
|
35
|
-
const annotations = deriveAnnotations({});
|
|
36
|
-
expect(annotations.readOnlyHint).toBeUndefined();
|
|
37
|
-
expect(annotations.destructiveHint).toBeUndefined();
|
|
38
|
-
expect(annotations.idempotentHint).toBeUndefined();
|
|
39
|
-
expect(annotations.title).toBeUndefined();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test('description maps to title', () => {
|
|
43
|
-
const annotations = deriveAnnotations({
|
|
44
|
-
description: 'Show entity details',
|
|
45
|
-
});
|
|
46
|
-
expect(annotations.title).toBe('Show entity details');
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('all markers plus description', () => {
|
|
50
|
-
const annotations = deriveAnnotations({
|
|
51
|
-
description: 'A trail',
|
|
52
|
-
destructive: true,
|
|
53
|
-
idempotent: true,
|
|
54
|
-
readOnly: true,
|
|
55
|
-
});
|
|
56
|
-
expect(annotations.readOnlyHint).toBe(true);
|
|
57
|
-
expect(annotations.destructiveHint).toBe(true);
|
|
58
|
-
expect(annotations.idempotentHint).toBe(true);
|
|
59
|
-
expect(annotations.title).toBe('A trail');
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('false values are not included', () => {
|
|
63
|
-
const annotations = deriveAnnotations({
|
|
64
|
-
destructive: false,
|
|
65
|
-
readOnly: false,
|
|
66
|
-
});
|
|
67
|
-
expect(annotations.readOnlyHint).toBeUndefined();
|
|
68
|
-
expect(annotations.destructiveHint).toBeUndefined();
|
|
69
|
-
});
|
|
70
|
-
});
|