webdaemon 28.1.0 → 28.2.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.
@@ -10,6 +10,7 @@ export * from "./js/ParentHelper.js";
10
10
  export * from "./js/QrCode.js";
11
11
  export * from "./js/Storage.js";
12
12
  /** Backend libs */
13
+ export * from "./ts/AbstractHandler.ts";
13
14
  export * from "./ts/Assertions.ts";
14
15
  export * from "./ts/GenerativeChatAgent.ts";
15
16
  export * from "./ts/GenerativeChatEvents.ts";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,kBAAkB;AAClB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAE9B,mBAAmB;AACnB,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAEhC,mBAAmB;AACnB,cAAc,oBAAoB,CAAC;AACnC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,kBAAkB;AAClB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAE9B,mBAAmB;AACnB,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAEhC,mBAAmB;AACnB,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC"}
@@ -1,14 +1,58 @@
1
+ /**
2
+ * Generates a signing keypair and exports it in the formats the platform
3
+ * uses: JWK (for Token signing and the daemon's `/device/<id>/public.jwk`
4
+ * and `/issuer/<id>` endpoints) and PEM.
5
+ *
6
+ * The default algorithm is RSASSA-PKCS1-v1_5 / 2048 / SHA-256 — the same
7
+ * scheme Token verification expects. Works browser- or agent-side, but
8
+ * requires a secure context (crypto.subtle).
9
+ *
10
+ * Usage:
11
+ *
12
+ * const keys = new KeyPair()
13
+ * await keys.generate()
14
+ * const publicJwk = await keys.publicJwk()
15
+ * const privateJwk = await keys.privateJwk()
16
+ */
1
17
  export class KeyPair {
2
- constructor(algorithm?: {
3
- name: string;
4
- modulusLength: number;
5
- publicExponent: Uint8Array<ArrayBuffer>;
6
- hash: string;
7
- });
18
+ /**
19
+ * @param {RsaHashedKeyGenParams | EcKeyGenParams} [algorithm] a crypto.subtle.generateKey algorithm;
20
+ * defaults to the platform's signing scheme.
21
+ * @throws {string} exception outside a secure context.
22
+ */
23
+ constructor(algorithm?: RsaHashedKeyGenParams | EcKeyGenParams);
24
+ /**
25
+ * Generates the keypair (extractable, usages sign/verify). Must be
26
+ * called before any of the export methods.
27
+ */
8
28
  generate(): Promise<void>;
29
+ /**
30
+ * Returns the public key as a JWK object.
31
+ *
32
+ * @return {Promise<JsonWebKey>} the public JWK.
33
+ * @throws {string} exception if generate() has not been called.
34
+ */
9
35
  publicJwk(): Promise<JsonWebKey>;
36
+ /**
37
+ * Returns the private key as a JWK object.
38
+ *
39
+ * @return {Promise<JsonWebKey>} the private JWK.
40
+ * @throws {string} exception if generate() has not been called.
41
+ */
10
42
  privateJwk(): Promise<JsonWebKey>;
43
+ /**
44
+ * Returns the public key in PEM (SPKI) format.
45
+ *
46
+ * @return {Promise<string>} the PEM string.
47
+ * @throws {string} exception if generate() has not been called.
48
+ */
11
49
  publicPem(): Promise<string>;
50
+ /**
51
+ * Returns the private key in PEM (PKCS#8) format.
52
+ *
53
+ * @return {Promise<string>} the PEM string.
54
+ * @throws {string} exception if generate() has not been called.
55
+ */
12
56
  privatePem(): Promise<string>;
13
57
  #private;
14
58
  }
@@ -1 +1 @@
1
- {"version":3,"file":"KeyPair.d.ts","sourceRoot":"","sources":["../../../js/KeyPair.js"],"names":[],"mappings":"AAOA;IAME;;;;;OAKC;IAED,0BAMC;IAED,iCAOC;IAED,kCAOC;IAED,6BAUC;IAED,8BAUC;;CACF"}
1
+ {"version":3,"file":"KeyPair.d.ts","sourceRoot":"","sources":["../../../js/KeyPair.js"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;GAeG;AACH;IAME;;;;OAIG;IACH,wBAJW,qBAAqB,GAAG,cAAc,EAShD;IAED;;;OAGG;IACH,0BAMC;IAED;;;;;OAKG;IACH,aAHY,OAAO,CAAC,UAAU,CAAC,CAU9B;IAED;;;;;OAKG;IACH,cAHY,OAAO,CAAC,UAAU,CAAC,CAU9B;IAED;;;;;OAKG;IACH,aAHY,OAAO,CAAC,MAAM,CAAC,CAa1B;IAED;;;;;OAKG;IACH,cAHY,OAAO,CAAC,MAAM,CAAC,CAa1B;;CACF"}
@@ -0,0 +1,55 @@
1
+ import { Token } from '../js/Token.js';
2
+ /**
3
+ * Base class for agent-side request handlers, giving each request a uniform
4
+ * shape: token verification, capability assertion, and error-to-response
5
+ * wrapping. An agent tab dispatches with a chain of
6
+ * `X.shouldHandle(request)` checks:
7
+ *
8
+ * ```ts
9
+ * Deno.serve({ port: 0 }, (request) => {
10
+ * if (Status.shouldHandle(request)) return new Status(request).handler()
11
+ * if (Ingest.shouldHandle(request)) return new Ingest(request).handler()
12
+ * return response({ error: '404 Not Found' })
13
+ * })
14
+ * ```
15
+ *
16
+ * Subclasses provide a static `shouldHandle(request)` and implement
17
+ * `handle()`. `handler()` validates the token then delegates to `handle()`;
18
+ * any thrown value becomes a standard error response. Handlers that accept
19
+ * token-less requests (OAuth callbacks, webhooks) override `validate()`:
20
+ *
21
+ * ```ts
22
+ * override async validate(): Promise<void> {
23
+ * await super.validate(false)
24
+ * }
25
+ * ```
26
+ */
27
+ export declare abstract class AbstractHandler {
28
+ token: Token | null;
29
+ request: Request;
30
+ url: URL;
31
+ protocol: string;
32
+ host: string;
33
+ constructor(request: Request);
34
+ /**
35
+ * Verifies the token signatory and that the token party matches the
36
+ * request host. With `enforceToken` (the default), a missing token
37
+ * throws; pass `false` for endpoints that accept token-less requests,
38
+ * which still verify a token when one is present.
39
+ */
40
+ validate(enforceToken?: boolean): Promise<void>;
41
+ /**
42
+ * Throws unless the request token holds the capability on this app's
43
+ * source. The daemon only forwards granted capabilities, so a present
44
+ * capability is indeed granted.
45
+ */
46
+ assertCapability(capability: string): void;
47
+ /**
48
+ * Validates then delegates to `handle()`. Never throws — any thrown
49
+ * value is logged and returned as a standard error response.
50
+ */
51
+ handler(): Promise<Response>;
52
+ /** The request implementation, provided by the subclass. */
53
+ abstract handle(): Promise<Response>;
54
+ }
55
+ //# sourceMappingURL=AbstractHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbstractHandler.d.ts","sourceRoot":"","sources":["../../../ts/AbstractHandler.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,8BAAsB,eAAe;IACnC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;IACnB,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,GAAG,CAAA;IACR,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;gBAEA,OAAO,EAAE,OAAO;IAQ5B;;;;;OAKG;IACG,QAAQ,CAAC,YAAY,UAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAalD;;;;OAIG;IACH,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAY1C;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC;IAYlC,4DAA4D;IAC5D,QAAQ,CAAC,MAAM,IAAI,OAAO,CAAC,QAAQ,CAAC;CACrC"}
@@ -1,16 +1,23 @@
1
1
  export type JSONRecord = Record<string, unknown>;
2
+ /** A tool invocation requested by the chat model. */
2
3
  export interface ChatToolCall {
3
4
  id: string;
4
5
  name: string;
5
6
  input: JSONRecord;
6
7
  }
8
+ /** A tool as presented to the chat model; executed agent-side. */
7
9
  export interface ChatToolDescriptor {
8
10
  type: 'function';
9
11
  name: string;
10
12
  execution: 'server';
11
13
  description?: string;
14
+ /** JSON Schema for the tool's input. */
12
15
  parameters?: JSONRecord;
13
16
  }
17
+ /**
18
+ * A tool executed in the browser by the app's frontend rather than by the
19
+ * agent; passed through `chatTools()` untouched.
20
+ */
14
21
  export interface ClientToolDescriptor {
15
22
  type: 'function';
16
23
  name: string;
@@ -18,18 +25,25 @@ export interface ClientToolDescriptor {
18
25
  description?: string;
19
26
  parameters?: JSONRecord;
20
27
  }
28
+ /** Outcome of one executed tool call, for the model's next turn. */
21
29
  export interface ToolResult {
22
30
  toolCallId: string;
23
31
  name?: string;
24
32
  content: string;
25
33
  isError?: boolean;
26
34
  }
35
+ /**
36
+ * How a catalog tool is reached: `kind` is `platform` (a daemon POST route
37
+ * such as `/ai/memory/search`) or `mcp` (an app's MCP server, addressed by
38
+ * `path` and optionally a differing `mcpToolName`).
39
+ */
27
40
  export interface ToolRoute {
28
41
  kind: string;
29
42
  method?: string;
30
43
  path?: string;
31
44
  mcpToolName?: string;
32
45
  }
46
+ /** One entry of the party tool catalog returned by `/ai/tools/catalog`. */
33
47
  export interface ToolCatalogEntry {
34
48
  tool?: {
35
49
  name?: string;
@@ -38,20 +52,43 @@ export interface ToolCatalogEntry {
38
52
  };
39
53
  route?: ToolRoute;
40
54
  }
55
+ /**
56
+ * Transports for {@link AgentToolRuntime}, both POSTing to party endpoints
57
+ * with the agent's token: `postParty` unwraps the daemon's `Ok`/`Error`
58
+ * envelope, `postPartyRaw` returns the raw JSON body (required for JSON-RPC,
59
+ * whose envelope must pass through untouched).
60
+ */
41
61
  export interface AgentToolRuntimeOptions {
42
62
  postParty: (path: string, body: JSONRecord) => Promise<JSONRecord>;
43
63
  postPartyRaw: (path: string, body: JSONRecord) => Promise<JSONRecord>;
44
64
  }
65
+ /**
66
+ * The single-party tool runtime: loads the party's tool catalog, exposes it
67
+ * as chat tool descriptors, and executes calls by routing each to its
68
+ * catalog-declared route — platform routes via `postParty`, MCP tools via a
69
+ * cached {@link JsonRpcMcpClient} per MCP path.
70
+ */
45
71
  export declare class AgentToolRuntime {
46
72
  #private;
47
73
  constructor(options: AgentToolRuntimeOptions);
48
74
  get toolCatalog(): ToolCatalogEntry[];
75
+ /** Reloads the party tool catalog from `/ai/tools/catalog`. */
49
76
  refreshCatalog(): Promise<void>;
77
+ /** Replaces the catalog with an already-fetched `tools` value. */
50
78
  setCatalog(value: unknown): void;
79
+ /** The catalog as chat tool descriptors, plus any given client tools. */
51
80
  chatTools(options?: {
52
81
  clientTools?: ClientToolDescriptor[];
53
82
  }): Array<ChatToolDescriptor | ClientToolDescriptor>;
83
+ /**
84
+ * Executes calls sequentially; a failed call yields an `isError` result
85
+ * rather than throwing, so one failure doesn't abort the batch.
86
+ */
54
87
  executeToolCalls(toolCalls: ChatToolCall[]): Promise<ToolResult[]>;
88
+ /**
89
+ * Executes one call via its catalog route and returns the JSON-stringified
90
+ * result. Throws on unknown tools or unsupported routes.
91
+ */
55
92
  executeToolCall(call: ChatToolCall): Promise<string>;
56
93
  }
57
94
  /**
@@ -112,6 +149,7 @@ export declare class GatewayToolRuntime implements SessionToolRuntime {
112
149
  }): Array<ChatToolDescriptor | ClientToolDescriptor>;
113
150
  executeToolCall(call: ChatToolCall): Promise<string>;
114
151
  }
152
+ /** A catalog entry as a chat tool descriptor; `null` if it has no name. */
115
153
  export declare function toChatTool(entry: ToolCatalogEntry): ChatToolDescriptor | null;
116
154
  /**
117
155
  * Combines an app's once-authored, app-level description (`appDescription`) with
@@ -1 +1 @@
1
- {"version":3,"file":"McpAgentTools.d.ts","sourceRoot":"","sources":["../../../ts/McpAgentTools.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEhD,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,UAAU,CAAA;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,UAAU,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,QAAQ,CAAA;IACnB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,UAAU,CAAA;CACxB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,UAAU,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,QAAQ,CAAA;IACnB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,UAAU,CAAA;CACxB;AAED,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO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AAM,GAAG,SAAS,CAIpB"}
@@ -1,17 +1,56 @@
1
+ /**
2
+ * Client side of the Model Context Protocol (MCP) over JSON-RPC 2.0 / HTTP.
3
+ *
4
+ * {@link JsonRpcMcpClient} talks to any MCP server that accepts JSON-RPC via
5
+ * HTTP POST — an app tab's own server (see McpServer.ts) or a daemon's MCP
6
+ * gateway at `/mcp/rpc`. Only the tool methods are implemented (`tools/list`,
7
+ * `tools/call`); there is no `initialize` handshake.
8
+ */
1
9
  import type { JSONValue } from './Assertions.ts';
2
10
  type JSONRecord = Record<string, unknown>;
11
+ /**
12
+ * Either a ready-made `post` transport (given a JSON-RPC body, returns the
13
+ * parsed JSON response — useful when requests must be signed or proxied), or a
14
+ * `url` to POST to directly, with optional `headers` (a value or a possibly
15
+ * async factory, e.g. to mint a fresh token per request) and a `fetch`
16
+ * replacement.
17
+ */
3
18
  export interface JsonRpcMcpClientOptions {
4
19
  post?: (body: JSONRecord) => Promise<JSONRecord>;
5
20
  url?: string;
6
21
  headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
7
22
  fetch?: typeof fetch;
8
23
  }
24
+ /**
25
+ * Minimal MCP client. Wire it to a server with either a `post` function or a
26
+ * `url` (see {@link JsonRpcMcpClientOptions}); request ids are assigned
27
+ * sequentially per client instance.
28
+ *
29
+ * ```ts
30
+ * const client = new JsonRpcMcpClient({
31
+ * url: 'https://alice.daemon.com/mcp/rpc',
32
+ * headers: () => ({ 'X-Tabserver-Token': token }),
33
+ * })
34
+ * const tools = await client.listTools()
35
+ * const result = await client.callTool('expert_ask', { question: '…' })
36
+ * ```
37
+ */
9
38
  export declare class JsonRpcMcpClient {
10
39
  #private;
11
40
  constructor(options: JsonRpcMcpClientOptions);
41
+ /** The server's tool descriptors (`tools/list`); empty array if none. */
12
42
  listTools(): Promise<JSONValue[]>;
43
+ /**
44
+ * Calls the named tool and returns its `structuredContent` (or `null` when
45
+ * the server sent none). Throws the server's error text when the result is
46
+ * flagged `isError`, and the JSON-RPC error message on protocol failures.
47
+ */
13
48
  callTool(name: string, args?: JSONRecord): Promise<JSONValue>;
14
49
  }
50
+ /**
51
+ * Extracts a human-readable message from an `isError` MCP tool result — the
52
+ * first `content` text block, or a generic fallback.
53
+ */
15
54
  export declare function mcpToolErrorMessage(result: unknown): string;
16
55
  export {};
17
56
  //# sourceMappingURL=McpClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"McpClient.d.ts","sourceRoot":"","sources":["../../../ts/McpClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAEhD,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEzC,MAAM,WAAW,uBAAuB;IACtC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,OAAO,CAAC,UAAU,CAAC,CAAA;IAChD,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,WAAW,GAAG,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAA;IAClE,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;CACrB;AAED,qBAAa,gBAAgB;;gBAIf,OAAO,EAAE,uBAAuB;IAwBtC,SAAS,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAMjC,QAAQ,CACZ,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,UAAe,GACpB,OAAO,CAAC,SAAS,CAAC;CA6BtB;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAO3D"}
1
+ {"version":3,"file":"McpClient.d.ts","sourceRoot":"","sources":["../../../ts/McpClient.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAEhD,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEzC;;;;;;GAMG;AACH,MAAM,WAAW,uBAAuB;IACtC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,OAAO,CAAC,UAAU,CAAC,CAAA;IAChD,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,WAAW,GAAG,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAA;IAClE,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;CACrB;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,gBAAgB;;gBAIf,OAAO,EAAE,uBAAuB;IAwB5C,yEAAyE;IACnE,SAAS,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAMvC;;;;OAIG;IACG,QAAQ,CACZ,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,UAAe,GACpB,OAAO,CAAC,SAAS,CAAC;CA6BtB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAO3D"}
@@ -1,11 +1,48 @@
1
+ /**
2
+ * Server side of the Model Context Protocol (MCP) over JSON-RPC 2.0 / HTTP.
3
+ *
4
+ * An app's agent tab uses {@link JsonRpcMcpServer} to expose tools declared in
5
+ * its YAML `mcp:` block at the tab's MCP path (by default `/rpc`). The daemon's
6
+ * MCP gateway (`/mcp/rpc`) aggregates these per-app servers into one catalog;
7
+ * see docs/reference/mcp-gateway.md.
8
+ *
9
+ * Typical agent-side wiring:
10
+ *
11
+ * ```ts
12
+ * const server = new JsonRpcMcpServer(
13
+ * new McpToolRegistry([myToolDefinition]),
14
+ * (request) => contextFromRequest(request),
15
+ * )
16
+ * // in the tab's fetch handler:
17
+ * if (url.pathname === '/rpc') return server.handle(request)
18
+ * ```
19
+ */
1
20
  import type { JSONObject, JSONValue } from './Assertions.ts';
21
+ /** The `arguments` object of a `tools/call` request, as sent by the client. */
2
22
  export type McpToolArguments = Record<string, unknown>;
23
+ /**
24
+ * Per-request context passed to every tool call, derived from the incoming
25
+ * HTTP request by the `context` function given to {@link JsonRpcMcpServer}.
26
+ * Servers may extend it with their own fields (e.g. the verified token).
27
+ */
3
28
  export interface McpContext {
29
+ /** Hostname of the party (daemon) the request addresses. */
4
30
  party?: string;
31
+ /** URL of the app source the request is for. */
5
32
  source?: string;
33
+ /** Request protocol, e.g. `https:`. */
6
34
  protocol?: string;
35
+ /** The app's tab prefix, when the request arrived via `/tab/<prefix>/…`. */
7
36
  sourcePrefix?: string;
8
37
  }
38
+ /**
39
+ * One tool as registered with a {@link McpToolRegistry}: its MCP metadata
40
+ * (mirrored verbatim into `tools/list`) plus the `call` implementation.
41
+ *
42
+ * `capability` is not part of the MCP wire format — it names the capability a
43
+ * caller's token must hold for this tool, and must match the tool's entry in
44
+ * the app YAML `mcp.tools` block (see McpToolAuthorization.ts).
45
+ */
9
46
  export interface McpToolDefinition<TContext extends McpContext> {
10
47
  name: string;
11
48
  title?: string;
@@ -16,31 +53,76 @@ export interface McpToolDefinition<TContext extends McpContext> {
16
53
  capability?: string;
17
54
  call: (args: McpToolArguments, context: TContext) => Promise<JSONValue> | JSONValue;
18
55
  }
56
+ /**
57
+ * Source of tools for a {@link JsonRpcMcpServer}. {@link McpToolRegistry} is
58
+ * the static implementation; implement this directly when the tool list is
59
+ * dynamic or depends on the caller (as the daemon's MCP gateway does).
60
+ */
19
61
  export interface McpToolProvider<TContext extends McpContext> {
62
+ /** Tool descriptors for `tools/list`, optionally scoped to the caller. */
20
63
  listTools(context?: TContext): Promise<JSONValue[]> | JSONValue[];
64
+ /**
65
+ * Runs the named tool and returns its structured result. Throw
66
+ * {@link ProtocolError} for protocol-level failures (unknown tool, bad
67
+ * params); any other thrown error becomes an in-band tool error result.
68
+ */
21
69
  callTool(name: string, args: McpToolArguments, context: TContext): Promise<JSONValue>;
22
70
  }
23
71
  export interface JsonRpcMcpServerOptions<TContext extends McpContext> {
72
+ /** Reported in the `initialize` response; defaults to `mcp-server`/`1`. */
24
73
  serverInfo?: {
25
74
  name: string;
26
75
  version: string;
27
76
  };
77
+ /** Derives the per-request {@link McpContext} passed to tool calls. */
28
78
  context: (request: Request) => TContext;
29
79
  }
80
+ /**
81
+ * A fixed list of {@link McpToolDefinition}s exposed as a
82
+ * {@link McpToolProvider}. `listTools` reflects each definition's metadata;
83
+ * `callTool` dispatches by name and rejects unknown names with JSON-RPC
84
+ * `-32602`.
85
+ */
30
86
  export declare class McpToolRegistry<TContext extends McpContext> implements McpToolProvider<TContext> {
31
87
  #private;
32
88
  constructor(tools: McpToolDefinition<TContext>[]);
33
89
  listTools(): JSONValue[];
34
90
  callTool(name: string, args: McpToolArguments, context: TContext): Promise<JSONValue>;
35
91
  }
92
+ /**
93
+ * A minimal MCP server speaking JSON-RPC 2.0 over HTTP POST. Supports the
94
+ * methods `initialize`, `notifications/initialized`, `tools/list` and
95
+ * `tools/call` (protocol version 2025-06-18); GET returns an SSE endpoint
96
+ * event for clients that probe for the legacy SSE transport. All responses
97
+ * carry `Access-Control-Allow-Origin: *`.
98
+ *
99
+ * Authentication is not handled here — callers gate `handle()` behind their
100
+ * own token checks (see McpToolAuthorization.ts).
101
+ */
36
102
  export declare class JsonRpcMcpServer<TContext extends McpContext = McpContext> {
37
103
  #private;
38
104
  constructor(tools: McpToolProvider<TContext>, contextOrOptions: ((request: Request) => TContext) | JsonRpcMcpServerOptions<TContext>);
105
+ /**
106
+ * Handles one HTTP request against the MCP endpoint and always resolves to
107
+ * a Response — protocol errors are encoded as JSON-RPC error responses,
108
+ * tool failures as in-band tool results with `isError: true`. Requests
109
+ * without an `id` (notifications) are acknowledged with `202`.
110
+ */
39
111
  handle(request: Request): Promise<Response>;
40
112
  }
113
+ /**
114
+ * A JSON-RPC protocol-level failure. Thrown from a {@link McpToolProvider} it
115
+ * becomes a JSON-RPC error response with the given `code` (e.g. `-32601`
116
+ * method not found, `-32602` invalid params) rather than a tool result.
117
+ */
41
118
  export declare class ProtocolError extends Error {
42
119
  code: number;
43
120
  constructor(code: number, message: string);
44
121
  }
122
+ /**
123
+ * Wraps a tool's structured result in the MCP `tools/call` result shape:
124
+ * a `content` text block (JSON-stringified unless already a string) alongside
125
+ * `structuredContent` and the `isError` flag.
126
+ */
45
127
  export declare function mcpToolResult(structuredContent: JSONValue, isError?: boolean): JSONValue;
46
128
  //# sourceMappingURL=McpServer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"McpServer.d.ts","sourceRoot":"","sources":["../../../ts/McpServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAS5D,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEtD,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,iBAAiB,CAAC,QAAQ,SAAS,UAAU;IAC5D,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,SAAS,CAAA;IACtB,YAAY,CAAC,EAAE,SAAS,CAAA;IACxB,WAAW,CAAC,EAAE,UAAU,CAAA;IACxB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,CACJ,IAAI,EAAE,gBAAgB,EACtB,OAAO,EAAE,QAAQ,KACd,OAAO,CAAC,SAAS,CAAC,GAAG,SAAS,CAAA;CACpC;AAED,MAAM,WAAW,eAAe,CAAC,QAAQ,SAAS,UAAU;IAC1D,SAAS,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,GAAG,SAAS,EAAE,CAAA;IACjE,QAAQ,CACN,IAAI,EAAE,MAAM,EACZ,IAAI,EA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;QACZ,OAAO,EAAE,MAAM,CAAA;KAChB,CAAA;IACD,uEAAuE;IACvE,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,CAAA;CACxC;AAED;;;;;GAKG;AACH,qBAAa,eAAe,CAAC,QAAQ,SAAS,UAAU,CACtD,YAAW,eAAe,CAAC,QAAQ,CAAC;;gBAGxB,KAAK,EAAE,iBAAiB,CAAC,QAAQ,CAAC,EAAE;IAIhD,SAAS,IAAI,SAAS,EAAE;IAelB,QAAQ,CACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,gBAAgB,EACtB,OAAO,EAAE,QAAQ,GAChB,OAAO,CAAC,SAAS,CAAC;CAOtB;AAED;;;;;;;;;GASG;AACH,qBAAa,gBAAgB,CAAC,QAAQ,SAAS,UAAU,GAAG,UAAU;;gBAMlE,KAAK,EAAE,eAAe,CAAC,QAAQ,CAAC,EAChC,gBAAgB,EACZ,CAAC,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,CAAC,GAChC,uBAAuB,CAAC,QAAQ,CAAC;IAkBvC;;;;;OAKG;IACG,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;CA8GlD;AAED;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,IAAI,EAAE,MAAM,CAAA;gBAEA,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAI1C;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,iBAAiB,EAAE,SAAS,EAC5B,OAAO,UAAQ,GACd,SAAS,CAaX"}
@@ -1,22 +1,55 @@
1
+ /**
2
+ * Authorization for MCP tool calls. A tool call succeeds on either of two
3
+ * paths (see docs/reference/mcp-gateway.md, "How a tool call is authorized"):
4
+ *
5
+ * 1. Direct grant — the caller's token holds the tool's `capability` on the
6
+ * provider's source.
7
+ * 2. `useTools` delegation — the caller's token holds only the broad
8
+ * `useTools` capability on its own source, and the provider's YAML both
9
+ * declares the tool/capability pair and grants that capability to the
10
+ * calling counterparty.
11
+ *
12
+ * Used by the daemon's MCP gateway and by agent tabs gating their own per-tab
13
+ * MCP servers.
14
+ */
1
15
  import type { Grant, YamlContent } from './YamlContent.ts';
16
+ /** The capability that lets a caller invoke provider-declared MCP tools. */
2
17
  export declare const USE_TOOLS_CAPABILITY = "useTools";
18
+ /** The subset of a verified `Token` that authorization decisions consume. */
3
19
  export interface McpCapabilityToken {
4
20
  hasCapability(source: string, capability: string): boolean;
5
21
  getCounterparty(): string;
6
22
  getSourceUrl(): URL;
7
23
  getSrc(): string;
8
24
  }
25
+ /** One tool call to authorize: who is calling, and what they are calling. */
9
26
  export interface McpToolAuthorization {
27
+ /** The caller's verified token; `null` always denies. */
10
28
  token: McpCapabilityToken | null;
29
+ /** Source URL of the app providing the tool. */
11
30
  providerSource: string;
12
31
  toolName: string;
32
+ /** The capability the tool requires (its YAML `capability` field). */
13
33
  capability: string;
34
+ /** The provider app's YAML; required for the `useTools` delegation path. */
14
35
  providerYaml?: YamlContent;
15
36
  }
37
+ /**
38
+ * Whether the call described by `authorization` is permitted, via direct
39
+ * grant or `useTools` delegation (see the module comment).
40
+ */
16
41
  export declare function hasMcpToolCapability(authorization: McpToolAuthorization): boolean;
42
+ /** `token.hasCapability`, with verification errors treated as "no". */
17
43
  export declare function tokenHasCapability(token: {
18
44
  hasCapability(source: string, capability: string): boolean;
19
45
  }, source: string, capability: string): boolean;
46
+ /** Whether the YAML `mcp.tools` block declares this tool/capability pair. */
20
47
  export declare function yamlDeclaresMcpToolCapability(yaml: Pick<YamlContent, 'mcp'>, toolName: string, capability: string): boolean;
48
+ /**
49
+ * Whether a YAML `grant` block grants `capability` to the given counterparty
50
+ * and source. Counterparty and source keys are SQL-`LIKE` patterns (`%`/`_`);
51
+ * counterparties match case-insensitively. A grant entry is either an array of
52
+ * capabilities (any source) or a map of source pattern → capability list.
53
+ */
21
54
  export declare function yamlGrantsCapability(grant: Grant | undefined, counterparty: string, src: string, capability: string): boolean;
22
55
  //# sourceMappingURL=McpToolAuthorization.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"McpToolAuthorization.d.ts","sourceRoot":"","sources":["../../../ts/McpToolAuthorization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE1D,eAAO,MAAM,oBAAoB,aAAa,CAAA;AAI9C,MAAM,WAAW,kBAAkB;IACjC,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAA;IAC1D,eAAe,IAAI,MAAM,CAAA;IACzB,YAAY,IAAI,GAAG,CAAA;IACnB,MAAM,IAAI,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAAA;IAChC,cAAc,EAAE,MAAM,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,WAAW,CAAA;CAC3B;AAED,wBAAgB,oBAAoB,CAClC,aAAa,EAAE,oBAAoB,GAClC,OAAO,CAwBT;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE;IAAE,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,EACrE,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,GACjB,OAAO,CAMT;AAED,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,EAC9B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GACjB,OAAO,CAMT;AAED,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,KAAK,GAAG,SAAS,EACxB,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,GACjB,OAAO,CA2BT"}
1
+ {"version":3,"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G,SAAS,EACxB,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,GACjB,OAAO,CA2BT"}
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "files": [
14
14
  "dist"
15
15
  ],
16
- "version": "28.1.0",
16
+ "version": "28.2.1",
17
17
  "description": "Web Daemon",
18
18
  "module": "./dist/index.js",
19
19
  "keywords": [