@openrouter/mcp 1.0.0 → 1.1.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.
Files changed (96) hide show
  1. package/README.md +40 -159
  2. package/esm/cache.d.ts +7 -0
  3. package/esm/cache.d.ts.map +1 -0
  4. package/esm/cache.js +2 -0
  5. package/esm/cache.js.map +1 -0
  6. package/esm/create-mcp-tools.d.ts +4 -10
  7. package/esm/create-mcp-tools.d.ts.map +1 -1
  8. package/esm/create-mcp-tools.js +3 -93
  9. package/esm/create-mcp-tools.js.map +1 -1
  10. package/esm/index.d.ts +8 -12
  11. package/esm/index.d.ts.map +1 -1
  12. package/esm/index.js +1 -10
  13. package/esm/index.js.map +1 -1
  14. package/esm/schema.d.ts +7 -0
  15. package/esm/schema.d.ts.map +1 -0
  16. package/esm/schema.js +2 -0
  17. package/esm/schema.js.map +1 -0
  18. package/esm/types.d.ts +3 -150
  19. package/esm/types.d.ts.map +1 -1
  20. package/package.json +9 -12
  21. package/esm/auth/auth-resolver.d.ts +0 -14
  22. package/esm/auth/auth-resolver.d.ts.map +0 -1
  23. package/esm/auth/auth-resolver.js +0 -27
  24. package/esm/auth/auth-resolver.js.map +0 -1
  25. package/esm/auth/auth-types.d.ts +0 -33
  26. package/esm/auth/auth-types.d.ts.map +0 -1
  27. package/esm/auth/auth-types.js +0 -4
  28. package/esm/auth/auth-types.js.map +0 -1
  29. package/esm/build-tools.d.ts +0 -29
  30. package/esm/build-tools.d.ts.map +0 -1
  31. package/esm/build-tools.js +0 -80
  32. package/esm/build-tools.js.map +0 -1
  33. package/esm/cache/cache-store.d.ts +0 -24
  34. package/esm/cache/cache-store.d.ts.map +0 -1
  35. package/esm/cache/cache-store.js +0 -20
  36. package/esm/cache/cache-store.js.map +0 -1
  37. package/esm/cache/cache-types.d.ts +0 -71
  38. package/esm/cache/cache-types.d.ts.map +0 -1
  39. package/esm/cache/cache-types.js +0 -49
  40. package/esm/cache/cache-types.js.map +0 -1
  41. package/esm/cache/serialize.d.ts +0 -25
  42. package/esm/cache/serialize.d.ts.map +0 -1
  43. package/esm/cache/serialize.js +0 -96
  44. package/esm/cache/serialize.js.map +0 -1
  45. package/esm/close-quietly.d.ts +0 -24
  46. package/esm/close-quietly.d.ts.map +0 -1
  47. package/esm/close-quietly.js +0 -30
  48. package/esm/close-quietly.js.map +0 -1
  49. package/esm/elicitation.d.ts +0 -11
  50. package/esm/elicitation.d.ts.map +0 -1
  51. package/esm/elicitation.js +0 -51
  52. package/esm/elicitation.js.map +0 -1
  53. package/esm/errors.d.ts +0 -82
  54. package/esm/errors.d.ts.map +0 -1
  55. package/esm/errors.js +0 -80
  56. package/esm/errors.js.map +0 -1
  57. package/esm/handle.d.ts +0 -66
  58. package/esm/handle.d.ts.map +0 -1
  59. package/esm/handle.js +0 -323
  60. package/esm/handle.js.map +0 -1
  61. package/esm/mcp-connection.d.ts +0 -142
  62. package/esm/mcp-connection.d.ts.map +0 -1
  63. package/esm/mcp-connection.js +0 -477
  64. package/esm/mcp-connection.js.map +0 -1
  65. package/esm/rehydrate.d.ts +0 -76
  66. package/esm/rehydrate.d.ts.map +0 -1
  67. package/esm/rehydrate.js +0 -499
  68. package/esm/rehydrate.js.map +0 -1
  69. package/esm/resource-tools.d.ts +0 -17
  70. package/esm/resource-tools.d.ts.map +0 -1
  71. package/esm/resource-tools.js +0 -155
  72. package/esm/resource-tools.js.map +0 -1
  73. package/esm/result-mapper.d.ts +0 -19
  74. package/esm/result-mapper.d.ts.map +0 -1
  75. package/esm/result-mapper.js +0 -40
  76. package/esm/result-mapper.js.map +0 -1
  77. package/esm/schema/json-schema-guards.d.ts +0 -14
  78. package/esm/schema/json-schema-guards.d.ts.map +0 -1
  79. package/esm/schema/json-schema-guards.js +0 -19
  80. package/esm/schema/json-schema-guards.js.map +0 -1
  81. package/esm/schema/json-schema-to-zod.d.ts +0 -20
  82. package/esm/schema/json-schema-to-zod.d.ts.map +0 -1
  83. package/esm/schema/json-schema-to-zod.js +0 -72
  84. package/esm/schema/json-schema-to-zod.js.map +0 -1
  85. package/esm/tool-wrapper.d.ts +0 -41
  86. package/esm/tool-wrapper.d.ts.map +0 -1
  87. package/esm/tool-wrapper.js +0 -131
  88. package/esm/tool-wrapper.js.map +0 -1
  89. package/esm/transport-types.d.ts +0 -45
  90. package/esm/transport-types.d.ts.map +0 -1
  91. package/esm/transport-types.js +0 -2
  92. package/esm/transport-types.js.map +0 -1
  93. package/esm/version.d.ts +0 -3
  94. package/esm/version.d.ts.map +0 -1
  95. package/esm/version.js +0 -5
  96. package/esm/version.js.map +0 -1
@@ -1,155 +0,0 @@
1
- import { markMcp, tool } from '@openrouter/agent/tool';
2
- import * as z from 'zod';
3
- // Hard cap on pagination pages. A well-behaved server terminates the cursor
4
- // chain by omitting `nextCursor`; this bounds a misbehaving one that never does.
5
- const MAX_LIST_PAGES = 1000;
6
- /**
7
- * Normalize a paginated `nextCursor` field: treat anything that is not a
8
- * non-empty string as "no more pages" so a malformed cursor terminates the loop.
9
- */
10
- function nextCursorOrUndefined(value) {
11
- return typeof value === 'string' && value.length > 0 ? value : undefined;
12
- }
13
- /**
14
- * Walk a paginated MCP list endpoint, following `nextCursor` (passed back as
15
- * `{ cursor }`) until exhausted, and return the flattened items. Stops when the
16
- * server omits `nextCursor`, repeats the same cursor, or the page cap is hit.
17
- */
18
- async function collectPages(fetchPage, requestOptions) {
19
- const collected = [];
20
- let cursor;
21
- for (let page = 0; page < MAX_LIST_PAGES; page += 1) {
22
- const params = cursor !== undefined
23
- ? {
24
- cursor,
25
- }
26
- : undefined;
27
- const { items, nextCursor } = await fetchPage(params, requestOptions);
28
- collected.push(...items);
29
- const next = nextCursorOrUndefined(nextCursor);
30
- if (next === undefined || next === cursor) {
31
- break;
32
- }
33
- cursor = next;
34
- }
35
- return collected;
36
- }
37
- /**
38
- * Build synthetic tools that let the model browse and read MCP resources
39
- * through the normal tool loop:
40
- * - `list_resources`: concrete resources plus resource templates.
41
- * - `read_resource`: fetch a resource's contents by URI.
42
- *
43
- * Only call this when the server advertises the `resources` capability.
44
- */
45
- export function buildResourceTools(options) {
46
- const prefix = options.namePrefix ?? '';
47
- const requestOptions = options.signal !== undefined
48
- ? {
49
- signal: options.signal,
50
- }
51
- : undefined;
52
- // `list_resources` always re-reads; `read_resource` honours the server's TTL.
53
- //
54
- // The asymmetry is deliberate. A listing is cheap and its whole purpose is to
55
- // tell the model what exists *now* — a model that creates a resource via a
56
- // tool call and immediately lists must see it, and being handed a cached
57
- // listing looks to the model like the write silently failed. The SDK does evict
58
- // `resources/list` on `notifications/resources/list_changed`, but that only
59
- // covers servers which both advertise and send it; a server with a non-trivial
60
- // `ttlMs` and no notification would serve a stale listing for the full TTL.
61
- //
62
- // Resource *contents* are the opposite: potentially large, and a
63
- // server-declared `ttlMs` on `resources/read` is a deliberate statement that
64
- // the bytes are reusable for that long. Overriding it would turn every model
65
- // read into a fetch and discard the caching the spec intends. Freshness there
66
- // is already handled per-URI — the SDK evicts on
67
- // `notifications/resources/updated`.
68
- const listRequestOptions = {
69
- cacheMode: 'refresh',
70
- ...(options.signal !== undefined && {
71
- signal: options.signal,
72
- }),
73
- };
74
- const listResources = tool({
75
- name: `${prefix}list_resources`,
76
- description: 'List the resources and resource templates exposed by the MCP server.',
77
- inputSchema: z.object({}),
78
- execute: async () => {
79
- const [resources, resourceTemplates] = await Promise.all([
80
- collectPages(async (params, opts) => {
81
- const page = await options.client.listResources(params, opts);
82
- return {
83
- items: page.resources,
84
- nextCursor: page.nextCursor,
85
- };
86
- }, listRequestOptions),
87
- // Templates are optional: a server may not support them. The whole
88
- // paginated fetch degrades gracefully to an empty list on any error.
89
- collectPages(async (params, opts) => {
90
- const page = await options.client.listResourceTemplates(params, opts);
91
- return {
92
- items: page.resourceTemplates,
93
- nextCursor: page.nextCursor,
94
- };
95
- }, listRequestOptions).catch(() => []),
96
- ]);
97
- return {
98
- resources: resources.map((r) => ({
99
- uri: r.uri,
100
- name: r.name,
101
- ...(r.description !== undefined && {
102
- description: r.description,
103
- }),
104
- ...(r.mimeType !== undefined && {
105
- mimeType: r.mimeType,
106
- }),
107
- })),
108
- resourceTemplates: resourceTemplates.map((t) => ({
109
- uriTemplate: t.uriTemplate,
110
- name: t.name,
111
- ...(t.description !== undefined && {
112
- description: t.description,
113
- }),
114
- })),
115
- };
116
- },
117
- });
118
- const readResource = tool({
119
- name: `${prefix}read_resource`,
120
- description: 'Read the contents of an MCP resource by its URI.',
121
- inputSchema: z.object({
122
- uri: z.string().describe('Resource URI to read'),
123
- }),
124
- execute: async (args) => {
125
- const result = await options.client.readResource({
126
- uri: args.uri,
127
- }, requestOptions);
128
- return {
129
- contents: result.contents.map((c) => {
130
- if ('text' in c) {
131
- return {
132
- uri: c.uri,
133
- text: c.text,
134
- ...(c.mimeType !== undefined && {
135
- mimeType: c.mimeType,
136
- }),
137
- };
138
- }
139
- return {
140
- uri: c.uri,
141
- blob: c.blob,
142
- ...(c.mimeType !== undefined && {
143
- mimeType: c.mimeType,
144
- }),
145
- };
146
- }),
147
- };
148
- },
149
- });
150
- return [
151
- markMcp(listResources),
152
- markMcp(readResource),
153
- ];
154
- }
155
- //# sourceMappingURL=resource-tools.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resource-tools.js","sourceRoot":"","sources":["../src/resource-tools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAQzB,4EAA4E;AAC5E,iFAAiF;AACjF,MAAM,cAAc,GAAG,IAAI,CAAC;AA6B5B;;;GAGG;AACH,SAAS,qBAAqB,CAAC,KAAyB;IACtD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3E,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,YAAY,CACz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IAAI;gCAC9B,QAAQ,EAAE,CAAC,CAAC,QAAQ;6BACrB,CAAC;yBACH,CAAC;oBACJ,CAAC;oBACD,OAAO;wBACL,GAAG,EAAE,CAAC,CAAC,GAAG;wBACV,IAAI,EAAE,CAAC,CAAC,IAAI;wBACZ,GAAG,CAAC,CAAC,CAAC,QAAQ,KAAK,SAAS,IAAI;4BAC9B,QAAQ,EAAE,CAAC,CAAC,QAAQ;yBACrB,CAAC;qBACH,CAAC;gBACJ,CAAC,CAAC;aACH,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;IAEH,OAAO;QACL,OAAO,CAAC,aAAa,CAAC;QACtB,OAAO,CAAC,YAAY,CAAC;KACtB,CAAC;AACJ,CAAC"}
@@ -1,19 +0,0 @@
1
- /**
2
- * The subset of an MCP `CallToolResult` we read. The SDK types it more richly,
3
- * but we narrow defensively from `unknown`-ish content rather than trusting the
4
- * wire shape.
5
- */
6
- export interface RawCallToolResult {
7
- content?: unknown;
8
- structuredContent?: unknown;
9
- isError?: boolean;
10
- [key: string]: unknown;
11
- }
12
- /**
13
- * Map an MCP tool result into a value `callModel` can hand back to the model.
14
- * Prefers `structuredContent` (already JSON), otherwise the collapsed text
15
- * content. Throws {@link MCPToolCallError} when the server flags `isError`, so
16
- * the agent loop reports the failure instead of treating error text as success.
17
- */
18
- export declare function mapCallToolResult(toolName: string, result: RawCallToolResult): unknown;
19
- //# sourceMappingURL=result-mapper.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"result-mapper.d.ts","sourceRoot":"","sources":["../src/result-mapper.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AA2BD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAStF"}
@@ -1,40 +0,0 @@
1
- import { MCPToolCallError } from './errors.js';
2
- import { isJsonSchemaObject } from './schema/json-schema-guards.js';
3
- function isTextBlock(block) {
4
- return isJsonSchemaObject(block) && block['type'] === 'text' && typeof block['text'] === 'string';
5
- }
6
- /** Collapse the content array into a single string for the model. */
7
- function contentToText(content) {
8
- if (!Array.isArray(content)) {
9
- return '';
10
- }
11
- const parts = [];
12
- for (const block of content) {
13
- if (isTextBlock(block)) {
14
- parts.push(block.text);
15
- }
16
- else if (isJsonSchemaObject(block) && typeof block['type'] === 'string') {
17
- // Non-text blocks (image/audio/resource) aren't passed through as media
18
- // in v1 — surface a typed placeholder so the model knows it exists.
19
- parts.push(`[${block['type']} content]`);
20
- }
21
- }
22
- return parts.join('\n');
23
- }
24
- /**
25
- * Map an MCP tool result into a value `callModel` can hand back to the model.
26
- * Prefers `structuredContent` (already JSON), otherwise the collapsed text
27
- * content. Throws {@link MCPToolCallError} when the server flags `isError`, so
28
- * the agent loop reports the failure instead of treating error text as success.
29
- */
30
- export function mapCallToolResult(toolName, result) {
31
- if (result.isError === true) {
32
- const message = contentToText(result.content) || 'MCP tool returned an error';
33
- throw new MCPToolCallError(toolName, message);
34
- }
35
- if (result.structuredContent !== undefined) {
36
- return result.structuredContent;
37
- }
38
- return contentToText(result.content);
39
- }
40
- //# sourceMappingURL=result-mapper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"result-mapper.js","sourceRoot":"","sources":["../src/result-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAcpE,SAAS,WAAW,CAAC,KAAc;IAIjC,OAAO,kBAAkB,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,MAAM,IAAI,OAAO,KA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- * server. MCP tool input/output schemas are untrusted `unknown` data, so we
4
- * narrow them with runtime checks rather than `as` casts.
5
- */
6
- /** A non-null, non-array object — the shape every JSON Schema node takes. */
7
- export declare function isJsonSchemaObject(value: unknown): value is Record<string, unknown>;
8
- /** A JSON Schema whose top-level `type` is `"object"`. */
9
- export declare function isObjectJsonSchema(value: unknown): value is Record<string, unknown> & {
10
- type: 'object';
11
- };
12
- /** The `properties` map of an object schema, when present and well-formed. */
13
- export declare function getSchemaProperties(schema: Record<string, unknown>): Record<string, unknown> | undefined;
14
- //# sourceMappingURL=json-schema-guards.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"json-schema-guards.d.ts","sourceRoot":"","sources":["../../src/schema/json-schema-guards.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,6EAA6E;AAC7E,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEnF;AAED,0DAA0D;AAC1D,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACrF,IAAI,EAAE,QAAQ,CAAC;CAChB,CAEA;AAED,8EAA8E;AAC9E,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAGrC"}
@@ -1,19 +0,0 @@
1
- /**
2
- * Typeguards over the raw JSON-Schema-shaped values that arrive from an MCP
3
- * server. MCP tool input/output schemas are untrusted `unknown` data, so we
4
- * narrow them with runtime checks rather than `as` casts.
5
- */
6
- /** A non-null, non-array object — the shape every JSON Schema node takes. */
7
- export function isJsonSchemaObject(value) {
8
- return typeof value === 'object' && value !== null && !Array.isArray(value);
9
- }
10
- /** A JSON Schema whose top-level `type` is `"object"`. */
11
- export function isObjectJsonSchema(value) {
12
- return isJsonSchemaObject(value) && value['type'] === 'object';
13
- }
14
- /** The `properties` map of an object schema, when present and well-formed. */
15
- export function getSchemaProperties(schema) {
16
- const { properties } = schema;
17
- return isJsonSchemaObject(properties) ? properties : undefined;
18
- }
19
- //# sourceMappingURL=json-schema-guards.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"json-schema-guards.js","sourceRoot":"","sources":["../../src/schema/json-schema-guards.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,6EAA6E;AAC7E,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAG/C,OAAO,kBAAkB,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,QAAQ,CAAC;AACjE,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,mBAAmB,CACjC,MAA+B;IAE/B,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IAC9B,OAAO,kBAAkB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;AACjE,CAAC"}
@@ -1,20 +0,0 @@
1
- import type { $ZodObject } from 'zod/v4/core';
2
- /**
3
- * How to handle a JSON Schema (sub)schema that Zod cannot represent.
4
- * - `looseLeaf` (default): substitute `z.unknown()` for only the offending
5
- * property so the rest of the tool's parameters stay faithful.
6
- * - `throw`: surface the conversion failure to the caller.
7
- */
8
- export type UnconvertibleSchemaMode = 'looseLeaf' | 'throw';
9
- /**
10
- * Convert an MCP tool's JSON Schema (input or output) into a Zod v4 object
11
- * schema. `callModel` derives the model-facing parameters from this Zod schema,
12
- * so the conversion must be faithful — a permissive passthrough would make the
13
- * model call the tool blind.
14
- *
15
- * Strategy: attempt a holistic `z.fromJSONSchema` conversion first (handles
16
- * `$ref`/`$defs`, `anyOf`, formats, nesting); on failure, fall back per the
17
- * chosen `mode`.
18
- */
19
- export declare function convertMcpInputSchema(jsonSchema: Record<string, unknown>, mode?: UnconvertibleSchemaMode): $ZodObject;
20
- //# sourceMappingURL=json-schema-to-zod.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"json-schema-to-zod.d.ts","sourceRoot":"","sources":["../../src/schema/json-schema-to-zod.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,aAAa,CAAC;AAIxD;;;;;GAKG;AACH,MAAM,MAAM,uBAAuB,GAAG,WAAW,GAAG,OAAO,CAAC;AA+C5D;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,IAAI,GAAE,uBAAqC,GAC1C,UAAU,CAkBZ"}
@@ -1,72 +0,0 @@
1
- import * as z from 'zod';
2
- import { MCPError } from '../errors.js';
3
- import { getSchemaProperties, isJsonSchemaObject } from './json-schema-guards.js';
4
- /** Narrow a Zod schema to an object schema via its runtime type tag (no `as`). */
5
- function isZodObject(schema) {
6
- return schema._zod.def.type === 'object';
7
- }
8
- /** The `required` array of an object schema, filtered to string keys. */
9
- function requiredKeys(schema) {
10
- const { required } = schema;
11
- if (!Array.isArray(required)) {
12
- return new Set();
13
- }
14
- return new Set(required.filter((key) => typeof key === 'string'));
15
- }
16
- /**
17
- * Build a Zod object by converting each property independently, substituting
18
- * `z.unknown()` for any property Zod cannot represent. Always yields a
19
- * `$ZodObject`, which is what `callModel`'s `tool()` factory requires.
20
- */
21
- function buildObjectFromProperties(jsonSchema, mode) {
22
- const properties = getSchemaProperties(jsonSchema) ?? {};
23
- const required = requiredKeys(jsonSchema);
24
- const shape = {};
25
- for (const [key, propSchema] of Object.entries(properties)) {
26
- let zodProp;
27
- try {
28
- zodProp = isJsonSchemaObject(propSchema) ? z.fromJSONSchema(propSchema) : z.unknown();
29
- }
30
- catch (err) {
31
- if (mode === 'throw') {
32
- throw new MCPError(`Cannot convert JSON Schema for property "${key}" to Zod`, {
33
- cause: err,
34
- });
35
- }
36
- zodProp = z.unknown();
37
- }
38
- shape[key] = required.has(key) ? zodProp : z.optional(zodProp);
39
- }
40
- return z.object(shape);
41
- }
42
- /**
43
- * Convert an MCP tool's JSON Schema (input or output) into a Zod v4 object
44
- * schema. `callModel` derives the model-facing parameters from this Zod schema,
45
- * so the conversion must be faithful — a permissive passthrough would make the
46
- * model call the tool blind.
47
- *
48
- * Strategy: attempt a holistic `z.fromJSONSchema` conversion first (handles
49
- * `$ref`/`$defs`, `anyOf`, formats, nesting); on failure, fall back per the
50
- * chosen `mode`.
51
- */
52
- export function convertMcpInputSchema(jsonSchema, mode = 'looseLeaf') {
53
- try {
54
- const converted = z.fromJSONSchema(jsonSchema);
55
- if (isZodObject(converted)) {
56
- return converted;
57
- }
58
- // MCP guarantees object-typed tool schemas; if a server sends something
59
- // else, degrade to a per-property object rather than handing callModel a
60
- // non-object schema it cannot use.
61
- return buildObjectFromProperties(jsonSchema, mode);
62
- }
63
- catch (err) {
64
- if (mode === 'throw') {
65
- throw new MCPError('Cannot convert MCP JSON Schema to Zod', {
66
- cause: err,
67
- });
68
- }
69
- return buildObjectFromProperties(jsonSchema, mode);
70
- }
71
- }
72
- //# sourceMappingURL=json-schema-to-zod.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"json-schema-to-zod.js","sourceRoot":"","sources":["../../src/schema/json-schema-to-zod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAUlF,kFAAkF;AAClF,SAAS,WAAW,CAAC,MAAgB;IACnC,OAAO,MAAM,CAAC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CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACjE,CAAC;IAED,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB,CACnC,UAAmC,EACnC,OAAgC,WAAW;IAE3C,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,CAAC,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;QAC/C,IAAI,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;YAC3B,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,wEAAwE;QACxE,yEAAyE;QACzE,mCAAmC;QACnC,OAAO,yBAAyB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACrD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;YACrB,MAAM,IAAI,QAAQ,CAAC,uCAAuC,EAAE;gBAC1D,KAAK,EAAE,GAAG;aACX,CAAC,CAAC;QACL,CAAC;QACD,OAAO,yBAAyB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACrD,CAAC;AACH,CAAC"}
@@ -1,41 +0,0 @@
1
- import type { Client } from '@modelcontextprotocol/client';
2
- import type { McpBranded, ToolLoopKey } from '@openrouter/agent/tool-types';
3
- import type { UnconvertibleSchemaMode } from './schema/json-schema-to-zod.js';
4
- /** A discovered MCP tool definition (the fields we consume). */
5
- export interface McpToolDef {
6
- name: string;
7
- description?: string;
8
- inputSchema: Record<string, unknown>;
9
- outputSchema?: Record<string, unknown>;
10
- /**
11
- * Doom-loop identity advertised by the server via
12
- * `_meta['openrouter/loopKey']` on the tool definition: a field-name
13
- * array (the declarative subset of arguments that identifies a call) or
14
- * `false` (the tool is exempt — repetition is its job, e.g. polling).
15
- * Data, not code — survives cache snapshots. A client-side `loopKeys`
16
- * entry in {@link WrapToolOptions} takes precedence.
17
- */
18
- loopKey?: readonly string[] | false;
19
- }
20
- export interface WrapToolOptions {
21
- client: Client;
22
- namePrefix?: string;
23
- schemaMode?: UnconvertibleSchemaMode;
24
- emitProgress?: boolean;
25
- signal?: AbortSignal;
26
- /**
27
- * Per-tool doom-loop identities, keyed by the tool's UNPREFIXED MCP name.
28
- * Any `ToolLoopKey` form (function | field list | `false`). Takes
29
- * precedence over a server-advertised `loopKey` on the definition.
30
- */
31
- loopKeys?: Readonly<Record<string, ToolLoopKey<Record<string, unknown>>>>;
32
- }
33
- /**
34
- * Wrap one discovered MCP tool as an `@openrouter/agent` tool. Emits a
35
- * generator tool (streaming progress events) when `emitProgress` is on,
36
- * otherwise a regular tool. The input schema (and output schema, when declared)
37
- * are converted to Zod so the model sees faithful parameters. The abort signal,
38
- * if supplied, is threaded into the underlying `callTool`.
39
- */
40
- export declare function wrapMcpTool(def: McpToolDef, options: WrapToolOptions): McpBranded;
41
- //# sourceMappingURL=tool-wrapper.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tool-wrapper.d.ts","sourceRoot":"","sources":["../src/tool-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAY,MAAM,8BAA8B,CAAC;AAErE,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAK5E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAG9E,gEAAgE;AAChE,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,KAAK,CAAC;CACrC;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,uBAAuB,CAAC;IACrC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;CAC3E;AA8CD;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,eAAe,GAAG,UAAU,CAqGjF"}
@@ -1,131 +0,0 @@
1
- import { markMcp, tool } from '@openrouter/agent/tool';
2
- import * as z from 'zod';
3
- import { mapCallToolResult } from './result-mapper.js';
4
- import { isJsonSchemaObject } from './schema/json-schema-guards.js';
5
- import { convertMcpInputSchema } from './schema/json-schema-to-zod.js';
6
- /** Event yielded by a progress-emitting generator tool. */
7
- const progressEventSchema = z.object({
8
- type: z.literal('progress'),
9
- progress: z.number(),
10
- total: z.optional(z.number()),
11
- message: z.optional(z.string()),
12
- });
13
- function callToolResultIsRaw(value) {
14
- return isJsonSchemaObject(value);
15
- }
16
- async function invokeTool(invokeArgs) {
17
- const { options, mcpName, args, onprogress } = invokeArgs;
18
- // SDK v2 signature is `callTool(params, options)` — v1's middle result-schema
19
- // argument is gone. Passing three args here would silently drop `signal` and
20
- // `onprogress` into an unread slot, killing cancellation and progress.
21
- const result = await options.client.callTool({
22
- name: mcpName,
23
- arguments: args,
24
- }, {
25
- ...(options.signal !== undefined && {
26
- signal: options.signal,
27
- }),
28
- ...(onprogress !== undefined && {
29
- onprogress,
30
- }),
31
- });
32
- if (!callToolResultIsRaw(result)) {
33
- return '';
34
- }
35
- return mapCallToolResult(mcpName, result);
36
- }
37
- /**
38
- * Wrap one discovered MCP tool as an `@openrouter/agent` tool. Emits a
39
- * generator tool (streaming progress events) when `emitProgress` is on,
40
- * otherwise a regular tool. The input schema (and output schema, when declared)
41
- * are converted to Zod so the model sees faithful parameters. The abort signal,
42
- * if supplied, is threaded into the underlying `callTool`.
43
- */
44
- export function wrapMcpTool(def, options) {
45
- const name = `${options.namePrefix ?? ''}${def.name}`;
46
- const inputSchema = convertMcpInputSchema(def.inputSchema, options.schemaMode);
47
- const outputSchema = def.outputSchema !== undefined
48
- ? convertMcpInputSchema(def.outputSchema, options.schemaMode)
49
- : undefined;
50
- // Client-side config wins over the server-advertised declaration; both
51
- // ride markMcp's injection point so every tool kind gets the same wiring.
52
- const loopKey = options.loopKeys !== undefined && Object.hasOwn(options.loopKeys, def.name)
53
- ? options.loopKeys[def.name]
54
- : def.loopKey;
55
- const markOptions = loopKey !== undefined
56
- ? {
57
- loopKey,
58
- }
59
- : undefined;
60
- if (options.emitProgress === true) {
61
- return markMcp(tool({
62
- name,
63
- ...(def.description !== undefined && {
64
- description: def.description,
65
- }),
66
- inputSchema,
67
- eventSchema: progressEventSchema,
68
- outputSchema: outputSchema ?? z.unknown(),
69
- execute: async function* (args) {
70
- const queue = [];
71
- let notify;
72
- const onprogress = (p) => {
73
- queue.push({
74
- type: 'progress',
75
- progress: p.progress,
76
- ...(p.total !== undefined && {
77
- total: p.total,
78
- }),
79
- ...(typeof p.message === 'string' && {
80
- message: p.message,
81
- }),
82
- });
83
- notify?.();
84
- };
85
- const resultPromise = invokeTool({
86
- options,
87
- mcpName: def.name,
88
- args,
89
- onprogress,
90
- });
91
- let done = false;
92
- const finalize = resultPromise.finally(() => {
93
- done = true;
94
- notify?.();
95
- });
96
- while (!done || queue.length > 0) {
97
- while (queue.length > 0) {
98
- const event = queue.shift();
99
- if (event !== undefined) {
100
- yield event;
101
- }
102
- }
103
- if (done) {
104
- break;
105
- }
106
- await new Promise((resolve) => {
107
- notify = resolve;
108
- });
109
- notify = undefined;
110
- }
111
- return await finalize;
112
- },
113
- }), markOptions);
114
- }
115
- return markMcp(tool({
116
- name,
117
- ...(def.description !== undefined && {
118
- description: def.description,
119
- }),
120
- inputSchema,
121
- ...(outputSchema !== undefined && {
122
- outputSchema,
123
- }),
124
- execute: (args) => invokeTool({
125
- options,
126
- mcpName: def.name,
127
- args,
128
- }),
129
- }), markOptions);
130
- }
131
- //# sourceMappingURL=tool-wrapper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tool-wrapper.js","sourceRoot":"","sources":["../src/tool-wrapper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAiCvE,2DAA2D;AAC3D,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;IAC3B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAC7B,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;CAChC,CAAC,CAAC;AAEH,SAAS,mBAAmB,CAAC,KAAc;IACzC,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC;AASD,KAAK,UAAU,UAAU,CAAC,UAA0B;IAClD,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,UAAU,CAAC;IAC1D,8EAA8E;IAC9E,6EAA6E;IAC7E,uEAAuE;IACvE,MAAM,MAAM,GAAG,MAAM,OAA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AC;oBACjC,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wBACxB,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;wBAC5B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;4BACxB,MAAM,KAAK,CAAC;wBACd,CAAC;oBACH,CAAC;oBACD,IAAI,IAAI,EAAE,CAAC;wBACT,MAAM;oBACR,CAAC;oBACD,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;wBAClC,MAAM,GAAG,OAAO,CAAC;oBACnB,CAAC,CAAC,CAAC;oBACH,MAAM,GAAG,SAAS,CAAC;gBACrB,CAAC;gBAED,OAAO,MAAM,QAAQ,CAAC;YACxB,CAAC;SACF,CAAC,EACF,WAAW,CACZ,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CACZ,IAAI,CAAC;QACH,IAAI;QACJ,GAAG,CAAC,GAAG,CAAC,WAAW,KAAK,SAAS,IAAI;YACnC,WAAW,EAAE,GAAG,CAAC,WAAW;SAC7B,CAAC;QACF,WAAW;QACX,GAAG,CAAC,YAAY,KAAK,SAAS,IAAI;YAChC,YAAY;SACb,CAAC;QACF,OAAO,EAAE,CAAC,IAA6B,EAAE,EAAE,CACzC,UAAU,CAAC;YACT,OAAO;YACP,OAAO,EAAE,GAAG,CAAC,IAAI;YACjB,IAAI;SACL,CAAC;KACL,CAAC,EACF,WAAW,CACZ,CAAC;AACJ,CAAC"}
@@ -1,45 +0,0 @@
1
- /**
2
- * Non-stdio MCP transports this package supports.
3
- *
4
- * `'sse'` (HTTP+SSE) is reclassified as Deprecated by MCP protocol revision
5
- * 2026-07-28 (SEP-2596) and remains only for legacy servers. Prefer
6
- * `'streamableHttp'`. See MIGRATION notes in the package README.
7
- */
8
- export type MCPTransportKind = 'streamableHttp' | 'sse';
9
- /**
10
- * How to negotiate the MCP protocol revision.
11
- *
12
- * - `'auto'` (our default) — probe the server with `server/discover`, then speak
13
- * whichever revision it offers. Definitive modern evidence selects
14
- * 2026-07-28; anything else falls back to the 2025-era `initialize`
15
- * handshake. Costs one extra round trip against legacy servers.
16
- * - `'legacy'` — skip the probe and always use the `initialize` handshake. Saves
17
- * that round trip when you already know the server is 2025-era.
18
- * - `{ pin }` — require exactly that revision; fail loudly rather than
19
- * falling back.
20
- *
21
- * **Setting this at all opts out of the automatic legacy retry.** When you leave
22
- * it unset, a failed connect is retried once with `'legacy'`, so a server behind
23
- * a probe-hostile proxy or gateway still connects. Naming a mode — including
24
- * `'auto'` — means you want that mode's failures too, and silently overriding a
25
- * `{ pin }` would defeat the point of pinning. So `'legacy'` is a performance
26
- * choice here, not a compatibility one.
27
- *
28
- * This is a policy, not a version — `{ pin: '2026-07-28' }` is how you request
29
- * a specific revision. Declared here rather than re-exported from the SDK so
30
- * the public API does not depend on SDK types.
31
- */
32
- export type MCPProtocolNegotiation = 'legacy' | 'auto' | {
33
- /**
34
- * Exact revision to speak, skipping negotiation.
35
- *
36
- * The two known revisions autocomplete and typo-check; the `(string & {})`
37
- * arm keeps any other value assignable, so pinning a revision this package
38
- * predates still compiles rather than forcing a cast. A wrong string there
39
- * fails at connect time, as before.
40
- */
41
- pin: MCPProtocolRevision | (string & {});
42
- };
43
- /** Protocol revisions this package knows by name. */
44
- export type MCPProtocolRevision = '2025-11-25' | '2026-07-28';
45
- //# sourceMappingURL=transport-types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transport-types.d.ts","sourceRoot":"","sources":["../src/transport-types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAAG,gBAAgB,GAAG,KAAK,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,sBAAsB,GAC9B,QAAQ,GACR,MAAM,GACN;IACE;;;;;;;OAOG;IACH,GAAG,EAAE,mBAAmB,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;CAC1C,CAAC;AAEN,qDAAqD;AACrD,MAAM,MAAM,mBAAmB,GAAG,YAAY,GAAG,YAAY,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=transport-types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transport-types.js","sourceRoot":"","sources":["../src/transport-types.ts"],"names":[],"mappings":""}
package/esm/version.d.ts DELETED
@@ -1,3 +0,0 @@
1
- /** This package's version, self-reported to MCP servers as `clientInfo`. */
2
- export declare const PACKAGE_VERSION = "1.0.0";
3
- //# sourceMappingURL=version.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAGA,4EAA4E;AAC5E,eAAO,MAAM,eAAe,UAAU,CAAC"}
package/esm/version.js DELETED
@@ -1,5 +0,0 @@
1
- // DO NOT EDIT — generated from package.json by scripts/gen-version.mjs.
2
- // Run `pnpm --filter @openrouter/mcp gen:version` after bumping the version.
3
- /** This package's version, self-reported to MCP servers as `clientInfo`. */
4
- export const PACKAGE_VERSION = '1.0.0';
5
- //# sourceMappingURL=version.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,6EAA6E;AAE7E,4EAA4E;AAC5E,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC"}