@graphorin/mcp 0.5.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/CHANGELOG.md +25 -0
- package/LICENSE +21 -0
- package/README.md +296 -0
- package/dist/client/adapt-result.d.ts +25 -0
- package/dist/client/adapt-result.d.ts.map +1 -0
- package/dist/client/adapt-result.js +174 -0
- package/dist/client/adapt-result.js.map +1 -0
- package/dist/client/client-handlers.js +134 -0
- package/dist/client/client-handlers.js.map +1 -0
- package/dist/client/client.d.ts +21 -0
- package/dist/client/client.d.ts.map +1 -0
- package/dist/client/client.js +358 -0
- package/dist/client/client.js.map +1 -0
- package/dist/client/defer-loading.d.ts +7 -0
- package/dist/client/defer-loading.d.ts.map +1 -0
- package/dist/client/defer-loading.js +81 -0
- package/dist/client/defer-loading.js.map +1 -0
- package/dist/client/inbound-filters.js +65 -0
- package/dist/client/inbound-filters.js.map +1 -0
- package/dist/client/index.d.ts +7 -0
- package/dist/client/index.js +7 -0
- package/dist/client/mcp-resource-reader.d.ts +22 -0
- package/dist/client/mcp-resource-reader.d.ts.map +1 -0
- package/dist/client/mcp-resource-reader.js +113 -0
- package/dist/client/mcp-resource-reader.js.map +1 -0
- package/dist/client/pinning.js +41 -0
- package/dist/client/pinning.js.map +1 -0
- package/dist/client/to-tools.d.ts +41 -0
- package/dist/client/to-tools.d.ts.map +1 -0
- package/dist/client/to-tools.js +125 -0
- package/dist/client/to-tools.js.map +1 -0
- package/dist/client/transport-factory.js +86 -0
- package/dist/client/transport-factory.js.map +1 -0
- package/dist/client/types.d.ts +353 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/errors/index.d.ts +120 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +88 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/helpers/identity.d.ts +22 -0
- package/dist/helpers/identity.d.ts.map +1 -0
- package/dist/helpers/identity.js +85 -0
- package/dist/helpers/identity.js.map +1 -0
- package/dist/helpers/index.d.ts +3 -0
- package/dist/helpers/index.js +4 -0
- package/dist/helpers/validate-config.d.ts +16 -0
- package/dist/helpers/validate-config.d.ts.map +1 -0
- package/dist/helpers/validate-config.js +61 -0
- package/dist/helpers/validate-config.js.map +1 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -0
- package/dist/oauth/bridge.d.ts +59 -0
- package/dist/oauth/bridge.d.ts.map +1 -0
- package/dist/oauth/bridge.js +75 -0
- package/dist/oauth/bridge.js.map +1 -0
- package/dist/oauth/index.d.ts +3 -0
- package/dist/oauth/index.js +4 -0
- package/dist/oauth/library.d.ts +23 -0
- package/dist/oauth/library.d.ts.map +1 -0
- package/dist/oauth/library.js +27 -0
- package/dist/oauth/library.js.map +1 -0
- package/dist/registry/json-schema.js +215 -0
- package/dist/registry/json-schema.js.map +1 -0
- package/dist/transport/index.d.ts +4 -0
- package/dist/transport/index.js +4 -0
- package/dist/transport/types.d.ts +93 -0
- package/dist/transport/types.d.ts.map +1 -0
- package/package.json +105 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
2
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
3
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
4
|
+
|
|
5
|
+
//#region src/client/transport-factory.ts
|
|
6
|
+
/**
|
|
7
|
+
* Factory that materialises a `@modelcontextprotocol/sdk` `Transport`
|
|
8
|
+
* instance from a {@link MCPTransportConfig}.
|
|
9
|
+
*
|
|
10
|
+
* The factory is small on purpose: every MCP-spec evolution (new
|
|
11
|
+
* transport, transport-specific option, transport-level header
|
|
12
|
+
* convention) lands here so the higher-level {@link createMCPClient}
|
|
13
|
+
* stays untouched.
|
|
14
|
+
*
|
|
15
|
+
* @packageDocumentation
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Wrap a `fetch` implementation so the live `Authorization` header is
|
|
19
|
+
* re-resolved and injected on **every** outgoing request. The wrapper
|
|
20
|
+
* always overwrites a caller-supplied `Authorization` header so the
|
|
21
|
+
* provider stays the single source of truth (refresh-ahead from
|
|
22
|
+
* {@link createOAuthAuthorizationProvider} fires per request).
|
|
23
|
+
*/
|
|
24
|
+
function authWrappedFetch(baseFetch, auth) {
|
|
25
|
+
return (async (input, init) => {
|
|
26
|
+
const header = await auth.resolveHeader();
|
|
27
|
+
const headers = new Headers(init?.headers);
|
|
28
|
+
headers.set("Authorization", header);
|
|
29
|
+
return baseFetch(input, {
|
|
30
|
+
...init,
|
|
31
|
+
headers
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Build a SDK `Transport` from a {@link MCPTransportConfig}.
|
|
37
|
+
*
|
|
38
|
+
* When an `auth` source is supplied (HTTP transports only) the factory
|
|
39
|
+
* installs a per-request fetch-wrapper that re-resolves the
|
|
40
|
+
* `Authorization` header on every outgoing call — this is the seam that
|
|
41
|
+
* makes a long-lived agent session survive OAuth token expiry without
|
|
42
|
+
* re-creating the client.
|
|
43
|
+
*
|
|
44
|
+
* @stable
|
|
45
|
+
*/
|
|
46
|
+
function buildTransport(config, options) {
|
|
47
|
+
switch (config.kind) {
|
|
48
|
+
case "stdio": {
|
|
49
|
+
const stdio = new StdioClientTransport({
|
|
50
|
+
command: config.command,
|
|
51
|
+
...config.args === void 0 ? {} : { args: [...config.args] },
|
|
52
|
+
...config.env === void 0 ? {} : { env: { ...config.env } },
|
|
53
|
+
...config.cwd === void 0 ? {} : { cwd: config.cwd },
|
|
54
|
+
...config.stderr === void 0 ? {} : { stderr: config.stderr }
|
|
55
|
+
});
|
|
56
|
+
return Object.freeze({ transport: stdio });
|
|
57
|
+
}
|
|
58
|
+
case "streamable-http": {
|
|
59
|
+
const url = typeof config.url === "string" ? new URL(config.url) : config.url;
|
|
60
|
+
const headers = { ...config.headers ?? {} };
|
|
61
|
+
const baseFetch = config.fetch ?? fetch;
|
|
62
|
+
const fetchImpl = options?.auth === void 0 ? config.fetch : authWrappedFetch(baseFetch, options.auth);
|
|
63
|
+
const transport = new StreamableHTTPClientTransport(url, {
|
|
64
|
+
...fetchImpl === void 0 ? {} : { fetch: fetchImpl },
|
|
65
|
+
requestInit: { headers },
|
|
66
|
+
...config.sessionId === void 0 ? {} : { sessionId: config.sessionId }
|
|
67
|
+
});
|
|
68
|
+
return Object.freeze({ transport });
|
|
69
|
+
}
|
|
70
|
+
case "sse": {
|
|
71
|
+
const url = typeof config.url === "string" ? new URL(config.url) : config.url;
|
|
72
|
+
const headers = { ...config.headers ?? {} };
|
|
73
|
+
const baseFetch = config.fetch ?? fetch;
|
|
74
|
+
const fetchImpl = options?.auth === void 0 ? config.fetch : authWrappedFetch(baseFetch, options.auth);
|
|
75
|
+
const transport = new SSEClientTransport(url, {
|
|
76
|
+
...fetchImpl === void 0 ? {} : { fetch: fetchImpl },
|
|
77
|
+
requestInit: { headers }
|
|
78
|
+
});
|
|
79
|
+
return Object.freeze({ transport });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//#endregion
|
|
85
|
+
export { buildTransport };
|
|
86
|
+
//# sourceMappingURL=transport-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport-factory.js","names":["stdio: Transport","transport: Transport"],"sources":["../../src/client/transport-factory.ts"],"sourcesContent":["/**\n * Factory that materialises a `@modelcontextprotocol/sdk` `Transport`\n * instance from a {@link MCPTransportConfig}.\n *\n * The factory is small on purpose: every MCP-spec evolution (new\n * transport, transport-specific option, transport-level header\n * convention) lands here so the higher-level {@link createMCPClient}\n * stays untouched.\n *\n * @packageDocumentation\n */\n\nimport { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';\nimport { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';\nimport { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';\nimport type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';\n\nimport type { MCPTransportConfig } from '../transport/types.js';\n\n/**\n * Outcome of the transport build, including the SDK transport\n * instance and the helper hooks the client needs to forward to the\n * SDK.\n */\nexport interface BuiltTransport {\n readonly transport: Transport;\n readonly disposeBeforeStart?: () => Promise<void>;\n}\n\n/**\n * Live source of the outbound `Authorization` header for the HTTP\n * transports. The bridge's `OAuthAuthorizationProvider` satisfies this\n * structurally (its `resolveHeader()` already returns the full\n * `Bearer <token>` value); a static `bearerToken` is wrapped into a\n * constant resolver by {@link createMCPClient}.\n *\n * @internal\n */\nexport interface TransportAuthSource {\n /** Resolve the full `Authorization` header value (e.g. `Bearer abc`). */\n resolveHeader(): Promise<string> | string;\n}\n\n/**\n * Wrap a `fetch` implementation so the live `Authorization` header is\n * re-resolved and injected on **every** outgoing request. The wrapper\n * always overwrites a caller-supplied `Authorization` header so the\n * provider stays the single source of truth (refresh-ahead from\n * {@link createOAuthAuthorizationProvider} fires per request).\n */\nfunction authWrappedFetch(baseFetch: typeof fetch, auth: TransportAuthSource): typeof fetch {\n return (async (input: Parameters<typeof fetch>[0], init?: RequestInit): Promise<Response> => {\n const header = await auth.resolveHeader();\n const headers = new Headers(init?.headers);\n headers.set('Authorization', header);\n return baseFetch(input, { ...init, headers });\n }) as typeof fetch;\n}\n\n/**\n * Build a SDK `Transport` from a {@link MCPTransportConfig}.\n *\n * When an `auth` source is supplied (HTTP transports only) the factory\n * installs a per-request fetch-wrapper that re-resolves the\n * `Authorization` header on every outgoing call — this is the seam that\n * makes a long-lived agent session survive OAuth token expiry without\n * re-creating the client.\n *\n * @stable\n */\nexport function buildTransport(\n config: MCPTransportConfig,\n options?: { readonly auth?: TransportAuthSource },\n): BuiltTransport {\n switch (config.kind) {\n case 'stdio': {\n const stdio: Transport = new StdioClientTransport({\n command: config.command,\n ...(config.args === undefined ? {} : { args: [...config.args] }),\n ...(config.env === undefined ? {} : { env: { ...config.env } }),\n ...(config.cwd === undefined ? {} : { cwd: config.cwd }),\n ...(config.stderr === undefined ? {} : { stderr: config.stderr }),\n });\n return Object.freeze({ transport: stdio });\n }\n case 'streamable-http': {\n const url = typeof config.url === 'string' ? new URL(config.url) : config.url;\n const headers = { ...(config.headers ?? {}) };\n const baseFetch = config.fetch ?? fetch;\n const fetchImpl =\n options?.auth === undefined ? config.fetch : authWrappedFetch(baseFetch, options.auth);\n // The SDK class's `sessionId: string | undefined` getter is\n // structurally narrower than `Transport.sessionId?: string` in\n // strict mode; route through `unknown` to keep the public\n // surface clean.\n const sdkTransport = new StreamableHTTPClientTransport(url, {\n ...(fetchImpl === undefined ? {} : { fetch: fetchImpl }),\n requestInit: { headers },\n ...(config.sessionId === undefined ? {} : { sessionId: config.sessionId }),\n });\n const transport = sdkTransport as unknown as Transport;\n return Object.freeze({ transport });\n }\n case 'sse': {\n const url = typeof config.url === 'string' ? new URL(config.url) : config.url;\n const headers = { ...(config.headers ?? {}) };\n const baseFetch = config.fetch ?? fetch;\n const fetchImpl =\n options?.auth === undefined ? config.fetch : authWrappedFetch(baseFetch, options.auth);\n const transport: Transport = new SSEClientTransport(url, {\n ...(fetchImpl === undefined ? {} : { fetch: fetchImpl }),\n requestInit: { headers },\n });\n return Object.freeze({ transport });\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAS,iBAAiB,WAAyB,MAAyC;AAC1F,SAAQ,OAAO,OAAoC,SAA0C;EAC3F,MAAM,SAAS,MAAM,KAAK,eAAe;EACzC,MAAM,UAAU,IAAI,QAAQ,MAAM,QAAQ;AAC1C,UAAQ,IAAI,iBAAiB,OAAO;AACpC,SAAO,UAAU,OAAO;GAAE,GAAG;GAAM;GAAS,CAAC;;;;;;;;;;;;;;AAejD,SAAgB,eACd,QACA,SACgB;AAChB,SAAQ,OAAO,MAAf;EACE,KAAK,SAAS;GACZ,MAAMA,QAAmB,IAAI,qBAAqB;IAChD,SAAS,OAAO;IAChB,GAAI,OAAO,SAAS,SAAY,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,OAAO,KAAK,EAAE;IAC/D,GAAI,OAAO,QAAQ,SAAY,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,OAAO,KAAK,EAAE;IAC9D,GAAI,OAAO,QAAQ,SAAY,EAAE,GAAG,EAAE,KAAK,OAAO,KAAK;IACvD,GAAI,OAAO,WAAW,SAAY,EAAE,GAAG,EAAE,QAAQ,OAAO,QAAQ;IACjE,CAAC;AACF,UAAO,OAAO,OAAO,EAAE,WAAW,OAAO,CAAC;;EAE5C,KAAK,mBAAmB;GACtB,MAAM,MAAM,OAAO,OAAO,QAAQ,WAAW,IAAI,IAAI,OAAO,IAAI,GAAG,OAAO;GAC1E,MAAM,UAAU,EAAE,GAAI,OAAO,WAAW,EAAE,EAAG;GAC7C,MAAM,YAAY,OAAO,SAAS;GAClC,MAAM,YACJ,SAAS,SAAS,SAAY,OAAO,QAAQ,iBAAiB,WAAW,QAAQ,KAAK;GAUxF,MAAM,YALe,IAAI,8BAA8B,KAAK;IAC1D,GAAI,cAAc,SAAY,EAAE,GAAG,EAAE,OAAO,WAAW;IACvD,aAAa,EAAE,SAAS;IACxB,GAAI,OAAO,cAAc,SAAY,EAAE,GAAG,EAAE,WAAW,OAAO,WAAW;IAC1E,CAAC;AAEF,UAAO,OAAO,OAAO,EAAE,WAAW,CAAC;;EAErC,KAAK,OAAO;GACV,MAAM,MAAM,OAAO,OAAO,QAAQ,WAAW,IAAI,IAAI,OAAO,IAAI,GAAG,OAAO;GAC1E,MAAM,UAAU,EAAE,GAAI,OAAO,WAAW,EAAE,EAAG;GAC7C,MAAM,YAAY,OAAO,SAAS;GAClC,MAAM,YACJ,SAAS,SAAS,SAAY,OAAO,QAAQ,iBAAiB,WAAW,QAAQ,KAAK;GACxF,MAAMC,YAAuB,IAAI,mBAAmB,KAAK;IACvD,GAAI,cAAc,SAAY,EAAE,GAAG,EAAE,OAAO,WAAW;IACvD,aAAa,EAAE,SAAS;IACzB,CAAC;AACF,UAAO,OAAO,OAAO,EAAE,WAAW,CAAC"}
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { MCPTransportConfig, ServerIdentity } from "../transport/types.js";
|
|
2
|
+
import { OAuthAuthorizationProvider } from "../oauth/bridge.js";
|
|
3
|
+
import { CollisionStrategy } from "@graphorin/tools/registry";
|
|
4
|
+
import { InboundSanitizationPolicy, ModelHint, ModelSpec, SideEffectClass, Tool, TruncationStrategy } from "@graphorin/core";
|
|
5
|
+
|
|
6
|
+
//#region src/client/types.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Options accepted by {@link createMCPClient}.
|
|
10
|
+
*
|
|
11
|
+
* @stable
|
|
12
|
+
*/
|
|
13
|
+
interface CreateMCPClientOptions {
|
|
14
|
+
readonly transport: MCPTransportConfig;
|
|
15
|
+
/**
|
|
16
|
+
* Pre-built OAuth provider that resolves the bearer header on every
|
|
17
|
+
* request. Mutually exclusive with {@link bearerToken}.
|
|
18
|
+
*/
|
|
19
|
+
readonly authProvider?: OAuthAuthorizationProvider;
|
|
20
|
+
/** Pre-shared bearer token (rare; prefer {@link authProvider}). */
|
|
21
|
+
readonly bearerToken?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Per-client default for the strategy-aware tool registry. Falls
|
|
24
|
+
* through to the per-call value on {@link MCPClient.toTools}.
|
|
25
|
+
*
|
|
26
|
+
* @default `'auto-prefix'`
|
|
27
|
+
*/
|
|
28
|
+
readonly collisionStrategy?: CollisionStrategy;
|
|
29
|
+
/** Per-client priority value used by the `'priority'` strategy. */
|
|
30
|
+
readonly priority?: number;
|
|
31
|
+
/** Operator-supplied server identity overrides. */
|
|
32
|
+
readonly serverInfoName?: string;
|
|
33
|
+
/** Operator-supplied logger. */
|
|
34
|
+
readonly logger?: (level: 'debug' | 'info' | 'warn' | 'error', message: string, fields?: Record<string, unknown>) => void;
|
|
35
|
+
/** Operator-supplied client name advertised to the server on `initialize`. */
|
|
36
|
+
readonly clientName?: string;
|
|
37
|
+
/** Operator-supplied client version advertised to the server on `initialize`. */
|
|
38
|
+
readonly clientVersion?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Skip the deprecated-transport WARN log. Useful for tests + the
|
|
41
|
+
* standalone server's startup banner.
|
|
42
|
+
*
|
|
43
|
+
* @default `false`
|
|
44
|
+
*/
|
|
45
|
+
readonly suppressDeprecatedTransportWarning?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Handler for server-initiated **elicitation** (`elicitation/create`)
|
|
48
|
+
* requests — the server asks the human for structured input mid-call
|
|
49
|
+
* (WI-13 / P2-2). When provided, the client advertises the
|
|
50
|
+
* `elicitation` capability and routes requests here; back it with a
|
|
51
|
+
* HITL surface (e.g. a CLI prompt or the agent's approval channel).
|
|
52
|
+
* When omitted, the capability is **not** advertised and a conforming
|
|
53
|
+
* server will not elicit (gated; no implicit prompting).
|
|
54
|
+
*
|
|
55
|
+
* Note: an elicitation arrives while a `callTool(...)` JSON-RPC request
|
|
56
|
+
* is in flight, so the handler resolves in-process — it does not
|
|
57
|
+
* durably suspend a Graphorin run. Durable-suspend elicitation across
|
|
58
|
+
* the request lifetime is a follow-up.
|
|
59
|
+
*/
|
|
60
|
+
readonly elicitation?: MCPElicitationHandler;
|
|
61
|
+
/**
|
|
62
|
+
* Handler for server-initiated **sampling** (`sampling/createMessage`)
|
|
63
|
+
* requests — the server asks the client's model to generate a
|
|
64
|
+
* completion (WI-13 / P2-2). When provided, the client advertises the
|
|
65
|
+
* `sampling` capability and routes requests here; back it with a
|
|
66
|
+
* `Provider`. The request messages are **MCP-derived (untrusted)**, so
|
|
67
|
+
* the backing provider should apply the usual sensitivity/redaction
|
|
68
|
+
* middleware. When omitted, the capability is **not** advertised
|
|
69
|
+
* (gated).
|
|
70
|
+
*/
|
|
71
|
+
readonly sampling?: MCPSamplingHandler;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Server-initiated elicitation request surfaced to the operator's HITL
|
|
75
|
+
* handler.
|
|
76
|
+
*
|
|
77
|
+
* @stable
|
|
78
|
+
*/
|
|
79
|
+
interface MCPElicitationRequest {
|
|
80
|
+
/** Human-readable prompt the server wants answered. */
|
|
81
|
+
readonly message: string;
|
|
82
|
+
/** JSON-Schema-like shape (`{ type: 'object', properties, required? }`) for the requested input. */
|
|
83
|
+
readonly requestedSchema: Readonly<Record<string, unknown>>;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Operator response to an {@link MCPElicitationRequest}. `accept` returns
|
|
87
|
+
* the collected flat values; `decline`/`cancel` carry no content.
|
|
88
|
+
*
|
|
89
|
+
* @stable
|
|
90
|
+
*/
|
|
91
|
+
type MCPElicitationResult = {
|
|
92
|
+
readonly action: 'accept';
|
|
93
|
+
readonly content?: Readonly<Record<string, string | number | boolean | ReadonlyArray<string>>>;
|
|
94
|
+
} | {
|
|
95
|
+
readonly action: 'decline';
|
|
96
|
+
} | {
|
|
97
|
+
readonly action: 'cancel';
|
|
98
|
+
};
|
|
99
|
+
/** Handler for server-initiated elicitation requests. */
|
|
100
|
+
type MCPElicitationHandler = (request: MCPElicitationRequest, opts: {
|
|
101
|
+
readonly signal?: AbortSignal;
|
|
102
|
+
}) => MCPElicitationResult | Promise<MCPElicitationResult>;
|
|
103
|
+
/** A single content block carried by a sampling message or result. */
|
|
104
|
+
type MCPSamplingContent = {
|
|
105
|
+
readonly type: 'text';
|
|
106
|
+
readonly text: string;
|
|
107
|
+
} | {
|
|
108
|
+
readonly type: 'image';
|
|
109
|
+
readonly data: string;
|
|
110
|
+
readonly mimeType: string;
|
|
111
|
+
} | {
|
|
112
|
+
readonly type: 'audio';
|
|
113
|
+
readonly data: string;
|
|
114
|
+
readonly mimeType: string;
|
|
115
|
+
};
|
|
116
|
+
/** A message in a sampling conversation. */
|
|
117
|
+
interface MCPSamplingMessage {
|
|
118
|
+
readonly role: 'user' | 'assistant';
|
|
119
|
+
/**
|
|
120
|
+
* Every content block of the SDK message (MC-13) — previously only
|
|
121
|
+
* the FIRST block survived, silently dropping e.g. the image in a
|
|
122
|
+
* text+image message before it reached the operator's handler.
|
|
123
|
+
*/
|
|
124
|
+
readonly content: ReadonlyArray<MCPSamplingContent>;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Server-initiated sampling request surfaced to the operator's handler
|
|
128
|
+
* (typically backed by a `Provider`).
|
|
129
|
+
*
|
|
130
|
+
* @stable
|
|
131
|
+
*/
|
|
132
|
+
interface MCPSamplingRequest {
|
|
133
|
+
readonly messages: ReadonlyArray<MCPSamplingMessage>;
|
|
134
|
+
readonly systemPrompt?: string;
|
|
135
|
+
readonly maxTokens: number;
|
|
136
|
+
readonly temperature?: number;
|
|
137
|
+
readonly stopSequences?: ReadonlyArray<string>;
|
|
138
|
+
readonly modelPreferences?: {
|
|
139
|
+
readonly hints?: ReadonlyArray<{
|
|
140
|
+
readonly name?: string;
|
|
141
|
+
}>;
|
|
142
|
+
readonly costPriority?: number;
|
|
143
|
+
readonly speedPriority?: number;
|
|
144
|
+
readonly intelligencePriority?: number;
|
|
145
|
+
};
|
|
146
|
+
readonly includeContext?: 'none' | 'thisServer' | 'allServers';
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Operator response to an {@link MCPSamplingRequest}.
|
|
150
|
+
*
|
|
151
|
+
* @stable
|
|
152
|
+
*/
|
|
153
|
+
interface MCPSamplingResult {
|
|
154
|
+
readonly role: 'assistant';
|
|
155
|
+
readonly content: MCPSamplingContent;
|
|
156
|
+
readonly model: string;
|
|
157
|
+
readonly stopReason?: string;
|
|
158
|
+
}
|
|
159
|
+
/** Handler for server-initiated sampling requests. */
|
|
160
|
+
type MCPSamplingHandler = (request: MCPSamplingRequest, opts: {
|
|
161
|
+
readonly signal?: AbortSignal;
|
|
162
|
+
}) => MCPSamplingResult | Promise<MCPSamplingResult>;
|
|
163
|
+
/**
|
|
164
|
+
* Per-MCP-server `toTools()` options.
|
|
165
|
+
*
|
|
166
|
+
* @stable
|
|
167
|
+
*/
|
|
168
|
+
interface MCPToToolsOptions {
|
|
169
|
+
/** Filter the produced tools. */
|
|
170
|
+
readonly filter?: (tool: MCPToolDefinition) => boolean;
|
|
171
|
+
/** Tool-name namespace prepended to every produced tool. */
|
|
172
|
+
readonly namespace?: string;
|
|
173
|
+
/**
|
|
174
|
+
* Per-server inbound prompt-injection sanitization policy override.
|
|
175
|
+
* Defaults to `'detect-and-strip-and-wrap'` for MCP-derived tools.
|
|
176
|
+
*/
|
|
177
|
+
readonly inboundSanitization?: InboundSanitizationPolicy;
|
|
178
|
+
/**
|
|
179
|
+
* Per-call timeout (ms) applied to every adapted tool's
|
|
180
|
+
* `client.callTool` invocation (MC-3/MC-5). Default: the SDK default.
|
|
181
|
+
*/
|
|
182
|
+
readonly callTimeoutMs?: number;
|
|
183
|
+
/**
|
|
184
|
+
* Operator-pinned definition fingerprints by MCP tool name (MC-6) —
|
|
185
|
+
* the `__definitionHash` stamped on a previously approved snapshot.
|
|
186
|
+
* A mismatch means the server changed the definition behind the name.
|
|
187
|
+
*/
|
|
188
|
+
readonly pinnedFingerprints?: Readonly<Record<string, string>>;
|
|
189
|
+
/**
|
|
190
|
+
* What to do on a pinned-fingerprint mismatch (MC-6). `'warn'`
|
|
191
|
+
* (default) audits `mcp.tools.pin-mismatch.total` and continues;
|
|
192
|
+
* `'reject'` throws `MCPToolPinningError`.
|
|
193
|
+
*/
|
|
194
|
+
readonly onPinMismatch?: 'warn' | 'reject';
|
|
195
|
+
/**
|
|
196
|
+
* Per-server `defer_loading` override. When unset and
|
|
197
|
+
* `listTools()` returns more than `deferLoadingThreshold` entries
|
|
198
|
+
* the auto-default flips deferral on for every tool from this
|
|
199
|
+
* server.
|
|
200
|
+
*/
|
|
201
|
+
readonly defer_loading?: boolean;
|
|
202
|
+
/** Auto-default trigger threshold. Defaults to `10`. */
|
|
203
|
+
readonly deferLoadingThreshold?: number;
|
|
204
|
+
/** Per-server token cap override applied at registration. */
|
|
205
|
+
readonly maxResultTokens?: number;
|
|
206
|
+
/** Per-server truncation strategy override applied at registration. */
|
|
207
|
+
readonly truncationStrategy?: TruncationStrategy;
|
|
208
|
+
/** Tool-name -> per-tool side-effect class override map. */
|
|
209
|
+
readonly sideEffectClassByTool?: Readonly<Record<string, SideEffectClass>>;
|
|
210
|
+
/** Tool-name -> per-tool preferred-model override map. */
|
|
211
|
+
readonly preferredModelByTool?: Readonly<Record<string, ModelHint | ModelSpec>>;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Single MCP tool descriptor returned by `listTools()`. Mirrors the
|
|
215
|
+
* MCP spec subset we consume.
|
|
216
|
+
*
|
|
217
|
+
* @stable
|
|
218
|
+
*/
|
|
219
|
+
interface MCPToolDefinition {
|
|
220
|
+
readonly name: string;
|
|
221
|
+
readonly description: string;
|
|
222
|
+
readonly inputSchema: Readonly<Record<string, unknown>>;
|
|
223
|
+
readonly outputSchema?: Readonly<Record<string, unknown>>;
|
|
224
|
+
readonly title?: string;
|
|
225
|
+
}
|
|
226
|
+
/** Resource descriptor returned by `listResources()`. */
|
|
227
|
+
interface MCPResourceDefinition {
|
|
228
|
+
readonly uri: string;
|
|
229
|
+
readonly name?: string;
|
|
230
|
+
readonly description?: string;
|
|
231
|
+
readonly mimeType?: string;
|
|
232
|
+
}
|
|
233
|
+
/** Prompt descriptor returned by `listPrompts()`. */
|
|
234
|
+
interface MCPPromptDefinition {
|
|
235
|
+
readonly name: string;
|
|
236
|
+
readonly description?: string;
|
|
237
|
+
readonly arguments?: ReadonlyArray<{
|
|
238
|
+
readonly name: string;
|
|
239
|
+
readonly description?: string;
|
|
240
|
+
readonly required?: boolean;
|
|
241
|
+
}>;
|
|
242
|
+
}
|
|
243
|
+
/** Resource content returned by `readResource(...)`. */
|
|
244
|
+
interface MCPResourceContent {
|
|
245
|
+
readonly uri: string;
|
|
246
|
+
readonly mimeType?: string;
|
|
247
|
+
readonly text?: string;
|
|
248
|
+
readonly blob?: string;
|
|
249
|
+
}
|
|
250
|
+
/** Tool result envelope returned by `callTool(...)`. */
|
|
251
|
+
interface MCPCallToolResult {
|
|
252
|
+
readonly content: ReadonlyArray<MCPContentPart>;
|
|
253
|
+
readonly structuredContent?: Readonly<Record<string, unknown>>;
|
|
254
|
+
readonly isError?: boolean;
|
|
255
|
+
}
|
|
256
|
+
/** Discriminated union over MCP content parts. */
|
|
257
|
+
type MCPContentPart = {
|
|
258
|
+
readonly type: 'text';
|
|
259
|
+
readonly text: string;
|
|
260
|
+
} | {
|
|
261
|
+
readonly type: 'image';
|
|
262
|
+
readonly data: string;
|
|
263
|
+
readonly mimeType: string;
|
|
264
|
+
} | {
|
|
265
|
+
readonly type: 'audio';
|
|
266
|
+
readonly data: string;
|
|
267
|
+
readonly mimeType: string;
|
|
268
|
+
} | {
|
|
269
|
+
readonly type: 'resource';
|
|
270
|
+
readonly resource: {
|
|
271
|
+
readonly uri: string;
|
|
272
|
+
readonly text?: string;
|
|
273
|
+
readonly blob?: string;
|
|
274
|
+
readonly mimeType?: string;
|
|
275
|
+
};
|
|
276
|
+
} | {
|
|
277
|
+
/**
|
|
278
|
+
* A link to a resource the server can serve on demand (MCP
|
|
279
|
+
* `resource_link`). Unlike an embedded `resource`, the body is
|
|
280
|
+
* **not** inlined: the adapter surfaces a preview + the `uri` as a
|
|
281
|
+
* result handle so the model fetches it via `read_result` only
|
|
282
|
+
* when needed (WI-13 / P2-2, ties to WI-10 result handles).
|
|
283
|
+
*/
|
|
284
|
+
readonly type: 'resource_link';
|
|
285
|
+
readonly uri: string;
|
|
286
|
+
readonly name: string;
|
|
287
|
+
readonly title?: string;
|
|
288
|
+
readonly description?: string;
|
|
289
|
+
readonly mimeType?: string;
|
|
290
|
+
readonly size?: number;
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* Public surface of an active MCP client.
|
|
294
|
+
*
|
|
295
|
+
* @stable
|
|
296
|
+
*/
|
|
297
|
+
interface MCPClient {
|
|
298
|
+
/** Stable identifier — derived from the transport. */
|
|
299
|
+
readonly id: string;
|
|
300
|
+
/** Server-advertised information from the `initialize` handshake. */
|
|
301
|
+
readonly serverInfo: {
|
|
302
|
+
readonly name: string;
|
|
303
|
+
readonly version: string;
|
|
304
|
+
};
|
|
305
|
+
/** Server identity descriptor consumed by the tool-registry resolver. */
|
|
306
|
+
readonly serverIdentity: ServerIdentity;
|
|
307
|
+
/** Per-client default collision strategy. */
|
|
308
|
+
readonly collisionStrategy: CollisionStrategy;
|
|
309
|
+
/** Per-client priority value used by the `'priority'` strategy. */
|
|
310
|
+
readonly priority?: number;
|
|
311
|
+
/**
|
|
312
|
+
* Whether the Streamable HTTP server assigned an `Mcp-Session-Id`
|
|
313
|
+
* at `initialize` time (MC-9). A session id means stateful routing —
|
|
314
|
+
* it is NOT a replay guarantee: per the Streamable HTTP spec,
|
|
315
|
+
* event replay is the SERVER's responsibility, and the SDK
|
|
316
|
+
* transport already auto-reconnects with `Last-Event-ID` when the
|
|
317
|
+
* server supports it.
|
|
318
|
+
*/
|
|
319
|
+
readonly sessionIdPresent: boolean;
|
|
320
|
+
/** @deprecated Alias of {@link sessionIdPresent} — same value, misleading name. */
|
|
321
|
+
readonly resumable: boolean;
|
|
322
|
+
listTools(opts?: {
|
|
323
|
+
signal?: AbortSignal;
|
|
324
|
+
}): Promise<ReadonlyArray<MCPToolDefinition>>;
|
|
325
|
+
listResources(opts?: {
|
|
326
|
+
signal?: AbortSignal;
|
|
327
|
+
}): Promise<ReadonlyArray<MCPResourceDefinition>>;
|
|
328
|
+
listPrompts(opts?: {
|
|
329
|
+
signal?: AbortSignal;
|
|
330
|
+
}): Promise<ReadonlyArray<MCPPromptDefinition>>;
|
|
331
|
+
callTool(name: string, args: unknown, opts?: {
|
|
332
|
+
signal?: AbortSignal;
|
|
333
|
+
timeoutMs?: number;
|
|
334
|
+
}): Promise<MCPCallToolResult>;
|
|
335
|
+
readResource(uri: string, opts?: {
|
|
336
|
+
signal?: AbortSignal;
|
|
337
|
+
}): Promise<MCPResourceContent>;
|
|
338
|
+
getPrompt(name: string, args?: unknown, opts?: {
|
|
339
|
+
signal?: AbortSignal;
|
|
340
|
+
}): Promise<{
|
|
341
|
+
readonly messages: ReadonlyArray<MCPPromptMessage>;
|
|
342
|
+
}>;
|
|
343
|
+
toTools(opts?: MCPToToolsOptions): Promise<ReadonlyArray<Tool>>;
|
|
344
|
+
close(): Promise<void>;
|
|
345
|
+
}
|
|
346
|
+
/** Single prompt message returned by `getPrompt(...)`. */
|
|
347
|
+
interface MCPPromptMessage {
|
|
348
|
+
readonly role: 'user' | 'assistant';
|
|
349
|
+
readonly content: MCPContentPart;
|
|
350
|
+
}
|
|
351
|
+
//#endregion
|
|
352
|
+
export { CreateMCPClientOptions, MCPCallToolResult, MCPClient, MCPContentPart, MCPElicitationHandler, MCPElicitationRequest, MCPElicitationResult, MCPPromptDefinition, MCPPromptMessage, MCPResourceContent, MCPResourceDefinition, MCPSamplingContent, MCPSamplingHandler, MCPSamplingMessage, MCPSamplingRequest, MCPSamplingResult, MCPToToolsOptions, MCPToolDefinition };
|
|
353
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/client/types.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AAgGA;AAaY,UApFK,sBAAA,CAoFe;EAImB,SAAA,SAAA,EAvF7B,kBAuF6B;EAA3C;;;AAOR;EACW,SAAA,YAAA,CAAA,EA1Fe,0BA0Ff;EACiB;EACvB,SAAA,WAAA,CAAA,EAAA,MAAA;EAA+B;;;AAGpC;AAMA;AAgBA;EACmC,SAAA,iBAAA,CAAA,EA7GJ,iBA6GI;EAAd;EAIM,SAAA,QAAA,CAAA,EAAA,MAAA;EAEN;EAAa,SAAA,cAAA,CAAA,EAAA,MAAA;EAajB;EAQL,SAAA,MAAA,CAAA,EAAA,CAAA,KAAkB,EAAA,OAAA,GAAA,MAAA,GAAA,MAAA,GAAA,OAAA,EAAA,OAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EA/HjB,MA+HiB,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,GAAA,IAAA;EACnB;EACiB,SAAA,UAAA,CAAA,EAAA,MAAA;EACvB;EAA4B,SAAA,aAAA,CAAA,EAAA,MAAA;EAAR;;AAOzB;;;;EAoBgC,SAAA,kCAAA,CAAA,EAAA,OAAA;EAmBA;;;;;;;;;AAahC;;;;;EAIkC,SAAA,WAAA,CAAA,EAtKT,qBAsKS;EAKjB;AAQjB;AAWA;AAQA;;;;;;AAOA;EAmCiB,SAAA,QAAS,CAAA,EArOJ,kBAqOI;;;;;;;;AAwB8C,UApPvD,qBAAA,CAoPuD;EAAd;EAAR,SAAA,OAAA,EAAA,MAAA;EAClB;EAAsC,SAAA,eAAA,EAjP1C,QAiP0C,CAjPjC,MAiPiC,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA;;;;;;;;AAMR,KA9OlD,oBAAA,GA8OkD;EAIxC,SAAA,MAAA,EAAA,QAAA;EAC0B,SAAA,OAAA,CAAA,EAhPvB,QAgPuB,CA/OxC,MA+OwC,CAAA,MAAA,EAAA,MAAA,GAAA,MAAA,GAAA,OAAA,GA/OG,aA+OH,CAAA,MAAA,CAAA,CAAA,CAAA;CAAd,GAAA;EAA7B,SAAA,MAAA,EAAA,SAAA;CACY,GAAA;EAA0C,SAAA,MAAA,EAAA,QAAA;CAAd;;AAClC,KA1OC,qBAAA,GA0OD,CAAA,OAAA,EAzOA,qBAyOA,EAAA,IAAA,EAAA;EAAO,SAAA,MAAA,CAAA,EAxOU,WAwOV;AAIlB,CAAA,EAAA,GA3OK,oBA2O4B,GA3OL,OA6OR,CA7OgB,oBA6OF,CAAA;;KA1OtB,kBAAA;;;;;;;;;;;;;UAMK,kBAAA;;;;;;;oBAOG,cAAc;;;;;;;;UASjB,kBAAA;qBACI,cAAc;;;;2BAIR;;qBAEN;;;;;;;;;;;;;;UAaJ,iBAAA;;oBAEG;;;;;KAMR,kBAAA,aACD;oBACiB;MACvB,oBAAoB,QAAQ;;;;;;UAOhB,iBAAA;;2BAEU;;;;;;;iCAOM;;;;;;;;;;;gCAWD,SAAS;;;;;;;;;;;;;;;;;;;gCAmBT;;mCAEG,SAAS,eAAe;;kCAEzB,SAAS,eAAe,YAAY;;;;;;;;UASrD,iBAAA;;;wBAGO,SAAS;0BACP,SAAS;;;;UAKlB,qBAAA;;;;;;;UAQA,mBAAA;;;uBAGM;;;;;;;UAQN,kBAAA;;;;;;;UAQA,iBAAA;oBACG,cAAc;+BACH,SAAS;;;;KAK5B,cAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAmCK,SAAA;;;;;;;;;2BAMU;;8BAEG;;;;;;;;;;;;;;;aAeA;MAAgB,QAAQ,cAAc;;aAClC;MAAgB,QAAQ,cAAc;;aACxC;MAAgB,QAAQ,cAAc;;aAIhD;;MACjB,QAAQ;;aACiC;MAAgB,QAAQ;;aAIhD;MACjB;uBAA6B,cAAc;;iBAC/B,oBAAoB,QAAQ,cAAc;WAChD;;;UAIM,gBAAA;;oBAEG"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
//#region src/errors/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Typed error union for the `@graphorin/mcp` package.
|
|
4
|
+
*
|
|
5
|
+
* Every error carries a stable lowercase {@link MCPErrorKind}
|
|
6
|
+
* discriminator, an actionable {@link MCPError.hint} field where
|
|
7
|
+
* applicable, and an optional structured `metadata` bag the audit
|
|
8
|
+
* emitter persists alongside the standard `runId` / `sessionId`
|
|
9
|
+
* context.
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Discriminator union for every error class produced by
|
|
15
|
+
* `@graphorin/mcp`. New kinds extend this union; never throw plain
|
|
16
|
+
* `Error` from framework code.
|
|
17
|
+
*
|
|
18
|
+
* @stable
|
|
19
|
+
*/
|
|
20
|
+
type MCPErrorKind = 'connection-failed' | 'protocol-error' | 'auth-error' | 'tool-not-found' | 'tool-execution' | 'pin-mismatch' | 'call-timeout' | 'cancelled' | 'invalid-config' | 'session-lost' | 'transport-not-supported' | 'transport-resumable-not-supported';
|
|
21
|
+
/** Common metadata bag attached to every {@link MCPError}. */
|
|
22
|
+
interface MCPErrorMetadata {
|
|
23
|
+
readonly server?: string;
|
|
24
|
+
readonly tool?: string;
|
|
25
|
+
readonly transport?: 'stdio' | 'streamable-http' | 'sse';
|
|
26
|
+
readonly cause?: unknown;
|
|
27
|
+
readonly httpStatus?: number;
|
|
28
|
+
readonly sessionId?: string;
|
|
29
|
+
readonly lastEventId?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Base class for every typed error produced by `@graphorin/mcp`.
|
|
33
|
+
*
|
|
34
|
+
* @stable
|
|
35
|
+
*/
|
|
36
|
+
declare abstract class GraphorinMCPError extends Error {
|
|
37
|
+
/** Lowercase discriminator. */
|
|
38
|
+
abstract readonly kind: MCPErrorKind;
|
|
39
|
+
/** Optional remediation hint surfaced in CLI output. */
|
|
40
|
+
readonly hint?: string;
|
|
41
|
+
/** Sanitized metadata; never carries secret material. */
|
|
42
|
+
readonly metadata: Readonly<MCPErrorMetadata>;
|
|
43
|
+
/** Underlying cause (chained errors). */
|
|
44
|
+
readonly cause?: unknown;
|
|
45
|
+
constructor(message: string, opts?: {
|
|
46
|
+
readonly hint?: string;
|
|
47
|
+
readonly metadata?: MCPErrorMetadata;
|
|
48
|
+
readonly cause?: unknown;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/** Raised when a transport fails to connect or is dropped unexpectedly. */
|
|
52
|
+
declare class MCPConnectionError extends GraphorinMCPError {
|
|
53
|
+
readonly kind: "connection-failed";
|
|
54
|
+
}
|
|
55
|
+
/** Raised on JSON-RPC / MCP protocol-level errors. */
|
|
56
|
+
declare class MCPProtocolError extends GraphorinMCPError {
|
|
57
|
+
readonly kind: "protocol-error";
|
|
58
|
+
}
|
|
59
|
+
/** Raised when an authentication / authorization step fails. */
|
|
60
|
+
declare class MCPAuthError extends GraphorinMCPError {
|
|
61
|
+
readonly kind: "auth-error";
|
|
62
|
+
}
|
|
63
|
+
/** Raised when {@link MCPClient.callTool} is invoked for an unknown tool. */
|
|
64
|
+
declare class MCPToolNotFoundError extends GraphorinMCPError {
|
|
65
|
+
readonly kind: "tool-not-found";
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Raised when a pinned tool-definition fingerprint does not match the
|
|
69
|
+
* server's current definition and `onPinMismatch: 'reject'` is set
|
|
70
|
+
* (MC-6) — the approve-then-swap rug-pull posture.
|
|
71
|
+
*/
|
|
72
|
+
declare class MCPToolPinningError extends GraphorinMCPError {
|
|
73
|
+
readonly kind: "pin-mismatch";
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Raised when the MCP server reports a tool-level failure
|
|
77
|
+
* (`CallToolResult.isError === true`, MC-4). The server's content text
|
|
78
|
+
* rides in the message so the model keeps its self-correction signal —
|
|
79
|
+
* while the executor records a real tool FAILURE (audit, retry and
|
|
80
|
+
* error policies all engage) instead of a fake success.
|
|
81
|
+
*/
|
|
82
|
+
declare class MCPToolExecutionError extends GraphorinMCPError {
|
|
83
|
+
readonly kind: "tool-execution";
|
|
84
|
+
}
|
|
85
|
+
/** Raised when a tool call exceeds its configured timeout / aborts. */
|
|
86
|
+
declare class MCPCallTimeoutError extends GraphorinMCPError {
|
|
87
|
+
readonly kind: 'call-timeout' | 'session-lost';
|
|
88
|
+
constructor(message: string, opts: {
|
|
89
|
+
readonly hint?: string;
|
|
90
|
+
readonly metadata?: MCPErrorMetadata;
|
|
91
|
+
readonly cause?: unknown;
|
|
92
|
+
readonly variant?: 'call-timeout' | 'session-lost';
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/** Raised when an in-flight call is cancelled by an `AbortSignal`. */
|
|
96
|
+
declare class MCPCancelledError extends GraphorinMCPError {
|
|
97
|
+
readonly kind: "cancelled";
|
|
98
|
+
}
|
|
99
|
+
/** Raised on invalid `createMCPClient(...)` configuration. */
|
|
100
|
+
declare class MCPInvalidConfigError extends GraphorinMCPError {
|
|
101
|
+
readonly kind: "invalid-config";
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Raised when an operator requests a transport / capability that the
|
|
105
|
+
* runtime does not support (e.g. `resumable: true` on `stdio`).
|
|
106
|
+
*
|
|
107
|
+
* @stable
|
|
108
|
+
*/
|
|
109
|
+
declare class MCPTransportNotSupportedError extends GraphorinMCPError {
|
|
110
|
+
readonly kind: 'transport-not-supported' | 'transport-resumable-not-supported';
|
|
111
|
+
constructor(message: string, opts: {
|
|
112
|
+
readonly hint?: string;
|
|
113
|
+
readonly metadata?: MCPErrorMetadata;
|
|
114
|
+
readonly cause?: unknown;
|
|
115
|
+
readonly variant?: 'transport-not-supported' | 'transport-resumable-not-supported';
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
export { GraphorinMCPError, MCPAuthError, MCPCallTimeoutError, MCPCancelledError, MCPConnectionError, MCPErrorKind, MCPErrorMetadata, MCPInvalidConfigError, MCPProtocolError, MCPToolExecutionError, MCPToolNotFoundError, MCPToolPinningError, MCPTransportNotSupportedError };
|
|
120
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/errors/index.ts"],"sourcesContent":[],"mappings":";;AAmBA;AAeA;AAeA;;;;;;;AA2BA;AAKA;AAKA;AAKA;AASA;AAWA;AAKA;AAoBA;AAKa,KA1HD,YAAA,GA0HC,mBAA8B,GAAA,gBAAiB,GAAA,YAAA,GAAA,gBAAA,GAAA,gBAAA,GAAA,cAAA,GAAA,cAAA,GAAA,WAAA,GAAA,gBAAA,GAAA,cAAA,GAAA,yBAAA,GAAA,mCAAA;AAU5D;UArHiB,gBAAA;;;;;;;;;;;;;;uBAeK,iBAAA,SAA0B,KAAA;;0BAEf;;;;qBAIL,SAAS;;;;;wBAQX;;;;;cAab,kBAAA,SAA2B,iBAAA;;;;cAK3B,gBAAA,SAAyB,iBAAA;;;;cAKzB,YAAA,SAAqB,iBAAA;;;;cAKrB,oBAAA,SAA6B,iBAAA;;;;;;;;cAS7B,mBAAA,SAA4B,iBAAA;;;;;;;;;;cAW5B,qBAAA,SAA8B,iBAAA;;;;cAK9B,mBAAA,SAA4B,iBAAA;;;;wBAOf;;;;;;cAab,iBAAA,SAA0B,iBAAA;;;;cAK1B,qBAAA,SAA8B,iBAAA;;;;;;;;;cAU9B,6BAAA,SAAsC,iBAAA;;;;wBAQzB"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
//#region src/errors/index.ts
|
|
2
|
+
/**
|
|
3
|
+
* Base class for every typed error produced by `@graphorin/mcp`.
|
|
4
|
+
*
|
|
5
|
+
* @stable
|
|
6
|
+
*/
|
|
7
|
+
var GraphorinMCPError = class extends Error {
|
|
8
|
+
/** Optional remediation hint surfaced in CLI output. */
|
|
9
|
+
hint;
|
|
10
|
+
/** Sanitized metadata; never carries secret material. */
|
|
11
|
+
metadata;
|
|
12
|
+
/** Underlying cause (chained errors). */
|
|
13
|
+
cause;
|
|
14
|
+
constructor(message, opts = {}) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = new.target.name;
|
|
17
|
+
if (opts.hint !== void 0) this.hint = opts.hint;
|
|
18
|
+
this.metadata = Object.freeze({ ...opts.metadata ?? {} });
|
|
19
|
+
if (opts.cause !== void 0) this.cause = opts.cause;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
/** Raised when a transport fails to connect or is dropped unexpectedly. */
|
|
23
|
+
var MCPConnectionError = class extends GraphorinMCPError {
|
|
24
|
+
kind = "connection-failed";
|
|
25
|
+
};
|
|
26
|
+
/** Raised on JSON-RPC / MCP protocol-level errors. */
|
|
27
|
+
var MCPProtocolError = class extends GraphorinMCPError {
|
|
28
|
+
kind = "protocol-error";
|
|
29
|
+
};
|
|
30
|
+
/** Raised when an authentication / authorization step fails. */
|
|
31
|
+
var MCPAuthError = class extends GraphorinMCPError {
|
|
32
|
+
kind = "auth-error";
|
|
33
|
+
};
|
|
34
|
+
/** Raised when {@link MCPClient.callTool} is invoked for an unknown tool. */
|
|
35
|
+
var MCPToolNotFoundError = class extends GraphorinMCPError {
|
|
36
|
+
kind = "tool-not-found";
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Raised when a pinned tool-definition fingerprint does not match the
|
|
40
|
+
* server's current definition and `onPinMismatch: 'reject'` is set
|
|
41
|
+
* (MC-6) — the approve-then-swap rug-pull posture.
|
|
42
|
+
*/
|
|
43
|
+
var MCPToolPinningError = class extends GraphorinMCPError {
|
|
44
|
+
kind = "pin-mismatch";
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Raised when the MCP server reports a tool-level failure
|
|
48
|
+
* (`CallToolResult.isError === true`, MC-4). The server's content text
|
|
49
|
+
* rides in the message so the model keeps its self-correction signal —
|
|
50
|
+
* while the executor records a real tool FAILURE (audit, retry and
|
|
51
|
+
* error policies all engage) instead of a fake success.
|
|
52
|
+
*/
|
|
53
|
+
var MCPToolExecutionError = class extends GraphorinMCPError {
|
|
54
|
+
kind = "tool-execution";
|
|
55
|
+
};
|
|
56
|
+
/** Raised when a tool call exceeds its configured timeout / aborts. */
|
|
57
|
+
var MCPCallTimeoutError = class extends GraphorinMCPError {
|
|
58
|
+
kind = "call-timeout";
|
|
59
|
+
constructor(message, opts) {
|
|
60
|
+
super(message, opts);
|
|
61
|
+
if (opts.variant !== void 0) this.kind = opts.variant;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
/** Raised when an in-flight call is cancelled by an `AbortSignal`. */
|
|
65
|
+
var MCPCancelledError = class extends GraphorinMCPError {
|
|
66
|
+
kind = "cancelled";
|
|
67
|
+
};
|
|
68
|
+
/** Raised on invalid `createMCPClient(...)` configuration. */
|
|
69
|
+
var MCPInvalidConfigError = class extends GraphorinMCPError {
|
|
70
|
+
kind = "invalid-config";
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Raised when an operator requests a transport / capability that the
|
|
74
|
+
* runtime does not support (e.g. `resumable: true` on `stdio`).
|
|
75
|
+
*
|
|
76
|
+
* @stable
|
|
77
|
+
*/
|
|
78
|
+
var MCPTransportNotSupportedError = class extends GraphorinMCPError {
|
|
79
|
+
kind = "transport-not-supported";
|
|
80
|
+
constructor(message, opts) {
|
|
81
|
+
super(message, opts);
|
|
82
|
+
if (opts.variant !== void 0) this.kind = opts.variant;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
export { GraphorinMCPError, MCPAuthError, MCPCallTimeoutError, MCPCancelledError, MCPConnectionError, MCPInvalidConfigError, MCPProtocolError, MCPToolExecutionError, MCPToolNotFoundError, MCPToolPinningError, MCPTransportNotSupportedError };
|
|
88
|
+
//# sourceMappingURL=index.js.map
|