holon-sh 0.0.1-dev.6 → 0.0.1-dev.8
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 +36 -87
- package/dist/context.d.ts +55 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +9 -0
- package/dist/context.js.map +1 -0
- package/dist/ext/files.client.d.ts +50 -0
- package/dist/ext/files.client.d.ts.map +1 -0
- package/dist/ext/files.client.js +359 -0
- package/dist/ext/files.client.js.map +1 -0
- package/dist/ext/files.d.ts +21 -0
- package/dist/ext/files.d.ts.map +1 -0
- package/dist/ext/files.js +3 -0
- package/dist/ext/files.js.map +1 -0
- package/dist/ext/platform.browser.d.ts +4 -0
- package/dist/ext/platform.browser.d.ts.map +1 -0
- package/dist/ext/platform.browser.js +15 -0
- package/dist/ext/platform.browser.js.map +1 -0
- package/dist/ext/platform.node.d.ts +4 -0
- package/dist/ext/platform.node.d.ts.map +1 -0
- package/dist/ext/platform.node.js +45 -0
- package/dist/ext/platform.node.js.map +1 -0
- package/dist/protocol.d.ts +76 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +32 -0
- package/dist/protocol.js.map +1 -0
- package/dist/runtime.d.ts +67 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +276 -0
- package/dist/runtime.js.map +1 -0
- package/package.json +42 -28
- package/src/context.ts +29 -0
- package/src/ext/files.client.ts +329 -0
- package/src/ext/files.ts +16 -0
- package/src/ext/platform.browser.ts +15 -0
- package/src/ext/platform.node.ts +43 -0
- package/{protocol.d.ts → src/protocol.ts} +38 -14
- package/src/runtime.ts +315 -0
- package/generated/holon-generated.json +0 -4
- package/generated/index.d.ts +0 -12
- package/generated/index.js +0 -5
- package/runtime.d.ts +0 -49
- package/runtime.mjs +0 -191
- package/validate.mjs +0 -10
- package/view.d.ts +0 -47
- package/view.js +0 -30
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { Client, isInputRequiredResult, SdkHttpError, StreamableHTTPClientTransport } from "@modelcontextprotocol/client";
|
|
2
|
+
import { AjvJsonSchemaValidator } from "@modelcontextprotocol/client/validators/ajv";
|
|
3
|
+
import { EXTENSION } from "./ext/files.js";
|
|
4
|
+
import { acceptUploadRequests, downloads, isUploadRequest, prepare, settings, upload } from "./ext/files.client.js";
|
|
5
|
+
import { ToolCallError } from "./protocol.js";
|
|
6
|
+
export { ToolCallError } from "./protocol.js";
|
|
7
|
+
// Environment-bound calls reuse the last server/discover result for the same endpoint and token instead of discovering
|
|
8
|
+
// the server on every call. A dependency keeps only its latest result, so a changed endpoint or token replaces it.
|
|
9
|
+
const DISCOVERY = Symbol("discovery");
|
|
10
|
+
const discovered = new Map();
|
|
11
|
+
const LEGACY_VERDICT_MS = 10 * 60 * 1000;
|
|
12
|
+
// Object methods JavaScript calls implicitly; tools with these names stay reachable through callTool.
|
|
13
|
+
const reserved = new Set(["then", "toJSON", "toString", "valueOf", "toLocaleString"]);
|
|
14
|
+
// The MCP client's own Ajv, one engine per schema so contracts that reuse an $id stay apart. Contracts are module
|
|
15
|
+
// constants, so each schema compiles once however often createApps runs.
|
|
16
|
+
const checks = new WeakMap();
|
|
17
|
+
function defaultValidator(schema) {
|
|
18
|
+
const cached = checks.get(schema);
|
|
19
|
+
if (cached)
|
|
20
|
+
return cached;
|
|
21
|
+
const compiled = new AjvJsonSchemaValidator().getValidator(schema);
|
|
22
|
+
const check = value => {
|
|
23
|
+
const { valid, errorMessage } = compiled(value);
|
|
24
|
+
check.errors = errorMessage;
|
|
25
|
+
return valid;
|
|
26
|
+
};
|
|
27
|
+
checks.set(schema, check);
|
|
28
|
+
return check;
|
|
29
|
+
}
|
|
30
|
+
function environment(name) {
|
|
31
|
+
const prefix = `${name.toUpperCase().replaceAll("-", "_")}_MCP_`;
|
|
32
|
+
const endpoint = process.env[`${prefix}URL`];
|
|
33
|
+
// Environment-bound dependencies connect for one call at a time, sending <NAME>_MCP_TOKEN as the bearer token when it is set.
|
|
34
|
+
const token = process.env[`${prefix}TOKEN`];
|
|
35
|
+
if (endpoint)
|
|
36
|
+
return { endpoint, scoped: true, [DISCOVERY]: `${endpoint} ${token ?? ""}`, ...(token && { authProvider: { token: async () => token } }) };
|
|
37
|
+
throw new Error(`Dependency ${name} is unavailable (${prefix}URL). Provide a binding or set the environment variable.`);
|
|
38
|
+
}
|
|
39
|
+
function validate(check, value, label) {
|
|
40
|
+
if (!check(value))
|
|
41
|
+
throw new Error(`Invalid ${label}: ${JSON.stringify(check.errors)}`);
|
|
42
|
+
}
|
|
43
|
+
function sleep(milliseconds, signal) {
|
|
44
|
+
return new Promise(resolve => {
|
|
45
|
+
const done = () => {
|
|
46
|
+
clearTimeout(timer);
|
|
47
|
+
signal?.removeEventListener("abort", done);
|
|
48
|
+
resolve();
|
|
49
|
+
};
|
|
50
|
+
const timer = setTimeout(done, milliseconds);
|
|
51
|
+
signal?.addEventListener("abort", done, { once: true });
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function untilAborted(promise, signal) {
|
|
55
|
+
if (!signal)
|
|
56
|
+
return promise;
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
const aborted = () => reject(signal.reason);
|
|
59
|
+
signal.addEventListener("abort", aborted, { once: true });
|
|
60
|
+
promise.then(resolve, reject).finally(() => signal.removeEventListener("abort", aborted));
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
// The MCP client ends a request after 60 s unless given a timeout. A request without one waits as long as a timer can
|
|
64
|
+
// (2^31 - 1 ms, about 24.8 days). A request with one asks for progress, and progress restarts its timeout.
|
|
65
|
+
function patient(options) {
|
|
66
|
+
return options?.timeout === undefined
|
|
67
|
+
? { ...options, timeout: 2 ** 31 - 1 }
|
|
68
|
+
: { onprogress: () => { }, resetTimeoutOnProgress: true, ...options };
|
|
69
|
+
}
|
|
70
|
+
/** Construct only the explicitly bound dependencies. Unknown names throw; an empty binding map selects none. Used by generated createApps factories. */
|
|
71
|
+
export function bindApps(identity, contracts, bindings, options) {
|
|
72
|
+
const selected = Object.fromEntries(Object.keys(bindings).map((name) => {
|
|
73
|
+
if (!Object.hasOwn(contracts, name) && !Object.hasOwn(identity.requires ?? {}, name))
|
|
74
|
+
throw new Error("Unknown app binding: " + name);
|
|
75
|
+
return [name, contracts[name] ?? null];
|
|
76
|
+
}));
|
|
77
|
+
return createApps(identity, selected, bindings, options);
|
|
78
|
+
}
|
|
79
|
+
/** Construct runtime clients from identity and contracts. Connections open lazily. Explicit and resolved endpoint bindings reuse one session unless scoped is true; <NAME>_MCP_URL bindings use one session per call. Close persistent clients on shutdown. Most callers use the generated clients. */
|
|
80
|
+
export function createApps(identity, contracts, bindings, options) {
|
|
81
|
+
const { validator = defaultValidator, resolve = environment, session: hosted } = options ?? {};
|
|
82
|
+
const apps = Object.create(null);
|
|
83
|
+
// Without explicit bindings, every declared dependency gets a client; those without a contract are untyped.
|
|
84
|
+
const members = { ...(bindings ? {} : Object.fromEntries(Object.keys(identity.requires ?? {}).map(name => [name, null]))), ...contracts };
|
|
85
|
+
for (const [name, contract] of Object.entries(members)) {
|
|
86
|
+
const binding = bindings?.[name];
|
|
87
|
+
// Without explicit bindings, the resolve hook supplies the binding on every call.
|
|
88
|
+
const current = () => binding ?? (bindings ? undefined : resolve(name));
|
|
89
|
+
let connection;
|
|
90
|
+
const connect = (resolved, prior) => {
|
|
91
|
+
// Every client can be asked: a call answers with elicit, or the question reaches its caller. Servers must not assume a client answers: https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/mrtr#server-requirements-basic-workflow
|
|
92
|
+
// On 2026-07-28 the client sends these capabilities in every request's _meta: https://github.com/modelcontextprotocol/typescript-sdk/blob/fcef852f6cdafea07f36cf6fae69b37c8adf85be/packages/client/src/client/client.ts#L700-L711
|
|
93
|
+
const client = new Client({ name: identity.name, version: identity.version }, { capabilities: { elicitation: { form: {}, url: {} }, extensions: { [EXTENSION]: { upload: {}, download: {} } } }, versionNegotiation: { mode: "auto" } });
|
|
94
|
+
const endpoint = new URL(resolved.endpoint);
|
|
95
|
+
const transport = acceptUploadRequests(new StreamableHTTPClientTransport(endpoint, { authProvider: resolved.authProvider, fetch: async (input, init) => {
|
|
96
|
+
if (String(input) === endpoint.href)
|
|
97
|
+
current.authorization = new Headers(init?.headers).get("authorization") ?? undefined;
|
|
98
|
+
const response = await (resolved.fetch ?? fetch)(input, init);
|
|
99
|
+
current.answered ||= response.ok;
|
|
100
|
+
return response;
|
|
101
|
+
}, requestInit: { credentials: "include", redirect: "error", headers: resolved.installationUID ? { "X-Holon-Installation-UID": resolved.installationUID } : {} } }));
|
|
102
|
+
transport.onclose = () => { if (connection === current)
|
|
103
|
+
connection = undefined; };
|
|
104
|
+
const ready = client.connect(transport, { prior }).catch(async (error) => {
|
|
105
|
+
await transport.close();
|
|
106
|
+
throw error;
|
|
107
|
+
});
|
|
108
|
+
const current = { client, resolved, ready, answered: false, close: async () => {
|
|
109
|
+
await transport.terminateSession().catch(() => { });
|
|
110
|
+
await transport.close();
|
|
111
|
+
await ready.catch(() => { });
|
|
112
|
+
} };
|
|
113
|
+
return current;
|
|
114
|
+
};
|
|
115
|
+
// The session hook serves bindings the runtime does not connect to itself.
|
|
116
|
+
const host = binding ? hosted?.(name, binding) : undefined;
|
|
117
|
+
const session = async (options, run) => {
|
|
118
|
+
options?.signal?.throwIfAborted();
|
|
119
|
+
if (host)
|
|
120
|
+
return run(host);
|
|
121
|
+
const resolved = current();
|
|
122
|
+
if (!resolved?.endpoint)
|
|
123
|
+
throw new Error(`Dependency ${name} is unavailable. Provide a binding.`);
|
|
124
|
+
// Bindings marked scoped connect for one call at a time.
|
|
125
|
+
const scoped = resolved.scoped === true;
|
|
126
|
+
const key = resolved[DISCOVERY];
|
|
127
|
+
const cached = discovered.get(name);
|
|
128
|
+
const prior = key !== undefined && cached?.key === key && Date.now() < cached.expires ? cached.prior : undefined;
|
|
129
|
+
const active = scoped ? connect(resolved, prior) : (connection ??= connect(resolved));
|
|
130
|
+
try {
|
|
131
|
+
await untilAborted(active.ready, options?.signal);
|
|
132
|
+
if (key !== undefined && !prior) {
|
|
133
|
+
const discover = active.client.getDiscoverResult();
|
|
134
|
+
discovered.set(name, { key, prior: discover ? { kind: "modern", discover } : { kind: "legacy" }, expires: discover ? Infinity : Date.now() + LEGACY_VERDICT_MS });
|
|
135
|
+
}
|
|
136
|
+
return await run(active.client, active);
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
// A server that no longer speaks the discovered protocol rejects the first request without running it.
|
|
140
|
+
if (!prior || active.answered || !(SdkHttpError.isInstance(error) && error.status === 400))
|
|
141
|
+
throw error;
|
|
142
|
+
discovered.delete(name);
|
|
143
|
+
return session(options, run);
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
if (scoped)
|
|
147
|
+
await active.close();
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
const tools = Object.create(null);
|
|
151
|
+
const definitions = new Map((contract?.tools ?? []).map(definition => [definition.name, { definition }]));
|
|
152
|
+
const callTool = async (request, { elicit, ...options } = {}) => {
|
|
153
|
+
const tool = definitions.get(request.name);
|
|
154
|
+
if (!tool && contract)
|
|
155
|
+
throw new Error(`Unknown tool ${name}.${request.name}.`);
|
|
156
|
+
// A contract's tool is the tool as its server listed it.
|
|
157
|
+
const sent = { ...patient(options), allowInputRequired: true, ...(tool && { toolDefinition: { ...tool.definition, outputSchema: undefined } }) };
|
|
158
|
+
const label = `${name}.${request.name}`;
|
|
159
|
+
const result = await session(options, async (client, connection) => {
|
|
160
|
+
const { arguments: args, files } = await prepare(request.arguments, {
|
|
161
|
+
label, connection,
|
|
162
|
+
schema: async () => tool?.definition.inputSchema ?? (await client.listTools(undefined, patient(options))).tools.find(({ name }) => name === request.name)?.inputSchema,
|
|
163
|
+
});
|
|
164
|
+
// The SDK's request type leaves out the continuation fields the protocol carries.
|
|
165
|
+
let next = files.size ? { ...request, arguments: args } : request;
|
|
166
|
+
let uploaded = false;
|
|
167
|
+
for (let round = 0;;) {
|
|
168
|
+
let result;
|
|
169
|
+
try {
|
|
170
|
+
result = await client.callTool(next, sent);
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
if (connection && isUploadRequest(error)) {
|
|
174
|
+
if (uploaded)
|
|
175
|
+
throw new Error(`${label}: the server asked for a second upload; the tool did not run.`);
|
|
176
|
+
const requestState = await upload(error.data, files, connection, options.signal, label);
|
|
177
|
+
uploaded = true;
|
|
178
|
+
const { inputResponses, ...retry } = next;
|
|
179
|
+
next = { ...retry, requestState };
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
if (uploaded)
|
|
183
|
+
throw new Error(`${label}: the outcome is unknown; the tool may have run (${error?.message ?? error}).`, { cause: error });
|
|
184
|
+
throw error;
|
|
185
|
+
}
|
|
186
|
+
// A server may keep asking, so answering stops after ten rounds, the MCP clients' own limit, and the last question reaches the caller.
|
|
187
|
+
if (!elicit || !isInputRequiredResult(result) || round++ === 10)
|
|
188
|
+
return connection ? downloads(result, connection, settings(connection) !== undefined) : result;
|
|
189
|
+
const inputResponses = {};
|
|
190
|
+
for (const [key, question] of Object.entries(result.inputRequests ?? {})) {
|
|
191
|
+
// Every client declares elicitation alone, so it answers nothing else and such a question reaches the caller.
|
|
192
|
+
if (question.method !== "elicitation/create")
|
|
193
|
+
return result;
|
|
194
|
+
inputResponses[key] = await elicit(question.params);
|
|
195
|
+
}
|
|
196
|
+
next = { ...next, inputResponses, requestState: result.requestState };
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
if (isInputRequiredResult(result))
|
|
200
|
+
return result;
|
|
201
|
+
// The server validates arguments; the client checks the output against the contract it was compiled against.
|
|
202
|
+
if (!result.isError && tool?.definition.outputSchema) {
|
|
203
|
+
validate(tool.output ??= validator(tool.definition.outputSchema), result.structuredContent, `structured output from ${name}.${request.name}`);
|
|
204
|
+
}
|
|
205
|
+
// isError tells ToolResult's success variant from its error variant.
|
|
206
|
+
return { ...result, resultType: "complete" };
|
|
207
|
+
};
|
|
208
|
+
const listTools = (options) => session(options, client => client.listTools(undefined, patient(options)));
|
|
209
|
+
for (const tool of contract?.tools ?? [])
|
|
210
|
+
if (!reserved.has(tool.name)) {
|
|
211
|
+
tools[tool.name] = async (input, options) => {
|
|
212
|
+
const result = await callTool({ name: tool.name, arguments: input }, options);
|
|
213
|
+
if (result.resultType === "input_required" || result.isError)
|
|
214
|
+
throw new ToolCallError(name, tool.name, result);
|
|
215
|
+
return tool.outputSchema ? result.structuredContent : result;
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
const resources = Object.create(null);
|
|
219
|
+
for (const resource of contract?.resources ?? []) {
|
|
220
|
+
let valid;
|
|
221
|
+
const parse = (result) => {
|
|
222
|
+
// Contracted resources are JSON in their first text content.
|
|
223
|
+
const [content] = result.contents;
|
|
224
|
+
if (!content || !("text" in content))
|
|
225
|
+
throw new Error(`Invalid contents from ${name} ${resource.uri}: no text content`);
|
|
226
|
+
const value = JSON.parse(content.text);
|
|
227
|
+
valid ??= validator(resource.outputSchema);
|
|
228
|
+
validate(valid, value, `contents from ${name} ${resource.uri}`);
|
|
229
|
+
return value;
|
|
230
|
+
};
|
|
231
|
+
const read = async (options) => parse(await session(options, client => client.readResource({ uri: resource.uri }, patient(options))));
|
|
232
|
+
const watch = async (onChange, { signal } = {}) => {
|
|
233
|
+
const resolved = current();
|
|
234
|
+
if (!resolved?.endpoint)
|
|
235
|
+
throw new Error(`Watching ${name} ${resource.uri} requires an endpoint binding.`);
|
|
236
|
+
// An abort ends the wait between attempts early instead of failing it.
|
|
237
|
+
for (let established = false; !signal?.aborted; await sleep(1000, signal)) {
|
|
238
|
+
const current = connect(resolved);
|
|
239
|
+
let failure;
|
|
240
|
+
try {
|
|
241
|
+
await untilAborted(current.ready, signal);
|
|
242
|
+
const { client } = current;
|
|
243
|
+
if (!client.getServerCapabilities()?.resources?.subscribe)
|
|
244
|
+
throw new Error(`${name} does not advertise resource subscriptions.`);
|
|
245
|
+
let reads = Promise.resolve();
|
|
246
|
+
const refresh = () => (reads = reads.then(async () => onChange(parse(await client.readResource({ uri: resource.uri }, patient({ signal, cacheMode: "bypass" })))))
|
|
247
|
+
.catch(error => { failure ??= error; return current.close(); }));
|
|
248
|
+
client.setNotificationHandler("notifications/resources/updated", ({ params }) => { if (params.uri === resource.uri)
|
|
249
|
+
void refresh(); });
|
|
250
|
+
const subscription = await client.listen({ resourceSubscriptions: [resource.uri] }, { signal });
|
|
251
|
+
if (!subscription.honoredFilter.resourceSubscriptions?.includes(resource.uri))
|
|
252
|
+
throw new Error(`${name} did not accept a subscription to ${resource.uri}.`);
|
|
253
|
+
established = true;
|
|
254
|
+
await refresh();
|
|
255
|
+
await subscription.closed;
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
failure ??= error;
|
|
259
|
+
}
|
|
260
|
+
finally {
|
|
261
|
+
await current.close();
|
|
262
|
+
}
|
|
263
|
+
if (signal?.aborted)
|
|
264
|
+
return;
|
|
265
|
+
if (failure && !established)
|
|
266
|
+
throw failure;
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
resources[resource.uri] = Object.freeze({ read, watch });
|
|
270
|
+
}
|
|
271
|
+
// Generated clients narrow callTool to their contract's tools and outputs, which validation upholds.
|
|
272
|
+
apps[name] = Object.freeze({ callTool: callTool, listTools, resources: Object.freeze(resources), close: async () => { await connection?.close(); }, tools: Object.freeze(tools) });
|
|
273
|
+
}
|
|
274
|
+
return Object.freeze(apps);
|
|
275
|
+
}
|
|
276
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,YAAY,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AAE1H,OAAO,EAAE,sBAAsB,EAAE,MAAM,6CAA6C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,CAAC,EAAE,KAAK,EAAE,KAAK,IAAI,EAAE,GAAG,MAAM,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAClN,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "holon-sh",
|
|
3
|
-
"version": "0.0.1-dev.
|
|
4
|
-
"description": "Typed MCP clients and
|
|
3
|
+
"version": "0.0.1-dev.8",
|
|
4
|
+
"description": "Typed MCP clients and the caller of an MCP request, for Node.js.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/holon-sh/sdk-ts.git",
|
|
@@ -16,45 +16,59 @@
|
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
18
|
"holon": {
|
|
19
|
-
"
|
|
20
|
-
"contractVersion": 1
|
|
19
|
+
"contractVersion": 2
|
|
21
20
|
},
|
|
22
21
|
"exports": {
|
|
23
|
-
".": {
|
|
24
|
-
"types": "./generated/index.d.ts",
|
|
25
|
-
"import": "./generated/index.js"
|
|
26
|
-
},
|
|
27
22
|
"./runtime": {
|
|
28
|
-
"types": "./runtime.d.ts",
|
|
29
|
-
"import": "./runtime.
|
|
23
|
+
"types": "./dist/runtime.d.ts",
|
|
24
|
+
"import": "./dist/runtime.js"
|
|
30
25
|
},
|
|
31
|
-
"./
|
|
32
|
-
"types": "./
|
|
33
|
-
"import": "./
|
|
26
|
+
"./context": {
|
|
27
|
+
"types": "./dist/context.d.ts",
|
|
28
|
+
"import": "./dist/context.js"
|
|
34
29
|
},
|
|
35
30
|
"./protocol": {
|
|
36
|
-
"types": "./protocol.d.ts",
|
|
37
|
-
"import": "./
|
|
31
|
+
"types": "./dist/protocol.d.ts",
|
|
32
|
+
"import": "./dist/protocol.js"
|
|
33
|
+
},
|
|
34
|
+
"./ext/files": {
|
|
35
|
+
"types": "./dist/ext/files.d.ts",
|
|
36
|
+
"import": "./dist/ext/files.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"typesVersions": {
|
|
40
|
+
"*": {
|
|
41
|
+
"runtime": [
|
|
42
|
+
"./dist/runtime.d.ts"
|
|
43
|
+
],
|
|
44
|
+
"context": [
|
|
45
|
+
"./dist/context.d.ts"
|
|
46
|
+
],
|
|
47
|
+
"protocol": [
|
|
48
|
+
"./dist/protocol.d.ts"
|
|
49
|
+
],
|
|
50
|
+
"ext/files": [
|
|
51
|
+
"./dist/ext/files.d.ts"
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"imports": {
|
|
56
|
+
"#platform": {
|
|
57
|
+
"node": "./dist/ext/platform.node.js",
|
|
58
|
+
"default": "./dist/ext/platform.browser.js"
|
|
38
59
|
}
|
|
39
60
|
},
|
|
40
61
|
"files": [
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"validate.mjs",
|
|
44
|
-
"protocol.d.ts",
|
|
45
|
-
"view.js",
|
|
46
|
-
"view.d.ts",
|
|
47
|
-
"generated/",
|
|
48
|
-
"README.md"
|
|
62
|
+
"dist",
|
|
63
|
+
"src"
|
|
49
64
|
],
|
|
50
65
|
"scripts": {
|
|
51
|
-
"build": "node scripts/build.
|
|
52
|
-
"prepack": "npm run build"
|
|
53
|
-
"docs:build": "node scripts/build-reference.mjs"
|
|
66
|
+
"build": "node scripts/build.ts && tsc",
|
|
67
|
+
"prepack": "npm run build"
|
|
54
68
|
},
|
|
55
69
|
"dependencies": {
|
|
56
70
|
"@modelcontextprotocol/client": "^2.3.1",
|
|
57
|
-
"
|
|
58
|
-
"
|
|
71
|
+
"ipaddr.js": "^2.5.0",
|
|
72
|
+
"undici": "^7.16.0"
|
|
59
73
|
}
|
|
60
74
|
}
|
package/src/context.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Standard OpenID Connect address claims. */
|
|
2
|
+
export interface AddressClaims {
|
|
3
|
+
formatted?: string; street_address?: string; locality?: string; region?: string; postal_code?: string; country?: string;
|
|
4
|
+
[claim: string]: unknown;
|
|
5
|
+
}
|
|
6
|
+
/** Standard OpenID Connect claims. Holon drops one whose value has the wrong type; other claims pass through as JSON. */
|
|
7
|
+
export interface IdentityClaims {
|
|
8
|
+
name?: string; given_name?: string; family_name?: string; middle_name?: string; nickname?: string;
|
|
9
|
+
preferred_username?: string; profile?: string; picture?: string; website?: string; email?: string;
|
|
10
|
+
email_verified?: boolean; gender?: string; birthdate?: string; zoneinfo?: string; locale?: string;
|
|
11
|
+
phone_number?: string; phone_number_verified?: boolean; address?: AddressClaims; updated_at?: number;
|
|
12
|
+
[claim: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
/** The user a request acts for, as Holon admitted it. */
|
|
15
|
+
export interface Principal { issuer: string; subject: string; clientId: string; scopes: string[]; claims: IdentityClaims; actor?: Record<string, unknown> }
|
|
16
|
+
/** The caller of the current MCP request. principal is null for anonymous requests. */
|
|
17
|
+
export interface RequestContext { principal: Principal | null }
|
|
18
|
+
|
|
19
|
+
// Holon admits the caller before the request reaches the server and hands it over as MCP's authInfo, with claims and
|
|
20
|
+
// act in these shapes.
|
|
21
|
+
interface Admitted { iss?: unknown; sub?: unknown; claims?: IdentityClaims; act?: Record<string, unknown> }
|
|
22
|
+
|
|
23
|
+
/** Read the caller from the context an MCP server receives: a tool callback's ctx.http, or the McpRequestContext of a createMcpHandler factory. */
|
|
24
|
+
export function getContext(context: { authInfo?: { clientId: string; scopes: string[]; extra?: Record<string, unknown> } } = {}): RequestContext {
|
|
25
|
+
const { authInfo } = context;
|
|
26
|
+
const { iss, sub, claims, act } = (authInfo?.extra ?? {}) as Admitted;
|
|
27
|
+
if (!authInfo || typeof iss !== "string" || typeof sub !== "string") return { principal: null };
|
|
28
|
+
return { principal: { issuer: iss, subject: sub, clientId: authInfo.clientId, scopes: authInfo.scopes, claims: claims ?? {}, ...(act && { actor: act }) } };
|
|
29
|
+
}
|