@openrouter/mcp 0.0.1 → 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.
- package/README.md +35 -4
- 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 -72
- 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 -101
- package/esm/types.d.ts.map +1 -1
- package/package.json +14 -13
- 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 -25
- 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 -27
- package/esm/build-tools.d.ts.map +0 -1
- package/esm/build-tools.js +0 -77
- 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 -54
- package/esm/cache/cache-types.d.ts.map +0 -1
- package/esm/cache/cache-types.js +0 -41
- 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 -85
- package/esm/cache/serialize.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 -35
- package/esm/errors.d.ts.map +0 -1
- package/esm/errors.js +0 -39
- package/esm/errors.js.map +0 -1
- package/esm/handle.d.ts +0 -41
- package/esm/handle.d.ts.map +0 -1
- package/esm/handle.js +0 -221
- package/esm/handle.js.map +0 -1
- package/esm/mcp-connection.d.ts +0 -35
- package/esm/mcp-connection.d.ts.map +0 -1
- package/esm/mcp-connection.js +0 -147
- package/esm/mcp-connection.js.map +0 -1
- package/esm/rehydrate.d.ts +0 -41
- package/esm/rehydrate.d.ts.map +0 -1
- package/esm/rehydrate.js +0 -173
- 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 -133
- 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 -26
- package/esm/tool-wrapper.d.ts.map +0 -1
- package/esm/tool-wrapper.js +0 -118
- package/esm/tool-wrapper.js.map +0 -1
- package/esm/transport-types.d.ts +0 -3
- 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/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`.
|
|
@@ -14,16 +20,41 @@ Expose the tools of a remote [Model Context Protocol](https://modelcontextprotoc
|
|
|
14
20
|
|
|
15
21
|
## Install
|
|
16
22
|
|
|
23
|
+
For new code, install the agent plus the optional MCP peer:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pnpm add @openrouter/agent @modelcontextprotocol/client
|
|
27
|
+
```
|
|
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
|
+
|
|
17
31
|
```bash
|
|
18
|
-
pnpm add @openrouter/mcp
|
|
32
|
+
pnpm add @openrouter/mcp
|
|
19
33
|
```
|
|
20
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
|
+
|
|
21
52
|
## Quick start
|
|
22
53
|
|
|
23
54
|
```ts
|
|
24
55
|
import { OpenRouter } from '@openrouter/agent';
|
|
25
56
|
import { callModel } from '@openrouter/agent/call-model';
|
|
26
|
-
import { createMCPTools } from '@openrouter/mcp';
|
|
57
|
+
import { createMCPTools } from '@openrouter/agent/mcp';
|
|
27
58
|
|
|
28
59
|
const client = new OpenRouter({ apiKey: process.env.OPENROUTER_API_KEY });
|
|
29
60
|
|
|
@@ -63,7 +94,7 @@ automatically.
|
|
|
63
94
|
Persist a snapshot and rebuild later without a `listTools()` round-trip:
|
|
64
95
|
|
|
65
96
|
```ts
|
|
66
|
-
import { createMCPTools, rehydrateMCPTools } from '@openrouter/mcp';
|
|
97
|
+
import { createMCPTools, rehydrateMCPTools } from '@openrouter/agent/mcp';
|
|
67
98
|
|
|
68
99
|
const mcp = await createMCPTools({ url, auth, cacheCredentials: true });
|
|
69
100
|
const snapshot = await mcp.serialize(); // plain JSON — store anywhere
|
|
@@ -75,7 +106,7 @@ const mcp2 = await rehydrateMCPTools({ snapshot, auth });
|
|
|
75
106
|
Or let a store manage it (rehydrate on hit, connect + write on miss):
|
|
76
107
|
|
|
77
108
|
```ts
|
|
78
|
-
import { InMemoryMCPCacheStore } from '@openrouter/mcp';
|
|
109
|
+
import { InMemoryMCPCacheStore } from '@openrouter/agent/mcp';
|
|
79
110
|
|
|
80
111
|
const store = new InMemoryMCPCacheStore(); // or your own Redis/DB-backed MCPCacheStore
|
|
81
112
|
const mcp = await createMCPTools({
|
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,75 +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
|
-
// and credential-caching behavior as a cold one.
|
|
27
|
-
const FORWARDED_REHYDRATE_KEYS = [
|
|
28
|
-
'auth',
|
|
29
|
-
'fetch',
|
|
30
|
-
'clientInfo',
|
|
31
|
-
'onUnconvertibleSchema',
|
|
32
|
-
'onElicitation',
|
|
33
|
-
'signal',
|
|
34
|
-
'toolNamePrefix',
|
|
35
|
-
'includeTools',
|
|
36
|
-
'excludeTools',
|
|
37
|
-
'resources',
|
|
38
|
-
'emitProgress',
|
|
39
|
-
'autoRefreshOnListChanged',
|
|
40
|
-
'cacheCredentials',
|
|
41
|
-
];
|
|
42
|
-
/** Copy the defined forwarded options from `createMCPTools` into a rehydrate base. */
|
|
43
|
-
function forwardedRehydrateOptions(options) {
|
|
44
|
-
const out = {};
|
|
45
|
-
for (const key of FORWARDED_REHYDRATE_KEYS) {
|
|
46
|
-
const value = options[key];
|
|
47
|
-
if (value !== undefined) {
|
|
48
|
-
Object.assign(out, {
|
|
49
|
-
[key]: value,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return out;
|
|
54
|
-
}
|
|
55
|
-
async function tryCacheHit(options, store, cacheKey) {
|
|
56
|
-
const snapshot = await store.get(cacheKey);
|
|
57
|
-
if (snapshot === null || snapshot === undefined || !isSerializedMCPServer(snapshot)) {
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
const maxAge = options.staleness?.maxAgeMs;
|
|
61
|
-
if (maxAge !== undefined && Date.now() - snapshot.cachedAt > maxAge) {
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
|
64
|
-
// Defer to rehydrate, which reconnects and falls back to a fresh connect on
|
|
65
|
-
// expiry.
|
|
66
|
-
return rehydrateMCPTools({
|
|
67
|
-
snapshot,
|
|
68
|
-
...forwardedRehydrateOptions(options),
|
|
69
|
-
cache: {
|
|
70
|
-
store,
|
|
71
|
-
key: cacheKey,
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
}
|
|
5
|
+
export { createMCPTools } from '@openrouter/agent/mcp/create-mcp-tools';
|
|
75
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, 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, MCPConnectionError, MCPError, 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"}
|
package/esm/types.d.ts
CHANGED
|
@@ -1,104 +1,6 @@
|
|
|
1
|
-
import type { Tool } from '@openrouter/agent/tool-types';
|
|
2
|
-
import type { MCPAuth } from './auth/auth-types.js';
|
|
3
|
-
import type { MCPCacheStore } from './cache/cache-store.js';
|
|
4
|
-
import type { UnconvertibleSchemaMode } from './schema/json-schema-to-zod.js';
|
|
5
|
-
import type { MCPTransportKind } from './transport-types.js';
|
|
6
|
-
export type { MCPTransportKind };
|
|
7
1
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
2
|
+
* @deprecated Import from `@openrouter/agent/mcp/types` instead.
|
|
3
|
+
* This compatibility subpath remains available for migration.
|
|
10
4
|
*/
|
|
11
|
-
export type ElicitationResponse
|
|
12
|
-
action: 'accept';
|
|
13
|
-
content: Record<string, unknown>;
|
|
14
|
-
} | {
|
|
15
|
-
action: 'decline';
|
|
16
|
-
} | {
|
|
17
|
-
action: 'cancel';
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Handler for server-initiated `elicitation/create` requests during a tool
|
|
21
|
-
* call. If omitted from options, requests are auto-declined so a tool call
|
|
22
|
-
* needing input fails gracefully rather than hanging.
|
|
23
|
-
*/
|
|
24
|
-
export type ElicitationHandler = (request: {
|
|
25
|
-
message: string;
|
|
26
|
-
requestedSchema: Record<string, unknown>;
|
|
27
|
-
}) => Promise<ElicitationResponse> | ElicitationResponse;
|
|
28
|
-
/** How MCP resources are exposed to the model. */
|
|
29
|
-
export type ResourcesOption = boolean | {
|
|
30
|
-
mode?: 'synthetic-tools';
|
|
31
|
-
};
|
|
32
|
-
export interface CreateMCPToolsOptions {
|
|
33
|
-
/** Remote MCP server endpoint. */
|
|
34
|
-
url: string | URL;
|
|
35
|
-
/** Transport to use; defaults to `streamableHttp` with SSE fallback. */
|
|
36
|
-
transport?: MCPTransportKind;
|
|
37
|
-
/** Authentication, supplied once and reused for discovery + every call. */
|
|
38
|
-
auth?: MCPAuth;
|
|
39
|
-
/** Custom fetch implementation for all network requests. */
|
|
40
|
-
fetch?: typeof fetch;
|
|
41
|
-
/** Client identity sent during `initialize`. */
|
|
42
|
-
clientInfo?: {
|
|
43
|
-
name: string;
|
|
44
|
-
version: string;
|
|
45
|
-
};
|
|
46
|
-
/** Prefix applied to every wrapped tool name (e.g. `"github_"`). */
|
|
47
|
-
toolNamePrefix?: string;
|
|
48
|
-
/**
|
|
49
|
-
* Allow-list of MCP tool names to expose. Applies to discovered MCP tools
|
|
50
|
-
* only; synthetic `list_resources`/`read_resource` tools are controlled
|
|
51
|
-
* exclusively by `resources`.
|
|
52
|
-
*/
|
|
53
|
-
includeTools?: readonly string[];
|
|
54
|
-
/**
|
|
55
|
-
* Deny-list of MCP tool names to skip. Applies to discovered MCP tools only;
|
|
56
|
-
* synthetic `list_resources`/`read_resource` tools are controlled
|
|
57
|
-
* exclusively by `resources`.
|
|
58
|
-
*/
|
|
59
|
-
excludeTools?: readonly string[];
|
|
60
|
-
/** Behavior when a tool's JSON Schema can't be fully represented in Zod. */
|
|
61
|
-
onUnconvertibleSchema?: UnconvertibleSchemaMode;
|
|
62
|
-
/** Cache store + key for automatic rehydrate-on-hit / write-on-miss. */
|
|
63
|
-
cache?: {
|
|
64
|
-
store: MCPCacheStore;
|
|
65
|
-
key?: string;
|
|
66
|
-
};
|
|
67
|
-
/** Persist resolved tokens/session into the snapshot. Off by default. */
|
|
68
|
-
cacheCredentials?: boolean;
|
|
69
|
-
/** Re-list tools when a cached snapshot is older than this. */
|
|
70
|
-
staleness?: {
|
|
71
|
-
maxAgeMs?: number;
|
|
72
|
-
};
|
|
73
|
-
/** Expose resources as synthetic `list_resources`/`read_resource` tools. */
|
|
74
|
-
resources?: ResourcesOption;
|
|
75
|
-
/** Map MCP progress notifications to generator-tool events. Default true. */
|
|
76
|
-
emitProgress?: boolean;
|
|
77
|
-
/** Auto-refresh tools on `tools/list_changed`. Default true when connected. */
|
|
78
|
-
autoRefreshOnListChanged?: boolean;
|
|
79
|
-
/** Handler for server-initiated elicitation; auto-declines when omitted. */
|
|
80
|
-
onElicitation?: ElicitationHandler;
|
|
81
|
-
/** Abort signal threaded into every underlying `callTool`. */
|
|
82
|
-
signal?: AbortSignal;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Handle returned by {@link createMCPTools}/`rehydrateMCPTools`. Holds a live
|
|
86
|
-
* connection (unless rehydrated offline) and the wrapped tools.
|
|
87
|
-
*/
|
|
88
|
-
export interface MCPToolsHandle {
|
|
89
|
-
/** Tools ready to pass into `callModel({ tools })`. */
|
|
90
|
-
readonly tools: readonly Tool[];
|
|
91
|
-
readonly serverInfo?: {
|
|
92
|
-
name?: string;
|
|
93
|
-
version?: string;
|
|
94
|
-
};
|
|
95
|
-
/** Snapshot for persistence; omits credentials unless `cacheCredentials`. */
|
|
96
|
-
serialize(): Promise<import('./cache/cache-types.js').SerializedMCPServer>;
|
|
97
|
-
/** Force a fresh `listTools()` and rebuild the tool set. */
|
|
98
|
-
refresh(): Promise<readonly Tool[]>;
|
|
99
|
-
/** Subscribe to auto-refreshes triggered by `tools/list_changed`. */
|
|
100
|
-
onToolsChanged(listener: (tools: readonly Tool[]) => void): () => void;
|
|
101
|
-
/** Close the transport and underlying client. */
|
|
102
|
-
close(): Promise<void>;
|
|
103
|
-
}
|
|
5
|
+
export type { CreateMCPToolsOptions, ElicitationHandler, ElicitationResponse, MCPProtocolNegotiation, MCPProtocolRevision, MCPToolsHandle, MCPTransportKind, ResourcesOption, } from '@openrouter/agent/mcp/types';
|
|
104
6
|
//# sourceMappingURL=types.d.ts.map
|
package/esm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,YAAY,EACV,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,eAAe,GAChB,MAAM,6BAA6B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openrouter/mcp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.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": [
|
|
@@ -30,12 +33,12 @@
|
|
|
30
33
|
"default": "./esm/types.js"
|
|
31
34
|
},
|
|
32
35
|
"./schema": {
|
|
33
|
-
"types": "./esm/schema
|
|
34
|
-
"default": "./esm/schema
|
|
36
|
+
"types": "./esm/schema.d.ts",
|
|
37
|
+
"default": "./esm/schema.js"
|
|
35
38
|
},
|
|
36
39
|
"./cache": {
|
|
37
|
-
"types": "./esm/cache
|
|
38
|
-
"default": "./esm/cache
|
|
40
|
+
"types": "./esm/cache.d.ts",
|
|
41
|
+
"default": "./esm/cache.js"
|
|
39
42
|
},
|
|
40
43
|
"./package.json": "./package.json"
|
|
41
44
|
},
|
|
@@ -54,19 +57,17 @@
|
|
|
54
57
|
"package.json",
|
|
55
58
|
"README.md"
|
|
56
59
|
],
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@modelcontextprotocol/client": "^2.0.0",
|
|
62
|
+
"@openrouter/agent": "0.10.0"
|
|
63
|
+
},
|
|
57
64
|
"scripts": {
|
|
58
65
|
"lint": "biome check src tests",
|
|
59
66
|
"lint:fix": "biome check --write src tests",
|
|
60
67
|
"build": "tsc",
|
|
61
68
|
"test": "vitest --run --project unit",
|
|
62
|
-
"test:e2e": "vitest --run --project e2e",
|
|
63
69
|
"test:watch": "vitest --watch --project unit",
|
|
64
|
-
"typecheck": "tsc --noEmit",
|
|
70
|
+
"typecheck": "pnpm run build && tsc --noEmit -p tsconfig.typecheck.json",
|
|
65
71
|
"compile": "tsc"
|
|
66
|
-
},
|
|
67
|
-
"dependencies": {
|
|
68
|
-
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
69
|
-
"@openrouter/agent": "workspace:*",
|
|
70
|
-
"zod": "^4.0.0"
|
|
71
72
|
}
|
|
72
|
-
}
|
|
73
|
+
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js';
|
|
2
|
-
import type { MCPAuth } from './auth-types.js';
|
|
3
|
-
/**
|
|
4
|
-
* The transport-level pieces derived from an {@link MCPAuth}: static headers to
|
|
5
|
-
* merge into `requestInit`, and/or an OAuth provider to hand to the transport.
|
|
6
|
-
* Both flow into the same connected client, so discovery and tool calls share
|
|
7
|
-
* one authenticated session.
|
|
8
|
-
*/
|
|
9
|
-
export interface ResolvedAuth {
|
|
10
|
-
headers: Record<string, string>;
|
|
11
|
-
authProvider?: OAuthClientProvider;
|
|
12
|
-
}
|
|
13
|
-
export declare function resolveAuth(auth: MCPAuth | undefined): ResolvedAuth;
|
|
14
|
-
//# sourceMappingURL=auth-resolver.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth-resolver.d.ts","sourceRoot":"","sources":["../../src/auth/auth-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AACpF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,YAAY,CAAC,EAAE,mBAAmB,CAAC;CACpC;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,YAAY,CAyBnE"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export function resolveAuth(auth) {
|
|
2
|
-
if (auth === undefined) {
|
|
3
|
-
return {
|
|
4
|
-
headers: {},
|
|
5
|
-
};
|
|
6
|
-
}
|
|
7
|
-
switch (auth.kind) {
|
|
8
|
-
case 'bearer':
|
|
9
|
-
return {
|
|
10
|
-
headers: {
|
|
11
|
-
Authorization: `Bearer ${auth.token}`,
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
case 'headers':
|
|
15
|
-
return {
|
|
16
|
-
headers: {
|
|
17
|
-
...auth.headers,
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
case 'oauth':
|
|
21
|
-
return {
|
|
22
|
-
headers: {},
|
|
23
|
-
authProvider: auth.provider,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=auth-resolver.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth-resolver.js","sourceRoot":"","sources":["../../src/auth/auth-resolver.ts"],"names":[],"mappings":"AAcA,MAAM,UAAU,WAAW,CAAC,IAAyB;IACnD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO;YACL,OAAO,EAAE,EAAE;SACZ,CAAC;IACJ,CAAC;IACD,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,QAAQ;YACX,OAAO;gBACL,OAAO,EAAE;oBACP,aAAa,EAAE,UAAU,IAAI,CAAC,KAAK,EAAE;iBACtC;aACF,CAAC;QACJ,KAAK,SAAS;YACZ,OAAO;gBACL,OAAO,EAAE;oBACP,GAAG,IAAI,CAAC,OAAO;iBAChB;aACF,CAAC;QACJ,KAAK,OAAO;YACV,OAAO;gBACL,OAAO,EAAE,EAAE;gBACX,YAAY,EAAE,IAAI,CAAC,QAAQ;aAC5B,CAAC;IACN,CAAC;AACH,CAAC"}
|
package/esm/auth/auth-types.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js';
|
|
2
|
-
/**
|
|
3
|
-
* Authentication for a remote MCP server. Supplied once and reused by the
|
|
4
|
-
* connected client for tool discovery and every subsequent tool call.
|
|
5
|
-
*
|
|
6
|
-
* - `bearer`: a static bearer token sent as `Authorization: Bearer <token>`.
|
|
7
|
-
* - `headers`: arbitrary static headers (e.g. API keys, custom auth schemes).
|
|
8
|
-
* - `oauth`: a user-supplied {@link OAuthClientProvider} that owns token
|
|
9
|
-
* acquisition/refresh. Preferred over caching static tokens.
|
|
10
|
-
*/
|
|
11
|
-
export type MCPAuth = {
|
|
12
|
-
kind: 'bearer';
|
|
13
|
-
token: string;
|
|
14
|
-
} | {
|
|
15
|
-
kind: 'headers';
|
|
16
|
-
headers: Readonly<Record<string, string>>;
|
|
17
|
-
} | {
|
|
18
|
-
kind: 'oauth';
|
|
19
|
-
provider: OAuthClientProvider;
|
|
20
|
-
};
|
|
21
|
-
export declare function isOAuthAuth(auth: MCPAuth | undefined): auth is {
|
|
22
|
-
kind: 'oauth';
|
|
23
|
-
provider: OAuthClientProvider;
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=auth-types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth-types.d.ts","sourceRoot":"","sources":["../../src/auth/auth-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAEpF;;;;;;;;GAQG;AACH,MAAM,MAAM,OAAO,GACf;IACE,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf,GACD;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC3C,GACD;IACE,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,mBAAmB,CAAC;CAC/B,CAAC;AAEN,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,IAAI;IAC9D,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,mBAAmB,CAAC;CAC/B,CAEA"}
|
package/esm/auth/auth-types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth-types.js","sourceRoot":"","sources":["../../src/auth/auth-types.ts"],"names":[],"mappings":"AAyBA,MAAM,UAAU,WAAW,CAAC,IAAyB;IAInD,OAAO,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC;AAChC,CAAC"}
|
package/esm/build-tools.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
2
|
-
import type { Tool } from '@openrouter/agent/tool-types';
|
|
3
|
-
import type { UnconvertibleSchemaMode } from './schema/json-schema-to-zod.js';
|
|
4
|
-
import type { McpToolDef } from './tool-wrapper.js';
|
|
5
|
-
import type { ResourcesOption } from './types.js';
|
|
6
|
-
export interface BuildToolsOptions {
|
|
7
|
-
client: Client;
|
|
8
|
-
toolDefs: readonly McpToolDef[];
|
|
9
|
-
namePrefix?: string;
|
|
10
|
-
includeTools?: readonly string[];
|
|
11
|
-
excludeTools?: readonly string[];
|
|
12
|
-
schemaMode?: UnconvertibleSchemaMode;
|
|
13
|
-
emitProgress?: boolean;
|
|
14
|
-
signal?: AbortSignal;
|
|
15
|
-
resources?: ResourcesOption;
|
|
16
|
-
/** Whether the server advertised the resources capability. */
|
|
17
|
-
serverHasResources: boolean;
|
|
18
|
-
}
|
|
19
|
-
/** Apply allow/deny filters to discovered MCP tool definitions. */
|
|
20
|
-
export declare function filterToolDefs(defs: readonly McpToolDef[], includeTools?: readonly string[], excludeTools?: readonly string[]): McpToolDef[];
|
|
21
|
-
/**
|
|
22
|
-
* Build the full ordered tool list for a handle: filtered + wrapped MCP tools,
|
|
23
|
-
* plus synthetic resource tools when enabled. Throws on a name collision so two
|
|
24
|
-
* tools never silently shadow each other in `callModel`.
|
|
25
|
-
*/
|
|
26
|
-
export declare function buildTools(options: BuildToolsOptions): Tool[];
|
|
27
|
-
//# sourceMappingURL=build-tools.d.ts.map
|
package/esm/build-tools.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"build-tools.d.ts","sourceRoot":"","sources":["../src/build-tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACxE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AAGzD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,SAAS,UAAU,EAAE,CAAC;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,UAAU,CAAC,EAAE,uBAAuB,CAAC;IACrC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,8DAA8D;IAC9D,kBAAkB,EAAE,OAAO,CAAC;CAC7B;AASD,mEAAmE;AACnE,wBAAgB,cAAc,CAC5B,IAAI,EAAE,SAAS,UAAU,EAAE,EAC3B,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,EAChC,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,GAC/B,UAAU,EAAE,CASd;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI,EAAE,CAqC7D"}
|