@mcpfn/core 0.0.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/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # McpFn Core
2
+
3
+ `@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:
4
+
5
+ - an explicit, validated tool, resource, template, and prompt registry;
6
+ - pagination, completions, subscriptions, and task-capable tools;
7
+ - server-initiated roots, sampling, elicitation, logging, and list-change notifications;
8
+ - MCP Apps resource and tool-link contracts;
9
+ - consistent structured and text results;
10
+ - deterministic, hashed manifests;
11
+ - breaking, additive, and model-behavior compatibility classification;
12
+ - stdio, Web Standard Streamable HTTP, and in-memory transport support through the official SDK.
13
+
14
+ ```ts
15
+ import {
16
+ McpFnRegistry,
17
+ createMcpFnServer,
18
+ structuredResult,
19
+ } from "@mcpfn/core";
20
+
21
+ const registry = new McpFnRegistry()
22
+ .register({
23
+ name: "greet",
24
+ description: "Greet one person by name.",
25
+ inputSchema: {
26
+ type: "object",
27
+ properties: { name: { type: "string" } },
28
+ required: ["name"],
29
+ additionalProperties: false,
30
+ },
31
+ outputSchema: {
32
+ type: "object",
33
+ properties: { greeting: { type: "string" } },
34
+ required: ["greeting"],
35
+ additionalProperties: false,
36
+ },
37
+ annotations: { readOnlyHint: true, openWorldHint: false },
38
+ handler: async ({ name }) =>
39
+ structuredResult({ greeting: `Hello, ${String(name)}!` }),
40
+ });
41
+
42
+ const server = createMcpFnServer({
43
+ info: { name: "example", version: "1.0.0" },
44
+ registry,
45
+ transports: ["stdio", "streamable-http"],
46
+ });
47
+
48
+ await server.serveStdio();
49
+ ```
50
+
51
+ Tool definitions are public contracts. Do not derive tool names, descriptions, or exposed fields from storage schemas without an explicit exposure manifest.
52
+
53
+ ## Server context and errors
54
+
55
+ Build trusted context once at the server boundary:
56
+
57
+ ```ts
58
+ const server = createMcpFnServer({
59
+ info: { name: "example", version: "1.0.0" },
60
+ registry: new McpFnRegistry<{ workspaceId: string }>(),
61
+ context: async (extra) => ({
62
+ workspaceId: await authenticateRequest(extra.requestInfo),
63
+ }),
64
+ });
65
+ ```
66
+
67
+ For tenant- or actor-specific discovery, use `toolVisibility`. McpFn applies
68
+ the hook to both `tools/list` and `tools/call`; a hidden call returns the same
69
+ protocol `MethodNotFound` response as an unknown tool. The static manifest
70
+ continues to describe the complete server contract.
71
+
72
+ ```ts
73
+ const server = createMcpFnServer({
74
+ info: { name: "admin", version: "1.0.0" },
75
+ registry,
76
+ context: (extra) => resolvePrincipal(extra.authInfo),
77
+ toolVisibility: ({ tool, context }) =>
78
+ context.permissions.includes(String(tool._meta?.permission)),
79
+ });
80
+ ```
81
+
82
+ 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.
83
+
84
+ Invalid input returns `MCPFN_INVALID_ARGUMENTS`; invalid declared output returns `MCPFN_INVALID_OUTPUT`; other handler failures return `MCPFN_TOOL_ERROR`. Error objects that already expose a string `code` keep it. `handleInvalidArguments` is available for existing domain packages that must map schema failures into a stable legacy envelope.
85
+
86
+ 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.
87
+
88
+ One `McpFnServer` instance connects to one transport. Create a new instance per concurrent connection and share the registry.
89
+
90
+ ## Resources, prompts, and client features
91
+
92
+ 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.
93
+
94
+ Task support is declared with `execution.taskSupport` and a `taskHandler`; a task-capable server must receive an official SDK `TaskStore`. `server.listRoots()`, `server.sample()`, and `server.elicit()` invoke matching client capabilities. Declare required client features in `clientRequirements` so manifests and host-profile tests can reject incompatible hosts before deployment.
95
+
96
+ `createWebStandardHandler()` accepts the official SDK `HandleRequestOptions`, including validated `authInfo`. Use `@mcpfn/auth` to publish OAuth protected-resource metadata and produce that trusted value.
97
+
98
+ 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).