@ontrails/mcp 1.0.0-beta.13 → 1.0.0-beta.15
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/.turbo/turbo-lint.log +1 -1
- package/CHANGELOG.md +18 -0
- package/README.md +18 -15
- package/dist/annotations.d.ts +1 -1
- package/dist/annotations.d.ts.map +1 -1
- package/dist/annotations.js.map +1 -1
- package/dist/build.d.ts +13 -10
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +38 -34
- package/dist/build.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/stdio.d.ts +1 -1
- package/dist/stdio.js +1 -1
- package/dist/surface.d.ts +35 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/{blaze.js → surface.js} +44 -29
- package/dist/surface.js.map +1 -0
- package/dist/trailhead.d.ts +28 -12
- package/dist/trailhead.d.ts.map +1 -1
- package/dist/trailhead.js +48 -20
- package/dist/trailhead.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/build.test.ts +162 -28
- package/src/__tests__/{trailhead.test.ts → surface.test.ts} +59 -26
- package/src/annotations.ts +4 -1
- package/src/build.ts +79 -62
- package/src/index.ts +9 -4
- package/src/stdio.ts +1 -1
- package/src/{trailhead.ts → surface.ts} +74 -49
- package/tsconfig.tests.json +10 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/blaze.d.ts +0 -41
- package/dist/blaze.d.ts.map +0 -1
- package/dist/blaze.js.map +0 -1
package/.turbo/turbo-lint.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @ontrails/mcp
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [4ad6b25]
|
|
8
|
+
- @ontrails/core@1.0.0-beta.15
|
|
9
|
+
|
|
10
|
+
## 1.0.0-beta.14
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- 69057e9: Add hierarchical CLI command trees and structured input, enforce established-only topo exports across trailheads, move developer topo and tracker state onto shared `trails.db` with pins and maintenance flows, and ship schema-derived stores through `@ontrails/store` and its Drizzle runtime.
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [69057e9]
|
|
19
|
+
- @ontrails/core@1.0.0-beta.14
|
|
20
|
+
|
|
3
21
|
## 1.0.0-beta.13
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# @ontrails/mcp
|
|
2
2
|
|
|
3
|
-
MCP
|
|
3
|
+
MCP surface connector. One `surface()` call turns a topo into an MCP server with tool definitions, annotations, and progress bridging -- all derived from the trail contracts.
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
7
7
|
```typescript
|
|
8
8
|
import { trail, topo, Result } from '@ontrails/core';
|
|
9
|
-
import {
|
|
9
|
+
import { surface } from '@ontrails/mcp';
|
|
10
10
|
import { z } from 'zod';
|
|
11
11
|
|
|
12
12
|
const greet = trail('greet', {
|
|
@@ -15,8 +15,8 @@ const greet = trail('greet', {
|
|
|
15
15
|
blaze: (input) => Result.ok(`Hello, ${input.name}!`),
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
const
|
|
19
|
-
await
|
|
18
|
+
const graph = topo('myapp', { greet });
|
|
19
|
+
await surface(graph);
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
This starts an MCP server over stdio with a `myapp_greet` tool. The tool gets `readOnlyHint: true` and a JSON Schema input -- both derived from the trail definition.
|
|
@@ -24,9 +24,9 @@ This starts an MCP server over stdio with a `myapp_greet` tool. The tool gets `r
|
|
|
24
24
|
For more control, build the tools yourself:
|
|
25
25
|
|
|
26
26
|
```typescript
|
|
27
|
-
import {
|
|
27
|
+
import { deriveMcpTools } from '@ontrails/mcp';
|
|
28
28
|
|
|
29
|
-
const result =
|
|
29
|
+
const result = deriveMcpTools(graph);
|
|
30
30
|
if (result.isErr()) throw result.error; // ValidationError on tool-name collision
|
|
31
31
|
for (const tool of result.value) {
|
|
32
32
|
server.registerTool(tool.name, tool.handler, {
|
|
@@ -36,23 +36,23 @@ for (const tool of result.value) {
|
|
|
36
36
|
}
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
`
|
|
39
|
+
`deriveMcpTools` returns `Result<McpToolDefinition[], Error>` rather than a bare array. It returns `Result.err(ValidationError)` if two trails derive the same MCP tool name. Each `McpToolDefinition` includes a `trailId` field that records which trail the tool was derived from.
|
|
40
40
|
|
|
41
41
|
## API
|
|
42
42
|
|
|
43
43
|
| Export | What it does |
|
|
44
44
|
| --- | --- |
|
|
45
|
-
| `
|
|
46
|
-
| `
|
|
45
|
+
| `surface(graph, options?)` | Start an MCP server with all trails as tools |
|
|
46
|
+
| `deriveMcpTools(graph, options?)` | Build tool definitions without starting a server |
|
|
47
47
|
| `deriveToolName(appName, trailId)` | Compute the MCP tool name from app and trail IDs |
|
|
48
|
-
| `deriveAnnotations(trail)` | Extract MCP annotations from trail intent and
|
|
48
|
+
| `deriveAnnotations(trail)` | Extract MCP annotations from trail intent, idempotency, and description |
|
|
49
49
|
| `createMcpProgressCallback(server)` | Bridge `ctx.progress` to MCP `notifications/progress` |
|
|
50
50
|
|
|
51
51
|
See the [API Reference](../../docs/api-reference.md) for the full list.
|
|
52
52
|
|
|
53
53
|
## Annotations
|
|
54
54
|
|
|
55
|
-
Trail intent and
|
|
55
|
+
Trail intent, idempotency, and description map directly to MCP annotations:
|
|
56
56
|
|
|
57
57
|
| Trail field | MCP annotation |
|
|
58
58
|
| --- | --- |
|
|
@@ -67,9 +67,9 @@ No manual annotation definitions. The contract is the source of truth.
|
|
|
67
67
|
|
|
68
68
|
Trail IDs become MCP tool names with the app prefix: `entity.show` in app `myapp` becomes `myapp_entity_show`. Dots and hyphens become underscores, everything lowercase.
|
|
69
69
|
|
|
70
|
-
##
|
|
70
|
+
## Resource resolution
|
|
71
71
|
|
|
72
|
-
Declared
|
|
72
|
+
Declared resources on each trail are resolved into the context before the implementation runs.
|
|
73
73
|
|
|
74
74
|
## Progress bridge
|
|
75
75
|
|
|
@@ -90,10 +90,13 @@ const importTrail = trail('data.import', {
|
|
|
90
90
|
## Filtering
|
|
91
91
|
|
|
92
92
|
```typescript
|
|
93
|
-
await
|
|
94
|
-
await
|
|
93
|
+
await surface(graph, { include: ['entity.**', 'search'] });
|
|
94
|
+
await surface(graph, { exclude: ['internal.debug'] });
|
|
95
95
|
```
|
|
96
96
|
|
|
97
|
+
`*` matches one dotted segment and `**` matches any depth. Trails declared with
|
|
98
|
+
`visibility: 'internal'` stay hidden unless you include their exact trail ID.
|
|
99
|
+
|
|
97
100
|
## Installation
|
|
98
101
|
|
|
99
102
|
```bash
|
package/dist/annotations.d.ts
CHANGED
|
@@ -15,5 +15,5 @@ export interface McpAnnotations {
|
|
|
15
15
|
* Only sets hints that are explicitly declared on the trail.
|
|
16
16
|
* Omitted hints let the MCP SDK use its defaults.
|
|
17
17
|
*/
|
|
18
|
-
export declare const deriveAnnotations: (trail: Pick<Trail<unknown, unknown>, "intent" | "idempotent" | "description">) => McpAnnotations;
|
|
18
|
+
export declare const deriveAnnotations: (trail: Pick<Trail<unknown, unknown, unknown>, "intent" | "idempotent" | "description">) => McpAnnotations;
|
|
19
19
|
//# sourceMappingURL=annotations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,CACT,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAChC,QAAQ,GAAG,YAAY,GAAG,aAAa,CACxC,KACA,cAoBF,CAAC"}
|
package/dist/annotations.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,KAGC,EACe,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/build.d.ts
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Build MCP tool definitions from a Trails
|
|
2
|
+
* Build MCP tool definitions from a Trails graph.
|
|
3
3
|
*
|
|
4
4
|
* Iterates the topo, generates McpToolDefinition[] with handlers that
|
|
5
|
-
* validate input, compose
|
|
5
|
+
* validate input, compose layers, execute the implementation, and map
|
|
6
6
|
* Results to MCP responses.
|
|
7
7
|
*/
|
|
8
8
|
import { Result } from '@ontrails/core';
|
|
9
|
-
import type {
|
|
9
|
+
import type { Intent, Layer, ResourceOverrideMap, Topo, TrailContextInit } from '@ontrails/core';
|
|
10
10
|
import type { McpAnnotations } from './annotations.js';
|
|
11
|
-
export interface
|
|
12
|
-
/** Config values for
|
|
11
|
+
export interface DeriveMcpToolsOptions {
|
|
12
|
+
/** Config values for resources that declare a `config` schema, keyed by resource ID. */
|
|
13
13
|
readonly configValues?: Readonly<Record<string, Record<string, unknown>>> | undefined;
|
|
14
14
|
readonly createContext?: (() => TrailContextInit | Promise<TrailContextInit>) | undefined;
|
|
15
|
-
readonly
|
|
16
|
-
readonly
|
|
17
|
-
readonly
|
|
18
|
-
readonly
|
|
15
|
+
readonly exclude?: readonly string[] | undefined;
|
|
16
|
+
readonly include?: readonly string[] | undefined;
|
|
17
|
+
readonly intent?: readonly Intent[] | undefined;
|
|
18
|
+
readonly layers?: readonly Layer[] | undefined;
|
|
19
|
+
readonly resources?: ResourceOverrideMap | undefined;
|
|
20
|
+
/** Set to `false` to skip topo validation while building tools. */
|
|
21
|
+
readonly validate?: boolean | undefined;
|
|
19
22
|
}
|
|
20
23
|
export interface McpToolDefinition {
|
|
21
24
|
readonly annotations: McpAnnotations | undefined;
|
|
@@ -42,5 +45,5 @@ export interface McpContent {
|
|
|
42
45
|
readonly type: 'text' | 'image' | 'resource';
|
|
43
46
|
readonly uri?: string | undefined;
|
|
44
47
|
}
|
|
45
|
-
export declare const
|
|
48
|
+
export declare const deriveMcpTools: (graph: Topo, options?: DeriveMcpToolsOptions) => Result<McpToolDefinition[], Error>;
|
|
46
49
|
//# sourceMappingURL=build.d.ts.map
|
package/dist/build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,MAAM,
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,MAAM,EAQP,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAEV,MAAM,EACN,KAAK,EACL,mBAAmB,EACnB,IAAI,EAEJ,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tB,+CAA+C;IAC/C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACrD,QAAQ,CAAC,YAAY,CAAC,EAClB,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,GACnD,SAAS,CAAC;IACd,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;CAChD;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,SAAS,UAAU,EAAE,CAAC;IACxC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACxC;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,UAAU,CAAC;IAC7C,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACnC;AAsSD,eAAO,MAAM,cAAc,GACzB,OAAO,IAAI,EACX,UAAS,qBAA0B,KAClC,MAAM,CAAC,iBAAiB,EAAE,EAAE,KAAK,CAOnC,CAAC"}
|
package/dist/build.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Build MCP tool definitions from a Trails
|
|
2
|
+
* Build MCP tool definitions from a Trails graph.
|
|
3
3
|
*
|
|
4
4
|
* Iterates the topo, generates McpToolDefinition[] with handlers that
|
|
5
|
-
* validate input, compose
|
|
5
|
+
* validate input, compose layers, execute the implementation, and map
|
|
6
6
|
* Results to MCP responses.
|
|
7
7
|
*/
|
|
8
|
-
import { Result, TRAILHEAD_KEY, ValidationError, executeTrail, isBlobRef, zodToJsonSchema, } from '@ontrails/core';
|
|
8
|
+
import { Result, TRAILHEAD_KEY, ValidationError, executeTrail, filterSurfaceTrails, isBlobRef, validateEstablishedTopo, zodToJsonSchema, } from '@ontrails/core';
|
|
9
9
|
import { deriveAnnotations } from './annotations.js';
|
|
10
10
|
import { createMcpProgressCallback } from './progress.js';
|
|
11
11
|
import { deriveToolName } from './tool-name.js';
|
|
@@ -121,15 +121,16 @@ const withMcpTrailhead = (progressCb) => ({
|
|
|
121
121
|
[TRAILHEAD_KEY]: 'mcp',
|
|
122
122
|
},
|
|
123
123
|
});
|
|
124
|
-
const createHandler = (t,
|
|
124
|
+
const createHandler = (graph, t, layers, options) => async (args, extra) => {
|
|
125
125
|
const progressCb = createMcpProgressCallback(extra);
|
|
126
126
|
const result = await executeTrail(t, args, {
|
|
127
127
|
abortSignal: extra.abortSignal,
|
|
128
128
|
configValues: options.configValues,
|
|
129
129
|
createContext: options.createContext,
|
|
130
130
|
ctx: withMcpTrailhead(progressCb),
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
layers,
|
|
132
|
+
resources: options.resources,
|
|
133
|
+
topo: graph,
|
|
133
134
|
});
|
|
134
135
|
if (result.isOk()) {
|
|
135
136
|
return { content: await serializeOutput(result.value) };
|
|
@@ -140,28 +141,14 @@ const createHandler = (t, gates, options) => async (args, extra) => {
|
|
|
140
141
|
// Builder
|
|
141
142
|
// ---------------------------------------------------------------------------
|
|
142
143
|
/**
|
|
143
|
-
* Build MCP tool definitions from
|
|
144
|
+
* Build MCP tool definitions from a graph's topology.
|
|
144
145
|
*
|
|
145
146
|
* Each trail in the topo becomes an McpToolDefinition with:
|
|
146
|
-
* - A derived tool name (
|
|
147
|
+
* - A derived tool name (topo-name-prefixed, underscore-delimited)
|
|
147
148
|
* - JSON Schema input from zodToJsonSchema
|
|
148
149
|
* - MCP annotations from trail meta
|
|
149
|
-
* - A handler that validates, composes
|
|
150
|
+
* - A handler that validates, composes layers, executes, and maps results
|
|
150
151
|
*/
|
|
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
152
|
/** Build a description with optional example input appended. */
|
|
166
153
|
const buildDescription = (trail) => {
|
|
167
154
|
let { description } = trail;
|
|
@@ -176,41 +163,58 @@ const buildDescription = (trail) => {
|
|
|
176
163
|
return description;
|
|
177
164
|
};
|
|
178
165
|
/** Build a single MCP tool definition from a trail. */
|
|
179
|
-
const buildToolDefinition = (
|
|
166
|
+
const buildToolDefinition = (graph, trail, layers, options) => {
|
|
180
167
|
const rawAnnotations = deriveAnnotations(trail);
|
|
181
168
|
const annotations = Object.keys(rawAnnotations).length > 0 ? rawAnnotations : undefined;
|
|
182
169
|
return {
|
|
183
170
|
annotations,
|
|
184
171
|
description: buildDescription(trail),
|
|
185
|
-
handler: createHandler(trail,
|
|
172
|
+
handler: createHandler(graph, trail, layers, options),
|
|
186
173
|
inputSchema: zodToJsonSchema(trail.input),
|
|
187
|
-
name: deriveToolName(
|
|
174
|
+
name: deriveToolName(graph.name, trail.id),
|
|
188
175
|
trailId: trail.id,
|
|
189
176
|
};
|
|
190
177
|
};
|
|
191
178
|
/** Register a trail as an MCP tool, checking for name collisions. */
|
|
192
|
-
const registerTool = (
|
|
193
|
-
const toolName = deriveToolName(
|
|
179
|
+
const registerTool = (graph, trailItem, layers, options, nameToTrailId, tools) => {
|
|
180
|
+
const toolName = deriveToolName(graph.name, trailItem.id);
|
|
194
181
|
const existingId = nameToTrailId.get(toolName);
|
|
195
182
|
if (existingId !== undefined) {
|
|
196
183
|
return Result.err(new ValidationError(`MCP tool-name collision: trails "${existingId}" and "${trailItem.id}" both derive the tool name "${toolName}"`));
|
|
197
184
|
}
|
|
198
185
|
nameToTrailId.set(toolName, trailItem.id);
|
|
199
|
-
tools.push(buildToolDefinition(
|
|
186
|
+
tools.push(buildToolDefinition(graph, trailItem, layers, options));
|
|
200
187
|
return Result.ok();
|
|
201
188
|
};
|
|
202
189
|
/** Filter topo items to eligible trails. */
|
|
203
|
-
const eligibleTrails = (
|
|
204
|
-
|
|
205
|
-
|
|
190
|
+
const eligibleTrails = (graph, options) => filterSurfaceTrails(graph.list(), {
|
|
191
|
+
exclude: options.exclude,
|
|
192
|
+
include: options.include,
|
|
193
|
+
intent: options.intent,
|
|
194
|
+
});
|
|
195
|
+
const validateToolBuild = (graph, options) => {
|
|
196
|
+
if (options.validate === false) {
|
|
197
|
+
return Result.ok();
|
|
198
|
+
}
|
|
199
|
+
const validated = validateEstablishedTopo(graph);
|
|
200
|
+
return validated.isErr() ? Result.err(validated.error) : Result.ok();
|
|
201
|
+
};
|
|
202
|
+
const registerTools = (graph, options, layers) => {
|
|
206
203
|
const tools = [];
|
|
207
204
|
const nameToTrailId = new Map();
|
|
208
|
-
for (const trailItem of eligibleTrails(
|
|
209
|
-
const registered = registerTool(
|
|
205
|
+
for (const trailItem of eligibleTrails(graph, options)) {
|
|
206
|
+
const registered = registerTool(graph, trailItem, layers, options, nameToTrailId, tools);
|
|
210
207
|
if (registered.isErr()) {
|
|
211
208
|
return registered;
|
|
212
209
|
}
|
|
213
210
|
}
|
|
214
211
|
return Result.ok(tools);
|
|
215
212
|
};
|
|
213
|
+
export const deriveMcpTools = (graph, options = {}) => {
|
|
214
|
+
const validation = validateToolBuild(graph, options);
|
|
215
|
+
if (validation.isErr()) {
|
|
216
|
+
return validation;
|
|
217
|
+
}
|
|
218
|
+
return registerTools(graph, options, options.layers ?? []);
|
|
219
|
+
};
|
|
216
220
|
//# sourceMappingURL=build.js.map
|
package/dist/build.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,eAAe,GAChB,MAAM,gBAAgB,CAAC;
|
|
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,mBAAmB,EACnB,SAAS,EACT,uBAAuB,EACvB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAYxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAyDhD,8EAA8E;AAC9E,wCAAwC;AACxC,8EAA8E;AAE9E,0EAA0E;AAC1E,MAAM,YAAY,GAAG,CACnB,MAAoB,EACpB,WAAmB,EACP,EAAE;IACd,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;IAC3C,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC;IACzB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,yDAAyD;AACzD,MAAM,aAAa,GAAG,KAAK,EACzB,MAAkC,EACb,EAAE;IACvB,MAAM,MAAM,GA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H,CAAC;IAED,OAAO,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,KAAW,EACX,UAAiC,EAAE,EACC,EAAE;IACtC,MAAM,UAAU,GAAG,iBAAiB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACrD,IAAI,UAAU,CAAC,KAAK,EAAE,EAAE,CAAC;QACvB,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,OAAO,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;AAC7D,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { deriveMcpTools, type DeriveMcpToolsOptions, type McpToolDefinition, type McpToolResult, type McpContent, type McpExtra, } from './build.js';
|
|
2
2
|
export { deriveToolName } from './tool-name.js';
|
|
3
3
|
export { deriveAnnotations, type McpAnnotations } from './annotations.js';
|
|
4
4
|
export { createMcpProgressCallback } from './progress.js';
|
|
5
|
-
export {
|
|
5
|
+
export { createServer, surface, type CreateServerOptions, type SurfaceMcpResult, } from './surface.js';
|
|
6
6
|
export { connectStdio } from './stdio.js';
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,KAAK,qBAAqB,EAC1B,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,EACL,YAAY,EACZ,OAAO,EACP,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,GACtB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// Build
|
|
2
|
-
export {
|
|
2
|
+
export { deriveMcpTools, } from './build.js';
|
|
3
3
|
// Tool naming
|
|
4
4
|
export { deriveToolName } from './tool-name.js';
|
|
5
5
|
// Annotations
|
|
6
6
|
export { deriveAnnotations } from './annotations.js';
|
|
7
7
|
// Progress
|
|
8
8
|
export { createMcpProgressCallback } from './progress.js';
|
|
9
|
-
//
|
|
10
|
-
export {
|
|
9
|
+
// Surface
|
|
10
|
+
export { createServer, surface, } from './surface.js';
|
|
11
11
|
// Transport
|
|
12
12
|
export { connectStdio } from './stdio.js';
|
|
13
13
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,QAAQ;AACR,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,QAAQ;AACR,OAAO,EACL,cAAc,GAMf,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,UAAU;AACV,OAAO,EACL,YAAY,EACZ,OAAO,GAGR,MAAM,cAAc,CAAC;AAEtB,YAAY;AACZ,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/stdio.d.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
|
import type { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
8
8
|
/**
|
package/dist/stdio.js
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
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
8
8
|
/**
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Surface helpers for exposing a topo over MCP.
|
|
3
|
+
*/
|
|
4
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
5
|
+
import type { Intent, Layer, ResourceOverrideMap, Topo, TrailContextInit } from '@ontrails/core';
|
|
6
|
+
export interface CreateServerOptions {
|
|
7
|
+
/** Config values for resources that declare a `config` schema, keyed by resource ID. */
|
|
8
|
+
readonly configValues?: Readonly<Record<string, Record<string, unknown>>> | undefined;
|
|
9
|
+
readonly createContext?: (() => TrailContextInit | Promise<TrailContextInit>) | undefined;
|
|
10
|
+
readonly description?: string | undefined;
|
|
11
|
+
readonly exclude?: readonly string[] | undefined;
|
|
12
|
+
readonly include?: readonly string[] | undefined;
|
|
13
|
+
readonly intent?: readonly Intent[] | undefined;
|
|
14
|
+
readonly layers?: readonly Layer[] | undefined;
|
|
15
|
+
readonly name?: string | undefined;
|
|
16
|
+
readonly resources?: ResourceOverrideMap | undefined;
|
|
17
|
+
/** Set to `false` to skip topo validation at startup. Defaults to `true`. */
|
|
18
|
+
readonly validate?: boolean | undefined;
|
|
19
|
+
readonly version?: string | undefined;
|
|
20
|
+
}
|
|
21
|
+
export interface SurfaceMcpResult {
|
|
22
|
+
readonly close: () => Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Build MCP tools from a topo and create an MCP server.
|
|
26
|
+
*/
|
|
27
|
+
export declare const createServer: (graph: Topo, options?: CreateServerOptions) => Server;
|
|
28
|
+
/**
|
|
29
|
+
* Build MCP tools from a topo, create a server, and connect via stdio.
|
|
30
|
+
*
|
|
31
|
+
* @remarks Opens the MCP server on stdio. For custom transports, use
|
|
32
|
+
* `createServer(graph)` with `connectStdio` or your own connector.
|
|
33
|
+
*/
|
|
34
|
+
export declare const surface: (graph: Topo, options?: CreateServerOptions) => Promise<SurfaceMcpResult>;
|
|
35
|
+
//# sourceMappingURL=surface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"surface.d.ts","sourceRoot":"","sources":["../src/surface.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAKnE,OAAO,KAAK,EACV,MAAM,EACN,KAAK,EACL,mBAAmB,EACnB,IAAI,EACJ,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AAUxB,MAAM,WAAW,mBAAmB;IAClC,wFAAwF;IACxF,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,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IACjD,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IACjD,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IAChD,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,KAAK,EAAE,GAAG,SAAS,CAAC;IAC/C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,SAAS,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAC;IACrD,6EAA6E;IAC7E,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACvC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC;AAkGD;;GAEG;AACH,eAAO,MAAM,YAAY,GACvB,OAAO,IAAI,EACX,UAAS,mBAAwB,KAChC,MAqBF,CAAC;AAMF;;;;;GAKG;AACH,eAAO,MAAM,OAAO,GAClB,OAAO,IAAI,EACX,UAAS,mBAAwB,KAChC,OAAO,CAAC,gBAAgB,CAS1B,CAAC"}
|
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Three lines to expose trails as MCP tools:
|
|
5
|
-
*
|
|
6
|
-
* ```ts
|
|
7
|
-
* const app = topo("myapp", entity);
|
|
8
|
-
* await blaze(app);
|
|
9
|
-
* ```
|
|
2
|
+
* Surface helpers for exposing a topo over MCP.
|
|
10
3
|
*/
|
|
11
4
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
12
5
|
import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
13
|
-
import {
|
|
14
|
-
import { buildMcpTools } from './build.js';
|
|
6
|
+
import { deriveMcpTools } from './build.js';
|
|
15
7
|
import { connectStdio } from './stdio.js';
|
|
16
8
|
// ---------------------------------------------------------------------------
|
|
17
9
|
// Internal: create MCP server with tool handlers
|
|
18
10
|
// ---------------------------------------------------------------------------
|
|
19
11
|
/**
|
|
20
12
|
* Create an MCP Server instance and register all tools.
|
|
13
|
+
*
|
|
14
|
+
* When provided, `info.description` is forwarded to the MCP SDK as the
|
|
15
|
+
* server's `instructions` field — the SDK's documented channel for
|
|
16
|
+
* "optional instructions describing how to use the server and its features."
|
|
21
17
|
*/
|
|
22
|
-
|
|
23
|
-
const server = new Server({ name: info.name, version: info.version }, {
|
|
18
|
+
const createMcpServer = (tools, info) => {
|
|
19
|
+
const server = new Server({ name: info.name, version: info.version }, {
|
|
20
|
+
capabilities: { tools: {} },
|
|
21
|
+
...(info.description === undefined
|
|
22
|
+
? {}
|
|
23
|
+
: { instructions: info.description }),
|
|
24
|
+
});
|
|
24
25
|
// Build a lookup map for tool dispatch
|
|
25
26
|
const toolMap = new Map();
|
|
26
27
|
for (const tool of tools) {
|
|
@@ -76,33 +77,47 @@ export const createMcpServer = (tools, info) => {
|
|
|
76
77
|
return server;
|
|
77
78
|
};
|
|
78
79
|
// ---------------------------------------------------------------------------
|
|
79
|
-
//
|
|
80
|
+
// createServer
|
|
80
81
|
// ---------------------------------------------------------------------------
|
|
81
82
|
/**
|
|
82
|
-
* Build MCP tools from
|
|
83
|
+
* Build MCP tools from a topo and create an MCP server.
|
|
83
84
|
*/
|
|
84
|
-
export const
|
|
85
|
-
|
|
86
|
-
const validated = validateTopo(app);
|
|
87
|
-
if (validated.isErr()) {
|
|
88
|
-
throw validated.error;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
const toolsResult = buildMcpTools(app, {
|
|
85
|
+
export const createServer = (graph, options = {}) => {
|
|
86
|
+
const toolsResult = deriveMcpTools(graph, {
|
|
92
87
|
configValues: options.configValues,
|
|
93
88
|
createContext: options.createContext,
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
exclude: options.exclude,
|
|
90
|
+
include: options.include,
|
|
91
|
+
intent: options.intent,
|
|
96
92
|
layers: options.layers,
|
|
97
|
-
|
|
93
|
+
resources: options.resources,
|
|
94
|
+
validate: options.validate,
|
|
98
95
|
});
|
|
99
96
|
if (toolsResult.isErr()) {
|
|
100
97
|
throw toolsResult.error;
|
|
101
98
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
return createMcpServer(toolsResult.value, {
|
|
100
|
+
description: options.description ?? graph.description,
|
|
101
|
+
name: options.name ?? graph.name,
|
|
102
|
+
version: options.version ?? graph.version ?? '0.1.0',
|
|
105
103
|
});
|
|
104
|
+
};
|
|
105
|
+
// ---------------------------------------------------------------------------
|
|
106
|
+
// surface
|
|
107
|
+
// ---------------------------------------------------------------------------
|
|
108
|
+
/**
|
|
109
|
+
* Build MCP tools from a topo, create a server, and connect via stdio.
|
|
110
|
+
*
|
|
111
|
+
* @remarks Opens the MCP server on stdio. For custom transports, use
|
|
112
|
+
* `createServer(graph)` with `connectStdio` or your own connector.
|
|
113
|
+
*/
|
|
114
|
+
export const surface = async (graph, options = {}) => {
|
|
115
|
+
const server = createServer(graph, options);
|
|
106
116
|
await connectStdio(server);
|
|
117
|
+
return {
|
|
118
|
+
close: async () => {
|
|
119
|
+
await server.close();
|
|
120
|
+
},
|
|
121
|
+
};
|
|
107
122
|
};
|
|
108
|
-
//# sourceMappingURL=
|
|
123
|
+
//# sourceMappingURL=surface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"surface.js","sourceRoot":"","sources":["../src/surface.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MA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