fascicle 0.18.0 → 0.19.0
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 +70 -0
- package/README.md +27 -1
- package/dist/AGENTS.md +71 -94
- package/dist/a2a.d.ts +358 -0
- package/dist/a2a.js +2234 -0
- package/dist/a2a.js.map +1 -0
- package/dist/acp.d.ts +120 -9
- package/dist/acp.js +927 -154
- package/dist/acp.js.map +1 -1
- package/dist/adapters-DYFauXE1.js +1147 -0
- package/dist/adapters-DYFauXE1.js.map +1 -0
- package/dist/adapters.d.ts +124 -36
- package/dist/adapters.js +1 -1
- package/dist/agents.d.ts +2 -2
- package/dist/agents.js +1 -1
- package/dist/{core-BH7sWpEG.js → core-xTtRZqdb.js} +217 -99
- package/dist/core-xTtRZqdb.js.map +1 -0
- package/dist/diagram_bin.js +1 -1
- package/dist/durable-CgU0kO2H.d.ts +144 -0
- package/dist/{engine-fOjYHcv6.js → engine-B_Yl7acj.js} +128 -42
- package/dist/engine-B_Yl7acj.js.map +1 -0
- package/dist/index.d.ts +9 -136
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/{invoke-7iu8db6V.js → invoke-Bbk0RuVL.js} +3 -3
- package/dist/{invoke-7iu8db6V.js.map → invoke-Bbk0RuVL.js.map} +1 -1
- package/dist/{leading_system-BeQUSAim.js → leading_system-m-x7HzbQ.js} +16 -4
- package/dist/leading_system-m-x7HzbQ.js.map +1 -0
- package/dist/mcp-D1hN5ywq.js +662 -0
- package/dist/mcp-D1hN5ywq.js.map +1 -0
- package/dist/mcp.d.ts +115 -5
- package/dist/mcp.js +2 -2
- package/dist/otel.d.ts +1 -1
- package/dist/stdio.d.ts +1 -1
- package/dist/stdio.js +2 -2
- package/dist/testing.d.ts +7 -5
- package/dist/testing.js +618 -318
- package/dist/testing.js.map +1 -1
- package/dist/{types-BUXt_zgJ.d.ts → types-BtRpSctv.d.ts} +38 -5
- package/dist/{types-Dk9tLpUq.d.ts → types-CDTW7XWB.d.ts} +2 -2
- package/dist/ui.d.ts +2 -2
- package/dist/viewer.js +2 -2
- package/dist/web.d.ts +1 -1
- package/package.json +17 -5
- package/dist/adapters-CpKpDk7r.js +0 -461
- package/dist/adapters-CpKpDk7r.js.map +0 -1
- package/dist/core-BH7sWpEG.js.map +0 -1
- package/dist/engine-fOjYHcv6.js.map +0 -1
- package/dist/leading_system-BeQUSAim.js.map +0 -1
- package/dist/mcp-CHJ88HiG.js +0 -262
- package/dist/mcp-CHJ88HiG.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-D1hN5ywq.js","names":[],"sources":["../src/mcp/errors.ts","../src/mcp/sdk_loader.ts","../src/mcp/resources.ts","../src/mcp/result_mapping.ts","../src/mcp/sampling.ts","../src/mcp/client.ts","../src/mcp/serve.ts"],"sourcesContent":["/**\n * Typed errors for the MCP adapter.\n *\n * Listed alongside src/core/errors.ts and src/engine/errors.ts in the\n * `no-class` rule ignores: `instanceof` branching is how callers distinguish a\n * missing optional peer from a tool-level failure surfaced over the wire, and\n * either of those from a server that wants credentials.\n */\n\nexport class mcp_sdk_missing_error extends Error {\n readonly kind = 'mcp_sdk_missing_error' as const;\n constructor(\n message = '@modelcontextprotocol/sdk is required for fascicle/mcp; install it: pnpm add @modelcontextprotocol/sdk',\n ) {\n super(message)\n this.name = 'mcp_sdk_missing_error'\n }\n}\n\nexport class mcp_error extends Error {\n readonly kind = 'mcp_error' as const;\n readonly tool_name: string | undefined;\n constructor(message: string, metadata: { tool_name?: string } = {}) {\n super(message)\n this.name = 'mcp_error'\n this.tool_name = metadata.tool_name\n }\n}\n\n/**\n * An HTTP MCP server answered that the caller isn't authorized, while\n * connecting or on a later request once a token has expired. `url` is the\n * server's address without its query string or any credentials written into\n * it, and `cause` is the SDK's own error.\n */\nexport class mcp_auth_required_error extends Error {\n readonly kind = 'mcp_auth_required_error' as const;\n readonly url: string;\n constructor(url: string, cause: unknown) {\n const detail = cause instanceof Error ? cause.message : String(cause)\n super(\n `MCP server at ${url} requires authorization (${detail}): pass \\`auth_provider\\` in the http config with a token the server accepts, or finish an interactive OAuth flow on a transport of your own and pass its client as \\`transport: 'client'\\``,\n { cause },\n )\n this.name = 'mcp_auth_required_error'\n this.url = url\n }\n}\n","/**\n * Lazy loader for the optional `@modelcontextprotocol/sdk` peer.\n *\n * `mcp_client` needs SDK values (the Client and transport constructors, and\n * the error classes it tells an auth failure by, the schemas a handler is\n * registered under), so it imports them dynamically rather than statically: a consumer can import\n * `fascicle/mcp` without the SDK installed and only pays the cost when they\n * actually connect. A missing peer surfaces as a typed `mcp_sdk_missing_error`\n * with install guidance, mirroring the engine's `load_optional_peer`.\n *\n * `serve_flow` is not covered here: it operates on a caller-constructed\n * `McpServer`, so it needs only a type-only import and no runtime SDK load.\n */\n\nimport { mcp_sdk_missing_error } from './errors.js'\n\nexport type McpClientSdk = Awaited<ReturnType<typeof load_client_sdk>>\n\n/**\n * Dynamically imports the `@modelcontextprotocol/sdk` client modules,\n * throwing a typed `mcp_sdk_missing_error` when the optional peer is not\n * installed.\n */\nexport async function load_client_sdk() {\n try {\n const [client_mod, stdio_mod, http_mod, auth_mod, types_mod] = await Promise.all([\n import('@modelcontextprotocol/sdk/client/index.js'),\n import('@modelcontextprotocol/sdk/client/stdio.js'),\n import('@modelcontextprotocol/sdk/client/streamableHttp.js'),\n import('@modelcontextprotocol/sdk/client/auth.js'),\n import('@modelcontextprotocol/sdk/types.js'),\n ])\n return {\n Client: client_mod.Client,\n StdioClientTransport: stdio_mod.StdioClientTransport,\n StreamableHTTPClientTransport: http_mod.StreamableHTTPClientTransport,\n StreamableHTTPError: http_mod.StreamableHTTPError,\n UnauthorizedError: auth_mod.UnauthorizedError,\n McpError: types_mod.McpError,\n CreateMessageRequestSchema: types_mod.CreateMessageRequestSchema,\n ResourceUpdatedNotificationSchema: types_mod.ResourceUpdatedNotificationSchema,\n ResourceListChangedNotificationSchema: types_mod.ResourceListChangedNotificationSchema,\n }\n } catch (err: unknown) {\n const detail = err instanceof Error ? err.message : String(err)\n throw new mcp_sdk_missing_error(\n `@modelcontextprotocol/sdk is required for fascicle/mcp; install it: pnpm add @modelcontextprotocol/sdk (cause: ${detail})`,\n )\n }\n}\n","/**\n * Inbound MCP resources: list, read, and watch what a server publishes, as\n * plain Fascicle-owned shapes.\n *\n * Each call is a thin translation of one SDK call. The one piece of state is\n * the set of callbacks waiting on each URI, which is what lets several\n * subscribers share one subscription on the wire.\n */\n\nimport type { Client } from '@modelcontextprotocol/sdk/client/index.js'\nimport { mcp_error } from './errors.js'\nimport { load_client_sdk } from './sdk_loader.js'\n\nexport type McpResource = {\n uri: string\n name: string\n description?: string\n mime_type?: string\n}\n\nexport type McpResourceTemplate = {\n // An RFC 6570 template, such as `file:///{path}`.\n uri_template: string\n name: string\n description?: string\n mime_type?: string\n}\n\n/** One part of a resource's content: `text` as written, or `blob` in base64. */\nexport type McpResourceContent = {\n uri: string\n mime_type?: string\n} & ({ text: string } | { blob: string })\n\nexport type McpResources = {\n /** Every resource the server lists, across all of its pages. */\n readonly list: () => Promise<McpResource[]>\n /** Every resource template the server lists, across all of its pages. */\n readonly templates: () => Promise<McpResourceTemplate[]>\n readonly read: (uri: string) => Promise<McpResourceContent[]>\n /**\n * Calls `on_update` with the URI each time the server says the resource\n * changed. The notification carries no content, so reading the resource\n * again is the callback's choice. Subscribers to one URI share a single\n * subscription on the server.\n */\n readonly subscribe: (uri: string, on_update: (uri: string) => void) => Promise<void>\n /** Drops every callback on the URI and ends the server's subscription. */\n readonly unsubscribe: (uri: string) => Promise<void>\n /** Calls `on_change` each time the server says its list of resources changed. */\n readonly on_list_changed: (on_change: () => void) => Promise<void>\n}\n\ntype Subscription = {\n callbacks: Set<(uri: string) => void>\n // Settles when the server has answered the `resources/subscribe` request.\n ready: Promise<void>\n}\n\ntype Feature = 'resources' | 'subscribe' | 'listChanged'\n\nconst REMEDIES: Record<Feature, string> = {\n resources: 'connect to a server that lists `resources` among its capabilities',\n subscribe: 'call resources.read when you need the current content',\n listChanged: 'call resources.list when you need the current listing',\n}\n\n/**\n * Builds the `resources` namespace of an `mcp_client` handle over a connected\n * client.\n *\n * Nothing is registered on the client until the first `subscribe` or\n * `on_list_changed`, so a caller who only wants tools pays nothing for this.\n * Every failed request goes through `translate`, which is how an expired\n * token on an HTTP connection reads the same here as it does on a tool call.\n */\nexport function create_resources(\n client: Client,\n translate: (err: unknown) => unknown,\n): McpResources {\n const subscriptions = new Map<string, Subscription>()\n const list_listeners = new Set<() => void>()\n let update_handler: Promise<void> | undefined\n let list_handler: Promise<void> | undefined\n\n const request = async <t>(send: () => Promise<t>): Promise<t> =>\n send().catch((err: unknown) => {\n throw translate(err)\n })\n\n const listen_for_updates = async (): Promise<void> => {\n update_handler ??= load_client_sdk().then((sdk) => {\n client.setNotificationHandler(sdk.ResourceUpdatedNotificationSchema, (notification) => {\n const uri = notification.params.uri\n notify_all(subscriptions.get(uri)?.callbacks ?? [], (on_update) => on_update(uri))\n })\n })\n return update_handler\n }\n\n const listen_for_list_changes = async (): Promise<void> => {\n list_handler ??= load_client_sdk().then((sdk) => {\n client.setNotificationHandler(sdk.ResourceListChangedNotificationSchema, () => {\n notify_all(list_listeners, (on_change) => on_change())\n })\n })\n return list_handler\n }\n\n return {\n list: async () => {\n require_capability(client, 'resources', 'resources.list')\n const found: McpResource[] = []\n let cursor: string | undefined\n do {\n const params = cursor !== undefined ? { cursor } : undefined\n const page = await request(() => client.listResources(params))\n for (const resource of page.resources) {\n found.push({ uri: resource.uri, name: resource.name, ...described(resource) })\n }\n cursor = page.nextCursor\n } while (cursor !== undefined)\n return found\n },\n\n templates: async () => {\n require_capability(client, 'resources', 'resources.templates')\n const found: McpResourceTemplate[] = []\n let cursor: string | undefined\n do {\n const params = cursor !== undefined ? { cursor } : undefined\n const page = await request(() => client.listResourceTemplates(params))\n for (const template of page.resourceTemplates) {\n found.push({ uri_template: template.uriTemplate, name: template.name, ...described(template) })\n }\n cursor = page.nextCursor\n } while (cursor !== undefined)\n return found\n },\n\n read: async (uri) => {\n require_capability(client, 'resources', 'resources.read')\n const result = await request(() => client.readResource({ uri }))\n return result.contents.map((part) => ({\n uri: part.uri,\n ...(part.mimeType !== undefined ? { mime_type: part.mimeType } : {}),\n ...('text' in part ? { text: part.text } : { blob: part.blob }),\n }))\n },\n\n subscribe: async (uri, on_update) => {\n require_capability(client, 'subscribe', 'resources.subscribe')\n await listen_for_updates()\n const existing = subscriptions.get(uri)\n if (existing !== undefined) {\n existing.callbacks.add(on_update)\n return existing.ready\n }\n const subscription: Subscription = {\n callbacks: new Set([on_update]),\n ready: request(async () => {\n await client.subscribeResource({ uri })\n }),\n }\n // In place before the server answers, so an update that arrives ahead\n // of the answer still reaches the callback.\n subscriptions.set(uri, subscription)\n return subscription.ready.catch((err: unknown) => {\n // A later subscribe may have replaced this entry already.\n if (subscriptions.get(uri) === subscription) subscriptions.delete(uri)\n throw err\n })\n },\n\n unsubscribe: async (uri) => {\n if (!subscriptions.delete(uri)) return\n await request(() => client.unsubscribeResource({ uri }))\n },\n\n on_list_changed: async (on_change) => {\n require_capability(client, 'listChanged', 'resources.on_list_changed')\n await listen_for_list_changes()\n list_listeners.add(on_change)\n },\n }\n}\n\n/**\n * Throws `mcp_error` when the server's handshake left out the capability a\n * resources call depends on.\n *\n * The SDK sends the request regardless, and the server's refusal comes back\n * as a bare JSON-RPC error (or, for a list-changed listener, as silence), so\n * the check happens here where the message can say what is missing. A session\n * rejoined by `session_id` skipped the handshake and has no capabilities to\n * read, so its requests go to the server unchecked.\n */\nfunction require_capability(client: Client, feature: Feature, action: string): void {\n const capabilities = client.getServerCapabilities()\n if (capabilities === undefined) return\n const resources = capabilities.resources\n if (resources === undefined) {\n throw new mcp_error(\n `MCP server does not advertise the \\`resources\\` capability, so ${action} has nothing to ask it: ${REMEDIES.resources}`,\n )\n }\n if (feature === 'resources' || resources[feature] === true) return\n throw new mcp_error(\n `MCP server does not advertise the \\`resources.${feature}\\` capability, so ${action} would never hear from it: ${REMEDIES[feature]}`,\n )\n}\n\n/**\n * The optional fields a resource and a resource template share, under\n * Fascicle's names and absent when the server sent none.\n */\nfunction described(entry: {\n description?: string | undefined\n mimeType?: string | undefined\n}): { description?: string; mime_type?: string } {\n return {\n ...(entry.description !== undefined ? { description: entry.description } : {}),\n ...(entry.mimeType !== undefined ? { mime_type: entry.mimeType } : {}),\n }\n}\n\n/**\n * Calls every callback, then rethrows the first failure.\n *\n * One subscriber that throws does not keep the rest from hearing the\n * notification. The rethrown failure lands in the SDK's notification\n * dispatch, which hands it to the client's `onerror`.\n */\nfunction notify_all<f>(callbacks: Iterable<f>, call: (callback: f) => void): void {\n const failures: unknown[] = []\n for (const callback of callbacks) {\n try {\n call(callback)\n } catch (err: unknown) {\n failures.push(err)\n }\n }\n if (failures.length > 0) throw failures[0]\n}\n","/**\n * Mapping between MCP `CallToolResult` payloads and Fascicle tool values, in\n * both directions: inbound results from `mcp_client` tools, outbound results\n * for `serve_flow`.\n */\n\nimport { as_record, is_record } from '#schema'\nimport { mcp_error } from './errors.js'\n\nexport type McpToolResult = {\n content: Array<{ type: 'text'; text: string }>\n structuredContent?: Record<string, unknown>\n}\n\n/**\n * Converts a remote tool's `CallToolResult` into the value a Fascicle\n * `Tool.execute` returns.\n *\n * `isError: true` marks a tool-level failure, so it throws `mcp_error` rather\n * than returning, letting the tool loop's error policy feed it back to the\n * model. `structuredContent` is preferred over joined text parts when present;\n * with neither, the raw `content` (or `null`) is returned.\n */\nexport function call_result_to_output(result: unknown, tool_name?: string): unknown {\n const record = as_record(result) ?? {}\n\n if (record['isError'] === true) {\n const detail = join_text(record['content']) ?? 'MCP tool returned an error'\n throw new mcp_error(detail, tool_name !== undefined ? { tool_name } : {})\n }\n\n if (is_record(record['structuredContent'])) return record['structuredContent']\n\n const text = join_text(record['content'])\n if (text !== undefined) return text\n\n return record['content'] ?? null\n}\n\n/**\n * Converts a Fascicle flow's output into a `CallToolResult` for `serve_flow`.\n *\n * A `to_result` override takes precedence over the default mapping. By\n * default, objects are emitted as both a JSON text part (every MCP host can\n * read text) and `structuredContent` (typed hosts get the object); everything\n * else becomes a single text part.\n */\nexport function output_to_call_result<o>(\n output: o,\n to_result?: (output: o) => { text: string; structured?: Record<string, unknown> },\n): McpToolResult {\n if (to_result !== undefined) {\n const shaped = to_result(output)\n return build_result(shaped.text, shaped.structured)\n }\n if (typeof output === 'string') return build_result(output)\n if (is_record(output)) return build_result(stringify(output), output)\n if (Array.isArray(output)) return build_result(stringify(output))\n return build_result(String(output))\n}\n\n/**\n * Assembles a `CallToolResult` with one text part and, when given, structured\n * content.\n */\nfunction build_result(text: string, structured?: Record<string, unknown>): McpToolResult {\n return structured !== undefined\n ? { content: [{ type: 'text', text }], structuredContent: structured }\n : { content: [{ type: 'text', text }] }\n}\n\n/**\n * Joins the `text` parts of an MCP content array with newlines, skipping\n * non-text parts; `undefined` when there is nothing to join.\n */\nfunction join_text(content: unknown): string | undefined {\n if (!Array.isArray(content)) return undefined\n const parts: string[] = []\n for (const part of content) {\n if (is_record(part) && part['type'] === 'text' && typeof part['text'] === 'string') {\n parts.push(part['text'])\n }\n }\n return parts.length > 0 ? parts.join('\\n') : undefined\n}\n\n/**\n * `JSON.stringify` that falls back to `String` instead of throwing on\n * unserializable values (circular references, BigInt).\n */\nfunction stringify(value: unknown): string {\n try {\n return JSON.stringify(value)\n } catch {\n return String(value)\n }\n}\n","/**\n * Inbound MCP sampling: answer a server's `sampling/createMessage` request\n * with a completion from a Fascicle engine.\n *\n * Sampling runs the other way from a tool call. The server asks and the\n * client spends the tokens, so everything here is about what a remote server\n * may ask for: one fixed model, a cap on output, text and images only, and no\n * tools.\n */\n\nimport type { Client } from '@modelcontextprotocol/sdk/client/index.js'\nimport type {\n CreateMessageRequest,\n CreateMessageResult,\n SamplingMessage,\n} from '@modelcontextprotocol/sdk/types.js'\nimport type { TrajectoryLogger } from '#core'\nimport type { AssistantContentPart, Engine, Message, UserContentPart } from '#engine'\nimport { mcp_error } from './errors.js'\nimport type { McpClientSdk } from './sdk_loader.js'\n\n// JSON-RPC's \"invalid params\", for a request this client declines to map.\nconst INVALID_PARAMS = -32602\n// The code the MCP specification's own example uses for a user's refusal.\nconst REJECTED = -1\n\n/**\n * A server's sampling request as the `on_request` hook sees it, already in\n * Fascicle's shapes. `max_tokens` is what the engine will be asked for, after\n * the config's cap. `model_preferences` is the server's hint object exactly as\n * sent, and nothing in Fascicle reads it.\n */\nexport type McpSamplingRequest = {\n messages: Message[]\n system?: string\n max_tokens: number\n model_preferences?: unknown\n}\n\nexport type McpSamplingConfig = {\n engine: Engine\n // Sent to the engine as written, for every request. The server's model\n // preferences never choose it.\n model: string\n provider?: string\n // The most output tokens one request may ask for. A request that asks for\n // more is answered within this. Unset caps a request at 4,096.\n max_tokens?: number\n // Called before each completion. A false answer refuses the request\n // before the engine is called. Required, since a server that you connect\n // to is asking to spend your tokens, and the answer is yours to give. Pass\n // `() => true` to allow every request.\n on_request: (request: McpSamplingRequest) => boolean | Promise<boolean>\n trajectory?: TrajectoryLogger\n}\n\n// What one sampling request may ask for when the config sets no `max_tokens`.\nconst DEFAULT_SAMPLING_MAX_TOKENS = 4096\n\ntype Refuse = (code: number, message: string) => Error\n\ntype SamplingBlock = Extract<SamplingMessage['content'], { type: string }>\n\n/**\n * Registers the sampling handler on a client that declared the `sampling`\n * capability.\n *\n * The SDK checks the capability when a handler is registered, and a client\n * constructed without it throws there. For a client the caller constructed\n * that is the caller's to fix, so the failure is rethrown as an `mcp_error`\n * that says how.\n */\nexport function register_sampling(sdk: McpClientSdk, client: Client, config: McpSamplingConfig): void {\n const handler = create_sampling_handler(config, (code, message) => new sdk.McpError(code, message))\n try {\n client.setRequestHandler(sdk.CreateMessageRequestSchema, handler)\n } catch (err: unknown) {\n const detail = err instanceof Error ? err.message : String(err)\n throw new mcp_error(\n `sampling can't be served on the client passed as \\`transport: 'client'\\` (${detail}): construct that Client with \\`capabilities: { sampling: {} }\\`, or drop the \\`sampling\\` option`,\n )\n }\n}\n\n/**\n * Builds the handler that turns one `sampling/createMessage` request into one\n * `engine.generate` call and its result.\n *\n * `refuse` makes the error the server is answered with when a request is\n * declined. A request carrying `tools` or `toolChoice` is declined outright:\n * the server would be choosing which of the host's tools run, which is the\n * decision tool approval exists to keep with the host. `stopSequences`,\n * `includeContext`, and `metadata` are dropped. A failure inside the engine is\n * left to the SDK, which answers the server with the error's message.\n */\nfunction create_sampling_handler(\n config: McpSamplingConfig,\n refuse: Refuse,\n): (request: CreateMessageRequest, extra: { signal: AbortSignal }) => Promise<CreateMessageResult> {\n return async (request, extra) => {\n const params = request.params\n if (params.tools !== undefined || params.toolChoice !== undefined) {\n throw refuse(\n INVALID_PARAMS,\n 'sampling with tools is not supported by this client: send the request without `tools` and `toolChoice`',\n )\n }\n const messages = params.messages.map((message) => to_message(message, refuse))\n const max_tokens = Math.min(params.maxTokens, config.max_tokens ?? DEFAULT_SAMPLING_MAX_TOKENS)\n\n const allowed = await config.on_request({\n messages,\n ...(params.systemPrompt !== undefined ? { system: params.systemPrompt } : {}),\n max_tokens,\n ...(params.modelPreferences !== undefined ? { model_preferences: params.modelPreferences } : {}),\n })\n if (!allowed) throw refuse(REJECTED, 'sampling request rejected by the client')\n\n const result = await config.engine.generate({\n model: config.model,\n ...(config.provider !== undefined ? { provider: config.provider } : {}),\n prompt: messages,\n ...(params.systemPrompt !== undefined ? { system: params.systemPrompt } : {}),\n max_tokens,\n ...(params.temperature !== undefined ? { temperature: params.temperature } : {}),\n abort: extra.signal,\n ...(config.trajectory !== undefined ? { trajectory: config.trajectory } : {}),\n })\n return {\n model: result.model_resolved.model_id,\n role: 'assistant',\n content: { type: 'text', text: result.content },\n stopReason: to_stop_reason(result.finish_reason),\n }\n }\n}\n\n/**\n * Maps the engine's finish reason onto MCP's `stopReason`. The two MCP names\n * with an engine counterpart are translated, and any other reason goes out\n * as the engine spelled it, which MCP allows.\n */\nfunction to_stop_reason(finish_reason: string): string {\n if (finish_reason === 'stop') return 'endTurn'\n if (finish_reason === 'length') return 'maxTokens'\n return finish_reason\n}\n\n/**\n * Converts one MCP sampling message into an engine `Message`. A message that\n * is a single text block becomes plain string content, the form every\n * provider transport takes.\n */\nfunction to_message(message: SamplingMessage, refuse: Refuse): Message {\n const blocks: SamplingBlock[] = Array.isArray(message.content) ? message.content : [message.content]\n const [only] = blocks\n if (blocks.length === 1 && only?.type === 'text') {\n return message.role === 'user'\n ? { role: 'user', content: only.text }\n : { role: 'assistant', content: only.text }\n }\n return message.role === 'user'\n ? { role: 'user', content: blocks.map((block) => to_user_part(block, refuse)) }\n : { role: 'assistant', content: blocks.map((block) => to_assistant_part(block, refuse)) }\n}\n\n/** Converts one block of a user message: text, or an image as base64. */\nfunction to_user_part(block: SamplingBlock, refuse: Refuse): UserContentPart {\n if (block.type === 'text') return { type: 'text', text: block.text }\n if (block.type === 'image') return { type: 'image', image: block.data, media_type: block.mimeType }\n throw unsupported(block.type, 'user', refuse)\n}\n\n/** Converts one block of an assistant message, which may only be text. */\nfunction to_assistant_part(block: SamplingBlock, refuse: Refuse): AssistantContentPart {\n if (block.type === 'text') return { type: 'text', text: block.text }\n throw unsupported(block.type, 'assistant', refuse)\n}\n\n/** The refusal for a content block this client has no engine shape for. */\nfunction unsupported(type: string, role: string, refuse: Refuse): Error {\n return refuse(\n INVALID_PARAMS,\n `sampling content of type '${type}' in a ${role} message is not supported by this client: send text, or an image in a user message`,\n )\n}\n","/**\n * Inbound MCP: connect to an external MCP server and surface its tools as plain\n * Fascicle `Tool[]`.\n */\n\nimport type { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js'\nimport type { Client } from '@modelcontextprotocol/sdk/client/index.js'\nimport type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js'\nimport type { Tool, ToolExecContext } from '#engine'\nimport { is_record, json_schema_to_standard } from '#schema'\nimport { mcp_auth_required_error, mcp_error } from './errors.js'\nimport { create_resources, type McpResources } from './resources.js'\nimport { call_result_to_output } from './result_mapping.js'\nimport { register_sampling, type McpSamplingConfig } from './sampling.js'\nimport { load_client_sdk, type McpClientSdk } from './sdk_loader.js'\n\nconst DEFAULT_CLIENT_INFO = { name: 'fascicle', version: '0.0.0' }\n\nexport type McpStdioConfig = {\n transport: 'stdio'\n command: string\n args?: string[]\n env?: Record<string, string>\n cwd?: string\n}\n\nexport type McpStreamableHttpConfig = {\n transport: 'http'\n url: string\n headers?: Record<string, string>\n // The SDK's OAuth provider interface, for a token that expires, refreshes,\n // or comes from a `client_credentials` grant. The transport asks it for a\n // token on each request. A flow that needs the user in a browser doesn't\n // fit here: run it on a transport of your own and pass `transport: 'client'`.\n auth_provider?: OAuthClientProvider\n // Replaces the global `fetch` for every request the transport makes, the\n // OAuth ones included (a proxy, a recorder, a test double).\n fetch?: McpFetch\n // Rejoins a session the server already knows. The handshake is skipped, so\n // the server's capabilities are unknown to this connection.\n session_id?: string\n // How the transport retries a dropped event stream.\n reconnection?: McpReconnectionOptions\n}\n\nexport type McpFetch = (url: string | URL, init?: RequestInit) => Promise<Response>\n\n/**\n * The backoff for reopening a dropped event stream. The wait before retry\n * `n` (counting from zero) is `initial_delay_ms * delay_grow_factor^n`, capped\n * at `max_delay_ms`, and the transport gives up after `max_retries`.\n */\nexport type McpReconnectionOptions = {\n max_retries: number\n initial_delay_ms: number\n max_delay_ms: number\n delay_grow_factor: number\n}\n\n// Escape hatch: hand in an already-connected Client (a transport the adapter\n// does not build, a test harness, a shared connection). Its lifecycle stays\n// with the caller, so the returned `close` is a no-op for this variant.\nexport type McpExistingClientConfig = {\n transport: 'client'\n client: Client\n}\n\nexport type McpClientConfig =\n | McpStdioConfig\n | McpStreamableHttpConfig\n | McpExistingClientConfig\n\nexport type McpClientOptions = {\n // Identity sent in the MCP handshake; defaults to Fascicle.\n client_info?: { name: string; version: string }\n // When set, only tools whose name is listed are surfaced.\n include?: ReadonlyArray<string>\n // Supplies a description for tools that advertise none.\n default_description?: (tool_name: string) => string\n // Prepended, as written, to each surfaced tool's name, so two servers'\n // tools can share a call without colliding. The server is still called by\n // its own name, and `include` and `default_description` see that name too.\n name_prefix?: string\n // Marks surfaced tools as needing approval, so the engine asks\n // `on_tool_approval` before each call and refuses the call when no handler\n // is set. Unset (the default) gates nothing. See McpApprovalPolicy.\n needs_approval?: McpApprovalPolicy\n // Lets the server ask this client for completions (MCP sampling), answered\n // by the engine and model named here. Setting it is what declares the\n // capability to the server, and unset declares nothing.\n sampling?: McpSamplingConfig\n}\n\n/**\n * What a server advertised about one tool, as an approval policy sees it. The\n * name is the server's own, without `name_prefix`. `annotations` holds the\n * hints the server sent (`readOnlyHint`, `destructiveHint`, and so on), and it\n * is absent when the server sent none. The server wrote those hints, so a\n * policy that trusts them trusts the server.\n */\nexport type McpAdvertisedTool = {\n name: string\n annotations?: Record<string, unknown>\n}\n\n/**\n * Which surfaced tools need approval. `true` gates every tool and `false`\n * gates none. A function is called once for each tool as it is surfaced, and\n * answers for that tool with a boolean or with a predicate over the call's\n * input, which becomes the tool's own `needs_approval`.\n */\nexport type McpApprovalPolicy =\n | boolean\n | ((tool: McpAdvertisedTool) => boolean | ((input: unknown) => boolean | Promise<boolean>))\n\nexport type McpClientHandle = {\n readonly tools: ReadonlyArray<Tool>\n readonly close: () => Promise<void>\n // What the server publishes besides tools. It costs nothing until a method\n // is called.\n readonly resources: McpResources\n}\n\n/**\n * Connects to an MCP server and surfaces its advertised tools as Fascicle\n * `Tool[]`, plus a `close` handle for the connection.\n *\n * Owns the connection lifecycle (config in, `{ tools, close }` out) so callers\n * do not have to import SDK transport classes themselves. Each advertised MCP\n * tool becomes an ordinary `Tool`: its JSON Schema is wrapped as a `ToolSchema`\n * the loop validates against and the provider receives back unchanged, and\n * `execute` forwards to `callTool`, propagating the run's abort signal. For the\n * `client` transport variant the caller keeps ownership of the connection, so\n * `close` is a no-op. A connection this call opened is closed again when\n * listing its tools fails. A server that advertises no tools is not asked\n * for any, and its handle carries an empty `tools` beside its `resources`.\n */\nexport async function mcp_client(\n config: McpClientConfig,\n options: McpClientOptions = {},\n): Promise<McpClientHandle> {\n const { client, owned, translate } = await open_connection(config, options)\n\n const include = options.include !== undefined ? new Set(options.include) : undefined\n const listed = advertises_no_tools(client)\n ? { tools: [] }\n : await client.listTools().catch(async (err: unknown) => {\n // A client this call connected has no other owner yet, so it closes\n // here, taking a spawned stdio server with it. The listing failure is\n // the one the caller sees, even if the close fails too.\n if (owned) await client.close().catch(() => undefined)\n throw translate(err)\n })\n const tools: Tool[] = []\n for (const advertised of listed.tools) {\n if (include !== undefined && !include.has(advertised.name)) continue\n tools.push(to_fascicle_tool(client, advertised, options, translate))\n }\n\n return {\n tools,\n close: async () => {\n if (owned) await client.close()\n },\n resources: create_resources(client, translate),\n }\n}\n\n/**\n * True when the handshake said the server has no tools at all, as a server\n * that only publishes resources does. Asking such a server to list its tools\n * is answered with a JSON-RPC error, so the handle carries an empty `tools`\n * instead. A connection with no handshake to read (a session rejoined by\n * `session_id`) is asked.\n */\nfunction advertises_no_tools(client: Client): boolean {\n const capabilities = client.getServerCapabilities()\n return capabilities !== undefined && capabilities.tools === undefined\n}\n\n/** Turns an error from the SDK into the one the caller should see. */\ntype ErrorTranslator = (err: unknown) => unknown\n\ntype Connection = {\n client: Client\n // False for a client the caller connected, whose lifecycle stays theirs.\n owned: boolean\n translate: ErrorTranslator\n}\n\n/**\n * Returns the caller's already-connected client as-is, or lazily loads the\n * SDK and connects a fresh client over the configured transport.\n *\n * An `http` connection carries a translator that turns the SDK's auth\n * failures into `mcp_auth_required_error`, for the handshake and for every\n * later request. A client the caller connected keeps the SDK's errors as they\n * are, since the caller built its transport and already holds the SDK.\n *\n * With `sampling` set, a fresh client declares the capability and has its\n * handler in place before it connects. A client the caller connected gets\n * the handler only, since its capabilities were declared when it was built.\n */\nasync function open_connection(\n config: McpClientConfig,\n options: McpClientOptions,\n): Promise<Connection> {\n const sampling = options.sampling\n if (config.transport === 'client') {\n if (sampling !== undefined) register_sampling(await load_client_sdk(), config.client, sampling)\n return { client: config.client, owned: false, translate: same_error }\n }\n const sdk = await load_client_sdk()\n const translate = config.transport === 'http' ? auth_translator(sdk, config.url) : same_error\n const info = options.client_info ?? DEFAULT_CLIENT_INFO\n // Capabilities are fixed when the Client is constructed, and the SDK\n // refuses a sampling handler on a client that declared none.\n const client =\n sampling !== undefined\n ? new sdk.Client(info, { capabilities: { sampling: {} } })\n : new sdk.Client(info)\n if (sampling !== undefined) register_sampling(sdk, client, sampling)\n await client.connect(build_transport(sdk, config)).catch((err: unknown) => {\n throw translate(err)\n })\n return { client, owned: true, translate }\n}\n\n/** The translator for a connection whose errors pass through untouched. */\nfunction same_error(err: unknown): unknown {\n return err\n}\n\n/**\n * Builds the translator for one HTTP server: an auth failure becomes\n * `mcp_auth_required_error`, and anything else passes through.\n *\n * The SDK reports an auth failure two ways. With an `authProvider` whose\n * flow ends short of a usable token it throws `UnauthorizedError`, from the\n * handshake or from any later request. With no provider, or when the server\n * still answers 401 to a fresh token, the POST fails as a\n * `StreamableHTTPError` whose `code` is 401. The error names the server by\n * origin and path only, since a query string or userinfo can hold a secret.\n */\nfunction auth_translator(sdk: McpClientSdk, url: string): ErrorTranslator {\n const parsed = new URL(url)\n const shown = `${parsed.origin}${parsed.pathname}`\n return (err) => {\n const unauthorized =\n err instanceof sdk.UnauthorizedError ||\n (err instanceof sdk.StreamableHTTPError && err.code === 401)\n return unauthorized ? new mcp_auth_required_error(shown, err) : err\n }\n}\n\n/**\n * Constructs the SDK transport matching the config: a spawned child process\n * for `stdio`, a Streamable HTTP connection for `http`. Each option reaches\n * the SDK only when the config sets it, so the SDK's own defaults hold for\n * the rest.\n */\nfunction build_transport(\n sdk: McpClientSdk,\n config: McpStdioConfig | McpStreamableHttpConfig,\n): Transport {\n if (config.transport === 'stdio') {\n return new sdk.StdioClientTransport({\n command: config.command,\n ...(config.args !== undefined ? { args: config.args } : {}),\n ...(config.env !== undefined ? { env: config.env } : {}),\n ...(config.cwd !== undefined ? { cwd: config.cwd } : {}),\n })\n }\n const reconnection = config.reconnection\n return new sdk.StreamableHTTPClientTransport(new URL(config.url), {\n ...(config.headers !== undefined ? { requestInit: { headers: config.headers } } : {}),\n ...(config.auth_provider !== undefined ? { authProvider: config.auth_provider } : {}),\n ...(config.fetch !== undefined ? { fetch: config.fetch } : {}),\n ...(config.session_id !== undefined ? { sessionId: config.session_id } : {}),\n ...(reconnection !== undefined\n ? {\n reconnectionOptions: {\n maxRetries: reconnection.max_retries,\n initialReconnectionDelay: reconnection.initial_delay_ms,\n maxReconnectionDelay: reconnection.max_delay_ms,\n reconnectionDelayGrowFactor: reconnection.delay_grow_factor,\n },\n }\n : {}),\n })\n}\n\ntype AdvertisedTool = {\n name: string\n description?: string | undefined\n inputSchema: unknown\n annotations?: Record<string, unknown> | undefined\n}\n\n/**\n * Settles the approval policy for one advertised tool into the value its\n * `Tool.needs_approval` carries, or undefined when no policy is set.\n *\n * A function policy runs here, once, with the server's own name for the tool\n * and the annotations it advertised. Nothing in this module reads the\n * annotations: they are the server's claims about itself, and whether to\n * believe them is the policy's decision.\n */\nfunction resolve_needs_approval(\n policy: McpApprovalPolicy | undefined,\n advertised: AdvertisedTool,\n): Tool['needs_approval'] {\n if (typeof policy !== 'function') return policy\n return policy({\n name: advertised.name,\n ...(advertised.annotations !== undefined ? { annotations: advertised.annotations } : {}),\n })\n}\n\n/**\n * Wraps one advertised MCP tool as a Fascicle `Tool` whose `execute` forwards\n * to `callTool` on the shared client. Only the `Tool`'s name carries\n * `name_prefix`; the call, the fallback description, and the errors use the\n * server's own name.\n *\n * An already-aborted signal short-circuits before the wire call; otherwise the\n * signal is passed through so cancelling the run cancels the remote call. A\n * failed call goes through `translate`, so a token that expired mid-session\n * reads the same as one that was refused at connect.\n */\nfunction to_fascicle_tool(\n client: Client,\n advertised: AdvertisedTool,\n options: McpClientOptions,\n translate: ErrorTranslator,\n): Tool {\n const name = advertised.name\n const description =\n advertised.description ?? options.default_description?.(name) ?? `MCP tool ${name}`\n const needs_approval = resolve_needs_approval(options.needs_approval, advertised)\n return {\n name: `${options.name_prefix ?? ''}${name}`,\n description,\n input_schema: json_schema_to_standard(advertised.inputSchema),\n ...(needs_approval !== undefined ? { needs_approval } : {}),\n execute: async (input: unknown, ctx: ToolExecContext) => {\n if (ctx.abort.aborted) {\n throw ctx.abort.reason instanceof Error\n ? ctx.abort.reason\n : new mcp_error(`MCP tool ${name} aborted before invocation`, { tool_name: name })\n }\n const result = await client\n .callTool({ name, arguments: is_record(input) ? input : undefined }, undefined, {\n signal: ctx.abort,\n })\n .catch((err: unknown) => {\n throw translate(err)\n })\n return call_result_to_output(result, name)\n },\n }\n}\n","/**\n * Outbound MCP: expose a composed Fascicle flow as an MCP tool.\n *\n * `serve_flow` registers onto a caller-constructed `McpServer` (the caller owns\n * the transport, identity, and lifecycle, and can host many flows on one\n * server), so it needs only a type-only SDK import. The registered handler\n * drives the existing `run`, threading the per-request abort signal so an MCP\n * client cancellation aborts the in-flight flow, and maps the result into a\n * `CallToolResult`. A thrown flow becomes an `isError` result rather than a\n * JSON-RPC protocol error.\n */\n\nimport type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { z } from 'zod'\nimport { run } from '#core'\nimport type { Step, TrajectoryLogger } from '#core'\nimport { output_to_call_result } from './result_mapping.js'\n\nexport type ServeFlowConfig<i, o> = {\n server: McpServer\n flow: Step<i, o>\n name: string\n description: string\n /**\n * Stays zod rather than joining the rest of the surface on `ToolSchema`.\n * `McpServer.registerTool` types `inputSchema` as a zod schema and offers no\n * JSON Schema entry point, and the SDK carries zod as a hard runtime\n * dependency, so a `serve_flow` caller already has zod resolved. Widening\n * this to a neutral schema would typecheck and then fail inside the SDK.\n */\n input_schema: z.ZodType<i>\n trajectory?: TrajectoryLogger\n // Overrides the default value-to-CallToolResult mapping.\n to_result?: (output: o) => { text: string; structured?: Record<string, unknown> }\n}\n\n/**\n * Registers a Fascicle flow as a tool on a caller-owned MCP server.\n *\n * Drives the flow with `run`, threading the per-request abort signal so an\n * MCP client cancellation aborts the in-flight flow, and maps the result\n * into a `CallToolResult`. A thrown flow becomes an `isError` result rather\n * than a JSON-RPC protocol error.\n */\nexport function serve_flow<i, o>(config: ServeFlowConfig<i, o>): void {\n const { server, flow, name, description, input_schema, trajectory, to_result } = config\n server.registerTool(\n name,\n { description, inputSchema: input_schema },\n async (input: i, extra) => {\n try {\n const output = await run(flow, input, {\n install_signal_handlers: false,\n abort: extra.signal,\n ...(trajectory !== undefined ? { trajectory } : {}),\n })\n return output_to_call_result(output, to_result)\n } catch (err: unknown) {\n return {\n isError: true,\n content: [{ type: 'text', text: err instanceof Error ? err.message : String(err) }],\n }\n }\n },\n )\n}\n"],"mappings":";;;;;;;;;;;;AASA,IAAa,wBAAb,cAA2C,MAAM;CAC/C,OAAgB;CAChB,YACE,UAAU,0GACV;EACA,MAAM,OAAO;EACb,KAAK,OAAO;CACd;AACF;AAEA,IAAa,YAAb,cAA+B,MAAM;CACnC,OAAgB;CAChB;CACA,YAAY,SAAiB,WAAmC,CAAC,GAAG;EAClE,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,YAAY,SAAS;CAC5B;AACF;;;;;;;AAQA,IAAa,0BAAb,cAA6C,MAAM;CACjD,OAAgB;CAChB;CACA,YAAY,KAAa,OAAgB;EACvC,MAAM,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EACpE,MACE,iBAAiB,IAAI,2BAA2B,OAAO,8LACvD,EAAE,MAAM,CACV;EACA,KAAK,OAAO;EACZ,KAAK,MAAM;CACb;AACF;;;;;;;;;;;;;;;;;;;;ACxBA,eAAsB,kBAAkB;CACtC,IAAI;EACF,MAAM,CAAC,YAAY,WAAW,UAAU,UAAU,aAAa,MAAM,QAAQ,IAAI;GAC/E,OAAO;GACP,OAAO;GACP,OAAO;GACP,OAAO;GACP,OAAO;EACT,CAAC;EACD,OAAO;GACL,QAAQ,WAAW;GACnB,sBAAsB,UAAU;GAChC,+BAA+B,SAAS;GACxC,qBA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IAAI,IAAI,MAAM,SACZ,MAAM,IAAI,MAAM,kBAAkB,QAC9B,IAAI,MAAM,SACV,IAAI,UAAU,YAAY,KAAK,6BAA6B,EAAE,WAAW,KAAK,CAAC;GASrF,OAAO,sBAAsB,MAPR,OAClB,SAAS;IAAE;IAAM,WAAW,UAAU,KAAK,IAAI,QAAQ,KAAA;GAAU,GAAG,KAAA,GAAW,EAC9E,QAAQ,IAAI,MACd,CAAC,CAAC,CACD,OAAO,QAAiB;IACvB,MAAM,UAAU,GAAG;GACrB,CAAC,GACkC,IAAI;EAC3C;CACF;AACF;;;;;;;;;;AC7TA,SAAgB,WAAiB,QAAqC;CACpE,MAAM,EAAE,QAAQ,MAAM,MAAM,aAAa,cAAc,YAAY,cAAc;CACjF,OAAO,aACL,MACA;EAAE;EAAa,aAAa;CAAa,GACzC,OAAO,OAAU,UAAU;EACzB,IAAI;GAMF,OAAO,sBAAsB,MALR,IAAI,MAAM,OAAO;IACpC,yBAAyB;IACzB,OAAO,MAAM;IACb,GAAI,eAAe,KAAA,IAAY,EAAE,WAAW,IAAI,CAAC;GACnD,CAAC,GACoC,SAAS;EAChD,SAAS,KAAc;GACrB,OAAO;IACL,SAAS;IACT,SAAS,CAAC;KAAE,MAAM;KAAQ,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;IAAE,CAAC;GACpF;EACF;CACF,CACF;AACF"}
|
package/dist/mcp.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { M as Tool } from "./types-
|
|
2
|
-
import { c as Step, h as TrajectoryLogger } from "./types-
|
|
1
|
+
import { M as Tool, _ as Message, u as Engine } from "./types-CDTW7XWB.js";
|
|
2
|
+
import { c as Step, h as TrajectoryLogger } from "./types-BtRpSctv.js";
|
|
3
3
|
import { r as ToolSchema } from "./types-CvghbZ0x.js";
|
|
4
|
+
import { OAuthClientProvider } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
4
5
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
5
6
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
6
7
|
import { z } from "zod";
|
|
@@ -16,6 +17,65 @@ import { z } from "zod";
|
|
|
16
17
|
* nothing.
|
|
17
18
|
*/
|
|
18
19
|
export declare function json_schema_to_standard(schema: unknown): ToolSchema;
|
|
20
|
+
type McpResource = {
|
|
21
|
+
uri: string;
|
|
22
|
+
name: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
mime_type?: string;
|
|
25
|
+
};
|
|
26
|
+
type McpResourceTemplate = {
|
|
27
|
+
uri_template: string;
|
|
28
|
+
name: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
mime_type?: string;
|
|
31
|
+
};
|
|
32
|
+
/** One part of a resource's content: `text` as written, or `blob` in base64. */
|
|
33
|
+
type McpResourceContent = {
|
|
34
|
+
uri: string;
|
|
35
|
+
mime_type?: string;
|
|
36
|
+
} & ({
|
|
37
|
+
text: string;
|
|
38
|
+
} | {
|
|
39
|
+
blob: string;
|
|
40
|
+
});
|
|
41
|
+
type McpResources = {
|
|
42
|
+
/** Every resource the server lists, across all of its pages. */
|
|
43
|
+
readonly list: () => Promise<McpResource[]>;
|
|
44
|
+
/** Every resource template the server lists, across all of its pages. */
|
|
45
|
+
readonly templates: () => Promise<McpResourceTemplate[]>;
|
|
46
|
+
readonly read: (uri: string) => Promise<McpResourceContent[]>;
|
|
47
|
+
/**
|
|
48
|
+
* Calls `on_update` with the URI each time the server says the resource
|
|
49
|
+
* changed. The notification carries no content, so reading the resource
|
|
50
|
+
* again is the callback's choice. Subscribers to one URI share a single
|
|
51
|
+
* subscription on the server.
|
|
52
|
+
*/
|
|
53
|
+
readonly subscribe: (uri: string, on_update: (uri: string) => void) => Promise<void>;
|
|
54
|
+
/** Drops every callback on the URI and ends the server's subscription. */
|
|
55
|
+
readonly unsubscribe: (uri: string) => Promise<void>;
|
|
56
|
+
/** Calls `on_change` each time the server says its list of resources changed. */
|
|
57
|
+
readonly on_list_changed: (on_change: () => void) => Promise<void>;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* A server's sampling request as the `on_request` hook sees it, already in
|
|
61
|
+
* Fascicle's shapes. `max_tokens` is what the engine will be asked for, after
|
|
62
|
+
* the config's cap. `model_preferences` is the server's hint object exactly as
|
|
63
|
+
* sent, and nothing in Fascicle reads it.
|
|
64
|
+
*/
|
|
65
|
+
type McpSamplingRequest = {
|
|
66
|
+
messages: Message[];
|
|
67
|
+
system?: string;
|
|
68
|
+
max_tokens: number;
|
|
69
|
+
model_preferences?: unknown;
|
|
70
|
+
};
|
|
71
|
+
type McpSamplingConfig = {
|
|
72
|
+
engine: Engine;
|
|
73
|
+
model: string;
|
|
74
|
+
provider?: string;
|
|
75
|
+
max_tokens?: number;
|
|
76
|
+
on_request: (request: McpSamplingRequest) => boolean | Promise<boolean>;
|
|
77
|
+
trajectory?: TrajectoryLogger;
|
|
78
|
+
};
|
|
19
79
|
type McpStdioConfig = {
|
|
20
80
|
transport: 'stdio';
|
|
21
81
|
command: string;
|
|
@@ -27,6 +87,22 @@ type McpStreamableHttpConfig = {
|
|
|
27
87
|
transport: 'http';
|
|
28
88
|
url: string;
|
|
29
89
|
headers?: Record<string, string>;
|
|
90
|
+
auth_provider?: OAuthClientProvider;
|
|
91
|
+
fetch?: McpFetch;
|
|
92
|
+
session_id?: string;
|
|
93
|
+
reconnection?: McpReconnectionOptions;
|
|
94
|
+
};
|
|
95
|
+
type McpFetch = (url: string | URL, init?: RequestInit) => Promise<Response>;
|
|
96
|
+
/**
|
|
97
|
+
* The backoff for reopening a dropped event stream. The wait before retry
|
|
98
|
+
* `n` (counting from zero) is `initial_delay_ms * delay_grow_factor^n`, capped
|
|
99
|
+
* at `max_delay_ms`, and the transport gives up after `max_retries`.
|
|
100
|
+
*/
|
|
101
|
+
type McpReconnectionOptions = {
|
|
102
|
+
max_retries: number;
|
|
103
|
+
initial_delay_ms: number;
|
|
104
|
+
max_delay_ms: number;
|
|
105
|
+
delay_grow_factor: number;
|
|
30
106
|
};
|
|
31
107
|
type McpExistingClientConfig = {
|
|
32
108
|
transport: 'client';
|
|
@@ -41,10 +117,31 @@ type McpClientOptions = {
|
|
|
41
117
|
include?: ReadonlyArray<string>;
|
|
42
118
|
default_description?: (tool_name: string) => string;
|
|
43
119
|
name_prefix?: string;
|
|
120
|
+
needs_approval?: McpApprovalPolicy;
|
|
121
|
+
sampling?: McpSamplingConfig;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* What a server advertised about one tool, as an approval policy sees it. The
|
|
125
|
+
* name is the server's own, without `name_prefix`. `annotations` holds the
|
|
126
|
+
* hints the server sent (`readOnlyHint`, `destructiveHint`, and so on), and it
|
|
127
|
+
* is absent when the server sent none. The server wrote those hints, so a
|
|
128
|
+
* policy that trusts them trusts the server.
|
|
129
|
+
*/
|
|
130
|
+
type McpAdvertisedTool = {
|
|
131
|
+
name: string;
|
|
132
|
+
annotations?: Record<string, unknown>;
|
|
44
133
|
};
|
|
134
|
+
/**
|
|
135
|
+
* Which surfaced tools need approval. `true` gates every tool and `false`
|
|
136
|
+
* gates none. A function is called once for each tool as it is surfaced, and
|
|
137
|
+
* answers for that tool with a boolean or with a predicate over the call's
|
|
138
|
+
* input, which becomes the tool's own `needs_approval`.
|
|
139
|
+
*/
|
|
140
|
+
type McpApprovalPolicy = boolean | ((tool: McpAdvertisedTool) => boolean | ((input: unknown) => boolean | Promise<boolean>));
|
|
45
141
|
type McpClientHandle = {
|
|
46
142
|
readonly tools: ReadonlyArray<Tool>;
|
|
47
143
|
readonly close: () => Promise<void>;
|
|
144
|
+
readonly resources: McpResources;
|
|
48
145
|
};
|
|
49
146
|
/**
|
|
50
147
|
* Connects to an MCP server and surfaces its advertised tools as Fascicle
|
|
@@ -57,7 +154,8 @@ type McpClientHandle = {
|
|
|
57
154
|
* `execute` forwards to `callTool`, propagating the run's abort signal. For the
|
|
58
155
|
* `client` transport variant the caller keeps ownership of the connection, so
|
|
59
156
|
* `close` is a no-op. A connection this call opened is closed again when
|
|
60
|
-
* listing its tools fails.
|
|
157
|
+
* listing its tools fails. A server that advertises no tools is not asked
|
|
158
|
+
* for any, and its handle carries an empty `tools` beside its `resources`.
|
|
61
159
|
*/
|
|
62
160
|
export declare function mcp_client(config: McpClientConfig, options?: McpClientOptions): Promise<McpClientHandle>;
|
|
63
161
|
type ServeFlowConfig<i, o> = {
|
|
@@ -93,7 +191,8 @@ export declare function serve_flow<i, o>(config: ServeFlowConfig<i, o>): void;
|
|
|
93
191
|
*
|
|
94
192
|
* Listed alongside src/core/errors.ts and src/engine/errors.ts in the
|
|
95
193
|
* `no-class` rule ignores: `instanceof` branching is how callers distinguish a
|
|
96
|
-
* missing optional peer from a tool-level failure surfaced over the wire
|
|
194
|
+
* missing optional peer from a tool-level failure surfaced over the wire, and
|
|
195
|
+
* either of those from a server that wants credentials.
|
|
97
196
|
*/
|
|
98
197
|
export declare class mcp_sdk_missing_error extends Error {
|
|
99
198
|
readonly kind: 'mcp_sdk_missing_error';
|
|
@@ -106,5 +205,16 @@ export declare class mcp_error extends Error {
|
|
|
106
205
|
tool_name?: string;
|
|
107
206
|
});
|
|
108
207
|
}
|
|
109
|
-
|
|
208
|
+
/**
|
|
209
|
+
* An HTTP MCP server answered that the caller isn't authorized, while
|
|
210
|
+
* connecting or on a later request once a token has expired. `url` is the
|
|
211
|
+
* server's address without its query string or any credentials written into
|
|
212
|
+
* it, and `cause` is the SDK's own error.
|
|
213
|
+
*/
|
|
214
|
+
export declare class mcp_auth_required_error extends Error {
|
|
215
|
+
readonly kind: 'mcp_auth_required_error';
|
|
216
|
+
readonly url: string;
|
|
217
|
+
constructor(url: string, cause: unknown);
|
|
218
|
+
}
|
|
219
|
+
export type { McpAdvertisedTool, McpApprovalPolicy, McpClientConfig, McpClientHandle, McpClientOptions, McpExistingClientConfig, McpFetch, McpReconnectionOptions, McpResource, McpResourceContent, McpResourceTemplate, McpResources, McpSamplingConfig, McpSamplingRequest, McpStdioConfig, McpStreamableHttpConfig, ServeFlowConfig };
|
|
110
220
|
//# sourceMappingURL=mcp.d.ts.map
|
package/dist/mcp.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { t as json_schema_to_standard } from "./json_schema_to_standard-BstoXjM8.js";
|
|
2
|
-
import {
|
|
3
|
-
export { json_schema_to_standard, mcp_client, mcp_error, mcp_sdk_missing_error, serve_flow };
|
|
2
|
+
import { a as mcp_sdk_missing_error, i as mcp_error, n as mcp_client, r as mcp_auth_required_error, t as serve_flow } from "./mcp-D1hN5ywq.js";
|
|
3
|
+
export { json_schema_to_standard, mcp_auth_required_error, mcp_client, mcp_error, mcp_sdk_missing_error, serve_flow };
|
package/dist/otel.d.ts
CHANGED
package/dist/stdio.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as Step, h as TrajectoryLogger } from "./types-
|
|
1
|
+
import { c as Step, h as TrajectoryLogger } from "./types-BtRpSctv.js";
|
|
2
2
|
import { t as AnySchema } from "./types-CvghbZ0x.js";
|
|
3
3
|
type RunStdioOptions<i, o> = {
|
|
4
4
|
readonly input_schema?: AnySchema<i>;
|
package/dist/stdio.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as route_console_to_stderr } from "./console-B1ozi_ii.js";
|
|
2
|
-
import { C as validate_schema, w as run } from "./core-
|
|
3
|
-
import {
|
|
2
|
+
import { C as validate_schema, w as run } from "./core-xTtRZqdb.js";
|
|
3
|
+
import { o as stderr_logger } from "./adapters-DYFauXE1.js";
|
|
4
4
|
import { text } from "node:stream/consumers";
|
|
5
5
|
// src/stdio/execute_stdio.ts
|
|
6
6
|
/**
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as UsageTotals, F as ToolCallRecord, G as NativeProviderAdapter, R as TurnRequest, h as GenerateResult, m as GenerateOptions, n as AssistantContentPart, p as FinishReason, u as Engine } from "./types-
|
|
2
|
-
import { n as CheckpointStore } from "./types-
|
|
1
|
+
import { B as UsageTotals, F as ToolCallRecord, G as NativeProviderAdapter, R as TurnRequest, h as GenerateResult, m as GenerateOptions, n as AssistantContentPart, p as FinishReason, u as Engine } from "./types-CDTW7XWB.js";
|
|
2
|
+
import { n as CheckpointStore } from "./types-BtRpSctv.js";
|
|
3
3
|
/**
|
|
4
4
|
* Check that every turn of every call in `requests` sends the turn before it
|
|
5
5
|
* unchanged: the same system prompt, the same tools in the same order
|
|
@@ -27,7 +27,8 @@ export declare function engine_from_generate(generate: Engine['generate']): Engi
|
|
|
27
27
|
type StoreConformanceOptions = {
|
|
28
28
|
/**
|
|
29
29
|
* Damage the value stored at `key` the way a torn write or a bad disk
|
|
30
|
-
* would. Given, the suite checks that a damaged value reads as a miss
|
|
30
|
+
* would. Given, the suite checks that a damaged value reads as a miss, and
|
|
31
|
+
* that `get_versioned` still reads it with a version.
|
|
31
32
|
*/
|
|
32
33
|
readonly corrupt?: (store: CheckpointStore, key: string) => Promise<void> | void;
|
|
33
34
|
/**
|
|
@@ -50,8 +51,9 @@ type StoreConformanceReport = {
|
|
|
50
51
|
*
|
|
51
52
|
* The capabilities are read off the first store `make_store` returns: scope
|
|
52
53
|
* checks run when it has `scope`, claim checks when it has `claim` or
|
|
53
|
-
* `release`, and
|
|
54
|
-
*
|
|
54
|
+
* `release`, compare-and-set checks when it has `get_versioned` or `set_if`,
|
|
55
|
+
* and the damage checks when `options.corrupt` is given. Every other check
|
|
56
|
+
* lands in `skipped`. Checks run one at a time, because some wait
|
|
55
57
|
* on claim expiry and a store's backing service may be shared between the
|
|
56
58
|
* stores `make_store` hands out.
|
|
57
59
|
*/
|