@draht/mcp 2026.10.31 → 2026.11.5-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config.d.ts +126 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +167 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/input-schema.d.ts +7 -0
- package/dist/input-schema.d.ts.map +1 -0
- package/dist/input-schema.js +13 -0
- package/dist/input-schema.js.map +1 -0
- package/dist/naming.d.ts +18 -0
- package/dist/naming.d.ts.map +1 -0
- package/dist/naming.js +29 -0
- package/dist/naming.js.map +1 -0
- package/dist/oauth/auth-provider.d.ts +63 -0
- package/dist/oauth/auth-provider.d.ts.map +1 -0
- package/dist/oauth/auth-provider.js +116 -0
- package/dist/oauth/auth-provider.js.map +1 -0
- package/dist/oauth/callback.d.ts.map +1 -1
- package/dist/oauth/callback.js +4 -0
- package/dist/oauth/callback.js.map +1 -1
- package/dist/oauth/client-metadata-base.d.ts +16 -0
- package/dist/oauth/client-metadata-base.d.ts.map +1 -0
- package/dist/oauth/client-metadata-base.js +27 -0
- package/dist/oauth/client-metadata-base.js.map +1 -0
- package/dist/oauth/client-settings.d.ts +131 -0
- package/dist/oauth/client-settings.d.ts.map +1 -0
- package/dist/oauth/client-settings.js +158 -0
- package/dist/oauth/client-settings.js.map +1 -0
- package/dist/oauth/errors.d.ts +7 -0
- package/dist/oauth/errors.d.ts.map +1 -1
- package/dist/oauth/errors.js +10 -0
- package/dist/oauth/errors.js.map +1 -1
- package/dist/oauth/flow.d.ts +33 -0
- package/dist/oauth/flow.d.ts.map +1 -1
- package/dist/oauth/flow.js +64 -10
- package/dist/oauth/flow.js.map +1 -1
- package/dist/oauth/index.d.ts +7 -2
- package/dist/oauth/index.d.ts.map +1 -1
- package/dist/oauth/index.js +6 -1
- package/dist/oauth/index.js.map +1 -1
- package/dist/oauth/loopback.d.ts +55 -0
- package/dist/oauth/loopback.d.ts.map +1 -0
- package/dist/oauth/loopback.js +106 -0
- package/dist/oauth/loopback.js.map +1 -0
- package/dist/oauth/provider.d.ts +4 -1
- package/dist/oauth/provider.d.ts.map +1 -1
- package/dist/oauth/provider.js +9 -3
- package/dist/oauth/provider.js.map +1 -1
- package/dist/oauth/sign-in.d.ts +82 -0
- package/dist/oauth/sign-in.d.ts.map +1 -0
- package/dist/oauth/sign-in.js +209 -0
- package/dist/oauth/sign-in.js.map +1 -0
- package/dist/oauth/types.d.ts +1 -0
- package/dist/oauth/types.d.ts.map +1 -1
- package/dist/oauth/types.js +8 -4
- package/dist/oauth/types.js.map +1 -1
- package/dist/output-limit.d.ts +24 -0
- package/dist/output-limit.d.ts.map +1 -0
- package/dist/output-limit.js +58 -0
- package/dist/output-limit.js.map +1 -0
- package/dist/transports/lines.d.ts +34 -0
- package/dist/transports/lines.d.ts.map +1 -0
- package/dist/transports/lines.js +85 -0
- package/dist/transports/lines.js.map +1 -0
- package/dist/transports/pipe.d.ts +49 -0
- package/dist/transports/pipe.d.ts.map +1 -0
- package/dist/transports/pipe.js +96 -0
- package/dist/transports/pipe.js.map +1 -0
- package/dist/transports/stdio.d.ts +1 -4
- package/dist/transports/stdio.d.ts.map +1 -1
- package/dist/transports/stdio.js +20 -51
- package/dist/transports/stdio.js.map +1 -1
- package/dist/transports/streamable-http.d.ts.map +1 -1
- package/dist/transports/streamable-http.js +77 -11
- package/dist/transports/streamable-http.js.map +1 -1
- package/package.json +3 -4
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `mcpServers` configuration shape that MCP clients share, so configurations can be copied between
|
|
3
|
+
* them: stdio servers (`command`, `args`, `env`, `cwd`), Streamable HTTP servers (`url`, `headers`,
|
|
4
|
+
* `oauth`), and `enabled`, `description` and `timeout` for both.
|
|
5
|
+
*
|
|
6
|
+
* ```json
|
|
7
|
+
* {
|
|
8
|
+
* "mcpServers": {
|
|
9
|
+
* "filesystem": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "."] },
|
|
10
|
+
* "docs": { "url": "https://example.com/mcp", "headers": { "Authorization": "Bearer ${DOCS_TOKEN}" } }
|
|
11
|
+
* }
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Applications add fields of their own: {@link validateMcpServerConfig} keeps fields it does not know
|
|
16
|
+
* for the caller to check afterwards.
|
|
17
|
+
*/
|
|
18
|
+
/** Fields every server entry may have. */
|
|
19
|
+
interface McpServerConfigBase {
|
|
20
|
+
/** What the server offers, in a sentence. */
|
|
21
|
+
description?: string;
|
|
22
|
+
/** Set to false to keep the entry without connecting. Default: true. */
|
|
23
|
+
enabled?: boolean;
|
|
24
|
+
/** Per-request timeout in seconds. */
|
|
25
|
+
timeout?: number;
|
|
26
|
+
}
|
|
27
|
+
/** A server started as a local program that speaks MCP over stdin and stdout. */
|
|
28
|
+
export interface McpStdioServerConfig extends McpServerConfigBase {
|
|
29
|
+
type?: "stdio";
|
|
30
|
+
command: string;
|
|
31
|
+
args?: string[];
|
|
32
|
+
/** Added to the environment. The application decides whether values may reference variables (`${NAME}`). */
|
|
33
|
+
env?: Record<string, string>;
|
|
34
|
+
/** The application decides what relative paths resolve against. */
|
|
35
|
+
cwd?: string;
|
|
36
|
+
}
|
|
37
|
+
/** OAuth client settings for servers that do not support dynamic client registration. */
|
|
38
|
+
export interface McpOAuthConfig {
|
|
39
|
+
/** Pre-registered client id. Without it, the application registers a client with the authorization server. */
|
|
40
|
+
clientId?: string;
|
|
41
|
+
/** As configured; the application decides whether it may reference variables. */
|
|
42
|
+
clientSecret?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Port of the loopback callback server, for clients registered with a fixed redirect URI. Without
|
|
45
|
+
* `callbackUrl`, the redirect URI is `http://127.0.0.1:<port>/callback`.
|
|
46
|
+
*/
|
|
47
|
+
callbackPort?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Redirect URI registered for `clientId`, for example `http://localhost:8080/oauth/callback`. It must
|
|
50
|
+
* be an `http` URI on `localhost`, `127.0.0.1`, or `[::1]`. Without a port, the callback server
|
|
51
|
+
* listens on `callbackPort` or a free port, which is added to the URI (RFC 8252).
|
|
52
|
+
*/
|
|
53
|
+
callbackUrl?: string;
|
|
54
|
+
/** Scopes to request, separated by spaces. Default: the scopes the server advertises. */
|
|
55
|
+
scope?: string;
|
|
56
|
+
/** `client_name` sent with dynamic client registration. Default: the application's name. */
|
|
57
|
+
clientName?: string;
|
|
58
|
+
/**
|
|
59
|
+
* How the application identifies itself without `clientId`. `dcr` (default): dynamic client
|
|
60
|
+
* registration. `cimd`: the operator's Client ID Metadata Document under `clientMetadataBaseUrl`, and
|
|
61
|
+
* sign-in fails when the authorization server does not support documents for public clients.
|
|
62
|
+
*
|
|
63
|
+
* draht: upstream's `auto` (the application's documents whenever the server supports them) is
|
|
64
|
+
* rejected, so a document is only used when the operator configured one.
|
|
65
|
+
*/
|
|
66
|
+
clientRegistration?: "dcr" | "cimd";
|
|
67
|
+
/**
|
|
68
|
+
* draht: required for `cimd` and rejected otherwise: an absolute https URL without userinfo, query, or
|
|
69
|
+
* fragment that the operator hosts `client.json` and `<callback ID>/client.json` under. Validation
|
|
70
|
+
* normalizes it to end in one `/`, keeping its path prefix. No default.
|
|
71
|
+
*/
|
|
72
|
+
clientMetadataBaseUrl?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Authorization server metadata document (RFC 8414 or OpenID Connect discovery) to use instead of
|
|
75
|
+
* discovery through the server, for servers that advertise a wrong authorization server or none.
|
|
76
|
+
* The document is trusted as configured. Must use https, except on loopback hosts.
|
|
77
|
+
*/
|
|
78
|
+
authServerMetadataUrl?: string;
|
|
79
|
+
}
|
|
80
|
+
/** A server reached over Streamable HTTP. */
|
|
81
|
+
export interface McpHttpServerConfig extends McpServerConfigBase {
|
|
82
|
+
type?: "http";
|
|
83
|
+
url: string;
|
|
84
|
+
/** Sent with every request. The application decides whether values may reference variables. */
|
|
85
|
+
headers?: Record<string, string>;
|
|
86
|
+
oauth?: McpOAuthConfig;
|
|
87
|
+
}
|
|
88
|
+
/** One entry of the `mcpServers` shape: a stdio or a Streamable HTTP server. */
|
|
89
|
+
export type McpServerConfig = McpStdioServerConfig | McpHttpServerConfig;
|
|
90
|
+
/**
|
|
91
|
+
* A validated server entry, tagged with its transport, or why it is invalid. The config is the entry
|
|
92
|
+
* as given: fields the validator does not know are kept, unchecked, for the caller to check. draht: with
|
|
93
|
+
* `cimd`, the config is a copy whose `oauth.clientMetadataBaseUrl` is normalized.
|
|
94
|
+
*/
|
|
95
|
+
export type McpServerConfigResult = {
|
|
96
|
+
kind: "stdio";
|
|
97
|
+
config: McpStdioServerConfig & Record<string, unknown>;
|
|
98
|
+
} | {
|
|
99
|
+
kind: "http";
|
|
100
|
+
config: McpHttpServerConfig & Record<string, unknown>;
|
|
101
|
+
} | {
|
|
102
|
+
kind: "invalid";
|
|
103
|
+
error: string;
|
|
104
|
+
};
|
|
105
|
+
/** What the application adds to the validation of server entries. */
|
|
106
|
+
export interface McpServerConfigOptions {
|
|
107
|
+
/**
|
|
108
|
+
* Checks the `oauth.callbackUrl` (undefined: none configured) of an entry with
|
|
109
|
+
* `oauth.clientRegistration: "cimd"`: the operator's Client ID Metadata Documents must list it.
|
|
110
|
+
* Returns an error message. Without this check, `"cimd"` is refused.
|
|
111
|
+
*/
|
|
112
|
+
checkMetadataDocumentCallback?(callbackUrl: string | undefined): string | undefined;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Validate one entry of the `mcpServers` shape (configuration files are a trust boundary). Server
|
|
116
|
+
* names are letters, digits, `_` and `-`, which tool names and namespaces are built from.
|
|
117
|
+
*/
|
|
118
|
+
export declare function validateMcpServerConfig(name: string, raw: unknown, options?: McpServerConfigOptions): McpServerConfigResult;
|
|
119
|
+
/**
|
|
120
|
+
* Whether an entry overrides a server defined elsewhere instead of defining one: it has no `command`,
|
|
121
|
+
* `url` or `type`. Applications let a less trusted file (a project's) override a few fields, such as
|
|
122
|
+
* `enabled`, of a server a trusted file defines; which fields is theirs to decide.
|
|
123
|
+
*/
|
|
124
|
+
export declare function isMcpServerOverride(entry: Record<string, unknown>): boolean;
|
|
125
|
+
export {};
|
|
126
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,0CAA0C;AAC1C,UAAU,mBAAmB;IAC5B,6CAA6C;IAC7C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wEAAwE;IACxE,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,sCAAsC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,iFAAiF;AACjF,MAAM,WAAW,oBAAqB,SAAQ,mBAAmB;IAChE,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,4GAA4G;IAC5G,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,mEAAmE;IACnE,GAAG,CAAC,EAAE,MAAM,CAAC;CACb;AAED,yFAAyF;AACzF,MAAM,WAAW,cAAc;IAC9B,8GAA8G;IAC9G,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iFAAiF;IACjF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yFAAyF;IACzF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4FAA4F;IAC5F,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;;;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E3E"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `mcpServers` configuration shape that MCP clients share, so configurations can be copied between
|
|
3
|
+
* them: stdio servers (`command`, `args`, `env`, `cwd`), Streamable HTTP servers (`url`, `headers`,
|
|
4
|
+
* `oauth`), and `enabled`, `description` and `timeout` for both.
|
|
5
|
+
*
|
|
6
|
+
* ```json
|
|
7
|
+
* {
|
|
8
|
+
* "mcpServers": {
|
|
9
|
+
* "filesystem": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "."] },
|
|
10
|
+
* "docs": { "url": "https://example.com/mcp", "headers": { "Authorization": "Bearer ${DOCS_TOKEN}" } }
|
|
11
|
+
* }
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Applications add fields of their own: {@link validateMcpServerConfig} keeps fields it does not know
|
|
16
|
+
* for the caller to check afterwards.
|
|
17
|
+
*/
|
|
18
|
+
import { parseClientMetadataBaseUrl } from "./oauth/client-metadata-base.js";
|
|
19
|
+
const SERVER_NAME = /^[A-Za-z0-9_-]+$/;
|
|
20
|
+
/**
|
|
21
|
+
* Validate one entry of the `mcpServers` shape (configuration files are a trust boundary). Server
|
|
22
|
+
* names are letters, digits, `_` and `-`, which tool names and namespaces are built from.
|
|
23
|
+
*/
|
|
24
|
+
export function validateMcpServerConfig(name, raw, options = {}) {
|
|
25
|
+
const invalid = (error) => ({ kind: "invalid", error });
|
|
26
|
+
if (!SERVER_NAME.test(name))
|
|
27
|
+
return invalid(`invalid server name "${name}" (use letters, digits, "_" and "-")`);
|
|
28
|
+
if (!isRecord(raw))
|
|
29
|
+
return invalid(`server "${name}" must be an object`);
|
|
30
|
+
const fieldsError = validateBaseFields(raw);
|
|
31
|
+
if (fieldsError)
|
|
32
|
+
return invalid(`server "${name}": ${fieldsError}`);
|
|
33
|
+
const { type, url, command } = raw;
|
|
34
|
+
if (type === "sse") {
|
|
35
|
+
return invalid(`server "${name}": legacy SSE transport is not supported; use the streamable HTTP URL`);
|
|
36
|
+
}
|
|
37
|
+
// The casts below hold because the fields were checked one by one, which the types cannot express.
|
|
38
|
+
if (typeof url === "string" && (type === undefined || type === "http" || type === "streamable-http")) {
|
|
39
|
+
const oauth = validateHttpFields(raw, url, options);
|
|
40
|
+
if (typeof oauth === "string")
|
|
41
|
+
return invalid(`server "${name}": ${oauth}`);
|
|
42
|
+
const config = oauth ? { ...raw, oauth } : raw;
|
|
43
|
+
return { kind: "http", config: config };
|
|
44
|
+
}
|
|
45
|
+
if (typeof command === "string" && (type === undefined || type === "stdio")) {
|
|
46
|
+
const error = validateStdioFields(raw);
|
|
47
|
+
if (error)
|
|
48
|
+
return invalid(`server "${name}": ${error}`);
|
|
49
|
+
return { kind: "stdio", config: raw };
|
|
50
|
+
}
|
|
51
|
+
return invalid(`server "${name}" needs either "command" (stdio) or "url" (streamable HTTP)`);
|
|
52
|
+
}
|
|
53
|
+
function isRecord(value) {
|
|
54
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
55
|
+
}
|
|
56
|
+
function validateBaseFields(entry) {
|
|
57
|
+
const { enabled, timeout, description } = entry;
|
|
58
|
+
if (enabled !== undefined && typeof enabled !== "boolean")
|
|
59
|
+
return "enabled must be a boolean";
|
|
60
|
+
if (description !== undefined && typeof description !== "string")
|
|
61
|
+
return "description must be a string";
|
|
62
|
+
if (timeout !== undefined && (typeof timeout !== "number" || !(timeout > 0))) {
|
|
63
|
+
return "timeout must be a positive number of seconds";
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
/** An error message, or the `oauth` object to put in the config when validation normalized it. */
|
|
68
|
+
function validateHttpFields(entry, url, options) {
|
|
69
|
+
if (!URL.canParse(url) || !/^https?:$/.test(new URL(url).protocol))
|
|
70
|
+
return "url must be an http or https URL";
|
|
71
|
+
if (entry.headers !== undefined && !isStringRecord(entry.headers))
|
|
72
|
+
return "headers must map names to strings";
|
|
73
|
+
return validateOAuth(entry.oauth, options);
|
|
74
|
+
}
|
|
75
|
+
function validateStdioFields(entry) {
|
|
76
|
+
const { args, env, cwd } = entry;
|
|
77
|
+
if (args !== undefined && !(Array.isArray(args) && args.every((arg) => typeof arg === "string"))) {
|
|
78
|
+
return "args must be an array of strings";
|
|
79
|
+
}
|
|
80
|
+
if (env !== undefined && !isStringRecord(env))
|
|
81
|
+
return "env must map names to strings";
|
|
82
|
+
if (cwd !== undefined && typeof cwd !== "string")
|
|
83
|
+
return "cwd must be a string";
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
function isStringRecord(value) {
|
|
87
|
+
return isRecord(value) && Object.values(value).every((entry) => typeof entry === "string");
|
|
88
|
+
}
|
|
89
|
+
const LOOPBACK_HOSTS = ["localhost", "127.0.0.1", "[::1]"];
|
|
90
|
+
/** An error message, a copy of `value` with a normalized `clientMetadataBaseUrl`, or `undefined` when valid as is. */
|
|
91
|
+
function validateOAuth(value, options) {
|
|
92
|
+
if (value === undefined)
|
|
93
|
+
return undefined;
|
|
94
|
+
if (!isRecord(value))
|
|
95
|
+
return "oauth must be an object";
|
|
96
|
+
if (value.clientId !== undefined && typeof value.clientId !== "string")
|
|
97
|
+
return "oauth.clientId must be a string";
|
|
98
|
+
if (value.clientSecret !== undefined && typeof value.clientSecret !== "string") {
|
|
99
|
+
return "oauth.clientSecret must be a string";
|
|
100
|
+
}
|
|
101
|
+
const port = value.callbackPort;
|
|
102
|
+
if (port !== undefined && (typeof port !== "number" || !Number.isInteger(port) || port < 1 || port > 65535)) {
|
|
103
|
+
return "oauth.callbackPort must be a port number";
|
|
104
|
+
}
|
|
105
|
+
if (value.callbackUrl !== undefined) {
|
|
106
|
+
if (typeof value.callbackUrl !== "string" || !isLoopbackRedirectUri(value.callbackUrl)) {
|
|
107
|
+
return "oauth.callbackUrl must be an http URI on localhost, 127.0.0.1, or [::1] without query or fragment";
|
|
108
|
+
}
|
|
109
|
+
const urlPort = new URL(value.callbackUrl).port;
|
|
110
|
+
if (urlPort && port !== undefined && Number(urlPort) !== port) {
|
|
111
|
+
return "oauth.callbackUrl and oauth.callbackPort name different ports";
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (value.scope !== undefined && typeof value.scope !== "string")
|
|
115
|
+
return "oauth.scope must be a string";
|
|
116
|
+
if (value.clientName !== undefined && (typeof value.clientName !== "string" || !value.clientName.trim())) {
|
|
117
|
+
return "oauth.clientName must be a non-empty string";
|
|
118
|
+
}
|
|
119
|
+
// draht: no `auto`. `cimd` is the operator's opt-in and a public client, so it takes no client id, name,
|
|
120
|
+
// or secret, and it needs the operator's base; a base without `cimd` is a configuration mistake.
|
|
121
|
+
const registration = value.clientRegistration;
|
|
122
|
+
let clientMetadataBaseUrl;
|
|
123
|
+
if (registration !== undefined && registration !== "dcr") {
|
|
124
|
+
if (registration !== "cimd")
|
|
125
|
+
return 'oauth.clientRegistration must be "dcr" or "cimd"';
|
|
126
|
+
if (value.clientId !== undefined || value.clientName !== undefined || value.clientSecret !== undefined) {
|
|
127
|
+
return 'oauth.clientRegistration "cimd" cannot be combined with oauth.clientId, oauth.clientName, or oauth.clientSecret';
|
|
128
|
+
}
|
|
129
|
+
if (!options.checkMetadataDocumentCallback) {
|
|
130
|
+
return 'oauth.clientRegistration "cimd" is not supported: there are no Client ID Metadata Documents';
|
|
131
|
+
}
|
|
132
|
+
const callbackError = options.checkMetadataDocumentCallback(typeof value.callbackUrl === "string" ? value.callbackUrl : undefined);
|
|
133
|
+
if (callbackError)
|
|
134
|
+
return callbackError;
|
|
135
|
+
clientMetadataBaseUrl = parseClientMetadataBaseUrl(value.clientMetadataBaseUrl);
|
|
136
|
+
if (!clientMetadataBaseUrl) {
|
|
137
|
+
return 'oauth.clientMetadataBaseUrl is required for "cimd" and must be an absolute HTTPS URL without userinfo, query, or fragment';
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else if (value.clientMetadataBaseUrl !== undefined) {
|
|
141
|
+
return 'oauth.clientMetadataBaseUrl requires oauth.clientRegistration "cimd"';
|
|
142
|
+
}
|
|
143
|
+
const metadataUrl = value.authServerMetadataUrl;
|
|
144
|
+
if (metadataUrl !== undefined) {
|
|
145
|
+
const url = typeof metadataUrl === "string" && URL.canParse(metadataUrl) ? new URL(metadataUrl) : undefined;
|
|
146
|
+
if (!url || !(url.protocol === "https:" || (url.protocol === "http:" && LOOPBACK_HOSTS.includes(url.hostname)))) {
|
|
147
|
+
return "oauth.authServerMetadataUrl must be an https URL, or http on localhost, 127.0.0.1, or [::1]";
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return clientMetadataBaseUrl ? { ...value, clientMetadataBaseUrl } : undefined;
|
|
151
|
+
}
|
|
152
|
+
/** Whether a redirect URI can be served by a loopback callback server. */
|
|
153
|
+
function isLoopbackRedirectUri(value) {
|
|
154
|
+
if (!URL.canParse(value))
|
|
155
|
+
return false;
|
|
156
|
+
const url = new URL(value);
|
|
157
|
+
return url.protocol === "http:" && LOOPBACK_HOSTS.includes(url.hostname) && url.search === "" && url.hash === "";
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Whether an entry overrides a server defined elsewhere instead of defining one: it has no `command`,
|
|
161
|
+
* `url` or `type`. Applications let a less trusted file (a project's) override a few fields, such as
|
|
162
|
+
* `enabled`, of a server a trusted file defines; which fields is theirs to decide.
|
|
163
|
+
*/
|
|
164
|
+
export function isMcpServerOverride(entry) {
|
|
165
|
+
return entry.command === undefined && entry.url === undefined && entry.type === undefined;
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAmG7E,MAAM,WAAW,GAAG,kBAAkB,CAAC;AAEvC;;;GAGG;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AC,CAAC,CAAC,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC5G,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,CAAC,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;YACjH,OAAO,6FAA6F,CAAC;QACtG,CAAC;IACF,CAAC;IACD,OAAO,qBAAqB,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,qBAAqB,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAChF,CAAC;AAED,0EAA0E;AAC1E,SAAS,qBAAqB,CAAC,KAAa;IAC3C,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;IAC3B,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE,IAAI,GAAG,CAAC,IAAI,KAAK,EAAE,CAAC;AAClH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAA8B;IACjE,OAAO,KAAK,CAAC,OAAO,KAAK,SAAS,IAAI,KAAK,CAAC,GAAG,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC;AAC3F,CAAC","sourcesContent":["/**\n * The `mcpServers` configuration shape that MCP clients share, so configurations can be copied between\n * them: stdio servers (`command`, `args`, `env`, `cwd`), Streamable HTTP servers (`url`, `headers`,\n * `oauth`), and `enabled`, `description` and `timeout` for both.\n *\n * ```json\n * {\n * \"mcpServers\": {\n * \"filesystem\": { \"command\": \"npx\", \"args\": [\"-y\", \"@modelcontextprotocol/server-filesystem\", \".\"] },\n * \"docs\": { \"url\": \"https://example.com/mcp\", \"headers\": { \"Authorization\": \"Bearer ${DOCS_TOKEN}\" } }\n * }\n * }\n * ```\n *\n * Applications add fields of their own: {@link validateMcpServerConfig} keeps fields it does not know\n * for the caller to check afterwards.\n */\n\nimport { parseClientMetadataBaseUrl } from \"./oauth/client-metadata-base.ts\";\n\n/** Fields every server entry may have. */\ninterface McpServerConfigBase {\n\t/** What the server offers, in a sentence. */\n\tdescription?: string;\n\t/** Set to false to keep the entry without connecting. Default: true. */\n\tenabled?: boolean;\n\t/** Per-request timeout in seconds. */\n\ttimeout?: number;\n}\n\n/** A server started as a local program that speaks MCP over stdin and stdout. */\nexport interface McpStdioServerConfig extends McpServerConfigBase {\n\ttype?: \"stdio\";\n\tcommand: string;\n\targs?: string[];\n\t/** Added to the environment. The application decides whether values may reference variables (`${NAME}`). */\n\tenv?: Record<string, string>;\n\t/** The application decides what relative paths resolve against. */\n\tcwd?: string;\n}\n\n/** OAuth client settings for servers that do not support dynamic client registration. */\nexport interface McpOAuthConfig {\n\t/** Pre-registered client id. Without it, the application registers a client with the authorization server. */\n\tclientId?: string;\n\t/** As configured; the application decides whether it may reference variables. */\n\tclientSecret?: string;\n\t/**\n\t * Port of the loopback callback server, for clients registered with a fixed redirect URI. Without\n\t * `callbackUrl`, the redirect URI is `http://127.0.0.1:<port>/callback`.\n\t */\n\tcallbackPort?: number;\n\t/**\n\t * Redirect URI registered for `clientId`, for example `http://localhost:8080/oauth/callback`. It must\n\t * be an `http` URI on `localhost`, `127.0.0.1`, or `[::1]`. Without a port, the callback server\n\t * listens on `callbackPort` or a free port, which is added to the URI (RFC 8252).\n\t */\n\tcallbackUrl?: string;\n\t/** Scopes to request, separated by spaces. Default: the scopes the server advertises. */\n\tscope?: string;\n\t/** `client_name` sent with dynamic client registration. Default: the application's name. */\n\tclientName?: string;\n\t/**\n\t * How the application identifies itself without `clientId`. `dcr` (default): dynamic client\n\t * registration. `cimd`: the operator's Client ID Metadata Document under `clientMetadataBaseUrl`, and\n\t * sign-in fails when the authorization server does not support documents for public clients.\n\t *\n\t * draht: upstream's `auto` (the application's documents whenever the server supports them) is\n\t * rejected, so a document is only used when the operator configured one.\n\t */\n\tclientRegistration?: \"dcr\" | \"cimd\";\n\t/**\n\t * draht: required for `cimd` and rejected otherwise: an absolute https URL without userinfo, query, or\n\t * fragment that the operator hosts `client.json` and `<callback ID>/client.json` under. Validation\n\t * normalizes it to end in one `/`, keeping its path prefix. No default.\n\t */\n\tclientMetadataBaseUrl?: string;\n\t/**\n\t * Authorization server metadata document (RFC 8414 or OpenID Connect discovery) to use instead of\n\t * discovery through the server, for servers that advertise a wrong authorization server or none.\n\t * The document is trusted as configured. Must use https, except on loopback hosts.\n\t */\n\tauthServerMetadataUrl?: string;\n}\n\n/** A server reached over Streamable HTTP. */\nexport interface McpHttpServerConfig extends McpServerConfigBase {\n\ttype?: \"http\";\n\turl: string;\n\t/** Sent with every request. The application decides whether values may reference variables. */\n\theaders?: Record<string, string>;\n\toauth?: McpOAuthConfig;\n}\n\n/** One entry of the `mcpServers` shape: a stdio or a Streamable HTTP server. */\nexport type McpServerConfig = McpStdioServerConfig | McpHttpServerConfig;\n\n/**\n * A validated server entry, tagged with its transport, or why it is invalid. The config is the entry\n * as given: fields the validator does not know are kept, unchecked, for the caller to check. draht: with\n * `cimd`, the config is a copy whose `oauth.clientMetadataBaseUrl` is normalized.\n */\nexport type McpServerConfigResult =\n\t| { kind: \"stdio\"; config: McpStdioServerConfig & Record<string, unknown> }\n\t| { kind: \"http\"; config: McpHttpServerConfig & Record<string, unknown> }\n\t| { kind: \"invalid\"; error: string };\n\n/** What the application adds to the validation of server entries. */\nexport interface McpServerConfigOptions {\n\t/**\n\t * Checks the `oauth.callbackUrl` (undefined: none configured) of an entry with\n\t * `oauth.clientRegistration: \"cimd\"`: the operator's Client ID Metadata Documents must list it.\n\t * Returns an error message. Without this check, `\"cimd\"` is refused.\n\t */\n\tcheckMetadataDocumentCallback?(callbackUrl: string | undefined): string | undefined;\n}\n\nconst SERVER_NAME = /^[A-Za-z0-9_-]+$/;\n\n/**\n * Validate one entry of the `mcpServers` shape (configuration files are a trust boundary). Server\n * names are letters, digits, `_` and `-`, which tool names and namespaces are built from.\n */\nexport function validateMcpServerConfig(\n\tname: string,\n\traw: unknown,\n\toptions: McpServerConfigOptions = {},\n): McpServerConfigResult {\n\tconst invalid = (error: string): McpServerConfigResult => ({ kind: \"invalid\", error });\n\tif (!SERVER_NAME.test(name)) return invalid(`invalid server name \"${name}\" (use letters, digits, \"_\" and \"-\")`);\n\tif (!isRecord(raw)) return invalid(`server \"${name}\" must be an object`);\n\tconst fieldsError = validateBaseFields(raw);\n\tif (fieldsError) return invalid(`server \"${name}\": ${fieldsError}`);\n\tconst { type, url, command } = raw;\n\tif (type === \"sse\") {\n\t\treturn invalid(`server \"${name}\": legacy SSE transport is not supported; use the streamable HTTP URL`);\n\t}\n\t// The casts below hold because the fields were checked one by one, which the types cannot express.\n\tif (typeof url === \"string\" && (type === undefined || type === \"http\" || type === \"streamable-http\")) {\n\t\tconst oauth = validateHttpFields(raw, url, options);\n\t\tif (typeof oauth === \"string\") return invalid(`server \"${name}\": ${oauth}`);\n\t\tconst config = oauth ? { ...raw, oauth } : raw;\n\t\treturn { kind: \"http\", config: config as McpHttpServerConfig & Record<string, unknown> };\n\t}\n\tif (typeof command === \"string\" && (type === undefined || type === \"stdio\")) {\n\t\tconst error = validateStdioFields(raw);\n\t\tif (error) return invalid(`server \"${name}\": ${error}`);\n\t\treturn { kind: \"stdio\", config: raw as McpStdioServerConfig & Record<string, unknown> };\n\t}\n\treturn invalid(`server \"${name}\" needs either \"command\" (stdio) or \"url\" (streamable HTTP)`);\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction validateBaseFields(entry: Record<string, unknown>): string | undefined {\n\tconst { enabled, timeout, description } = entry;\n\tif (enabled !== undefined && typeof enabled !== \"boolean\") return \"enabled must be a boolean\";\n\tif (description !== undefined && typeof description !== \"string\") return \"description must be a string\";\n\tif (timeout !== undefined && (typeof timeout !== \"number\" || !(timeout > 0))) {\n\t\treturn \"timeout must be a positive number of seconds\";\n\t}\n\treturn undefined;\n}\n\n/** An error message, or the `oauth` object to put in the config when validation normalized it. */\nfunction validateHttpFields(\n\tentry: Record<string, unknown>,\n\turl: string,\n\toptions: McpServerConfigOptions,\n): string | Record<string, unknown> | undefined {\n\tif (!URL.canParse(url) || !/^https?:$/.test(new URL(url).protocol)) return \"url must be an http or https URL\";\n\tif (entry.headers !== undefined && !isStringRecord(entry.headers)) return \"headers must map names to strings\";\n\treturn validateOAuth(entry.oauth, options);\n}\n\nfunction validateStdioFields(entry: Record<string, unknown>): string | undefined {\n\tconst { args, env, cwd } = entry;\n\tif (args !== undefined && !(Array.isArray(args) && args.every((arg) => typeof arg === \"string\"))) {\n\t\treturn \"args must be an array of strings\";\n\t}\n\tif (env !== undefined && !isStringRecord(env)) return \"env must map names to strings\";\n\tif (cwd !== undefined && typeof cwd !== \"string\") return \"cwd must be a string\";\n\treturn undefined;\n}\n\nfunction isStringRecord(value: unknown): value is Record<string, string> {\n\treturn isRecord(value) && Object.values(value).every((entry) => typeof entry === \"string\");\n}\n\nconst LOOPBACK_HOSTS = [\"localhost\", \"127.0.0.1\", \"[::1]\"];\n\n/** An error message, a copy of `value` with a normalized `clientMetadataBaseUrl`, or `undefined` when valid as is. */\nfunction validateOAuth(value: unknown, options: McpServerConfigOptions): string | Record<string, unknown> | undefined {\n\tif (value === undefined) return undefined;\n\tif (!isRecord(value)) return \"oauth must be an object\";\n\tif (value.clientId !== undefined && typeof value.clientId !== \"string\") return \"oauth.clientId must be a string\";\n\tif (value.clientSecret !== undefined && typeof value.clientSecret !== \"string\") {\n\t\treturn \"oauth.clientSecret must be a string\";\n\t}\n\tconst port = value.callbackPort;\n\tif (port !== undefined && (typeof port !== \"number\" || !Number.isInteger(port) || port < 1 || port > 65535)) {\n\t\treturn \"oauth.callbackPort must be a port number\";\n\t}\n\tif (value.callbackUrl !== undefined) {\n\t\tif (typeof value.callbackUrl !== \"string\" || !isLoopbackRedirectUri(value.callbackUrl)) {\n\t\t\treturn \"oauth.callbackUrl must be an http URI on localhost, 127.0.0.1, or [::1] without query or fragment\";\n\t\t}\n\t\tconst urlPort = new URL(value.callbackUrl).port;\n\t\tif (urlPort && port !== undefined && Number(urlPort) !== port) {\n\t\t\treturn \"oauth.callbackUrl and oauth.callbackPort name different ports\";\n\t\t}\n\t}\n\tif (value.scope !== undefined && typeof value.scope !== \"string\") return \"oauth.scope must be a string\";\n\tif (value.clientName !== undefined && (typeof value.clientName !== \"string\" || !value.clientName.trim())) {\n\t\treturn \"oauth.clientName must be a non-empty string\";\n\t}\n\t// draht: no `auto`. `cimd` is the operator's opt-in and a public client, so it takes no client id, name,\n\t// or secret, and it needs the operator's base; a base without `cimd` is a configuration mistake.\n\tconst registration = value.clientRegistration;\n\tlet clientMetadataBaseUrl: string | undefined;\n\tif (registration !== undefined && registration !== \"dcr\") {\n\t\tif (registration !== \"cimd\") return 'oauth.clientRegistration must be \"dcr\" or \"cimd\"';\n\t\tif (value.clientId !== undefined || value.clientName !== undefined || value.clientSecret !== undefined) {\n\t\t\treturn 'oauth.clientRegistration \"cimd\" cannot be combined with oauth.clientId, oauth.clientName, or oauth.clientSecret';\n\t\t}\n\t\tif (!options.checkMetadataDocumentCallback) {\n\t\t\treturn 'oauth.clientRegistration \"cimd\" is not supported: there are no Client ID Metadata Documents';\n\t\t}\n\t\tconst callbackError = options.checkMetadataDocumentCallback(\n\t\t\ttypeof value.callbackUrl === \"string\" ? value.callbackUrl : undefined,\n\t\t);\n\t\tif (callbackError) return callbackError;\n\t\tclientMetadataBaseUrl = parseClientMetadataBaseUrl(value.clientMetadataBaseUrl);\n\t\tif (!clientMetadataBaseUrl) {\n\t\t\treturn 'oauth.clientMetadataBaseUrl is required for \"cimd\" and must be an absolute HTTPS URL without userinfo, query, or fragment';\n\t\t}\n\t} else if (value.clientMetadataBaseUrl !== undefined) {\n\t\treturn 'oauth.clientMetadataBaseUrl requires oauth.clientRegistration \"cimd\"';\n\t}\n\tconst metadataUrl = value.authServerMetadataUrl;\n\tif (metadataUrl !== undefined) {\n\t\tconst url = typeof metadataUrl === \"string\" && URL.canParse(metadataUrl) ? new URL(metadataUrl) : undefined;\n\t\tif (!url || !(url.protocol === \"https:\" || (url.protocol === \"http:\" && LOOPBACK_HOSTS.includes(url.hostname)))) {\n\t\t\treturn \"oauth.authServerMetadataUrl must be an https URL, or http on localhost, 127.0.0.1, or [::1]\";\n\t\t}\n\t}\n\treturn clientMetadataBaseUrl ? { ...value, clientMetadataBaseUrl } : undefined;\n}\n\n/** Whether a redirect URI can be served by a loopback callback server. */\nfunction isLoopbackRedirectUri(value: string): boolean {\n\tif (!URL.canParse(value)) return false;\n\tconst url = new URL(value);\n\treturn url.protocol === \"http:\" && LOOPBACK_HOSTS.includes(url.hostname) && url.search === \"\" && url.hash === \"\";\n}\n\n/**\n * Whether an entry overrides a server defined elsewhere instead of defining one: it has no `command`,\n * `url` or `type`. Applications let a less trusted file (a project's) override a few fields, such as\n * `enabled`, of a server a trusted file defines; which fields is theirs to decide.\n */\nexport function isMcpServerOverride(entry: Record<string, unknown>): boolean {\n\treturn entry.command === undefined && entry.url === undefined && entry.type === undefined;\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
export type { AuthProvider, McpFetch, UnauthorizedContext } from "./auth-provider.ts";
|
|
2
2
|
export { McpClient, type McpClientOptions, type McpRequestOptions } from "./client.ts";
|
|
3
|
+
export { isMcpServerOverride, type McpHttpServerConfig, type McpOAuthConfig, type McpServerConfig, type McpServerConfigOptions, type McpServerConfigResult, type McpStdioServerConfig, validateMcpServerConfig, } from "./config.ts";
|
|
4
|
+
export { normalizeMcpInputSchema } from "./input-schema.ts";
|
|
5
|
+
export { createMcpToolName, mcpNamespace } from "./naming.ts";
|
|
6
|
+
export { type LimitedMcpContent, limitMcpContent, MCP_OUTPUT_MAX_BYTES, type McpOutputSaver, } from "./output-limit.ts";
|
|
3
7
|
export { type AudioContent, type BlobResourceContents, type CallToolResult, type ContentAnnotations, type ContentBlock, type EmbeddedResourceContent, type ImageContent, type LlmContent, type ResourceLinkContent, type TextContent, type TextResourceContents, toLlmContent, } from "./protocol/content.ts";
|
|
4
8
|
export { isJsonRpcNotification, isJsonRpcRequest, isJsonRpcResponse, JSON_RPC_ERROR_CODES, type JsonRpcErrorObject, type JsonRpcErrorResponse, type JsonRpcId, type JsonRpcMessage, type JsonRpcNotification, type JsonRpcRequest, type JsonRpcResponse, type JsonRpcSuccessResponse, McpAbortError, McpConnectionClosedError, McpError, McpTimeoutError, parseJsonRpcMessage, } from "./protocol/jsonrpc.ts";
|
|
5
9
|
export { type CancelledNotification, type ClientCapabilities, type Implementation, type InitializeParams, type InitializeResult, LATEST_PROTOCOL_VERSION, type ListResourcesResult, type ListResourceTemplatesResult, type ListToolsResult, type ProgressNotification, type ReadResourceResult, type Resource, type ResourceTemplate, type Root, type ServerCapabilities, SUPPORTED_PROTOCOL_VERSIONS, type SupportedProtocolVersion, type Tool, type ToolAnnotations, type ToolExecution, } from "./protocol/types.ts";
|
|
10
|
+
export { type McpPipe, type McpPipeHandlers, PipeTransport, type PipeTransportOptions, } from "./transports/pipe.ts";
|
|
6
11
|
export { StdioTransport, type StdioTransportOptions } from "./transports/stdio.ts";
|
|
7
12
|
export { McpAuthRequiredError, McpHttpError, McpSessionExpiredError, StreamableHttpTransport, type StreamableHttpTransportOptions, } from "./transports/streamable-http.ts";
|
|
8
13
|
export type { McpTransport, McpTransportCloseListener, McpTransportErrorListener, McpTransportMessageListener, McpTransportSendOptions, } from "./transports/transport.ts";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts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,EACvB,KAAK,oBAAoB,EACzB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,aAAa,EACb,wBAAwB,EACxB,QAAQ,EACR,eAAe,EACf,mBAAmB,GACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,uBAAuB,EACvB,KAAK,mBAAmB,EACxB,KAAK,2BAA2B,EAChC,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,IAAI,EACT,KAAK,kBAAkB,EACvB,2BAA2B,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,IAAI,EACT,KAAK,eAAe,EACpB,KAAK,aAAa,GAClB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,KAAK,OAAO,EACZ,KAAK,eAAe,EACpB,aAAa,EACb,KAAK,oBAAoB,GACzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACnF,OAAO,EACN,oBAAoB,EACpB,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,EACvB,KAAK,8BAA8B,GACnC,MAAM,iCAAiC,CAAC;AACzC,YAAY,EACX,YAAY,EACZ,yBAAyB,EACzB,yBAAyB,EACzB,2BAA2B,EAC3B,uBAAuB,GACvB,MAAM,2BAA2B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
export { McpClient } from "./client.js";
|
|
2
|
+
export { isMcpServerOverride, validateMcpServerConfig, } from "./config.js";
|
|
3
|
+
export { normalizeMcpInputSchema } from "./input-schema.js";
|
|
4
|
+
export { createMcpToolName, mcpNamespace } from "./naming.js";
|
|
5
|
+
export { limitMcpContent, MCP_OUTPUT_MAX_BYTES, } from "./output-limit.js";
|
|
2
6
|
export { toLlmContent, } from "./protocol/content.js";
|
|
3
7
|
export { isJsonRpcNotification, isJsonRpcRequest, isJsonRpcResponse, JSON_RPC_ERROR_CODES, McpAbortError, McpConnectionClosedError, McpError, McpTimeoutError, parseJsonRpcMessage, } from "./protocol/jsonrpc.js";
|
|
4
8
|
export { LATEST_PROTOCOL_VERSION, SUPPORTED_PROTOCOL_VERSIONS, } from "./protocol/types.js";
|
|
9
|
+
export { PipeTransport, } from "./transports/pipe.js";
|
|
5
10
|
export { StdioTransport } from "./transports/stdio.js";
|
|
6
11
|
export { McpAuthRequiredError, McpHttpError, McpSessionExpiredError, StreamableHttpTransport, } from "./transports/streamable-http.js";
|
|
7
12
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAiD,MAAM,aAAa,CAAC;AACvF,OAAO,EAYN,YAAY,GACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EASpB,aAAa,EACb,wBAAwB,EACxB,QAAQ,EACR,eAAe,EACf,mBAAmB,GACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAMN,uBAAuB,EAUvB,2BAA2B,GAK3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAA8B,MAAM,uBAAuB,CAAC;AACnF,OAAO,EACN,oBAAoB,EACpB,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,GAEvB,MAAM,iCAAiC,CAAC","sourcesContent":["export type { AuthProvider, McpFetch, UnauthorizedContext } from \"./auth-provider.ts\";\nexport { McpClient, type McpClientOptions, type McpRequestOptions } from \"./client.ts\";\nexport {\n\ttype AudioContent,\n\ttype BlobResourceContents,\n\ttype CallToolResult,\n\ttype ContentAnnotations,\n\ttype ContentBlock,\n\ttype EmbeddedResourceContent,\n\ttype ImageContent,\n\ttype LlmContent,\n\ttype ResourceLinkContent,\n\ttype TextContent,\n\ttype TextResourceContents,\n\ttoLlmContent,\n} from \"./protocol/content.ts\";\nexport {\n\tisJsonRpcNotification,\n\tisJsonRpcRequest,\n\tisJsonRpcResponse,\n\tJSON_RPC_ERROR_CODES,\n\ttype JsonRpcErrorObject,\n\ttype JsonRpcErrorResponse,\n\ttype JsonRpcId,\n\ttype JsonRpcMessage,\n\ttype JsonRpcNotification,\n\ttype JsonRpcRequest,\n\ttype JsonRpcResponse,\n\ttype JsonRpcSuccessResponse,\n\tMcpAbortError,\n\tMcpConnectionClosedError,\n\tMcpError,\n\tMcpTimeoutError,\n\tparseJsonRpcMessage,\n} from \"./protocol/jsonrpc.ts\";\nexport {\n\ttype CancelledNotification,\n\ttype ClientCapabilities,\n\ttype Implementation,\n\ttype InitializeParams,\n\ttype InitializeResult,\n\tLATEST_PROTOCOL_VERSION,\n\ttype ListResourcesResult,\n\ttype ListResourceTemplatesResult,\n\ttype ListToolsResult,\n\ttype ProgressNotification,\n\ttype ReadResourceResult,\n\ttype Resource,\n\ttype ResourceTemplate,\n\ttype Root,\n\ttype ServerCapabilities,\n\tSUPPORTED_PROTOCOL_VERSIONS,\n\ttype SupportedProtocolVersion,\n\ttype Tool,\n\ttype ToolAnnotations,\n\ttype ToolExecution,\n} from \"./protocol/types.ts\";\nexport { StdioTransport, type StdioTransportOptions } from \"./transports/stdio.ts\";\nexport {\n\tMcpAuthRequiredError,\n\tMcpHttpError,\n\tMcpSessionExpiredError,\n\tStreamableHttpTransport,\n\ttype StreamableHttpTransportOptions,\n} from \"./transports/streamable-http.ts\";\nexport type {\n\tMcpTransport,\n\tMcpTransportCloseListener,\n\tMcpTransportErrorListener,\n\tMcpTransportMessageListener,\n\tMcpTransportSendOptions,\n} from \"./transports/transport.ts\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAiD,MAAM,aAAa,CAAC;AACvF,OAAO,EACN,mBAAmB,EAOnB,uBAAuB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAEN,eAAe,EACf,oBAAoB,GAEpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAYN,YAAY,GACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EASpB,aAAa,EACb,wBAAwB,EACxB,QAAQ,EACR,eAAe,EACf,mBAAmB,GACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAMN,uBAAuB,EAUvB,2BAA2B,GAK3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAGN,aAAa,GAEb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAA8B,MAAM,uBAAuB,CAAC;AACnF,OAAO,EACN,oBAAoB,EACpB,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,GAEvB,MAAM,iCAAiC,CAAC","sourcesContent":["export type { AuthProvider, McpFetch, UnauthorizedContext } from \"./auth-provider.ts\";\nexport { McpClient, type McpClientOptions, type McpRequestOptions } from \"./client.ts\";\nexport {\n\tisMcpServerOverride,\n\ttype McpHttpServerConfig,\n\ttype McpOAuthConfig,\n\ttype McpServerConfig,\n\ttype McpServerConfigOptions,\n\ttype McpServerConfigResult,\n\ttype McpStdioServerConfig,\n\tvalidateMcpServerConfig,\n} from \"./config.ts\";\nexport { normalizeMcpInputSchema } from \"./input-schema.ts\";\nexport { createMcpToolName, mcpNamespace } from \"./naming.ts\";\nexport {\n\ttype LimitedMcpContent,\n\tlimitMcpContent,\n\tMCP_OUTPUT_MAX_BYTES,\n\ttype McpOutputSaver,\n} from \"./output-limit.ts\";\nexport {\n\ttype AudioContent,\n\ttype BlobResourceContents,\n\ttype CallToolResult,\n\ttype ContentAnnotations,\n\ttype ContentBlock,\n\ttype EmbeddedResourceContent,\n\ttype ImageContent,\n\ttype LlmContent,\n\ttype ResourceLinkContent,\n\ttype TextContent,\n\ttype TextResourceContents,\n\ttoLlmContent,\n} from \"./protocol/content.ts\";\nexport {\n\tisJsonRpcNotification,\n\tisJsonRpcRequest,\n\tisJsonRpcResponse,\n\tJSON_RPC_ERROR_CODES,\n\ttype JsonRpcErrorObject,\n\ttype JsonRpcErrorResponse,\n\ttype JsonRpcId,\n\ttype JsonRpcMessage,\n\ttype JsonRpcNotification,\n\ttype JsonRpcRequest,\n\ttype JsonRpcResponse,\n\ttype JsonRpcSuccessResponse,\n\tMcpAbortError,\n\tMcpConnectionClosedError,\n\tMcpError,\n\tMcpTimeoutError,\n\tparseJsonRpcMessage,\n} from \"./protocol/jsonrpc.ts\";\nexport {\n\ttype CancelledNotification,\n\ttype ClientCapabilities,\n\ttype Implementation,\n\ttype InitializeParams,\n\ttype InitializeResult,\n\tLATEST_PROTOCOL_VERSION,\n\ttype ListResourcesResult,\n\ttype ListResourceTemplatesResult,\n\ttype ListToolsResult,\n\ttype ProgressNotification,\n\ttype ReadResourceResult,\n\ttype Resource,\n\ttype ResourceTemplate,\n\ttype Root,\n\ttype ServerCapabilities,\n\tSUPPORTED_PROTOCOL_VERSIONS,\n\ttype SupportedProtocolVersion,\n\ttype Tool,\n\ttype ToolAnnotations,\n\ttype ToolExecution,\n} from \"./protocol/types.ts\";\nexport {\n\ttype McpPipe,\n\ttype McpPipeHandlers,\n\tPipeTransport,\n\ttype PipeTransportOptions,\n} from \"./transports/pipe.ts\";\nexport { StdioTransport, type StdioTransportOptions } from \"./transports/stdio.ts\";\nexport {\n\tMcpAuthRequiredError,\n\tMcpHttpError,\n\tMcpSessionExpiredError,\n\tStreamableHttpTransport,\n\ttype StreamableHttpTransportOptions,\n} from \"./transports/streamable-http.ts\";\nexport type {\n\tMcpTransport,\n\tMcpTransportCloseListener,\n\tMcpTransportErrorListener,\n\tMcpTransportMessageListener,\n\tMcpTransportSendOptions,\n} from \"./transports/transport.ts\";\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** An MCP tool's input schema in the shape LLM tool APIs accept. */
|
|
2
|
+
/**
|
|
3
|
+
* The tool's input schema as an object schema. Tool parameters must be objects, MCP servers may omit
|
|
4
|
+
* `type`, and some providers reject object schemas without `properties`. Other keywords are kept.
|
|
5
|
+
*/
|
|
6
|
+
export declare function normalizeMcpInputSchema(schema: Record<string, unknown>): Record<string, unknown>;
|
|
7
|
+
//# sourceMappingURL=input-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-schema.d.ts","sourceRoot":"","sources":["../src/input-schema.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAEpE;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAMhG"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** An MCP tool's input schema in the shape LLM tool APIs accept. */
|
|
2
|
+
/**
|
|
3
|
+
* The tool's input schema as an object schema. Tool parameters must be objects, MCP servers may omit
|
|
4
|
+
* `type`, and some providers reject object schemas without `properties`. Other keywords are kept.
|
|
5
|
+
*/
|
|
6
|
+
export function normalizeMcpInputSchema(schema) {
|
|
7
|
+
return {
|
|
8
|
+
...schema,
|
|
9
|
+
type: schema.type ?? "object",
|
|
10
|
+
...(schema.properties === undefined ? { properties: {} } : {}),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=input-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-schema.js","sourceRoot":"","sources":["../src/input-schema.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAEpE;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAA+B;IACtE,OAAO;QACN,GAAG,MAAM;QACT,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,QAAQ;QAC7B,GAAG,CAAC,MAAM,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC9D,CAAC;AACH,CAAC","sourcesContent":["/** An MCP tool's input schema in the shape LLM tool APIs accept. */\n\n/**\n * The tool's input schema as an object schema. Tool parameters must be objects, MCP servers may omit\n * `type`, and some providers reject object schemas without `properties`. Other keywords are kept.\n */\nexport function normalizeMcpInputSchema(schema: Record<string, unknown>): Record<string, unknown> {\n\treturn {\n\t\t...schema,\n\t\ttype: schema.type ?? \"object\",\n\t\t...(schema.properties === undefined ? { properties: {} } : {}),\n\t};\n}\n"]}
|
package/dist/naming.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Names of MCP tools and of their servers' namespaces as models and code mode scripts see them.
|
|
3
|
+
* Applications that name tools the same way rank and group them the same way in tool search and
|
|
4
|
+
* code mode.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* `mcp__<server>__<tool>`, sanitized and shortened with a hash suffix when too long. Like Codex,
|
|
8
|
+
* everything but `[A-Za-z0-9_]` becomes `_`, so the name is also the identifier code mode scripts
|
|
9
|
+
* call it by. `isTaken` reports names used by a different MCP tool: sanitizing can map two tools to
|
|
10
|
+
* one name (`a-b` and `a_b`), which then get the hash suffix.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createMcpToolName(server: string, tool: string, isTaken?: (name: string) => boolean): string;
|
|
13
|
+
/**
|
|
14
|
+
* Namespace of a server's tools: `mcp__<server>` with `-` replaced by `_`, like the tool names. Server
|
|
15
|
+
* names that differ only in `-` and `_` share a namespace, so a configuration must not have both.
|
|
16
|
+
*/
|
|
17
|
+
export declare function mcpNamespace(server: string): string;
|
|
18
|
+
//# sourceMappingURL=naming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"naming.d.ts","sourceRoot":"","sources":["../src/naming.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAqB,GAC9C,MAAM,CAKR;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEnD"}
|
package/dist/naming.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Names of MCP tools and of their servers' namespaces as models and code mode scripts see them.
|
|
3
|
+
* Applications that name tools the same way rank and group them the same way in tool search and
|
|
4
|
+
* code mode.
|
|
5
|
+
*/
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
/** Provider tool names are limited to 64 characters of `[A-Za-z0-9_-]`. */
|
|
8
|
+
const MAX_TOOL_NAME_LENGTH = 64;
|
|
9
|
+
/**
|
|
10
|
+
* `mcp__<server>__<tool>`, sanitized and shortened with a hash suffix when too long. Like Codex,
|
|
11
|
+
* everything but `[A-Za-z0-9_]` becomes `_`, so the name is also the identifier code mode scripts
|
|
12
|
+
* call it by. `isTaken` reports names used by a different MCP tool: sanitizing can map two tools to
|
|
13
|
+
* one name (`a-b` and `a_b`), which then get the hash suffix.
|
|
14
|
+
*/
|
|
15
|
+
export function createMcpToolName(server, tool, isTaken = () => false) {
|
|
16
|
+
const name = `mcp__${server}__${tool}`.replace(/[^A-Za-z0-9_]/g, "_");
|
|
17
|
+
if (name.length <= MAX_TOOL_NAME_LENGTH && !isTaken(name))
|
|
18
|
+
return name;
|
|
19
|
+
const hash = createHash("sha256").update(`${server}\0${tool}`).digest("hex").slice(0, 8);
|
|
20
|
+
return `${name.slice(0, MAX_TOOL_NAME_LENGTH - hash.length - 1)}_${hash}`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Namespace of a server's tools: `mcp__<server>` with `-` replaced by `_`, like the tool names. Server
|
|
24
|
+
* names that differ only in `-` and `_` share a namespace, so a configuration must not have both.
|
|
25
|
+
*/
|
|
26
|
+
export function mcpNamespace(server) {
|
|
27
|
+
return `mcp__${server.replace(/-/g, "_")}`;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=naming.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"naming.js","sourceRoot":"","sources":["../src/naming.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,2EAA2E;AAC3E,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAEhC;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAChC,MAAc,EACd,IAAY,EACZ,OAAO,GAA8B,GAAG,EAAE,CAAC,KAAK;IAEhD,MAAM,IAAI,GAAG,QAAQ,MAAM,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC;IACtE,IAAI,IAAI,CAAC,MAAM,IAAI,oBAAoB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACvE,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,MAAM,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACzF,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,oBAAoB,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;AAC3E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,MAAc;IAC1C,OAAO,QAAQ,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;AAC5C,CAAC","sourcesContent":["/**\n * Names of MCP tools and of their servers' namespaces as models and code mode scripts see them.\n * Applications that name tools the same way rank and group them the same way in tool search and\n * code mode.\n */\n\nimport { createHash } from \"node:crypto\";\n\n/** Provider tool names are limited to 64 characters of `[A-Za-z0-9_-]`. */\nconst MAX_TOOL_NAME_LENGTH = 64;\n\n/**\n * `mcp__<server>__<tool>`, sanitized and shortened with a hash suffix when too long. Like Codex,\n * everything but `[A-Za-z0-9_]` becomes `_`, so the name is also the identifier code mode scripts\n * call it by. `isTaken` reports names used by a different MCP tool: sanitizing can map two tools to\n * one name (`a-b` and `a_b`), which then get the hash suffix.\n */\nexport function createMcpToolName(\n\tserver: string,\n\ttool: string,\n\tisTaken: (name: string) => boolean = () => false,\n): string {\n\tconst name = `mcp__${server}__${tool}`.replace(/[^A-Za-z0-9_]/g, \"_\");\n\tif (name.length <= MAX_TOOL_NAME_LENGTH && !isTaken(name)) return name;\n\tconst hash = createHash(\"sha256\").update(`${server}\\0${tool}`).digest(\"hex\").slice(0, 8);\n\treturn `${name.slice(0, MAX_TOOL_NAME_LENGTH - hash.length - 1)}_${hash}`;\n}\n\n/**\n * Namespace of a server's tools: `mcp__<server>` with `-` replaced by `_`, like the tool names. Server\n * names that differ only in `-` and `_` share a namespace, so a configuration must not have both.\n */\nexport function mcpNamespace(server: string): string {\n\treturn `mcp__${server.replace(/-/g, \"_\")}`;\n}\n"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The auth provider for connections to an OAuth-protected MCP server: it sends the stored access token
|
|
3
|
+
* and refreshes it, but never starts a browser flow. When the user has to sign in, it fails with
|
|
4
|
+
* `McpOAuthAuthorizationRequiredError` and the application runs `startMcpSignIn`.
|
|
5
|
+
*/
|
|
6
|
+
import type { AuthProvider, McpFetch } from "../auth-provider.ts";
|
|
7
|
+
import { type McpOAuthClientOptions, type McpOAuthSettings } from "./client-settings.ts";
|
|
8
|
+
import { type OAuthFlowResult } from "./flow.ts";
|
|
9
|
+
import type { McpOAuthState } from "./provider.ts";
|
|
10
|
+
import type { OAuthChallenge } from "./types.ts";
|
|
11
|
+
/** An `AuthProvider` that can say when its refreshes have finished. */
|
|
12
|
+
export interface McpAuthProvider extends AuthProvider {
|
|
13
|
+
/** Resolves when no refresh is running, so shutdown does not drop rotated tokens before they are saved. */
|
|
14
|
+
settled(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Auth provider for MCP connections: sends the stored access token and refreshes it when it is about
|
|
18
|
+
* to expire or after a 401. Throws `McpOAuthAuthorizationRequiredError` when the user has to sign in,
|
|
19
|
+
* including when the server asks for more scope (`insufficient_scope`). `onChallenge` receives the
|
|
20
|
+
* server's `WWW-Authenticate` challenge so sign-in can use its resource metadata URL and scope.
|
|
21
|
+
* `settings` is only called when a refresh is needed, so a secret that fails to resolve fails the
|
|
22
|
+
* refresh instead of the whole connection setup, and reading a cached token never resolves one.
|
|
23
|
+
*
|
|
24
|
+
* Many servers rotate refresh tokens, so two refreshes with the same refresh token lose the grant.
|
|
25
|
+
* Requests in this process share one refresh, and other processes are kept out by the store's
|
|
26
|
+
* refresh lock, held from reading the tokens to saving new ones. Tokens that changed meanwhile
|
|
27
|
+
* (another process refreshed them, or the user signed in) are used without refreshing.
|
|
28
|
+
*
|
|
29
|
+
* draht: stored tokens are only sent and refreshed when they belong to the client `clientMetadataBaseUrl`
|
|
30
|
+
* names; tokens of a former registration mode or metadata base need a new sign-in.
|
|
31
|
+
*/
|
|
32
|
+
export declare function createMcpAuthProvider(options: Omit<McpOAuthClientOptions, "settings"> & {
|
|
33
|
+
/**
|
|
34
|
+
* draht: the client stored tokens must belong to: the operator's validated `clientMetadataBaseUrl` with
|
|
35
|
+
* `cimd`, `undefined` otherwise. Passed apart from `settings` so reading a cached token never calls
|
|
36
|
+
* `settings`, which may resolve secrets. Must name the same base as `settings().clientMetadataBaseUrl`;
|
|
37
|
+
* a refresh with settings that name another one is refused.
|
|
38
|
+
*/
|
|
39
|
+
clientMetadataBaseUrl: string | undefined;
|
|
40
|
+
settings: () => McpOAuthSettings;
|
|
41
|
+
onChallenge: (challenge: OAuthChallenge) => void;
|
|
42
|
+
/**
|
|
43
|
+
* A redirect URI the application signs in with, such as its https callback route. Refreshing tokens
|
|
44
|
+
* from a sign-in with a Client ID Metadata Document needs a redirect URI the documents list; a
|
|
45
|
+
* refresh never redirects, so any listed one works. Default: the loopback redirect URI of `settings`.
|
|
46
|
+
*/
|
|
47
|
+
redirectUrl?: string;
|
|
48
|
+
}): McpAuthProvider;
|
|
49
|
+
/**
|
|
50
|
+
* Refresh the tokens of `state` with the stored client (or the document it signed in with), or report
|
|
51
|
+
* `REDIRECT` when that is not possible. `options.redirectUrl` is a redirect URI the application signs in
|
|
52
|
+
* with, tried before the loopback ones of the settings and the stored client. Never registers a client or
|
|
53
|
+
* prepares an authorization request, so a pending sign-in stays usable. Call while holding the store's
|
|
54
|
+
* refresh lock. Not cancellable: a refresh the server answered may have rotated the refresh token, so its
|
|
55
|
+
* answer must be saved.
|
|
56
|
+
* draht: tokens that do not belong to the client `client.settings` identify as are not refreshed.
|
|
57
|
+
*/
|
|
58
|
+
export declare function refreshStoredTokens(client: McpOAuthClientOptions, state: McpOAuthState, options?: {
|
|
59
|
+
fetch?: McpFetch;
|
|
60
|
+
challenge?: OAuthChallenge;
|
|
61
|
+
redirectUrl?: string;
|
|
62
|
+
}): Promise<OAuthFlowResult>;
|
|
63
|
+
//# sourceMappingURL=auth-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-provider.d.ts","sourceRoot":"","sources":["../../src/oauth/auth-provider.ts"],"names":[],"mappings":"AAAA;;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