@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/esm/build-tools.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { MCPError } from './errors.js';
|
|
2
|
-
import { buildResourceTools } from './resource-tools.js';
|
|
3
|
-
import { wrapMcpTool } from './tool-wrapper.js';
|
|
4
|
-
function resourcesEnabled(option) {
|
|
5
|
-
if (option === undefined) {
|
|
6
|
-
return true;
|
|
7
|
-
}
|
|
8
|
-
return option === true || (typeof option === 'object' && option !== null);
|
|
9
|
-
}
|
|
10
|
-
/** Apply allow/deny filters to discovered MCP tool definitions. */
|
|
11
|
-
export function filterToolDefs(defs, includeTools, excludeTools) {
|
|
12
|
-
const include = includeTools !== undefined ? new Set(includeTools) : undefined;
|
|
13
|
-
const exclude = new Set(excludeTools ?? []);
|
|
14
|
-
return defs.filter((def) => {
|
|
15
|
-
if (include !== undefined && !include.has(def.name)) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
return !exclude.has(def.name);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
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 function buildTools(options) {
|
|
27
|
-
const filtered = filterToolDefs(options.toolDefs, options.includeTools, options.excludeTools);
|
|
28
|
-
const wrapOptions = {
|
|
29
|
-
client: options.client,
|
|
30
|
-
...(options.namePrefix !== undefined && {
|
|
31
|
-
namePrefix: options.namePrefix,
|
|
32
|
-
}),
|
|
33
|
-
...(options.schemaMode !== undefined && {
|
|
34
|
-
schemaMode: options.schemaMode,
|
|
35
|
-
}),
|
|
36
|
-
...(options.emitProgress !== undefined && {
|
|
37
|
-
emitProgress: options.emitProgress,
|
|
38
|
-
}),
|
|
39
|
-
...(options.signal !== undefined && {
|
|
40
|
-
signal: options.signal,
|
|
41
|
-
}),
|
|
42
|
-
};
|
|
43
|
-
const tools = filtered.map((def) => wrapMcpTool(def, wrapOptions));
|
|
44
|
-
if (options.serverHasResources && resourcesEnabled(options.resources)) {
|
|
45
|
-
tools.push(...buildResourceTools({
|
|
46
|
-
client: options.client,
|
|
47
|
-
...(options.namePrefix !== undefined && {
|
|
48
|
-
namePrefix: options.namePrefix,
|
|
49
|
-
}),
|
|
50
|
-
...(options.signal !== undefined && {
|
|
51
|
-
signal: options.signal,
|
|
52
|
-
}),
|
|
53
|
-
}));
|
|
54
|
-
}
|
|
55
|
-
assertNoDuplicateNames(tools);
|
|
56
|
-
return tools;
|
|
57
|
-
}
|
|
58
|
-
function toolName(tool) {
|
|
59
|
-
if ('function' in tool && typeof tool.function.name === 'string') {
|
|
60
|
-
return tool.function.name;
|
|
61
|
-
}
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
|
64
|
-
function assertNoDuplicateNames(tools) {
|
|
65
|
-
const seen = new Set();
|
|
66
|
-
for (const tool of tools) {
|
|
67
|
-
const name = toolName(tool);
|
|
68
|
-
if (name === undefined) {
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
if (seen.has(name)) {
|
|
72
|
-
throw new MCPError(`Duplicate tool name "${name}". Use toolNamePrefix or excludeTools to disambiguate.`);
|
|
73
|
-
}
|
|
74
|
-
seen.add(name);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
//# sourceMappingURL=build-tools.js.map
|
package/esm/build-tools.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"build-tools.js","sourceRoot":"","sources":["../src/build-tools.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGzD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAiBhD,SAAS,gBAAgB,CAAC,MAAmC;IAC3D,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,MAAM,KAAK,IAAI,IA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;YACnB,MAAM,IAAI,QAAQ,CAChB,wBAAwB,IAAI,wDAAwD,CACrF,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACjB,CAAC;AACH,CAAC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { SerializedMCPServer } from './cache-types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Pluggable cache for MCP server snapshots. Implement this to back the cache
|
|
4
|
-
* with Redis, a database, or the filesystem. All methods may be async.
|
|
5
|
-
*
|
|
6
|
-
* SECURITY: when `cacheCredentials` is enabled, stored snapshots contain bearer
|
|
7
|
-
* tokens/headers — treat the store as a secret store (encrypt at rest, scope
|
|
8
|
-
* access) and namespace keys by principal in multi-tenant setups.
|
|
9
|
-
*/
|
|
10
|
-
export interface MCPCacheStore {
|
|
11
|
-
get(key: string): Promise<SerializedMCPServer | null> | SerializedMCPServer | null;
|
|
12
|
-
set(key: string, value: SerializedMCPServer): Promise<void> | void;
|
|
13
|
-
delete?(key: string): Promise<void> | void;
|
|
14
|
-
}
|
|
15
|
-
/** Default in-process cache backed by a `Map`. Not shared across processes. */
|
|
16
|
-
export declare class InMemoryMCPCacheStore implements MCPCacheStore {
|
|
17
|
-
private readonly entries;
|
|
18
|
-
get(key: string): SerializedMCPServer | null;
|
|
19
|
-
set(key: string, value: SerializedMCPServer): void;
|
|
20
|
-
delete(key: string): void;
|
|
21
|
-
}
|
|
22
|
-
/** Default cache key for a server URL. Override via `cache.key` for multi-tenant. */
|
|
23
|
-
export declare function defaultCacheKey(url: string): string;
|
|
24
|
-
//# sourceMappingURL=cache-store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cache-store.d.ts","sourceRoot":"","sources":["../../src/cache/cache-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAE5D;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC,GAAG,mBAAmB,GAAG,IAAI,CAAC;IACnF,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACnE,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAC5C;AAED,+EAA+E;AAC/E,qBAAa,qBAAsB,YAAW,aAAa;IACzD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA0C;IAElE,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,mBAAmB,GAAG,IAAI;IAI5C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB,GAAG,IAAI;IAIlD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;CAG1B;AAED,qFAAqF;AACrF,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEnD"}
|
package/esm/cache/cache-store.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/** Default in-process cache backed by a `Map`. Not shared across processes. */
|
|
2
|
-
export class InMemoryMCPCacheStore {
|
|
3
|
-
constructor() {
|
|
4
|
-
this.entries = new Map();
|
|
5
|
-
}
|
|
6
|
-
get(key) {
|
|
7
|
-
return this.entries.get(key) ?? null;
|
|
8
|
-
}
|
|
9
|
-
set(key, value) {
|
|
10
|
-
this.entries.set(key, value);
|
|
11
|
-
}
|
|
12
|
-
delete(key) {
|
|
13
|
-
this.entries.delete(key);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
/** Default cache key for a server URL. Override via `cache.key` for multi-tenant. */
|
|
17
|
-
export function defaultCacheKey(url) {
|
|
18
|
-
return `openrouter-mcp:${url}`;
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=cache-store.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cache-store.js","sourceRoot":"","sources":["../../src/cache/cache-store.ts"],"names":[],"mappings":"AAgBA,+EAA+E;AAC/E,MAAM,OAAO,qBAAqB;IAAlC;QACmB,YAAO,GAAG,IAAI,GAAG,EAA+B,CAAC;IAapE,CAAC;IAXC,GAAG,CAAC,GAAW;QACb,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;IACvC,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAA0B;QACzC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM,CAAC,GAAW;QAChB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;CACF;AAED,qFAAqF;AACrF,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC,OAAO,kBAAkB,GAAG,EAAE,CAAC;AACjC,CAAC"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { MCPTransportKind } from '../transport-types.js';
|
|
2
|
-
/** A discovered tool definition as stored in a cache snapshot. */
|
|
3
|
-
export interface SerializedMCPToolDef {
|
|
4
|
-
name: string;
|
|
5
|
-
description?: string;
|
|
6
|
-
inputSchema: Readonly<Record<string, unknown>>;
|
|
7
|
-
outputSchema?: Readonly<Record<string, unknown>>;
|
|
8
|
-
}
|
|
9
|
-
/** OAuth/bearer token material, persisted only when `cacheCredentials` is on. */
|
|
10
|
-
export interface SerializedTokenSet {
|
|
11
|
-
accessToken: string;
|
|
12
|
-
tokenType?: string;
|
|
13
|
-
refreshToken?: string;
|
|
14
|
-
/** Epoch ms; absence means unknown/no declared expiry. */
|
|
15
|
-
expiresAt?: number;
|
|
16
|
-
scope?: string;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Serializable snapshot of a connected MCP server: enough to rebuild the tool
|
|
20
|
-
* set (and, opt-in, reconnect with cached credentials) without re-listing or
|
|
21
|
-
* re-authenticating.
|
|
22
|
-
*/
|
|
23
|
-
export interface SerializedMCPServer {
|
|
24
|
-
version: 1;
|
|
25
|
-
url: string;
|
|
26
|
-
transport: MCPTransportKind;
|
|
27
|
-
serverInfo?: {
|
|
28
|
-
name?: string;
|
|
29
|
-
version?: string;
|
|
30
|
-
};
|
|
31
|
-
capabilities?: Readonly<Record<string, unknown>>;
|
|
32
|
-
sessionId?: string;
|
|
33
|
-
tools: SerializedMCPToolDef[];
|
|
34
|
-
auth?: {
|
|
35
|
-
headers?: Readonly<Record<string, string>>;
|
|
36
|
-
tokens?: SerializedTokenSet;
|
|
37
|
-
};
|
|
38
|
-
cachedAt: number;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* The shared "valid `cachedAt`" rule: a finite, non-negative epoch (ms).
|
|
42
|
-
* Consumed by both the read-side snapshot validator and the write-side
|
|
43
|
-
* serializer so the two can't drift. Rejecting negatives keeps the invariant
|
|
44
|
-
* honest at the boundary rather than relying on downstream maxAge arithmetic to
|
|
45
|
-
* fail-safe on a clock-skewed or garbage value.
|
|
46
|
-
*/
|
|
47
|
-
export declare function isFiniteEpoch(value: unknown): value is number;
|
|
48
|
-
/**
|
|
49
|
-
* Validate an untrusted value as a {@link SerializedMCPServer}. Cache stores may
|
|
50
|
-
* be backed by a DB or another org member's data, so snapshots are checked
|
|
51
|
-
* structurally before use — never trusted by shape alone.
|
|
52
|
-
*/
|
|
53
|
-
export declare function isSerializedMCPServer(value: unknown): value is SerializedMCPServer;
|
|
54
|
-
//# sourceMappingURL=cache-types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cache-types.d.ts","sourceRoot":"","sources":["../../src/cache/cache-types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,kEAAkE;AAClE,MAAM,WA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O,GAAG,KAAK,IAAI,mBAAmB,CAelF"}
|
package/esm/cache/cache-types.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { isJsonSchemaObject } from '../schema/json-schema-guards.js';
|
|
2
|
-
function isTransportKind(value) {
|
|
3
|
-
return value === 'streamableHttp' || value === 'sse';
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* The shared "valid `cachedAt`" rule: a finite, non-negative epoch (ms).
|
|
7
|
-
* Consumed by both the read-side snapshot validator and the write-side
|
|
8
|
-
* serializer so the two can't drift. Rejecting negatives keeps the invariant
|
|
9
|
-
* honest at the boundary rather than relying on downstream maxAge arithmetic to
|
|
10
|
-
* fail-safe on a clock-skewed or garbage value.
|
|
11
|
-
*/
|
|
12
|
-
export function isFiniteEpoch(value) {
|
|
13
|
-
return typeof value === 'number' && Number.isFinite(value) && value >= 0;
|
|
14
|
-
}
|
|
15
|
-
function isSerializedToolDef(value) {
|
|
16
|
-
return (isJsonSchemaObject(value) &&
|
|
17
|
-
typeof value['name'] === 'string' &&
|
|
18
|
-
isJsonSchemaObject(value['inputSchema']));
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Validate an untrusted value as a {@link SerializedMCPServer}. Cache stores may
|
|
22
|
-
* be backed by a DB or another org member's data, so snapshots are checked
|
|
23
|
-
* structurally before use — never trusted by shape alone.
|
|
24
|
-
*/
|
|
25
|
-
export function isSerializedMCPServer(value) {
|
|
26
|
-
if (!isJsonSchemaObject(value)) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
if (value['version'] !== 1) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
if (typeof value['url'] !== 'string' || !isTransportKind(value['transport'])) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
if (!isFiniteEpoch(value['cachedAt'])) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
const { tools } = value;
|
|
39
|
-
return Array.isArray(tools) && tools.every(isSerializedToolDef);
|
|
40
|
-
}
|
|
41
|
-
//# sourceMappingURL=cache-types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cache-types.js","sourceRoot":"","sources":["../../src/cache/cache-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AA4CrE,SAAS,eAAe,CAAC,KAAc;IACrC,OAAO,KAAK,KAAK,gBAAgB,IAAI,KAAK,KAAK,KAAK,CAAC;AACvD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AAC3E,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAc;IACzC,OAAO,CACL,kBAAkB,CAAC,KAAK,CAAC;QACzB,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,QAAQ;QACjC,kBAAkB,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CACzC,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAc;IAClD,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,QAAQ,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC;QAC7E,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;QACtC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IACxB,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;AAClE,CAAC"}
|
package/esm/cache/serialize.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { MCPAuth } from '../auth/auth-types.js';
|
|
2
|
-
import type { McpToolDef } from '../tool-wrapper.js';
|
|
3
|
-
import type { MCPTransportKind } from '../types.js';
|
|
4
|
-
import type { SerializedMCPServer } from './cache-types.js';
|
|
5
|
-
export interface SerializeInput {
|
|
6
|
-
url: string;
|
|
7
|
-
transport: MCPTransportKind;
|
|
8
|
-
toolDefs: readonly McpToolDef[];
|
|
9
|
-
serverInfo?: {
|
|
10
|
-
name?: string;
|
|
11
|
-
version?: string;
|
|
12
|
-
};
|
|
13
|
-
capabilities?: Readonly<Record<string, unknown>>;
|
|
14
|
-
sessionId?: string;
|
|
15
|
-
auth?: MCPAuth;
|
|
16
|
-
cacheCredentials: boolean;
|
|
17
|
-
cachedAt: number;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Build a serializable snapshot. Credentials (tokens/headers, session id) are
|
|
21
|
-
* included only when `cacheCredentials` is true; otherwise the snapshot holds
|
|
22
|
-
* just the structural data needed to rebuild the tool set after a fresh auth.
|
|
23
|
-
*/
|
|
24
|
-
export declare function serializeServer(input: SerializeInput): Promise<SerializedMCPServer>;
|
|
25
|
-
//# sourceMappingURL=serialize.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../src/cache/serialize.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,mBAAmB,EAAsB,MAAM,kBAAkB,CAAC;AAGhF,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,gBAAgB,CAAC;IAC5B,QAAQ,EAAE,SAAS,UAAU,EAAE,CAAC;IAChC,UAAU,CAAC,EAAE;QACX,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,YAAY,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,gBAAgB,EAAE,OAAO,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAgDD;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAqCzF"}
|
package/esm/cache/serialize.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { resolveAuth } from '../auth/auth-resolver.js';
|
|
2
|
-
import { isFiniteEpoch } from './cache-types.js';
|
|
3
|
-
/** Pull a serializable token set from an OAuth provider, if it has tokens. */
|
|
4
|
-
async function tokensFromProvider(provider) {
|
|
5
|
-
const tokens = await provider.tokens();
|
|
6
|
-
if (tokens === undefined) {
|
|
7
|
-
return undefined;
|
|
8
|
-
}
|
|
9
|
-
const expiresInMs = typeof tokens.expires_in === 'number' ? tokens.expires_in * 1000 : undefined;
|
|
10
|
-
return {
|
|
11
|
-
accessToken: tokens.access_token,
|
|
12
|
-
...(typeof tokens.token_type === 'string' && {
|
|
13
|
-
tokenType: tokens.token_type,
|
|
14
|
-
}),
|
|
15
|
-
...(typeof tokens.refresh_token === 'string' && {
|
|
16
|
-
refreshToken: tokens.refresh_token,
|
|
17
|
-
}),
|
|
18
|
-
...(typeof tokens.scope === 'string' && {
|
|
19
|
-
scope: tokens.scope,
|
|
20
|
-
}),
|
|
21
|
-
...(expiresInMs !== undefined && {
|
|
22
|
-
expiresAt: Date.now() + expiresInMs,
|
|
23
|
-
}),
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
async function buildAuthBlock(auth) {
|
|
27
|
-
if (auth === undefined) {
|
|
28
|
-
return undefined;
|
|
29
|
-
}
|
|
30
|
-
if (auth.kind === 'oauth') {
|
|
31
|
-
const tokens = await tokensFromProvider(auth.provider);
|
|
32
|
-
return tokens !== undefined
|
|
33
|
-
? {
|
|
34
|
-
tokens,
|
|
35
|
-
}
|
|
36
|
-
: undefined;
|
|
37
|
-
}
|
|
38
|
-
const { headers } = resolveAuth(auth);
|
|
39
|
-
return Object.keys(headers).length > 0
|
|
40
|
-
? {
|
|
41
|
-
headers,
|
|
42
|
-
}
|
|
43
|
-
: undefined;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Build a serializable snapshot. Credentials (tokens/headers, session id) are
|
|
47
|
-
* included only when `cacheCredentials` is true; otherwise the snapshot holds
|
|
48
|
-
* just the structural data needed to rebuild the tool set after a fresh auth.
|
|
49
|
-
*/
|
|
50
|
-
export async function serializeServer(input) {
|
|
51
|
-
const tools = input.toolDefs.map((def) => ({
|
|
52
|
-
name: def.name,
|
|
53
|
-
...(def.description !== undefined && {
|
|
54
|
-
description: def.description,
|
|
55
|
-
}),
|
|
56
|
-
inputSchema: def.inputSchema,
|
|
57
|
-
...(def.outputSchema !== undefined && {
|
|
58
|
-
outputSchema: def.outputSchema,
|
|
59
|
-
}),
|
|
60
|
-
}));
|
|
61
|
-
const snapshot = {
|
|
62
|
-
version: 1,
|
|
63
|
-
url: input.url,
|
|
64
|
-
transport: input.transport,
|
|
65
|
-
...(input.serverInfo !== undefined && {
|
|
66
|
-
serverInfo: input.serverInfo,
|
|
67
|
-
}),
|
|
68
|
-
...(input.capabilities !== undefined && {
|
|
69
|
-
capabilities: input.capabilities,
|
|
70
|
-
}),
|
|
71
|
-
tools,
|
|
72
|
-
cachedAt: isFiniteEpoch(input.cachedAt) ? input.cachedAt : Date.now(),
|
|
73
|
-
};
|
|
74
|
-
if (input.cacheCredentials) {
|
|
75
|
-
const auth = await buildAuthBlock(input.auth);
|
|
76
|
-
if (auth !== undefined) {
|
|
77
|
-
snapshot.auth = auth;
|
|
78
|
-
}
|
|
79
|
-
if (input.sessionId !== undefined) {
|
|
80
|
-
snapshot.sessionId = input.sessionId;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return snapshot;
|
|
84
|
-
}
|
|
85
|
-
//# sourceMappingURL=serialize.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.js","sourceRoot":"","sources":["../../src/cache/serialize.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAKvD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAiBjD,8EAA8E;AAC9E,KAAK,UAAU,kBAAkB,CAC/B,QAA6B;IAE7B,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,MAAM,EAAE,CAAC;IACvC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,WAAW,GAAG,OAAO,MAAM,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IACjG,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,YAAY;QAChC,GAAG,CAAC,OAAO,MAAM,CAAC,UAAU,KAAK,QAAQ,IAAI;YAC3C,SAAS,EAAE,MAAM,CAAC,UAAU;SAC7B,CAAC;QACF,GAAG,CAAC,OAAO,MAAM,CAAC,aAAa,KAAK,QAAQ,IAAI;YAC9C,YAAY,EAAE,MAAM,CAAC,aAAa;SACnC,CAAC;QACF,GAAG,CAAC,OAAO,MAAM,CAAC,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,MAAM,QAAQ,GAAwB;QACpC,OAAO,EAAE,CAAC;QACV,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,GAAG,CAAC,KAAK,CAAC,UAAU,KAAK,SAAS,IAAI;YACpC,UAAU,EAAE,KAAK,CAAC,UAAU;SAC7B,CAAC;QACF,GAAG,CAAC,KAAK,CAAC,YAAY,KAAK,SAAS,IAAI;YACtC,YAAY,EAAE,KAAK,CAAC,YAAY;SACjC,CAAC;QACF,KAAK;QACL,QAAQ,EAAE,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;KACtE,CAAC;IAEF,IAAI,KAAK,CAAC,gBAAgB,EAAE,CAAC;QAC3B,MAAM,IAAI,GAAG,MAAM,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC9C,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC;QACvB,CAAC;QACD,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YAClC,QAAQ,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;QACvC,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/esm/elicitation.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { ElicitRequest, ElicitResult } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
-
import type { ElicitationHandler } from './types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Build the `elicitation/create` request handler registered on the MCP client.
|
|
5
|
-
* Delegates to the caller's {@link ElicitationHandler}; when none is supplied,
|
|
6
|
-
* auto-declines so a tool call awaiting input fails gracefully instead of
|
|
7
|
-
* hanging. The MCP spec forbids eliciting sensitive/PII data — that contract is
|
|
8
|
-
* the server's responsibility; callers should treat requested fields as such.
|
|
9
|
-
*/
|
|
10
|
-
export declare function makeElicitationRequestHandler(handler: ElicitationHandler | undefined): (request: ElicitRequest) => Promise<ElicitResult>;
|
|
11
|
-
//# sourceMappingURL=elicitation.d.ts.map
|
package/esm/elicitation.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"elicitation.d.ts","sourceRoot":"","sources":["../src/elicitation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAEtF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AA4BrD;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,kBAAkB,GAAG,SAAS,GACtC,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,YAAY,CAAC,CA2BnD"}
|
package/esm/elicitation.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { isJsonSchemaObject } from './schema/json-schema-guards.js';
|
|
2
|
-
/** A form-mode elicitation request carries a `requestedSchema`. */
|
|
3
|
-
function hasRequestedSchema(params) {
|
|
4
|
-
return 'requestedSchema' in params;
|
|
5
|
-
}
|
|
6
|
-
/** Narrow handler-returned content to the primitive record the spec allows. */
|
|
7
|
-
function toElicitContent(content) {
|
|
8
|
-
const out = {};
|
|
9
|
-
for (const [key, value] of Object.entries(content)) {
|
|
10
|
-
if (typeof value === 'string' ||
|
|
11
|
-
typeof value === 'number' ||
|
|
12
|
-
typeof value === 'boolean' ||
|
|
13
|
-
(Array.isArray(value) && value.every((v) => typeof v === 'string'))) {
|
|
14
|
-
out[key] = value;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return out;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Build the `elicitation/create` request handler registered on the MCP client.
|
|
21
|
-
* Delegates to the caller's {@link ElicitationHandler}; when none is supplied,
|
|
22
|
-
* auto-declines so a tool call awaiting input fails gracefully instead of
|
|
23
|
-
* hanging. The MCP spec forbids eliciting sensitive/PII data — that contract is
|
|
24
|
-
* the server's responsibility; callers should treat requested fields as such.
|
|
25
|
-
*/
|
|
26
|
-
export function makeElicitationRequestHandler(handler) {
|
|
27
|
-
return async (request) => {
|
|
28
|
-
if (handler === undefined) {
|
|
29
|
-
return {
|
|
30
|
-
action: 'decline',
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
const { params } = request;
|
|
34
|
-
const requestedSchema = hasRequestedSchema(params) ? params.requestedSchema : undefined;
|
|
35
|
-
const schema = isJsonSchemaObject(requestedSchema) ? requestedSchema : {};
|
|
36
|
-
const response = await handler({
|
|
37
|
-
message: params.message,
|
|
38
|
-
requestedSchema: schema,
|
|
39
|
-
});
|
|
40
|
-
if (response.action === 'accept') {
|
|
41
|
-
return {
|
|
42
|
-
action: 'accept',
|
|
43
|
-
content: toElicitContent(response.content),
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
action: response.action,
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
//# sourceMappingURL=elicitation.js.map
|
package/esm/elicitation.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"elicitation.js","sourceRoot":"","sources":["../src/elicitation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAMpE,mEAAmE;AACnE,SAAS,kBAAkB,CAAC,MAA+B;IAGzD,OAAO,iBAAiB,IAAI,MAAM,CAAC;AACrC,CAAC;AAED,+EAA+E;AAC/E,SAAS,eAAe,CAAC,OAAgC;IACvD,MAAM,GAAG,GAAuC,EAAE,CAAC;IACnD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACnD,IACE,OAAO,KAAK,KAAK,QAA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0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base error for all @openrouter/mcp failures.
|
|
3
|
-
*/
|
|
4
|
-
export declare class MCPError extends Error {
|
|
5
|
-
constructor(message: string, options?: {
|
|
6
|
-
cause?: unknown;
|
|
7
|
-
});
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Raised when an MCP tool call returns `isError: true` or when the result
|
|
11
|
-
* cannot be mapped to a usable model output.
|
|
12
|
-
*/
|
|
13
|
-
export declare class MCPToolCallError extends MCPError {
|
|
14
|
-
readonly toolName: string;
|
|
15
|
-
constructor(toolName: string, message: string, options?: {
|
|
16
|
-
cause?: unknown;
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Raised when a cached snapshot cannot be validated or rehydrated.
|
|
21
|
-
*/
|
|
22
|
-
export declare class MCPCacheError extends MCPError {
|
|
23
|
-
constructor(message: string, options?: {
|
|
24
|
-
cause?: unknown;
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Raised when connecting to the MCP server fails across all attempted transports.
|
|
29
|
-
*/
|
|
30
|
-
export declare class MCPConnectionError extends MCPError {
|
|
31
|
-
constructor(message: string, options?: {
|
|
32
|
-
cause?: unknown;
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
//# sourceMappingURL=errors.d.ts.map
|
package/esm/errors.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;gBAE/B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CAKJ;AAED;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,QAAQ;IAC5C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAGxB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CAMJ;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,QAAQ;gBAEvC,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CAKJ;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,QAAQ;gBAE5C,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CAKJ"}
|
package/esm/errors.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base error for all @openrouter/mcp failures.
|
|
3
|
-
*/
|
|
4
|
-
export class MCPError extends Error {
|
|
5
|
-
constructor(message, options) {
|
|
6
|
-
super(message, options);
|
|
7
|
-
this.name = 'MCPError';
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Raised when an MCP tool call returns `isError: true` or when the result
|
|
12
|
-
* cannot be mapped to a usable model output.
|
|
13
|
-
*/
|
|
14
|
-
export class MCPToolCallError extends MCPError {
|
|
15
|
-
constructor(toolName, message, options) {
|
|
16
|
-
super(message, options);
|
|
17
|
-
this.name = 'MCPToolCallError';
|
|
18
|
-
this.toolName = toolName;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Raised when a cached snapshot cannot be validated or rehydrated.
|
|
23
|
-
*/
|
|
24
|
-
export class MCPCacheError extends MCPError {
|
|
25
|
-
constructor(message, options) {
|
|
26
|
-
super(message, options);
|
|
27
|
-
this.name = 'MCPCacheError';
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Raised when connecting to the MCP server fails across all attempted transports.
|
|
32
|
-
*/
|
|
33
|
-
export class MCPConnectionError extends MCPError {
|
|
34
|
-
constructor(message, options) {
|
|
35
|
-
super(message, options);
|
|
36
|
-
this.name = 'MCPConnectionError';
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=errors.js.map
|
package/esm/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjC,YACE,OAAe,EACf,OAEC;QAED,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,gBAAiB,SAAQ,QAAQ;IAG5C,YACE,QAAgB,EAChB,OAAe,EACf,OAEC;QAED,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,QAAQ;IACzC,YACE,OAAe,EACf,OAEC;QAED,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,QAAQ;IAC9C,YACE,OAAe,EACf,OAEC;QAED,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF"}
|
package/esm/handle.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { MCPConnection } from './mcp-connection.js';
|
|
2
|
-
import type { McpToolDef } from './tool-wrapper.js';
|
|
3
|
-
import type { MCPTransportKind } from './transport-types.js';
|
|
4
|
-
import type { CreateMCPToolsOptions, MCPToolsHandle } from './types.js';
|
|
5
|
-
export declare function normalizeUrl(url: string | URL): URL;
|
|
6
|
-
/**
|
|
7
|
-
* Read the discovered tools off the live connection into our internal shape.
|
|
8
|
-
*
|
|
9
|
-
* `tools/list` is paginated: each response may carry a `nextCursor` that must be
|
|
10
|
-
* passed back as `{ cursor }` to fetch the next page. We accumulate every page so
|
|
11
|
-
* servers that paginate their tool list aren't silently truncated.
|
|
12
|
-
*/
|
|
13
|
-
export declare function listToolDefs(connection: MCPConnection, signal: AbortSignal | undefined): Promise<McpToolDef[]>;
|
|
14
|
-
interface HandleContext {
|
|
15
|
-
url: URL;
|
|
16
|
-
transport: MCPTransportKind;
|
|
17
|
-
cacheKey: string;
|
|
18
|
-
}
|
|
19
|
-
export interface MakeHandleArgs {
|
|
20
|
-
connection: MCPConnection;
|
|
21
|
-
options: CreateMCPToolsOptions;
|
|
22
|
-
context: HandleContext;
|
|
23
|
-
initialToolDefs: McpToolDef[];
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Connect, discover tools via `listTools()`, and build a handle WITHOUT
|
|
27
|
-
* consulting the cache for a hit. The cache (when present on `options`) is still
|
|
28
|
-
* written through `makeHandle`, so refreshes persist. This is the cold cache-miss
|
|
29
|
-
* path, and is also called directly by `rehydrateMCPTools`'s fallback: routing
|
|
30
|
-
* the fallback here instead of back through `createMCPTools` is what prevents the
|
|
31
|
-
* cache-fallback loop — re-reading the same snapshot would re-enter rehydrate and
|
|
32
|
-
* recurse without bound.
|
|
33
|
-
*/
|
|
34
|
-
export declare function freshConnect(options: CreateMCPToolsOptions, url: URL, cacheKey: string): Promise<MCPToolsHandle>;
|
|
35
|
-
/**
|
|
36
|
-
* Construct an {@link MCPToolsHandle} around a live connection, wiring refresh,
|
|
37
|
-
* serialize, list_changed listeners, and cache writes.
|
|
38
|
-
*/
|
|
39
|
-
export declare function makeHandle(args: MakeHandleArgs): Promise<MCPToolsHandle>;
|
|
40
|
-
export {};
|
|
41
|
-
//# sourceMappingURL=handle.d.ts.map
|
package/esm/handle.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handle.d.ts","sourceRoot":"","sources":["../src/handle.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAExE,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,GAAG,GAAG,CAEnD;AAcD;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,aAAa,EACzB,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,OAAO,CAAC,UAAU,EAAE,CAAC,CAsCvB;AAOD,UAAU,aAAa;IACrB,GAAG,EAAE,GAAG,CAAC;IACT,SAAS,EAAE,gBAAgB,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,aAAa,CAAC;IAC1B,OAAO,EAAE,qBAAqB,CAAC;IAC/B,OAAO,EAAE,aAAa,CAAC;IACvB,eAAe,EAAE,UAAU,EAAE,CAAC;CAC/B;AAED;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,qBAAqB,EAC9B,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,cAAc,CAAC,CAsCzB;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAmE9E"}
|