@mcpfn/core 0.0.4 → 0.0.5
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/README.md +114 -1
- package/dist/index.cjs +10641 -1188
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +176 -10
- package/dist/index.d.ts +176 -10
- package/dist/index.js +10630 -1194
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -14,6 +14,8 @@ definitions, the declaration clones the registry before adding them.
|
|
|
14
14
|
`@mcpfn/core` is the shared MCP runtime for Superfunctions. It delegates wire protocol and transport behavior to the official Model Context Protocol SDK while providing the pieces product code needs to remain stable:
|
|
15
15
|
|
|
16
16
|
- an explicit, validated tool, resource, template, and prompt registry;
|
|
17
|
+
- authenticated, versioned client-profile catalog projection and trusted enrichment;
|
|
18
|
+
- actionable, value-free JSON Schema diagnostics;
|
|
17
19
|
- pagination, completions, subscriptions, and task-capable tools;
|
|
18
20
|
- server-initiated roots, sampling, elicitation, logging, and list-change notifications;
|
|
19
21
|
- MCP Apps resource and tool-link contracts;
|
|
@@ -92,12 +94,75 @@ const server = createMcpFnServer({
|
|
|
92
94
|
|
|
93
95
|
Do not accept workspace, tenant, actor, or credential identifiers as tool arguments. The context factory receives the official SDK request metadata and runs before every tool call.
|
|
94
96
|
|
|
95
|
-
Invalid input returns `MCPFN_INVALID_ARGUMENTS`; invalid declared output returns
|
|
97
|
+
Invalid input returns `MCPFN_INVALID_ARGUMENTS`; invalid declared output returns
|
|
98
|
+
`MCPFN_INVALID_OUTPUT`; other handler failures return `MCPFN_TOOL_ERROR`.
|
|
99
|
+
Error objects that already expose a string `code` keep it. Schema issues retain
|
|
100
|
+
`instancePath`, `schemaPath`, `keyword`, and safe keyword-specific names
|
|
101
|
+
such as `rejectedProperty` and `missingProperty`; rejected values are never
|
|
102
|
+
included. `handleInvalidArguments` is available for existing domain packages
|
|
103
|
+
that must map schema failures into a stable legacy envelope.
|
|
96
104
|
|
|
97
105
|
When a tool declares a success `outputSchema`, error details remain in its JSON text content and `structuredContent` is omitted so the official SDK does not validate an error envelope against the success schema. Tools without an output schema retain both structured and text error envelopes.
|
|
98
106
|
|
|
99
107
|
One `McpFnServer` instance connects to one transport. Create a new instance per concurrent connection and share the registry.
|
|
100
108
|
|
|
109
|
+
## Authenticated client profiles
|
|
110
|
+
|
|
111
|
+
Use `clientProfiles` only when an authenticated client needs a projected
|
|
112
|
+
catalog and server-owned required arguments. Profile matching receives a
|
|
113
|
+
`McpFnVerifiedClientIdentity` produced from trusted context; reported client
|
|
114
|
+
name/version and capabilities are available to hooks separately and cannot
|
|
115
|
+
select the profile.
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
const server = createMcpFnServer({
|
|
119
|
+
info: { name: "example", version: "1.0.0" },
|
|
120
|
+
registry,
|
|
121
|
+
context: (extra) => authenticateRequest(extra.authInfo),
|
|
122
|
+
clientProfiles: {
|
|
123
|
+
resolveVerifiedIdentity: ({ context }) => ({
|
|
124
|
+
subject: context.authenticatedClientId,
|
|
125
|
+
}),
|
|
126
|
+
profiles: [{
|
|
127
|
+
id: "consumer/trusted",
|
|
128
|
+
version: "1",
|
|
129
|
+
matches: ({ subject }) => subject === "trusted-client-id",
|
|
130
|
+
serverOwnedArguments: { lookup: ["workspaceId"] },
|
|
131
|
+
projectCatalog: ({ tools }) => tools.map((tool) => {
|
|
132
|
+
if (tool.name !== "lookup") return tool;
|
|
133
|
+
const { workspaceId: _hidden, ...properties } =
|
|
134
|
+
tool.inputSchema.properties ?? {};
|
|
135
|
+
return {
|
|
136
|
+
...tool,
|
|
137
|
+
inputSchema: {
|
|
138
|
+
...tool.inputSchema,
|
|
139
|
+
properties,
|
|
140
|
+
required: tool.inputSchema.required?.filter(
|
|
141
|
+
(name) => name !== "workspaceId",
|
|
142
|
+
),
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}),
|
|
146
|
+
enrichArguments: ({ arguments: args, context }) => ({
|
|
147
|
+
...args,
|
|
148
|
+
workspaceId: context.workspaceId,
|
|
149
|
+
}),
|
|
150
|
+
}],
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
McpFn applies canonical visibility before projection, checks calls against the
|
|
156
|
+
same effective catalog, rejects model-supplied server-owned fields, enriches
|
|
157
|
+
from trusted context, and only then invokes canonical Ajv validation. Declared
|
|
158
|
+
server-owned fields must be canonical required properties, must be absent from
|
|
159
|
+
the projected schema, and must be supplied by the enricher. A profile cannot
|
|
160
|
+
invent or duplicate tools or mutate model-owned arguments. No matching profile
|
|
161
|
+
preserves canonical behavior.
|
|
162
|
+
|
|
163
|
+
The optional `evidence` sink receives only bounded structural lifecycle
|
|
164
|
+
events. It is observational: a sink failure cannot fail or change a request.
|
|
165
|
+
|
|
101
166
|
## Resources, prompts, and client features
|
|
102
167
|
|
|
103
168
|
Use `registerResource`, `registerResourceTemplate`, and `registerPrompt` on the same registry. Resource-template and prompt completers advertise the completions capability automatically. Resource subscription handlers advertise `resources.subscribe`. List calls use stable `mcpfn:<offset>` cursors and a configurable server page size.
|
|
@@ -106,4 +171,52 @@ Task support is declared with `execution.taskSupport` and a `taskHandler`; a tas
|
|
|
106
171
|
|
|
107
172
|
`createWebStandardHandler()` accepts the official SDK `HandleRequestOptions`, including validated `authInfo`. Use `@mcpfn/auth` to publish OAuth protected-resource metadata and produce that trusted value. In stateless mode, McpFn creates and disposes an isolated SDK server and transport for every request. Attach protocol instrumentation with `configureRequestServer`; it receives the live isolated server before transport connection and runs once per request, or once per session initialization attempt. Because configuration precedes SDK request validation, a rejected attempt can invoke the hook without retaining a session. Supply a cryptographically secure `sessionIdGenerator` when the server uses sampling, elicitation, or another server-to-client request that must be correlated across HTTP requests; session-enabled handlers retain their transport across the session.
|
|
108
173
|
|
|
174
|
+
## Cloudflare Workers and edge runtimes
|
|
175
|
+
|
|
176
|
+
`@mcpfn/core` is a self-contained bundle: the official MCP SDK and a single
|
|
177
|
+
pinned Zod runtime are inlined into `dist`. Bundle it into a Cloudflare Worker
|
|
178
|
+
next to your application's own root `zod` dependency without adding a bundler
|
|
179
|
+
alias for `zod`/`zod/v4`, an import condition override, or any other
|
|
180
|
+
application-local shim. Enable Cloudflare's `nodejs_compat` compatibility flag,
|
|
181
|
+
which provides Node built-ins such as `node:crypto` used by the official MCP
|
|
182
|
+
SDK, and serve MCP through `createWebStandardHandler()`. Schema validation uses
|
|
183
|
+
Ajv draft-07 on Node and `@cfworker/json-schema` with the same dialect on
|
|
184
|
+
Cloudflare Workers and other runtimes that forbid runtime code generation. See
|
|
185
|
+
[ADR-0001](https://github.com/21nCo/super-functions/blob/main/mcpfn/ADR-0001-COMPATIBILITY.md)
|
|
186
|
+
for the compatibility policy.
|
|
187
|
+
|
|
109
188
|
See the [architecture](https://github.com/21nCo/super-functions/blob/main/mcpfn/ARCHITECTURE.md), [testing guide](https://github.com/21nCo/super-functions/blob/main/mcpfn/TESTING.md), and runnable [calculator example](https://github.com/21nCo/super-functions/blob/main/mcpfn/examples/calculator-server.ts).
|
|
189
|
+
|
|
190
|
+
Profile hooks that consume initialization metadata require a sessionful HTTP
|
|
191
|
+
handler (`sessionIdGenerator`). Stateless handlers accept only profiles explicitly
|
|
192
|
+
marked `requiresReportedClient: false`; their hooks must depend solely on verified
|
|
193
|
+
identity and request context. Model-owned property schemas retain their canonical
|
|
194
|
+
types and constraints. Projection may hide server-owned required fields, but does
|
|
195
|
+
not replace the canonical validator.
|
|
196
|
+
|
|
197
|
+
Projected input schemas may use static references within the document or an
|
|
198
|
+
embedded `$id` resource. Named draft-07 `$id` fragments and modern anchors are
|
|
199
|
+
aliases in their containing resource, so `#` and `#/...` still address that
|
|
200
|
+
resource's root. Dynamic, recursive, and unresolved external references fail
|
|
201
|
+
closed during catalog validation. Server-owned fields may only be hidden where
|
|
202
|
+
the root object contract can be compared without conditional or whole-object
|
|
203
|
+
ownership-sensitive constraints.
|
|
204
|
+
Draft-07 `$ref` siblings evaluated by the registry's Ajv, including `$id`
|
|
205
|
+
resource scope, are rejected during catalog validation because draft-07 clients
|
|
206
|
+
can ignore them while the runtime validator evaluates them.
|
|
207
|
+
The MCP-required root `type: "object"` is permitted; place other assertions on
|
|
208
|
+
the referenced target. Later-draft keywords and unknown extensions ignored by
|
|
209
|
+
the registry's draft-07 Ajv may remain beside `$ref`.
|
|
210
|
+
|
|
211
|
+
Structural diagnostics retain exact unknown property names and instance paths;
|
|
212
|
+
consumer report sinks must apply an aggregate size cap (the testing suite defaults
|
|
213
|
+
to one MiB) rather than silently shortening property names.
|
|
214
|
+
|
|
215
|
+
Task profile evidence distinguishes the creation handler from result persistence.
|
|
216
|
+
`handler` reports the creation callback's outcome; `task-result-storage: failed`
|
|
217
|
+
reports the first observed persistence failure for that request, including delayed
|
|
218
|
+
writes after creation returns. Retries do not repeat that failure event. It does
|
|
219
|
+
not reverse handler success or claim a final task status. Output validation still
|
|
220
|
+
runs for each attempted result before persistence.
|
|
221
|
+
|
|
222
|
+
Lifecycle evidence retains only recognized framework error codes; application-defined codes become `MCPFN_TOOL_ERROR`. Protocol error responses preserve the original application code and details.
|