@fitchmultz/pi-mcp-adapter 5.0.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.
Files changed (176) hide show
  1. package/CHANGELOG.md +750 -0
  2. package/LICENSE +21 -0
  3. package/OAUTH.md +462 -0
  4. package/README.md +820 -0
  5. package/abort.ts +34 -0
  6. package/agent-dir.ts +24 -0
  7. package/app-bridge.bundle.js +67 -0
  8. package/banner.png +0 -0
  9. package/checkpoint.ts +55 -0
  10. package/cli.js +222 -0
  11. package/commands.ts +619 -0
  12. package/config.ts +1204 -0
  13. package/consent-manager.ts +25 -0
  14. package/direct-tools.ts +408 -0
  15. package/dist/abort.d.ts +2 -0
  16. package/dist/abort.js +35 -0
  17. package/dist/agent-dir.d.ts +3 -0
  18. package/dist/agent-dir.js +21 -0
  19. package/dist/app-bridge.bundle.js +67 -0
  20. package/dist/checkpoint.d.ts +18 -0
  21. package/dist/checkpoint.js +53 -0
  22. package/dist/commands.d.ts +20 -0
  23. package/dist/commands.js +521 -0
  24. package/dist/config.d.ts +109 -0
  25. package/dist/config.js +1013 -0
  26. package/dist/consent-manager.d.ts +8 -0
  27. package/dist/consent-manager.js +21 -0
  28. package/dist/direct-tools.d.ts +10 -0
  29. package/dist/direct-tools.js +350 -0
  30. package/dist/docs/client-metadata.json +14 -0
  31. package/dist/elicitation-handler.d.ts +17 -0
  32. package/dist/elicitation-handler.js +308 -0
  33. package/dist/error-signal.d.ts +15 -0
  34. package/dist/error-signal.js +21 -0
  35. package/dist/glimpse-ui.d.ts +9 -0
  36. package/dist/glimpse-ui.js +75 -0
  37. package/dist/host-html-template.d.ts +15 -0
  38. package/dist/host-html-template.js +429 -0
  39. package/dist/index.d.ts +7 -0
  40. package/dist/index.js +840 -0
  41. package/dist/init.d.ts +25 -0
  42. package/dist/init.js +562 -0
  43. package/dist/legacy-migration.d.ts +18 -0
  44. package/dist/legacy-migration.js +45 -0
  45. package/dist/lifecycle.d.ts +40 -0
  46. package/dist/lifecycle.js +167 -0
  47. package/dist/logger.d.ts +38 -0
  48. package/dist/logger.js +102 -0
  49. package/dist/mcp-auth-flow.d.ts +113 -0
  50. package/dist/mcp-auth-flow.js +834 -0
  51. package/dist/mcp-auth.d.ts +127 -0
  52. package/dist/mcp-auth.js +658 -0
  53. package/dist/mcp-callback-server.d.ts +56 -0
  54. package/dist/mcp-callback-server.js +371 -0
  55. package/dist/mcp-code.d.ts +51 -0
  56. package/dist/mcp-code.js +366 -0
  57. package/dist/mcp-keyring-helper.cjs +89 -0
  58. package/dist/mcp-oauth-provider.d.ts +154 -0
  59. package/dist/mcp-oauth-provider.js +672 -0
  60. package/dist/mcp-output-guard.d.ts +59 -0
  61. package/dist/mcp-output-guard.js +332 -0
  62. package/dist/mcp-panel.d.ts +66 -0
  63. package/dist/mcp-panel.js +889 -0
  64. package/dist/mcp-script-worker.mjs +128 -0
  65. package/dist/mcp-setup-panel.d.ts +84 -0
  66. package/dist/mcp-setup-panel.js +561 -0
  67. package/dist/mcp-status.d.ts +11 -0
  68. package/dist/mcp-status.js +96 -0
  69. package/dist/mcp-trace.d.ts +95 -0
  70. package/dist/mcp-trace.js +233 -0
  71. package/dist/metadata-cache.d.ts +18 -0
  72. package/dist/metadata-cache.js +277 -0
  73. package/dist/npx-resolver.d.ts +6 -0
  74. package/dist/npx-resolver.js +448 -0
  75. package/dist/onboarding-state.d.ts +11 -0
  76. package/dist/onboarding-state.js +47 -0
  77. package/dist/panel-keys.d.ts +16 -0
  78. package/dist/panel-keys.js +15 -0
  79. package/dist/prompts.d.ts +56 -0
  80. package/dist/prompts.js +284 -0
  81. package/dist/proxy-modes.d.ts +38 -0
  82. package/dist/proxy-modes.js +1235 -0
  83. package/dist/resource-tools.d.ts +1 -0
  84. package/dist/resource-tools.js +14 -0
  85. package/dist/runtime-owner.d.ts +18 -0
  86. package/dist/runtime-owner.js +117 -0
  87. package/dist/sampling-handler.d.ts +15 -0
  88. package/dist/sampling-handler.js +211 -0
  89. package/dist/search-ranking.d.ts +20 -0
  90. package/dist/search-ranking.js +180 -0
  91. package/dist/server-manager.d.ts +114 -0
  92. package/dist/server-manager.js +1175 -0
  93. package/dist/session-recovery.d.ts +31 -0
  94. package/dist/session-recovery.js +310 -0
  95. package/dist/state.d.ts +63 -0
  96. package/dist/state.js +1 -0
  97. package/dist/tool-approval.d.ts +10 -0
  98. package/dist/tool-approval.js +42 -0
  99. package/dist/tool-metadata.d.ts +9 -0
  100. package/dist/tool-metadata.js +193 -0
  101. package/dist/tool-registrar.d.ts +10 -0
  102. package/dist/tool-registrar.js +64 -0
  103. package/dist/tool-result-renderer.d.ts +45 -0
  104. package/dist/tool-result-renderer.js +224 -0
  105. package/dist/ts-shape.d.ts +2 -0
  106. package/dist/ts-shape.js +147 -0
  107. package/dist/types.d.ts +516 -0
  108. package/dist/types.js +168 -0
  109. package/dist/ui-resource-handler.d.ts +17 -0
  110. package/dist/ui-resource-handler.js +209 -0
  111. package/dist/ui-server.d.ts +51 -0
  112. package/dist/ui-server.js +669 -0
  113. package/dist/ui-session.d.ts +39 -0
  114. package/dist/ui-session.js +463 -0
  115. package/dist/ui-stream-types.d.ts +104 -0
  116. package/dist/ui-stream-types.js +58 -0
  117. package/dist/ui-tool-visibility.d.ts +4 -0
  118. package/dist/ui-tool-visibility.js +26 -0
  119. package/dist/unix-socket-transport.d.ts +15 -0
  120. package/dist/unix-socket-transport.js +84 -0
  121. package/dist/utils.d.ts +30 -0
  122. package/dist/utils.js +276 -0
  123. package/docs/client-metadata.json +14 -0
  124. package/elicitation-handler.ts +349 -0
  125. package/error-signal.ts +21 -0
  126. package/glimpse-ui.ts +80 -0
  127. package/host-html-template.ts +456 -0
  128. package/index.ts +900 -0
  129. package/init.ts +627 -0
  130. package/legacy-migration.ts +47 -0
  131. package/lifecycle.ts +165 -0
  132. package/logger.ts +127 -0
  133. package/mcp-auth-flow.ts +975 -0
  134. package/mcp-auth.ts +793 -0
  135. package/mcp-callback-server.ts +450 -0
  136. package/mcp-code.ts +386 -0
  137. package/mcp-keyring-helper.cjs +89 -0
  138. package/mcp-oauth-provider.ts +774 -0
  139. package/mcp-output-guard.ts +412 -0
  140. package/mcp-panel.ts +978 -0
  141. package/mcp-script-worker.mjs +128 -0
  142. package/mcp-setup-panel.ts +666 -0
  143. package/mcp-status.ts +109 -0
  144. package/mcp-trace.ts +295 -0
  145. package/metadata-cache.ts +333 -0
  146. package/npx-resolver.ts +488 -0
  147. package/onboarding-state.ts +58 -0
  148. package/package.json +182 -0
  149. package/panel-keys.ts +37 -0
  150. package/prompts.ts +337 -0
  151. package/proxy-modes.ts +1361 -0
  152. package/resource-tools.ts +17 -0
  153. package/runtime-owner.ts +123 -0
  154. package/sampling-handler.ts +273 -0
  155. package/scripts/build.mjs +131 -0
  156. package/scripts/prepare.mjs +102 -0
  157. package/search-ranking.ts +196 -0
  158. package/server-manager.ts +1320 -0
  159. package/session-recovery.ts +316 -0
  160. package/skills/mcp-scripting/SKILL.md +38 -0
  161. package/state.ts +64 -0
  162. package/tool-approval.ts +78 -0
  163. package/tool-metadata.ts +235 -0
  164. package/tool-registrar.ts +69 -0
  165. package/tool-result-renderer.ts +286 -0
  166. package/ts-shape.ts +145 -0
  167. package/tsconfig.build.json +13 -0
  168. package/tsconfig.json +16 -0
  169. package/types.ts +810 -0
  170. package/ui-resource-handler.ts +249 -0
  171. package/ui-server.ts +808 -0
  172. package/ui-session.ts +568 -0
  173. package/ui-stream-types.ts +89 -0
  174. package/ui-tool-visibility.ts +25 -0
  175. package/unix-socket-transport.ts +85 -0
  176. package/utils.ts +309 -0
@@ -0,0 +1,40 @@
1
+ import { type ServerDefinition } from "./types.ts";
2
+ import type { McpServerManager } from "./server-manager.ts";
3
+ import { hasPendingAuth } from "./mcp-auth-flow.ts";
4
+ export type ReconnectCallback = (serverName: string) => void;
5
+ export type ReconnectFailureCallback = (serverName: string, error: unknown) => void;
6
+ export declare class McpLifecycleManager {
7
+ private readonly manager;
8
+ private readonly hasPendingAuthForServer;
9
+ private keepAliveServers;
10
+ private allServers;
11
+ private serverSettings;
12
+ private globalIdleTimeout;
13
+ private healthCheckInterval;
14
+ private onReconnect;
15
+ private onReconnectFailure;
16
+ private onIdleShutdown;
17
+ private activeHealthCheck;
18
+ private shutdownPromise;
19
+ private stopped;
20
+ private checkpointPauses;
21
+ hasActiveHealthCheck(): boolean;
22
+ /** Skip ticks, without cancelling accepted work or permanently closing the manager. */
23
+ pauseForCheckpoint(): () => void;
24
+ private healthSignal;
25
+ private removeHealthAbortListener;
26
+ constructor(manager: McpServerManager, hasPendingAuthForServer?: typeof hasPendingAuth);
27
+ setReconnectCallback(callback: ReconnectCallback): void;
28
+ setReconnectFailureCallback(callback: ReconnectFailureCallback): void;
29
+ markKeepAlive(name: string, definition: ServerDefinition): void;
30
+ registerServer(name: string, definition: ServerDefinition, settings?: {
31
+ idleTimeout?: number;
32
+ }): void;
33
+ setGlobalIdleTimeout(minutes: number): void;
34
+ setIdleShutdownCallback(callback: (serverName: string) => void): void;
35
+ startHealthChecks(signalOrInterval?: AbortSignal | number, maybeIntervalMs?: number): void;
36
+ private checkConnections;
37
+ private getIdleTimeout;
38
+ gracefulShutdown(): Promise<void>;
39
+ private shutdownOnce;
40
+ }
@@ -0,0 +1,167 @@
1
+ import { isServerDisabled } from "./types.js";
2
+ import { hasPendingAuth } from "./mcp-auth-flow.js";
3
+ import { logger } from "./logger.js";
4
+ import { formatTerminalError, sanitizeTerminalText } from "./utils.js";
5
+ export class McpLifecycleManager {
6
+ manager;
7
+ hasPendingAuthForServer;
8
+ keepAliveServers = new Map();
9
+ allServers = new Map();
10
+ serverSettings = new Map();
11
+ globalIdleTimeout = 10 * 60 * 1000;
12
+ healthCheckInterval;
13
+ onReconnect;
14
+ onReconnectFailure;
15
+ onIdleShutdown;
16
+ activeHealthCheck;
17
+ shutdownPromise;
18
+ stopped = false;
19
+ checkpointPauses = 0;
20
+ hasActiveHealthCheck() { return this.activeHealthCheck !== undefined; }
21
+ /** Skip ticks, without cancelling accepted work or permanently closing the manager. */
22
+ pauseForCheckpoint() {
23
+ this.checkpointPauses++;
24
+ let released = false;
25
+ return () => {
26
+ if (!released) {
27
+ released = true;
28
+ this.checkpointPauses--;
29
+ }
30
+ };
31
+ }
32
+ healthSignal;
33
+ removeHealthAbortListener;
34
+ constructor(manager, hasPendingAuthForServer = hasPendingAuth) {
35
+ this.manager = manager;
36
+ this.hasPendingAuthForServer = hasPendingAuthForServer;
37
+ }
38
+ setReconnectCallback(callback) {
39
+ this.onReconnect = callback;
40
+ }
41
+ setReconnectFailureCallback(callback) {
42
+ this.onReconnectFailure = callback;
43
+ }
44
+ markKeepAlive(name, definition) {
45
+ if (isServerDisabled(definition))
46
+ return;
47
+ this.keepAliveServers.set(name, definition);
48
+ }
49
+ registerServer(name, definition, settings) {
50
+ if (isServerDisabled(definition))
51
+ return;
52
+ this.allServers.set(name, definition);
53
+ if (settings?.idleTimeout !== undefined)
54
+ this.serverSettings.set(name, settings);
55
+ }
56
+ setGlobalIdleTimeout(minutes) {
57
+ this.globalIdleTimeout = minutes * 60 * 1000;
58
+ }
59
+ setIdleShutdownCallback(callback) {
60
+ this.onIdleShutdown = callback;
61
+ }
62
+ startHealthChecks(signalOrInterval, maybeIntervalMs = 30000) {
63
+ const signal = typeof signalOrInterval === "number" ? undefined : signalOrInterval;
64
+ const intervalMs = typeof signalOrInterval === "number" ? signalOrInterval : maybeIntervalMs;
65
+ if (this.healthCheckInterval)
66
+ clearInterval(this.healthCheckInterval);
67
+ this.removeHealthAbortListener?.();
68
+ this.stopped = false;
69
+ this.healthSignal = signal;
70
+ if (signal?.aborted) {
71
+ this.stopped = true;
72
+ this.healthSignal = undefined;
73
+ return;
74
+ }
75
+ const stop = () => {
76
+ this.stopped = true;
77
+ if (this.healthCheckInterval)
78
+ clearInterval(this.healthCheckInterval);
79
+ this.healthCheckInterval = undefined;
80
+ };
81
+ signal?.addEventListener("abort", stop, { once: true });
82
+ this.removeHealthAbortListener = () => signal?.removeEventListener("abort", stop);
83
+ this.healthCheckInterval = setInterval(() => {
84
+ if (this.stopped || signal?.aborted || this.activeHealthCheck || this.checkpointPauses > 0)
85
+ return;
86
+ const check = this.checkConnections(signal)
87
+ .catch(error => {
88
+ console.error(`MCP: Health check failed: ${formatTerminalError(error)}`);
89
+ })
90
+ .finally(() => {
91
+ if (this.activeHealthCheck === check)
92
+ this.activeHealthCheck = undefined;
93
+ });
94
+ this.activeHealthCheck = check;
95
+ }, intervalMs);
96
+ this.healthCheckInterval.unref();
97
+ }
98
+ async checkConnections(signal) {
99
+ if (this.stopped || signal?.aborted)
100
+ return;
101
+ for (const [name, definition] of this.keepAliveServers) {
102
+ if (isServerDisabled(definition))
103
+ continue;
104
+ const connection = this.manager.getConnection(name);
105
+ if (!connection || connection.status !== "connected") {
106
+ if (this.hasPendingAuthForServer(name)) {
107
+ logger.debug(`Skipping reconnect for ${name} while OAuth authorization is pending`);
108
+ continue;
109
+ }
110
+ try {
111
+ await this.manager.connect(name, definition, signal);
112
+ if (this.stopped || signal?.aborted)
113
+ return;
114
+ logger.debug(`Reconnected to ${name}`);
115
+ this.onReconnect?.(name);
116
+ }
117
+ catch (error) {
118
+ if (this.stopped || signal?.aborted)
119
+ return;
120
+ this.onReconnectFailure?.(name, error);
121
+ const message = error instanceof Error ? error.message : String(error);
122
+ console.error(`MCP: Failed to reconnect to ${name}: ${sanitizeTerminalText(message)}`);
123
+ }
124
+ }
125
+ }
126
+ for (const [name] of this.allServers) {
127
+ if (this.keepAliveServers.has(name))
128
+ continue;
129
+ const timeout = this.getIdleTimeout(name);
130
+ if (timeout > 0 && this.manager.isIdle(name, timeout)) {
131
+ await this.manager.close(name);
132
+ if (this.stopped || signal?.aborted)
133
+ return;
134
+ this.onIdleShutdown?.(name);
135
+ }
136
+ }
137
+ }
138
+ getIdleTimeout(name) {
139
+ const perServer = this.serverSettings.get(name)?.idleTimeout;
140
+ if (perServer !== undefined)
141
+ return perServer * 60 * 1000;
142
+ return this.globalIdleTimeout;
143
+ }
144
+ async gracefulShutdown() {
145
+ if (this.shutdownPromise)
146
+ return this.shutdownPromise;
147
+ this.shutdownPromise = this.shutdownOnce();
148
+ return this.shutdownPromise;
149
+ }
150
+ async shutdownOnce() {
151
+ this.stopped = true;
152
+ if (this.healthCheckInterval)
153
+ clearInterval(this.healthCheckInterval);
154
+ this.healthCheckInterval = undefined;
155
+ this.removeHealthAbortListener?.();
156
+ this.removeHealthAbortListener = undefined;
157
+ this.healthSignal = undefined;
158
+ await this.activeHealthCheck;
159
+ this.activeHealthCheck = undefined;
160
+ this.onReconnect = undefined;
161
+ this.onReconnectFailure = undefined;
162
+ this.onIdleShutdown = undefined;
163
+ if (typeof this.manager.closeAll === "function") {
164
+ await this.manager.closeAll();
165
+ }
166
+ }
167
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Centralized logging for MCP UI operations.
3
+ * Provides structured, contextual logs with levels.
4
+ */
5
+ export type LogLevel = "debug" | "info" | "warn" | "error";
6
+ export interface LogContext {
7
+ server?: string;
8
+ session?: string;
9
+ tool?: string;
10
+ uri?: string;
11
+ [key: string]: unknown;
12
+ }
13
+ declare class Logger {
14
+ private minLevel;
15
+ setLevel(level: LogLevel): void;
16
+ private shouldLog;
17
+ private emit;
18
+ debug(message: string, context?: LogContext): void;
19
+ info(message: string, context?: LogContext): void;
20
+ warn(message: string, context?: LogContext): void;
21
+ error(message: string, error?: Error, context?: LogContext): void;
22
+ /**
23
+ * Create a child logger with additional default context.
24
+ */
25
+ child(context: LogContext): ChildLogger;
26
+ }
27
+ declare class ChildLogger {
28
+ private parent;
29
+ private context;
30
+ constructor(parent: Logger, context: LogContext);
31
+ debug(message: string, context?: LogContext): void;
32
+ info(message: string, context?: LogContext): void;
33
+ warn(message: string, context?: LogContext): void;
34
+ error(message: string, error?: Error, context?: LogContext): void;
35
+ child(context: LogContext): ChildLogger;
36
+ }
37
+ export declare const logger: Logger;
38
+ export {};
package/dist/logger.js ADDED
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Centralized logging for MCP UI operations.
3
+ * Provides structured, contextual logs with levels.
4
+ */
5
+ const LEVEL_PRIORITY = {
6
+ debug: 0,
7
+ info: 1,
8
+ warn: 2,
9
+ error: 3,
10
+ };
11
+ const LEVEL_PREFIX = {
12
+ debug: "[MCP-UI:DEBUG]",
13
+ info: "[MCP-UI]",
14
+ warn: "[MCP-UI:WARN]",
15
+ error: "[MCP-UI:ERROR]",
16
+ };
17
+ class Logger {
18
+ minLevel = "info";
19
+ setLevel(level) {
20
+ this.minLevel = level;
21
+ }
22
+ shouldLog(level) {
23
+ return LEVEL_PRIORITY[level] >= LEVEL_PRIORITY[this.minLevel];
24
+ }
25
+ emit(level, message, context, error) {
26
+ if (!this.shouldLog(level))
27
+ return;
28
+ const prefix = LEVEL_PREFIX[level];
29
+ const contextStr = formatContext(context);
30
+ const fullMessage = contextStr ? `${prefix} ${message} ${contextStr}` : `${prefix} ${message}`;
31
+ if (level === "error") {
32
+ console.error(fullMessage, error ?? "");
33
+ }
34
+ else if (level === "warn") {
35
+ console.warn(fullMessage);
36
+ }
37
+ else if (level === "debug") {
38
+ console.debug(fullMessage);
39
+ }
40
+ else {
41
+ console.log(fullMessage);
42
+ }
43
+ }
44
+ debug(message, context) {
45
+ this.emit("debug", message, context);
46
+ }
47
+ info(message, context) {
48
+ this.emit("info", message, context);
49
+ }
50
+ warn(message, context) {
51
+ this.emit("warn", message, context);
52
+ }
53
+ error(message, error, context) {
54
+ this.emit("error", message, context, error);
55
+ }
56
+ /**
57
+ * Create a child logger with additional default context.
58
+ */
59
+ child(context) {
60
+ return new ChildLogger(this, context);
61
+ }
62
+ }
63
+ class ChildLogger {
64
+ parent;
65
+ context;
66
+ constructor(parent, context) {
67
+ this.parent = parent;
68
+ this.context = context;
69
+ }
70
+ debug(message, context) {
71
+ this.parent.debug(message, { ...this.context, ...context });
72
+ }
73
+ info(message, context) {
74
+ this.parent.info(message, { ...this.context, ...context });
75
+ }
76
+ warn(message, context) {
77
+ this.parent.warn(message, { ...this.context, ...context });
78
+ }
79
+ error(message, error, context) {
80
+ this.parent.error(message, error, { ...this.context, ...context });
81
+ }
82
+ child(context) {
83
+ return new ChildLogger(this.parent, { ...this.context, ...context });
84
+ }
85
+ }
86
+ function formatContext(context) {
87
+ if (!context || Object.keys(context).length === 0)
88
+ return "";
89
+ const parts = [];
90
+ for (const [key, value] of Object.entries(context)) {
91
+ if (value !== undefined && value !== null) {
92
+ parts.push(`${key}=${typeof value === "string" ? value : JSON.stringify(value)}`);
93
+ }
94
+ }
95
+ return parts.length > 0 ? `(${parts.join(", ")})` : "";
96
+ }
97
+ // Singleton instance
98
+ export const logger = new Logger();
99
+ // Enable debug mode via environment variable
100
+ if (process.env.MCP_UI_DEBUG === "1" || process.env.MCP_UI_DEBUG === "true") {
101
+ logger.setLevel("debug");
102
+ }
@@ -0,0 +1,113 @@
1
+ /**
2
+ * MCP Auth Flow
3
+ *
4
+ * High-level OAuth flow management using the MCP SDK's built-in auth functions.
5
+ */
6
+ import { UnauthorizedError, InsufficientScopeError, SdkHttpError } from "@modelcontextprotocol/client";
7
+ import { type McpOAuthConfig } from "./mcp-oauth-provider.ts";
8
+ import { type AuthStorageOptions } from "./mcp-auth.ts";
9
+ import { type ServerEntry } from "./types.ts";
10
+ /** Auth status for a server */
11
+ export type AuthStatus = "authenticated" | "expired" | "not_authenticated";
12
+ import type { McpCheckpointEvent } from "./checkpoint.ts";
13
+ export interface McpOAuthRuntime {
14
+ readonly signal: AbortSignal;
15
+ }
16
+ export interface AuthenticateOptions {
17
+ onAuthorizationUrl?: (authorizationUrl: string) => void | Promise<void>;
18
+ authStorageOptions?: AuthStorageOptions;
19
+ signal?: AbortSignal;
20
+ runtime?: McpOAuthRuntime;
21
+ }
22
+ export declare function createOAuthRuntime(signal?: AbortSignal): McpOAuthRuntime;
23
+ export declare function holdOAuthCheckpoint(runtime: McpOAuthRuntime, event: McpCheckpointEvent): () => void;
24
+ export declare function getOAuthCheckpointBlocker(runtime: McpOAuthRuntime): string | undefined;
25
+ type OAuthRequest = {
26
+ serverName: string;
27
+ serverUrl: string;
28
+ requestedScope?: string;
29
+ challenge?: {
30
+ requiredScope?: string;
31
+ resourceMetadataUrl?: URL;
32
+ };
33
+ issuer?: string;
34
+ };
35
+ export declare function isOAuthChallenge(error: unknown): error is InsufficientScopeError | UnauthorizedError | SdkHttpError;
36
+ export declare function getOAuthRequest(serverName: string, serverUrl: string, storageBase: string, runtime?: McpOAuthRuntime): OAuthRequest | undefined;
37
+ /** Observe native challenges only; no credential reads or auth work here. */
38
+ export declare function recordOAuthChallenge(serverName: string, serverUrl: string, storageBase: string, error: unknown, runtime?: McpOAuthRuntime): void;
39
+ export declare function bindOAuthRequestIssuer(serverName: string, serverUrl: string, storageBase: string, issuer: string, runtime?: McpOAuthRuntime): void;
40
+ export declare function hasPendingAuth(serverName: string, options?: AuthStorageOptions, runtime?: McpOAuthRuntime): boolean;
41
+ /**
42
+ * Extract OAuth configuration from a ServerEntry.
43
+ */
44
+ export declare function extractOAuthConfig(definition: ServerEntry): McpOAuthConfig;
45
+ /**
46
+ * Start OAuth authentication flow for a server.
47
+ * Returns the authorization URL when browser authorization is required.
48
+ */
49
+ export declare const startAuth: typeof startAuthOperation;
50
+ declare function startAuthOperation(serverName: string, serverUrl: string, definition?: ServerEntry, options?: AuthenticateOptions): Promise<{
51
+ authorizationUrl: string;
52
+ }>;
53
+ /** Authorization code plus the optional RFC 9207 `iss` callback parameter. */
54
+ export interface AuthorizationCodeInput {
55
+ code: string;
56
+ iss?: string;
57
+ }
58
+ /**
59
+ * Extract an OAuth authorization code (and the RFC 9207 `iss` parameter, when
60
+ * present) from either a raw code, a query string, or the full localhost
61
+ * redirect URL copied from the browser address bar.
62
+ */
63
+ type AuthorizationResponseInput = AuthorizationCodeInput | {
64
+ error: string;
65
+ errorDescription?: string;
66
+ iss?: string;
67
+ code?: never;
68
+ };
69
+ export declare function parseAuthorizationRedirectInput(input: string, expectedState?: string): AuthorizationResponseInput;
70
+ /**
71
+ * Complete OAuth authentication from pasted input or a captured browser callback.
72
+ */
73
+ export declare function completeAuthFromInput(serverName: string, input?: string, options?: AuthenticateOptions): Promise<AuthStatus>;
74
+ /**
75
+ * Complete OAuth authentication with an explicit code or a captured callback.
76
+ */
77
+ export declare const completeAuth: typeof completeAuthOperation;
78
+ declare function completeAuthOperation(serverName: string, authorizationCode?: string | AuthorizationResponseInput, options?: AuthenticateOptions): Promise<AuthStatus>;
79
+ /**
80
+ * Perform the complete OAuth authentication flow for a server.
81
+ *
82
+ * @param serverName - The name of the MCP server
83
+ * @param serverUrl - The URL of the MCP server
84
+ * @param definition - The server definition (optional)
85
+ * @returns The final auth status
86
+ */
87
+ export declare function authenticate(serverName: string, serverUrl: string, definition?: ServerEntry, options?: AuthenticateOptions): Promise<AuthStatus>;
88
+ /**
89
+ * Remove all OAuth credentials for a server.
90
+ *
91
+ * @param serverName - The name of the MCP server
92
+ */
93
+ export declare const removeAuth: typeof removeAuthOperation;
94
+ declare function removeAuthOperation(serverName: string, options?: AuthenticateOptions): Promise<void>;
95
+ /**
96
+ * Check if OAuth is supported for a server configuration.
97
+ * OAuth is supported for HTTP servers unless explicitly disabled.
98
+ *
99
+ * @param definition - The server definition
100
+ * @returns True if OAuth is supported
101
+ */
102
+ export declare function supportsOAuth(definition: ServerEntry): boolean;
103
+ /**
104
+ * Initialize the OAuth system on startup.
105
+ * OAuth callback binding is lazy and starts from startAuth() only.
106
+ */
107
+ export declare function initializeOAuth(runtimeOrSignal?: McpOAuthRuntime | AbortSignal): Promise<McpOAuthRuntime>;
108
+ /**
109
+ * Shutdown one OAuth runtime. The callback server remains process-shared while
110
+ * another runtime has pending/reserved callback state or is still active.
111
+ */
112
+ export declare function shutdownOAuth(runtime?: McpOAuthRuntime): Promise<void>;
113
+ export {};