@ontrails/mcp 0.2.4 → 0.4.1
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 +40 -0
- package/README.md +23 -3
- package/package.json +8 -3
- package/src/build.ts +208 -211
- package/src/fetch-boundary.ts +102 -0
- package/src/fetch.ts +86 -0
- package/src/index.ts +22 -6
- package/src/output-rendering.ts +67 -0
- package/src/permit-resolution.ts +102 -0
- package/src/resource-access.ts +71 -0
- package/src/resources.ts +14 -9
- package/src/server.ts +336 -0
- package/src/stdio.ts +13 -15
- package/src/surface.ts +13 -264
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
# @ontrails/mcp
|
|
2
2
|
|
|
3
|
+
## 0.4.1
|
|
4
|
+
|
|
5
|
+
No changes in this release.
|
|
6
|
+
|
|
7
|
+
## 0.4.0
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- [`b767357`](https://github.com/outfitter-dev/trails/commit/b767357eb73fa7cbf8744c23557f57f0e890204d): Preserve raw non-object output values and schemas on modern MCP connections while keeping legacy `{ data: ... }` rendering and the standalone `deriveMcpTools()` API compatible. Select tool and trailhead output schemas after protocol negotiation, and expose matching schemas through the surface-map resource.
|
|
12
|
+
|
|
13
|
+
## 0.3.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- [`c2b11a4`](https://github.com/outfitter-dev/trails/commit/c2b11a4c5d61648471da1d9e919007b3d32960b3): Correct the default JSON-RPC `not_found` code from `-32601` (method not found) to `-32001`. Clients matching the previous numeric code must update or use the error category; HTTP status and CLI exit mappings are unchanged.
|
|
18
|
+
|
|
19
|
+
Export the shared JSON-RPC error data shape and public rendering helper from core, with a method-specific override for MCP `resources/read`. Unknown MCP resources retain protocol code `-32602` and now include `data.category`, `data.name`, and `data.retryable`. Trail failures remain `isError` tool results with shared metadata and public redaction.
|
|
20
|
+
- [`01361a6`](https://github.com/outfitter-dev/trails/commit/01361a6e1fca0c6445633e4428b973598a87b815): Network MCP surfaces never inherit a `createContext` permit. `deriveMcpTools` and the server options gain `credentialPosture`; `@ontrails/mcp/fetch` always builds on the `network` posture, where identity enters only through `resolvePermit`: a seeded `createContext` permit is discarded at runtime (one diagnostic names the migration) for tools and resource reads, `extra.permit` is ignored, a presented bearer with no resolver is an `AuthError` instead of absence, and a handler that exposes protected trails without a resolver is refused at build time with a `ValidationError` naming them. The stdio `host` posture is unchanged.
|
|
21
|
+
|
|
22
|
+
Migration: apps that seeded a permit through `createContext` on a network host move that credential into a verifier passed as `resolvePermit` (for example a JWKS or opaque adapter from `@ontrails/permits`) and keep `createContext` for the logger, extensions and resources it seeds. `--dev-permit` is not a migration path for network surfaces.
|
|
23
|
+
- [`76661d3`](https://github.com/outfitter-dev/trails/commit/76661d3b888295c3a515885f695677f0b7c2a3db): Pass raw Authorization and best-effort Bearer candidates to configured MCP permit policies without requiring a successful Bearer parse. Share request permit resolution internally while preserving trusted host permit precedence and unconfigured parser behavior. Configured policies must distinguish absent credentials from selected invalid credentials; metadata and tool arguments are not synthesized into headers.
|
|
24
|
+
- [`4b5d5bb`](https://github.com/outfitter-dev/trails/commit/4b5d5bb56639cbbec48c3072792f0ddc9deb2cb0): Add the portable `@ontrails/mcp/fetch` entry with a shared server factory for modern MCP and legacy stateless HTTP. Validate the authoritative request URL, optional Host authority and explicit HTTP(S) Origin allowlist before SDK dispatch. Forward actual request Authorization and per-request metadata to the existing permit resolver without synthesizing SDK auth information. Keep stdio imports outside the portable entry. HTTP challenge integration and real client interoperability retain separate acceptance gates.
|
|
25
|
+
- [`7c8d396`](https://github.com/outfitter-dev/trails/commit/7c8d396923495ab6758bc78f75332053c86e39ae): Resolve MCP tool permits from each request's bearer credential and application `_meta`, and remove `sessionId` from `ResolveMcpPermitInput` and `McpExtra`. Protocol sessions no longer supply permit inputs. Custom resolvers must remove session-derived state and trace identifiers; application state belongs in explicit handles in trail input/output schemas.
|
|
26
|
+
|
|
27
|
+
A configured resolver now runs even when no bearer token is present, allowing it to inspect untrusted metadata candidates or reject missing credentials according to the app's policy. Resolvers must handle absent bearer and metadata values and verify credentials before returning a permit. Explicit host-provided permits remain available for local stdio policy outside OAuth.
|
|
28
|
+
|
|
29
|
+
This establishes the MCP tool and stdio seam. The separately implemented fetch host must supply the same per-request context before fetch-path acceptance is complete.
|
|
30
|
+
- [`7868df9`](https://github.com/outfitter-dev/trails/commit/7868df908f310a4e3ad3e60e8bb1bc934d4e816a): Resolve permits for every MCP resource list and read request, and add `authorizeResourceRead` over the verified permit and canonical resource descriptor. Permission denials omit listed resources and reject direct reads; credential and operational failures remain terminal. Resolvers now receive resource requests, including requests without bearer credentials, and must return absence only when no accepted credential was selected. Resource policy preserves trusted local-host permits after absence and never after a verification error. This does not establish the separate fetch-shaped MCP host or private tool discovery.
|
|
31
|
+
- [`72274ce`](https://github.com/outfitter-dev/trails/commit/72274ce04d4f45eb69b70df2857f26f100fba195): Migrate MCP stdio serving to the official SDK v2 and its protocol-aware `serveStdio` entry. Replace the `@modelcontextprotocol/sdk` peer with `@modelcontextprotocol/server ^2.4.0`. `surface(graph)` remains the stdio one-liner and supports modern 2026-07-28 and legacy connections.
|
|
32
|
+
|
|
33
|
+
This is a documented 0.x break. Custom stdio hosts must change `await connectStdio(server)` to `const connection = await connectStdio(() => createServer(graph))` and close the returned connection handle. The factory must return a fresh server for SDK discovery and connection selection. Remove copied `transport: 'stdio'` properties; that documented option never existed.
|
|
34
|
+
|
|
35
|
+
Non-image blob results now emit valid embedded binary resources with nested `resource: { uri, mimeType, blob }` instead of invalid flat resource entries. Non-image streams are read and buffered into base64. Custom consumers must use the nested resource shape. Structured trail output descriptors are unchanged. MCP content types now follow the SDK's discriminated content shapes.
|
|
36
|
+
|
|
37
|
+
Session-permit API removal, the fetch-shaped handler, modern scalar/array output contract changes, and the temporary adopter migration skill have separate implementation gates.
|
|
38
|
+
|
|
39
|
+
## 0.2.5
|
|
40
|
+
|
|
41
|
+
No changes in this release.
|
|
42
|
+
|
|
3
43
|
## 0.2.4
|
|
4
44
|
|
|
5
45
|
No changes in this release.
|
package/README.md
CHANGED
|
@@ -48,6 +48,10 @@ for (const tool of result.value) {
|
|
|
48
48
|
|
|
49
49
|
`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.
|
|
50
50
|
|
|
51
|
+
## Portable HTTP Entry
|
|
52
|
+
|
|
53
|
+
Import `createFetchHandler` from `@ontrails/mcp/fetch` to obtain `{ fetch, close }` for Bun or Hono. The subpath avoids stdio imports and serves modern MCP plus legacy stateless HTTP. Hostnames default to loopback only; browser origins require an explicit exact HTTP(S) allowlist. Actual request Authorization and application metadata reach the existing permit resolver. See [MCP Over HTTP](../../docs/surfaces/mcp-http.md) for the Bun and Hono attachments, validation rules and the separate HTTP challenge and live-client follow-ups.
|
|
54
|
+
|
|
51
55
|
## API
|
|
52
56
|
|
|
53
57
|
| Export | What it does |
|
|
@@ -61,6 +65,20 @@ for (const tool of result.value) {
|
|
|
61
65
|
|
|
62
66
|
See the [API Reference](../../docs/api-reference.md) for the full list.
|
|
63
67
|
|
|
68
|
+
## Request credential resolution
|
|
69
|
+
|
|
70
|
+
A configured `resolvePermit` receives each request's raw `authorization`, best-effort `bearerToken` and untrusted application `_meta`. It owns the accepted credential source and syntax. An opaque key in Authorization can therefore reach that policy without first passing Bearer parsing. Metadata fields and tool arguments are never promoted into header credentials. HTTP header candidates require a real hosting adapter; the core does not synthesize them from `_meta`.
|
|
71
|
+
|
|
72
|
+
Return `Result.ok(null)` or `undefined` only when no accepted credential was selected. A selected malformed or invalid credential, lookup miss or operational failure must return an error; it stops even a public tool before host-context fallback or execution. Choose precedence before verification and never fall back to another candidate after selected failure. A Bearer-only policy must reject malformed presented Bearer credentials itself.
|
|
73
|
+
|
|
74
|
+
Two credential postures exist (`credentialPosture` on the derive and server options). On the `host` posture, which stdio uses, explicit host-provided `extra.permit` keeps its precedence and, when the configured resolver returns absence, trusted `createContext` permit configuration remains available as the launcher's own policy; a resolver error cannot use that fallback. On the `network` posture, which `@ontrails/mcp/fetch` always sets, identity enters only through `resolvePermit`: a `createContext` permit is discarded at runtime (one diagnostic names the migration), `extra.permit` is ignored, a presented bearer with no resolver is an `AuthError` rather than absence, and a surface that exposes protected trails without a resolver is refused at build time with a `ValidationError` listing the trails. Resolver absence means anonymous: public trails run, protected trails fail at enforcement.
|
|
75
|
+
|
|
76
|
+
Migration for apps that seeded a permit through `createContext` on a network host: move the credential into a verifier passed as `resolvePermit` (a JWKS or opaque adapter from `@ontrails/permits`), and keep `createContext` for the logger, extensions and resources it still seeds. `--dev-permit` is not a migration path for network surfaces.
|
|
77
|
+
|
|
78
|
+
Tool invocation and resource list/read requests share one internal request permit-resolution seam. Resource requests resolve once, then evaluate optional `authorizeResourceRead({ permit, resource })` policy against canonical catalog descriptors. Return `Result.ok()` to allow a URI or a `PermissionError` to deny it. Listing omits permission-denied URIs; direct reads reject them, and other errors fail the request. The descriptor carries a real `trailId` for trail-specific resources and none for aggregates. Without explicit read policy, the authored static resource population remains public.
|
|
79
|
+
|
|
80
|
+
Resolvers now receive resource requests even without bearer credentials. Every read rechecks; prior lists and other callers grant no authority. On the host posture, trusted `createContext` permits are available only after request-credential absence, never after verification failure; the network posture never consults them. Resource policy does not alter static tool discovery or redact the surface-map aggregate; deny unsafe aggregates when private member-level discovery is required. See [resource read policy](../../docs/surfaces/mcp.md#resource-read-policy) for configuration and migration guidance. This change does not establish Fetch hosting, query credentials, application-cookie policy or header extraction for a future host.
|
|
81
|
+
|
|
64
82
|
## Annotations
|
|
65
83
|
|
|
66
84
|
Trail intent, idempotency, and description map directly to MCP annotations:
|
|
@@ -76,7 +94,7 @@ No manual annotation definitions. The contract is the source of truth.
|
|
|
76
94
|
|
|
77
95
|
## Schemas and Examples
|
|
78
96
|
|
|
79
|
-
MCP tool definitions include the trail's input schema
|
|
97
|
+
MCP tool definitions include the trail's input schema and, when declared, its `outputSchema`. Modern MCP returns the authored output directly in `structuredContent`, including arrays, scalars, and `null`. Legacy MCP and standalone `deriveMcpTools()` keep the `{ data: ... }` envelope for schemas without an object root. See [Output Schema and Examples](../../docs/surfaces/mcp.md#output-schema-and-examples).
|
|
80
98
|
|
|
81
99
|
Trail examples are rendered as structured metadata under `_meta["ontrails/examples"]`. Each rendered example preserves its input, expected output or error, a success/error kind, and provenance pointing back to the authored `trail.examples` field.
|
|
82
100
|
|
|
@@ -141,8 +159,10 @@ await surface(graph, { exclude: ['internal.debug'] });
|
|
|
141
159
|
|
|
142
160
|
## Installation
|
|
143
161
|
|
|
144
|
-
|
|
162
|
+
The source targets the SDK v2 migration release, with `@modelcontextprotocol/server` 2.x (minimum 2.4.0) as its peer. Source support does not establish publication; use the Trails release containing this migration and its matching peer requirements.
|
|
145
163
|
|
|
146
164
|
```bash
|
|
147
|
-
bun add
|
|
165
|
+
bun add @ontrails/mcp '@modelcontextprotocol/server@^2.4.0'
|
|
148
166
|
```
|
|
167
|
+
|
|
168
|
+
See [SDK v2 Migration](../../docs/surfaces/mcp.md#sdk-v2-migration) for the stdio factory API and embedded binary content changes.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ontrails/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/outfitter-dev/trails.git",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"type": "module",
|
|
18
18
|
"exports": {
|
|
19
19
|
".": "./src/index.ts",
|
|
20
|
+
"./fetch": "./src/fetch.ts",
|
|
20
21
|
"./package.json": "./package.json"
|
|
21
22
|
},
|
|
22
23
|
"scripts": {
|
|
@@ -27,10 +28,14 @@
|
|
|
27
28
|
"clean": "rm -rf dist *.tsbuildinfo"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
30
|
-
"@ontrails/core": "^0.
|
|
31
|
+
"@ontrails/core": "^0.4.1"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@modelcontextprotocol/client": "^2.4.0",
|
|
35
|
+
"hono": "^4.13.13"
|
|
31
36
|
},
|
|
32
37
|
"peerDependencies": {
|
|
33
|
-
"@modelcontextprotocol/
|
|
38
|
+
"@modelcontextprotocol/server": "^2.4.0",
|
|
34
39
|
"zod": "^4.3.5"
|
|
35
40
|
}
|
|
36
41
|
}
|