@openrouter/mcp 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -159
- package/esm/cache.d.ts +7 -0
- package/esm/cache.d.ts.map +1 -0
- package/esm/cache.js +2 -0
- package/esm/cache.js.map +1 -0
- package/esm/create-mcp-tools.d.ts +4 -10
- package/esm/create-mcp-tools.d.ts.map +1 -1
- package/esm/create-mcp-tools.js +3 -93
- package/esm/create-mcp-tools.js.map +1 -1
- package/esm/index.d.ts +8 -12
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -10
- package/esm/index.js.map +1 -1
- package/esm/schema.d.ts +7 -0
- package/esm/schema.d.ts.map +1 -0
- package/esm/schema.js +2 -0
- package/esm/schema.js.map +1 -0
- package/esm/types.d.ts +3 -150
- package/esm/types.d.ts.map +1 -1
- package/package.json +9 -12
- package/esm/auth/auth-resolver.d.ts +0 -14
- package/esm/auth/auth-resolver.d.ts.map +0 -1
- package/esm/auth/auth-resolver.js +0 -27
- package/esm/auth/auth-resolver.js.map +0 -1
- package/esm/auth/auth-types.d.ts +0 -33
- package/esm/auth/auth-types.d.ts.map +0 -1
- package/esm/auth/auth-types.js +0 -4
- package/esm/auth/auth-types.js.map +0 -1
- package/esm/build-tools.d.ts +0 -29
- package/esm/build-tools.d.ts.map +0 -1
- package/esm/build-tools.js +0 -80
- package/esm/build-tools.js.map +0 -1
- package/esm/cache/cache-store.d.ts +0 -24
- package/esm/cache/cache-store.d.ts.map +0 -1
- package/esm/cache/cache-store.js +0 -20
- package/esm/cache/cache-store.js.map +0 -1
- package/esm/cache/cache-types.d.ts +0 -71
- package/esm/cache/cache-types.d.ts.map +0 -1
- package/esm/cache/cache-types.js +0 -49
- package/esm/cache/cache-types.js.map +0 -1
- package/esm/cache/serialize.d.ts +0 -25
- package/esm/cache/serialize.d.ts.map +0 -1
- package/esm/cache/serialize.js +0 -96
- package/esm/cache/serialize.js.map +0 -1
- package/esm/close-quietly.d.ts +0 -24
- package/esm/close-quietly.d.ts.map +0 -1
- package/esm/close-quietly.js +0 -30
- package/esm/close-quietly.js.map +0 -1
- package/esm/elicitation.d.ts +0 -11
- package/esm/elicitation.d.ts.map +0 -1
- package/esm/elicitation.js +0 -51
- package/esm/elicitation.js.map +0 -1
- package/esm/errors.d.ts +0 -82
- package/esm/errors.d.ts.map +0 -1
- package/esm/errors.js +0 -80
- package/esm/errors.js.map +0 -1
- package/esm/handle.d.ts +0 -66
- package/esm/handle.d.ts.map +0 -1
- package/esm/handle.js +0 -323
- package/esm/handle.js.map +0 -1
- package/esm/mcp-connection.d.ts +0 -142
- package/esm/mcp-connection.d.ts.map +0 -1
- package/esm/mcp-connection.js +0 -477
- package/esm/mcp-connection.js.map +0 -1
- package/esm/rehydrate.d.ts +0 -76
- package/esm/rehydrate.d.ts.map +0 -1
- package/esm/rehydrate.js +0 -499
- package/esm/rehydrate.js.map +0 -1
- package/esm/resource-tools.d.ts +0 -17
- package/esm/resource-tools.d.ts.map +0 -1
- package/esm/resource-tools.js +0 -155
- package/esm/resource-tools.js.map +0 -1
- package/esm/result-mapper.d.ts +0 -19
- package/esm/result-mapper.d.ts.map +0 -1
- package/esm/result-mapper.js +0 -40
- package/esm/result-mapper.js.map +0 -1
- package/esm/schema/json-schema-guards.d.ts +0 -14
- package/esm/schema/json-schema-guards.d.ts.map +0 -1
- package/esm/schema/json-schema-guards.js +0 -19
- package/esm/schema/json-schema-guards.js.map +0 -1
- package/esm/schema/json-schema-to-zod.d.ts +0 -20
- package/esm/schema/json-schema-to-zod.d.ts.map +0 -1
- package/esm/schema/json-schema-to-zod.js +0 -72
- package/esm/schema/json-schema-to-zod.js.map +0 -1
- package/esm/tool-wrapper.d.ts +0 -41
- package/esm/tool-wrapper.d.ts.map +0 -1
- package/esm/tool-wrapper.js +0 -131
- package/esm/tool-wrapper.js.map +0 -1
- package/esm/transport-types.d.ts +0 -45
- package/esm/transport-types.d.ts.map +0 -1
- package/esm/transport-types.js +0 -2
- package/esm/transport-types.js.map +0 -1
- package/esm/version.d.ts +0 -3
- package/esm/version.d.ts.map +0 -1
- package/esm/version.js +0 -5
- package/esm/version.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @openrouter/mcp
|
|
2
2
|
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This package is a migration-only compatibility facade. New code should import
|
|
5
|
+
> the canonical `@openrouter/agent/mcp` subpath. Existing `@openrouter/mcp` root
|
|
6
|
+
> and subpath imports remain functional and would only be removed in a future
|
|
7
|
+
> breaking release after migration notice.
|
|
8
|
+
|
|
3
9
|
Expose the tools of a remote [Model Context Protocol](https://modelcontextprotocol.io) server
|
|
4
10
|
(Streamable HTTP or SSE) as tools you can pass straight into
|
|
5
11
|
[`@openrouter/agent`](https://www.npmjs.com/package/@openrouter/agent)'s `callModel`.
|
|
@@ -9,25 +15,46 @@ Expose the tools of a remote [Model Context Protocol](https://modelcontextprotoc
|
|
|
9
15
|
- Faithful JSON Schema → Zod conversion so the model sees real parameters.
|
|
10
16
|
- Serializable, rehydratable cache so you can skip re-listing (and, opt-in, re-authenticating).
|
|
11
17
|
- Progress streaming, `tools/list_changed` auto-refresh, cancellation, resources, and elicitation.
|
|
12
|
-
- Speaks both MCP protocol revisions (`2025-11-25` and `2026-07-28`), negotiated per server.
|
|
13
18
|
|
|
14
19
|
> stdio servers are intentionally out of scope.
|
|
15
20
|
|
|
16
21
|
## Install
|
|
17
22
|
|
|
18
|
-
|
|
19
|
-
`engines.node: >=20`; this package declares the same).
|
|
23
|
+
For new code, install the agent plus the optional MCP peer:
|
|
20
24
|
|
|
21
25
|
```bash
|
|
22
|
-
pnpm add @openrouter/
|
|
26
|
+
pnpm add @openrouter/agent @modelcontextprotocol/client
|
|
23
27
|
```
|
|
24
28
|
|
|
29
|
+
Existing applications can keep installing only the compatibility package; it retains `@modelcontextprotocol/client` as a dependency, so the prior transitive-install behavior is unchanged:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pnpm add @openrouter/mcp
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The agent package is marked `sideEffects: false`, and MCP code is exposed only
|
|
36
|
+
through explicit `/mcp` exports. Root and `/tool-set` imports do not statically
|
|
37
|
+
load MCP modules; the MCP SDK is not installed transitively for base agent users.
|
|
38
|
+
The `/mcp` entry point also loads the optional SDK lazily: importing it is safe
|
|
39
|
+
without the peer, while the first connection attempt throws an actionable
|
|
40
|
+
`MCPMissingPeerDependencyError` when the SDK has not been installed.
|
|
41
|
+
|
|
42
|
+
## Compatibility subpaths
|
|
43
|
+
|
|
44
|
+
| Existing facade | Canonical replacement |
|
|
45
|
+
| --- | --- |
|
|
46
|
+
| `@openrouter/mcp` | `@openrouter/agent/mcp` |
|
|
47
|
+
| `@openrouter/mcp/create-mcp-tools` | `@openrouter/agent/mcp/create-mcp-tools` |
|
|
48
|
+
| `@openrouter/mcp/types` | `@openrouter/agent/mcp/types` |
|
|
49
|
+
| `@openrouter/mcp/schema` | `@openrouter/agent/mcp/schema` |
|
|
50
|
+
| `@openrouter/mcp/cache` | `@openrouter/agent/mcp/cache` |
|
|
51
|
+
|
|
25
52
|
## Quick start
|
|
26
53
|
|
|
27
54
|
```ts
|
|
28
55
|
import { OpenRouter } from '@openrouter/agent';
|
|
29
56
|
import { callModel } from '@openrouter/agent/call-model';
|
|
30
|
-
import { createMCPTools } from '@openrouter/mcp';
|
|
57
|
+
import { createMCPTools } from '@openrouter/agent/mcp';
|
|
31
58
|
|
|
32
59
|
const client = new OpenRouter({ apiKey: process.env.OPENROUTER_API_KEY });
|
|
33
60
|
|
|
@@ -59,15 +86,15 @@ auth: { kind: 'headers', headers: { 'X-API-Key': key } }
|
|
|
59
86
|
auth: { kind: 'oauth', provider }
|
|
60
87
|
```
|
|
61
88
|
|
|
62
|
-
Prefer an
|
|
63
|
-
automatically.
|
|
89
|
+
Prefer an `OAuthClientProvider` over caching static tokens — the transport refreshes through it
|
|
90
|
+
automatically.
|
|
64
91
|
|
|
65
92
|
## Caching & rehydration
|
|
66
93
|
|
|
67
94
|
Persist a snapshot and rebuild later without a `listTools()` round-trip:
|
|
68
95
|
|
|
69
96
|
```ts
|
|
70
|
-
import { createMCPTools, rehydrateMCPTools } from '@openrouter/mcp';
|
|
97
|
+
import { createMCPTools, rehydrateMCPTools } from '@openrouter/agent/mcp';
|
|
71
98
|
|
|
72
99
|
const mcp = await createMCPTools({ url, auth, cacheCredentials: true });
|
|
73
100
|
const snapshot = await mcp.serialize(); // plain JSON — store anywhere
|
|
@@ -79,7 +106,7 @@ const mcp2 = await rehydrateMCPTools({ snapshot, auth });
|
|
|
79
106
|
Or let a store manage it (rehydrate on hit, connect + write on miss):
|
|
80
107
|
|
|
81
108
|
```ts
|
|
82
|
-
import { InMemoryMCPCacheStore } from '@openrouter/mcp';
|
|
109
|
+
import { InMemoryMCPCacheStore } from '@openrouter/agent/mcp';
|
|
83
110
|
|
|
84
111
|
const store = new InMemoryMCPCacheStore(); // or your own Redis/DB-backed MCPCacheStore
|
|
85
112
|
const mcp = await createMCPTools({
|
|
@@ -90,44 +117,9 @@ const mcp = await createMCPTools({
|
|
|
90
117
|
});
|
|
91
118
|
```
|
|
92
119
|
|
|
93
|
-
`staleness.maxAgeMs` is honoured by `rehydrateMCPTools()` as well as by `createMCPTools()`'s
|
|
94
|
-
cache-hit path, and on every path — including `reconnectOnExpiry: false`, which opts out of
|
|
95
|
-
rebuilding the transport, not out of bounded-age tools. An over-age snapshot re-lists over
|
|
96
|
-
the replayed connection. If that re-list fails, the call rejects with `MCPStaleSnapshotError`
|
|
97
|
-
rather than quietly serving tools you declared too old; catch it to opt back in:
|
|
98
|
-
|
|
99
|
-
```ts
|
|
100
|
-
import { rehydrateMCPTools, MCPStaleSnapshotError } from '@openrouter/mcp';
|
|
101
|
-
|
|
102
|
-
try {
|
|
103
|
-
return await rehydrateMCPTools({
|
|
104
|
-
snapshot,
|
|
105
|
-
staleness: { maxAgeMs: 60_000 },
|
|
106
|
-
reconnectOnExpiry: false,
|
|
107
|
-
});
|
|
108
|
-
} catch (err) {
|
|
109
|
-
if (err instanceof MCPStaleSnapshotError) {
|
|
110
|
-
// Connection was fine, only the re-list failed — take the cached tool set.
|
|
111
|
-
return await rehydrateMCPTools({ snapshot, reconnectOnExpiry: false });
|
|
112
|
-
}
|
|
113
|
-
throw err;
|
|
114
|
-
}
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
It subclasses `MCPCacheError`, so existing `catch (e instanceof MCPCacheError)` sites keep
|
|
118
|
-
working. Note that a successful replay does not write to the store — the snapshot it would
|
|
119
|
-
write is the one just read. Seeding a store from a snapshot obtained elsewhere means writing
|
|
120
|
-
it yourself or calling `handle.refresh()` after rehydrating. Writing a snapshot back to your store is best-effort: a store outage leaves you with a
|
|
121
|
-
working handle and a stale cache entry rather than a failed call. Catch `MCPCacheWriteError`
|
|
122
|
-
from `handle.refresh()` if you would rather treat that as fatal. `handle.refresh()` also always reaches the server: SDK v2 caches `tools/list` per
|
|
123
|
-
client up to the server's `ttlMs`, and every internal list read bypasses that so a refresh
|
|
124
|
-
cannot hand back the previous tool set.
|
|
125
|
-
|
|
126
120
|
> **Security:** `cacheCredentials` is `false` by default. When enabled, snapshots contain bearer
|
|
127
121
|
> tokens/headers — treat the store as a secret store and namespace cache keys by principal in
|
|
128
|
-
> multi-tenant setups.
|
|
129
|
-
> bearer-equivalent to an authenticated server session, and nothing reads it back, so it would
|
|
130
|
-
> be attack surface for no functionality. A `sessionId` found in an old snapshot is ignored.
|
|
122
|
+
> multi-tenant setups.
|
|
131
123
|
|
|
132
124
|
## Multiple servers
|
|
133
125
|
|
|
@@ -149,9 +141,7 @@ const result = callModel(client, {
|
|
|
149
141
|
| Option | Description |
|
|
150
142
|
| --- | --- |
|
|
151
143
|
| `url` | Remote MCP server endpoint. |
|
|
152
|
-
| `transport` | `'streamableHttp'` (default, falls back to SSE) or `'sse'
|
|
153
|
-
| `protocolNegotiation` | `'auto'` (default), `'legacy'`, or `{ pin }`. See Protocol revisions. |
|
|
154
|
-
| `probeTimeoutMs` | Ceiling on the `server/discover` probe (default 30000). |
|
|
144
|
+
| `transport` | `'streamableHttp'` (default, falls back to SSE) or `'sse'`. |
|
|
155
145
|
| `auth` | Bearer token, headers, or an `OAuthClientProvider`. |
|
|
156
146
|
| `toolNamePrefix` | Prefix every wrapped tool name. |
|
|
157
147
|
| `includeTools` / `excludeTools` | Allow/deny lists by MCP tool name. |
|
|
@@ -160,117 +150,8 @@ const result = callModel(client, {
|
|
|
160
150
|
| `resources` | Expose synthetic `list_resources` / `read_resource` tools (default on). |
|
|
161
151
|
| `emitProgress` | Stream MCP progress as generator-tool events (default on). |
|
|
162
152
|
| `autoRefreshOnListChanged` | Re-list on `tools/list_changed` (default on). |
|
|
163
|
-
| `onElicitation` | Handle elicitation requests
|
|
164
|
-
| `signal` |
|
|
165
|
-
|
|
166
|
-
## Client identity
|
|
167
|
-
|
|
168
|
-
The client identifies itself to every server it connects to via MCP `clientInfo`
|
|
169
|
-
(`{ name, version }`). Pass `clientInfo` in options to override it; otherwise the default
|
|
170
|
-
is `@openrouter/mcp` at this package's version.
|
|
171
|
-
|
|
172
|
-
That version is **generated** into `src/version.ts` from `package.json`, which is the
|
|
173
|
-
single source of truth. `build` regenerates it, so a changesets version bump is picked up
|
|
174
|
-
automatically before publish. To regenerate by hand:
|
|
175
|
-
|
|
176
|
-
```bash
|
|
177
|
-
pnpm --filter @openrouter/mcp gen:version
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
The generated file is committed rather than gitignored, because CI's lint, typecheck, and
|
|
181
|
-
unit-test jobs compile `src` without running a build. `tests/unit/version.test.ts` fails
|
|
182
|
-
if the committed constant drifts from `package.json`, so a stale value cannot merge.
|
|
183
|
-
|
|
184
|
-
## Protocol revisions
|
|
185
|
-
|
|
186
|
-
Both current MCP revisions are supported, and the right one is chosen for you. Point this
|
|
187
|
-
at any server and it works:
|
|
188
|
-
|
|
189
|
-
```ts
|
|
190
|
-
const mcp = await createMCPTools({ url: 'https://mcp.example.com/mcp' });
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
By default (`protocolNegotiation: 'auto'`) the client probes with `server/discover` and
|
|
194
|
-
then speaks whichever revision the server offers:
|
|
195
|
-
|
|
196
|
-
| Server | What goes on the wire |
|
|
197
|
-
| --- | --- |
|
|
198
|
-
| **`2026-07-28`** | `server/discover`, then requests carrying the per-request `_meta` envelope and `Mcp-Method` / `Mcp-Name` headers. No `initialize` — the handshake is removed in this revision (SEP-2575). |
|
|
199
|
-
| **`2025-11-25`** and earlier | `server/discover`, then a fallback to the classic `initialize` + `notifications/initialized` handshake, byte-equivalent to a 2025-only client. |
|
|
200
|
-
|
|
201
|
-
A probe is a new request, and some infrastructure dislikes new requests — a proxy, WAF, or
|
|
202
|
-
strict gateway may hang or 5xx on an unknown method. **You don't need to configure anything
|
|
203
|
-
for that case.** When you have not set `protocolNegotiation`, a failed connect is retried
|
|
204
|
-
once with `'legacy'`, so such a server connects exactly as it did before this package
|
|
205
|
-
probed at all. That covers the pinned `transport: 'sse'` path and the Streamable HTTP → SSE
|
|
206
|
-
fallback too, since all three share one client factory.
|
|
207
|
-
|
|
208
|
-
Override when you need to:
|
|
209
|
-
|
|
210
|
-
```ts
|
|
211
|
-
// Skip the probe. A performance choice, not a compatibility one: saves the extra
|
|
212
|
-
// round trip when you already know the server is 2025-era.
|
|
213
|
-
await createMCPTools({ url, protocolNegotiation: 'legacy' });
|
|
214
|
-
|
|
215
|
-
// Require a specific revision; fail loudly rather than falling back.
|
|
216
|
-
await createMCPTools({ url, protocolNegotiation: { pin: '2026-07-28' } });
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
> Setting `protocolNegotiation` at all — **including to `'auto'`** — opts out of the
|
|
220
|
-
> automatic legacy retry. Naming a mode means you want that mode's failures too, and
|
|
221
|
-
> silently overriding a `{ pin }` would defeat the point of pinning.
|
|
222
|
-
|
|
223
|
-
The probe is bounded at 30s; pass `probeTimeoutMs` to change it. Without a bound the SDK gives
|
|
224
|
-
the probe the full 60s request timeout, so a black-holing gateway takes minutes to fail. The
|
|
225
|
-
ceiling is not tighter because a probe timeout is *not* recoverable — on HTTP it counts as an
|
|
226
|
-
outage, and the legacy retry speaks a handshake that `2026-07-28` removed — so a modern-only
|
|
227
|
-
server slower than the ceiling would fail outright rather than just take longer. Lower it when
|
|
228
|
-
you control the server and want to fail fast; raise it for known-slow cold starts.
|
|
229
|
-
|
|
230
|
-
`'auto'` costs one extra round trip against legacy servers. When a connect fails, the retry
|
|
231
|
-
re-walks the same transport ladder under `'legacy'`, so an unreachable server is dialled up to
|
|
232
|
-
four times before erroring — the price of guaranteeing that a legacy server reachable only
|
|
233
|
-
over SSE still connects when its probe is refused.
|
|
234
|
-
|
|
235
|
-
An auth failure skips the retry: the SDK's `UnauthorizedError`, or — when an OAuth provider is
|
|
236
|
-
configured — a **401** status from the probe (which the SDK reports as an `SdkHttpError`
|
|
237
|
-
rather than routing through the OAuth flow), from any attempt, not only the last. A **403**
|
|
238
|
-
never skips it, even under OAuth: the SDK's PKCE side effects occur only on 401, so a 403
|
|
239
|
-
retry re-drives nothing, while gateways commonly answer unknown methods with 403 — the exact
|
|
240
|
-
case the retry exists to rescue. Rejected credentials are not something a different protocol
|
|
241
|
-
revision fixes, and retrying a 401 would drive an OAuth authorization flow twice and overwrite
|
|
242
|
-
the saved PKCE verifier.
|
|
243
|
-
|
|
244
|
-
`MCPConnectionError` exposes every underlying failure on `errors` (like `AggregateError`), flat
|
|
245
|
-
and in attempt order across both negotiation passes, so nothing is hidden behind `cause` —
|
|
246
|
-
which holds only the last attempt.
|
|
247
|
-
|
|
248
|
-
There are no hardcoded protocol version strings in this package — negotiation is delegated to
|
|
249
|
-
`@modelcontextprotocol/client`.
|
|
250
|
-
|
|
251
|
-
### What differs between the revisions
|
|
252
|
-
|
|
253
|
-
Mostly nothing you need to care about, with three exceptions:
|
|
254
|
-
|
|
255
|
-
| Surface | Behavior |
|
|
256
|
-
| --- | --- |
|
|
257
|
-
| `onElicitation` | **Works on both.** On 2025-era servers it handles `elicitation/create`; on 2026-07-28 that request is gone, but the SDK's multi-round-trip driver (SEP-2322) routes `input_required` results through the same handler and retries the call. |
|
|
258
|
-
| `sessionId` | 2025-era only. Protocol sessions and `Mcp-Session-Id` are removed in 2026-07-28 (SEP-2567), so it is `undefined` there. Snapshots keep the field so older ones still deserialize. |
|
|
259
|
-
| `transport: 'sse'` | Still supported for legacy servers, but HTTP+SSE is reclassified Deprecated (SEP-2596). Prefer `streamableHttp`. |
|
|
260
|
-
|
|
261
|
-
Sampling and Roots are deprecated in the new revision and were never implemented here, so
|
|
262
|
-
there is nothing to migrate.
|
|
263
|
-
|
|
264
|
-
The SDK also keeps its own per-client response cache (24h ceiling), independent of the
|
|
265
|
-
`MCPCacheStore` described above. The two are unrelated: `MCPCacheStore` persists a tool
|
|
266
|
-
snapshot across processes and, opt-in, credentials.
|
|
267
|
-
|
|
268
|
-
### OAuth provider types
|
|
269
|
-
|
|
270
|
-
If you pass `{ kind: 'oauth', provider }`, type your provider with
|
|
271
|
-
`MCPOAuthClientProvider` from this package rather than importing from
|
|
272
|
-
`@modelcontextprotocol/client` — that import path is an implementation detail and has
|
|
273
|
-
changed once already.
|
|
153
|
+
| `onElicitation` | Handle server elicitation requests; auto-declines when omitted. |
|
|
154
|
+
| `signal` | Abort signal threaded into every tool call. |
|
|
274
155
|
|
|
275
156
|
## License
|
|
276
157
|
|
package/esm/cache.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated Import from `@openrouter/agent/mcp/cache` instead.
|
|
3
|
+
* This compatibility subpath remains available for migration.
|
|
4
|
+
*/
|
|
5
|
+
export type { MCPCacheStore } from '@openrouter/agent/mcp/cache';
|
|
6
|
+
export { defaultCacheKey, InMemoryMCPCacheStore } from '@openrouter/agent/mcp/cache';
|
|
7
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,YAAY,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC"}
|
package/esm/cache.js
ADDED
package/esm/cache.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC"}
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import type { SerializedMCPServer } from './cache/cache-types.js';
|
|
2
|
-
import type { CreateMCPToolsOptions, MCPToolsHandle } from './types.js';
|
|
3
1
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* once and reused for discovery and every subsequent tool call.
|
|
7
|
-
*
|
|
8
|
-
* When `cache` is provided, a valid non-stale snapshot is rehydrated instead of
|
|
9
|
-
* re-listing; otherwise the fresh result is written back to the cache.
|
|
2
|
+
* @deprecated Import from `@openrouter/agent/mcp/create-mcp-tools` instead.
|
|
3
|
+
* This compatibility subpath remains available for migration.
|
|
10
4
|
*/
|
|
11
|
-
export
|
|
12
|
-
export
|
|
5
|
+
export type { SerializedMCPServer } from '@openrouter/agent/mcp/create-mcp-tools';
|
|
6
|
+
export { createMCPTools } from '@openrouter/agent/mcp/create-mcp-tools';
|
|
13
7
|
//# sourceMappingURL=create-mcp-tools.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-mcp-tools.d.ts","sourceRoot":"","sources":["../src/create-mcp-tools.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-mcp-tools.d.ts","sourceRoot":"","sources":["../src/create-mcp-tools.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,YAAY,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC"}
|
package/esm/create-mcp-tools.js
CHANGED
|
@@ -1,96 +1,6 @@
|
|
|
1
|
-
import { defaultCacheKey } from './cache/cache-store.js';
|
|
2
|
-
import { isSerializedMCPServer } from './cache/cache-types.js';
|
|
3
|
-
import { freshConnect, normalizeUrl } from './handle.js';
|
|
4
|
-
import { rehydrateMCPTools } from './rehydrate.js';
|
|
5
1
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* once and reused for discovery and every subsequent tool call.
|
|
9
|
-
*
|
|
10
|
-
* When `cache` is provided, a valid non-stale snapshot is rehydrated instead of
|
|
11
|
-
* re-listing; otherwise the fresh result is written back to the cache.
|
|
2
|
+
* @deprecated Import from `@openrouter/agent/mcp/create-mcp-tools` instead.
|
|
3
|
+
* This compatibility subpath remains available for migration.
|
|
12
4
|
*/
|
|
13
|
-
export
|
|
14
|
-
const url = normalizeUrl(options.url);
|
|
15
|
-
const cacheKey = options.cache?.key ?? defaultCacheKey(url.href);
|
|
16
|
-
if (options.cache !== undefined) {
|
|
17
|
-
const hit = await tryCacheHit(options, options.cache.store, cacheKey);
|
|
18
|
-
if (hit !== undefined) {
|
|
19
|
-
return hit;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return freshConnect(options, url, cacheKey);
|
|
23
|
-
}
|
|
24
|
-
// Option keys forwarded verbatim from a cache-hit `createMCPTools` call into
|
|
25
|
-
// `rehydrateMCPTools`, so a warm handle applies the same auth, filters, prefix,
|
|
26
|
-
// loop identities, and credential-caching behavior as a cold one. Anything
|
|
27
|
-
// omitted here is SILENTLY DROPPED on a cache hit — when adding an option to
|
|
28
|
-
// `CreateMCPToolsOptions` that rehydrate also honors, add it here too.
|
|
29
|
-
const FORWARDED_REHYDRATE_KEYS = [
|
|
30
|
-
'auth',
|
|
31
|
-
'fetch',
|
|
32
|
-
'clientInfo',
|
|
33
|
-
'onUnconvertibleSchema',
|
|
34
|
-
'onElicitation',
|
|
35
|
-
'signal',
|
|
36
|
-
'toolNamePrefix',
|
|
37
|
-
'includeTools',
|
|
38
|
-
'excludeTools',
|
|
39
|
-
'resources',
|
|
40
|
-
'emitProgress',
|
|
41
|
-
'loopKeys',
|
|
42
|
-
'autoRefreshOnListChanged',
|
|
43
|
-
'cacheCredentials',
|
|
44
|
-
'protocolNegotiation',
|
|
45
|
-
'probeTimeoutMs',
|
|
46
|
-
'staleness',
|
|
47
|
-
];
|
|
48
|
-
/** Copy the defined forwarded options from `createMCPTools` into a rehydrate base. */
|
|
49
|
-
function forwardedRehydrateOptions(options) {
|
|
50
|
-
const out = {};
|
|
51
|
-
for (const key of FORWARDED_REHYDRATE_KEYS) {
|
|
52
|
-
const value = options[key];
|
|
53
|
-
if (value !== undefined) {
|
|
54
|
-
Object.assign(out, {
|
|
55
|
-
[key]: value,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return out;
|
|
60
|
-
}
|
|
61
|
-
async function tryCacheHit(options, store, cacheKey) {
|
|
62
|
-
// A failed read is a miss, not a failure. The cache exists to skip a
|
|
63
|
-
// listTools() round trip; a store blip on the lookup must not reject a call
|
|
64
|
-
// that a plain miss would have served via a fresh connect. This mirrors the
|
|
65
|
-
// write side, which is best-effort everywhere — without it, "a store outage
|
|
66
|
-
// leaves you with a working handle" only held if the outage arrived after
|
|
67
|
-
// the read. Wrapped in try/catch rather than `.catch()`: `MCPCacheStore.get`
|
|
68
|
-
// may return synchronously, and a synchronous throw would bypass a
|
|
69
|
-
// promise-level handler — the exact hole `closeQuietly` exists to plug on
|
|
70
|
-
// the teardown side.
|
|
71
|
-
let snapshot;
|
|
72
|
-
try {
|
|
73
|
-
snapshot = await store.get(cacheKey);
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
snapshot = undefined;
|
|
77
|
-
}
|
|
78
|
-
if (snapshot === null || snapshot === undefined || !isSerializedMCPServer(snapshot)) {
|
|
79
|
-
return undefined;
|
|
80
|
-
}
|
|
81
|
-
const maxAge = options.staleness?.maxAgeMs;
|
|
82
|
-
if (maxAge !== undefined && Date.now() - snapshot.cachedAt > maxAge) {
|
|
83
|
-
return undefined;
|
|
84
|
-
}
|
|
85
|
-
// Defer to rehydrate, which reconnects and falls back to a fresh connect on
|
|
86
|
-
// expiry.
|
|
87
|
-
return rehydrateMCPTools({
|
|
88
|
-
snapshot,
|
|
89
|
-
...forwardedRehydrateOptions(options),
|
|
90
|
-
cache: {
|
|
91
|
-
store,
|
|
92
|
-
key: cacheKey,
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
}
|
|
5
|
+
export { createMCPTools } from '@openrouter/agent/mcp/create-mcp-tools';
|
|
96
6
|
//# sourceMappingURL=create-mcp-tools.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-mcp-tools.js","sourceRoot":"","sources":["../src/create-mcp-tools.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-mcp-tools.js","sourceRoot":"","sources":["../src/create-mcp-tools.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC"}
|
package/esm/index.d.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export {
|
|
8
|
-
export
|
|
9
|
-
export { rehydrateMCPTools } from './rehydrate.js';
|
|
10
|
-
export type { UnconvertibleSchemaMode } from './schema/json-schema-to-zod.js';
|
|
11
|
-
export { convertMcpInputSchema } from './schema/json-schema-to-zod.js';
|
|
12
|
-
export type { CreateMCPToolsOptions, ElicitationHandler, ElicitationResponse, MCPProtocolNegotiation, MCPProtocolRevision, MCPToolsHandle, MCPTransportKind, ResourcesOption, } from './types.js';
|
|
1
|
+
/**
|
|
2
|
+
* Compatibility facade for the canonical `@openrouter/agent/mcp` integration.
|
|
3
|
+
*
|
|
4
|
+
* @deprecated Import from `@openrouter/agent/mcp` instead. This facade remains
|
|
5
|
+
* available for migration and may be removed only in a future breaking release.
|
|
6
|
+
*/
|
|
7
|
+
export type { CreateMCPToolsOptions, ElicitationHandler, ElicitationResponse, MCPAuth, MCPCacheStore, MCPOAuthClientProvider, MCPProtocolNegotiation, MCPProtocolRevision, MCPToolsHandle, MCPTransportKind, RehydrateMCPToolsOptions, ResourcesOption, SerializedMCPServer, SerializedMCPToolDef, SerializedTokenSet, UnconvertibleSchemaMode, } from '@openrouter/agent/mcp';
|
|
8
|
+
export { convertMcpInputSchema, createMCPTools, defaultCacheKey, InMemoryMCPCacheStore, isSerializedMCPServer, MCPCacheError, MCPCacheWriteError, MCPConnectionError, MCPError, MCPMissingPeerDependencyError, MCPStaleSnapshotError, MCPToolCallError, rehydrateMCPTools, } from '@openrouter/agent/mcp';
|
|
13
9
|
//# sourceMappingURL=index.d.ts.map
|
package/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,YAAY,EACV,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,EACnB,OAAO,EACP,aAAa,EACb,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,wBAAwB,EACxB,eAAe,EACf,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACrB,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,QAAQ,EACR,6BAA6B,EAC7B,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,uBAAuB,CAAC"}
|
package/esm/index.js
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
// Cache
|
|
3
|
-
export { defaultCacheKey, InMemoryMCPCacheStore } from './cache/cache-store.js';
|
|
4
|
-
export { isSerializedMCPServer } from './cache/cache-types.js';
|
|
5
|
-
export { createMCPTools } from './create-mcp-tools.js';
|
|
6
|
-
// Errors
|
|
7
|
-
export { MCPCacheError, MCPCacheWriteError, MCPConnectionError, MCPError, MCPStaleSnapshotError, MCPToolCallError, } from './errors.js';
|
|
8
|
-
export { rehydrateMCPTools } from './rehydrate.js';
|
|
9
|
-
// Schema conversion (exported for testing/reuse)
|
|
10
|
-
export { convertMcpInputSchema } from './schema/json-schema-to-zod.js';
|
|
1
|
+
export { convertMcpInputSchema, createMCPTools, defaultCacheKey, InMemoryMCPCacheStore, isSerializedMCPServer, MCPCacheError, MCPCacheWriteError, MCPConnectionError, MCPError, MCPMissingPeerDependencyError, MCPStaleSnapshotError, MCPToolCallError, rehydrateMCPTools, } from '@openrouter/agent/mcp';
|
|
11
2
|
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAwBA,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACrB,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,QAAQ,EACR,6BAA6B,EAC7B,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,uBAAuB,CAAC"}
|
package/esm/schema.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated Import from `@openrouter/agent/mcp/schema` instead.
|
|
3
|
+
* This compatibility subpath remains available for migration.
|
|
4
|
+
*/
|
|
5
|
+
export type { UnconvertibleSchemaMode } from '@openrouter/agent/mcp/schema';
|
|
6
|
+
export { convertMcpInputSchema } from '@openrouter/agent/mcp/schema';
|
|
7
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,YAAY,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC"}
|
package/esm/schema.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC"}
|