@openrouter/mcp 0.0.1 → 1.0.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/README.md +156 -6
- package/esm/auth/auth-resolver.d.ts +1 -1
- package/esm/auth/auth-resolver.d.ts.map +1 -1
- package/esm/auth/auth-types.d.ts +9 -1
- package/esm/auth/auth-types.d.ts.map +1 -1
- package/esm/auth/auth-types.js.map +1 -1
- package/esm/build-tools.d.ts +4 -2
- package/esm/build-tools.d.ts.map +1 -1
- package/esm/build-tools.js +3 -0
- package/esm/build-tools.js.map +1 -1
- package/esm/cache/cache-types.d.ts +17 -0
- package/esm/cache/cache-types.d.ts.map +1 -1
- package/esm/cache/cache-types.js +11 -3
- package/esm/cache/cache-types.js.map +1 -1
- package/esm/cache/serialize.d.ts +4 -4
- package/esm/cache/serialize.d.ts.map +1 -1
- package/esm/cache/serialize.js +17 -6
- package/esm/cache/serialize.js.map +1 -1
- package/esm/close-quietly.d.ts +24 -0
- package/esm/close-quietly.d.ts.map +1 -0
- package/esm/close-quietly.js +30 -0
- package/esm/close-quietly.js.map +1 -0
- package/esm/create-mcp-tools.d.ts.map +1 -1
- package/esm/create-mcp-tools.js +23 -2
- package/esm/create-mcp-tools.js.map +1 -1
- package/esm/elicitation.d.ts +1 -1
- package/esm/elicitation.d.ts.map +1 -1
- package/esm/errors.d.ts +47 -0
- package/esm/errors.d.ts.map +1 -1
- package/esm/errors.js +41 -0
- package/esm/errors.js.map +1 -1
- package/esm/handle.d.ts +25 -0
- package/esm/handle.d.ts.map +1 -1
- package/esm/handle.js +116 -14
- package/esm/handle.js.map +1 -1
- package/esm/index.d.ts +3 -3
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/mcp-connection.d.ts +114 -7
- package/esm/mcp-connection.d.ts.map +1 -1
- package/esm/mcp-connection.js +364 -34
- package/esm/mcp-connection.js.map +1 -1
- package/esm/rehydrate.d.ts +40 -5
- package/esm/rehydrate.d.ts.map +1 -1
- package/esm/rehydrate.js +381 -55
- package/esm/rehydrate.js.map +1 -1
- package/esm/resource-tools.d.ts +1 -1
- package/esm/resource-tools.d.ts.map +1 -1
- package/esm/resource-tools.js +24 -2
- package/esm/resource-tools.js.map +1 -1
- package/esm/tool-wrapper.d.ts +17 -2
- package/esm/tool-wrapper.d.ts.map +1 -1
- package/esm/tool-wrapper.js +16 -3
- package/esm/tool-wrapper.js.map +1 -1
- package/esm/transport-types.d.ts +43 -1
- package/esm/transport-types.d.ts.map +1 -1
- package/esm/types.d.ts +56 -7
- package/esm/types.d.ts.map +1 -1
- package/esm/version.d.ts +3 -0
- package/esm/version.d.ts.map +1 -0
- package/esm/version.js +5 -0
- package/esm/version.js.map +1 -0
- package/package.json +13 -9
package/esm/tool-wrapper.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Client } from '@modelcontextprotocol/
|
|
2
|
-
import type { McpBranded } from '@openrouter/agent/tool-types';
|
|
1
|
+
import type { Client } from '@modelcontextprotocol/client';
|
|
2
|
+
import type { McpBranded, ToolLoopKey } from '@openrouter/agent/tool-types';
|
|
3
3
|
import type { UnconvertibleSchemaMode } from './schema/json-schema-to-zod.js';
|
|
4
4
|
/** A discovered MCP tool definition (the fields we consume). */
|
|
5
5
|
export interface McpToolDef {
|
|
@@ -7,6 +7,15 @@ export interface McpToolDef {
|
|
|
7
7
|
description?: string;
|
|
8
8
|
inputSchema: Record<string, unknown>;
|
|
9
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;
|
|
10
19
|
}
|
|
11
20
|
export interface WrapToolOptions {
|
|
12
21
|
client: Client;
|
|
@@ -14,6 +23,12 @@ export interface WrapToolOptions {
|
|
|
14
23
|
schemaMode?: UnconvertibleSchemaMode;
|
|
15
24
|
emitProgress?: boolean;
|
|
16
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>>>>;
|
|
17
32
|
}
|
|
18
33
|
/**
|
|
19
34
|
* Wrap one discovered MCP tool as an `@openrouter/agent` tool. Emits a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-wrapper.d.ts","sourceRoot":"","sources":["../src/tool-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,
|
|
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"}
|
package/esm/tool-wrapper.js
CHANGED
|
@@ -15,10 +15,13 @@ function callToolResultIsRaw(value) {
|
|
|
15
15
|
}
|
|
16
16
|
async function invokeTool(invokeArgs) {
|
|
17
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.
|
|
18
21
|
const result = await options.client.callTool({
|
|
19
22
|
name: mcpName,
|
|
20
23
|
arguments: args,
|
|
21
|
-
},
|
|
24
|
+
}, {
|
|
22
25
|
...(options.signal !== undefined && {
|
|
23
26
|
signal: options.signal,
|
|
24
27
|
}),
|
|
@@ -44,6 +47,16 @@ export function wrapMcpTool(def, options) {
|
|
|
44
47
|
const outputSchema = def.outputSchema !== undefined
|
|
45
48
|
? convertMcpInputSchema(def.outputSchema, options.schemaMode)
|
|
46
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;
|
|
47
60
|
if (options.emitProgress === true) {
|
|
48
61
|
return markMcp(tool({
|
|
49
62
|
name,
|
|
@@ -97,7 +110,7 @@ export function wrapMcpTool(def, options) {
|
|
|
97
110
|
}
|
|
98
111
|
return await finalize;
|
|
99
112
|
},
|
|
100
|
-
}));
|
|
113
|
+
}), markOptions);
|
|
101
114
|
}
|
|
102
115
|
return markMcp(tool({
|
|
103
116
|
name,
|
|
@@ -113,6 +126,6 @@ export function wrapMcpTool(def, options) {
|
|
|
113
126
|
mcpName: def.name,
|
|
114
127
|
args,
|
|
115
128
|
}),
|
|
116
|
-
}));
|
|
129
|
+
}), markOptions);
|
|
117
130
|
}
|
|
118
131
|
//# sourceMappingURL=tool-wrapper.js.map
|
package/esm/tool-wrapper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-wrapper.js","sourceRoot":"","sources":["../src/tool-wrapper.ts"],"names":[],"mappings":"
|
|
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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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"}
|
package/esm/transport-types.d.ts
CHANGED
|
@@ -1,3 +1,45 @@
|
|
|
1
|
-
/**
|
|
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
|
+
*/
|
|
2
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';
|
|
3
45
|
//# sourceMappingURL=transport-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport-types.d.ts","sourceRoot":"","sources":["../src/transport-types.ts"],"names":[],"mappings":"AAAA
|
|
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"}
|
package/esm/types.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { Tool } from '@openrouter/agent/tool-types';
|
|
1
|
+
import type { Tool, ToolLoopKey } from '@openrouter/agent/tool-types';
|
|
2
2
|
import type { MCPAuth } from './auth/auth-types.js';
|
|
3
3
|
import type { MCPCacheStore } from './cache/cache-store.js';
|
|
4
4
|
import type { UnconvertibleSchemaMode } from './schema/json-schema-to-zod.js';
|
|
5
|
-
import type { MCPTransportKind } from './transport-types.js';
|
|
6
|
-
export type { MCPTransportKind };
|
|
5
|
+
import type { MCPProtocolNegotiation, MCPProtocolRevision, MCPTransportKind } from './transport-types.js';
|
|
6
|
+
export type { MCPProtocolNegotiation, MCPProtocolRevision, MCPTransportKind };
|
|
7
7
|
/**
|
|
8
8
|
* Response to a server-initiated elicitation request. `accept` must carry
|
|
9
9
|
* `content` matching the server's `requestedSchema`.
|
|
@@ -34,11 +34,29 @@ export interface CreateMCPToolsOptions {
|
|
|
34
34
|
url: string | URL;
|
|
35
35
|
/** Transport to use; defaults to `streamableHttp` with SSE fallback. */
|
|
36
36
|
transport?: MCPTransportKind;
|
|
37
|
+
/**
|
|
38
|
+
* Protocol-revision negotiation policy. Defaults to `'auto'`, which probes
|
|
39
|
+
* the server and speaks either 2025-11-25 or 2026-07-28 as appropriate.
|
|
40
|
+
*/
|
|
41
|
+
protocolNegotiation?: MCPProtocolNegotiation;
|
|
42
|
+
/**
|
|
43
|
+
* Ceiling on the `server/discover` probe, in ms. Defaults to 30000 —
|
|
44
|
+
* `DEFAULT_PROBE_TIMEOUT_MS` in `mcp-connection.ts` is the source of truth.
|
|
45
|
+
*
|
|
46
|
+
* Raise it for a server slow to answer its first request. The SDK's own default
|
|
47
|
+
* is the full request timeout, which makes a hanging gateway far slower to fail
|
|
48
|
+
* than it needs to be.
|
|
49
|
+
*/
|
|
50
|
+
probeTimeoutMs?: number;
|
|
37
51
|
/** Authentication, supplied once and reused for discovery + every call. */
|
|
38
52
|
auth?: MCPAuth;
|
|
39
53
|
/** Custom fetch implementation for all network requests. */
|
|
40
54
|
fetch?: typeof fetch;
|
|
41
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* Client identity self-reported to the server while connecting — via the
|
|
57
|
+
* `initialize` handshake on revision 2025-11-25, or the per-request `_meta`
|
|
58
|
+
* envelope on 2026-07-28 (which has no `initialize`). Honoured on both.
|
|
59
|
+
*/
|
|
42
60
|
clientInfo?: {
|
|
43
61
|
name: string;
|
|
44
62
|
version: string;
|
|
@@ -64,7 +82,12 @@ export interface CreateMCPToolsOptions {
|
|
|
64
82
|
store: MCPCacheStore;
|
|
65
83
|
key?: string;
|
|
66
84
|
};
|
|
67
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* Persist resolved credentials (bearer/header values, or the OAuth provider's
|
|
87
|
+
* current tokens) into the snapshot. Off by default. Session ids are never
|
|
88
|
+
* serialized — protocol sessions are removed in revision 2026-07-28
|
|
89
|
+
* (SEP-2567), and a rehydrate always performs a fresh handshake.
|
|
90
|
+
*/
|
|
68
91
|
cacheCredentials?: boolean;
|
|
69
92
|
/** Re-list tools when a cached snapshot is older than this. */
|
|
70
93
|
staleness?: {
|
|
@@ -74,11 +97,37 @@ export interface CreateMCPToolsOptions {
|
|
|
74
97
|
resources?: ResourcesOption;
|
|
75
98
|
/** Map MCP progress notifications to generator-tool events. Default true. */
|
|
76
99
|
emitProgress?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Doom-loop identities for wrapped tools (see the `doomLoop` option on
|
|
102
|
+
* `callModel`), keyed by the tool's UNPREFIXED MCP name. Any `ToolLoopKey`
|
|
103
|
+
* form: a function computing key material, a declarative field-name array
|
|
104
|
+
* (e.g. `{ run_command: ['command', 'cwd'] }`), or `false` to exempt a
|
|
105
|
+
* tool. Takes precedence over a server-advertised
|
|
106
|
+
* `_meta['openrouter/loopKey']` declaration. Function forms are
|
|
107
|
+
* client-side only (they cannot be cached or transported); prefer field
|
|
108
|
+
* lists where possible.
|
|
109
|
+
*/
|
|
110
|
+
loopKeys?: Readonly<Record<string, ToolLoopKey<Record<string, unknown>>>>;
|
|
77
111
|
/** Auto-refresh tools on `tools/list_changed`. Default true when connected. */
|
|
78
112
|
autoRefreshOnListChanged?: boolean;
|
|
79
|
-
/**
|
|
113
|
+
/**
|
|
114
|
+
* Handler for elicitation requests; auto-declines when omitted.
|
|
115
|
+
*
|
|
116
|
+
* Works against both protocol revisions. On 2025-11-25 the server sends
|
|
117
|
+
* `elicitation/create` directly. On 2026-07-28 that request no longer
|
|
118
|
+
* exists — the server answers with an `input_required` result instead
|
|
119
|
+
* (SEP-2322) — but the SDK's multi-round-trip driver dispatches it through
|
|
120
|
+
* this same handler and then retries the original call, so callers see
|
|
121
|
+
* identical behavior either way.
|
|
122
|
+
*/
|
|
80
123
|
onElicitation?: ElicitationHandler;
|
|
81
|
-
/**
|
|
124
|
+
/**
|
|
125
|
+
* Abort signal threaded into every underlying `callTool` — and, new in this
|
|
126
|
+
* release, into the connection itself: connecting, the negotiation probe, the
|
|
127
|
+
* implicit legacy retry, and any reconnect all abort with it. An early
|
|
128
|
+
* cancellation can therefore surface as a connection failure, not only as a
|
|
129
|
+
* cancelled tool call.
|
|
130
|
+
*/
|
|
82
131
|
signal?: AbortSignal;
|
|
83
132
|
}
|
|
84
133
|
/**
|
package/esm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,KAAK,EACV,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,E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AAC,KAAK,EAAE,SAAS,IAAI,EAAE,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACvE,iDAAiD;IACjD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}
|
package/esm/version.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openrouter/mcp",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"engines": {
|
|
5
|
+
"node": ">=20"
|
|
6
|
+
},
|
|
4
7
|
"author": "OpenRouter",
|
|
5
8
|
"description": "Expose remote MCP server tools (Streamable HTTP / SSE) as tools for @openrouter/agent's callModel, with serializable caching and pluggable auth.",
|
|
6
9
|
"keywords": [
|
|
@@ -54,19 +57,20 @@
|
|
|
54
57
|
"package.json",
|
|
55
58
|
"README.md"
|
|
56
59
|
],
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@modelcontextprotocol/client": "^2.0.0",
|
|
62
|
+
"zod": "^4.0.0",
|
|
63
|
+
"@openrouter/agent": "0.9.0"
|
|
64
|
+
},
|
|
57
65
|
"scripts": {
|
|
58
66
|
"lint": "biome check src tests",
|
|
59
67
|
"lint:fix": "biome check --write src tests",
|
|
60
|
-
"
|
|
68
|
+
"gen:version": "node scripts/gen-version.mjs",
|
|
69
|
+
"build": "node scripts/gen-version.mjs && tsc",
|
|
61
70
|
"test": "vitest --run --project unit",
|
|
62
71
|
"test:e2e": "vitest --run --project e2e",
|
|
63
72
|
"test:watch": "vitest --watch --project unit",
|
|
64
73
|
"typecheck": "tsc --noEmit",
|
|
65
|
-
"compile": "tsc"
|
|
66
|
-
},
|
|
67
|
-
"dependencies": {
|
|
68
|
-
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
69
|
-
"@openrouter/agent": "workspace:*",
|
|
70
|
-
"zod": "^4.0.0"
|
|
74
|
+
"compile": "node scripts/gen-version.mjs && tsc"
|
|
71
75
|
}
|
|
72
|
-
}
|
|
76
|
+
}
|