operon-agents-core 0.1.0-alpha.10 → 0.1.0-alpha.11
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/index.d.ts +1 -1
- package/dist/config/schema.d.ts +53 -4
- package/dist/config/schema.js +53 -1
- package/dist/mcp/auth-tool.d.ts +3 -1
- package/dist/mcp/auth-tool.js +2 -2
- package/dist/mcp/index.d.ts +2 -2
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/manager.d.ts +3 -1
- package/dist/mcp/manager.js +9 -1
- package/dist/mcp/oauth/callback-server.d.ts +10 -1
- package/dist/mcp/oauth/callback-server.js +27 -4
- package/dist/mcp/oauth/index.d.ts +2 -2
- package/dist/mcp/oauth/provider.d.ts +18 -0
- package/dist/mcp/oauth/provider.js +30 -0
- package/dist/mcp/oauth/service.d.ts +9 -3
- package/dist/mcp/oauth/service.js +29 -4
- package/package.json +1 -1
package/dist/config/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { AgentFrameworkConfigSchema, ModelCredentialsSchema, ModelAliasSchema, McpServerConfigSchema, PermissionRuleConfigSchema, ProviderConfigSchema, parseConfig, } from "./schema.ts";
|
|
2
|
-
export type { AgentFrameworkConfig, HookDefConfig, LoopControl, McpServerConfig, ModelAlias, ModelCredentialsConfig, PermissionConfig, PermissionRuleConfig, PluginRef, ProviderConfig, ProviderType, ThinkingConfig, } from "./schema.ts";
|
|
2
|
+
export type { AgentFrameworkConfig, HookDefConfig, LoopControl, McpServerConfig, McpOAuthClientConfig, ModelAlias, ModelCredentialsConfig, PermissionConfig, PermissionRuleConfig, PluginRef, ProviderConfig, ProviderType, ThinkingConfig, } from "./schema.ts";
|
|
3
3
|
export { mergeConfigs } from "./merge.ts";
|
|
4
4
|
export { ModelCatalog } from "./model-catalog.ts";
|
|
5
5
|
export type { ModelCapabilityInfo } from "./model-catalog.ts";
|
package/dist/config/schema.d.ts
CHANGED
|
@@ -137,7 +137,13 @@ export declare const ThinkingConfigSchema: z.ZodObject<{
|
|
|
137
137
|
high: "high";
|
|
138
138
|
}>>;
|
|
139
139
|
}, z.core.$strip>;
|
|
140
|
-
export declare const
|
|
140
|
+
export declare const McpOAuthClientConfigSchema: z.ZodObject<{
|
|
141
|
+
clientId: z.ZodString;
|
|
142
|
+
clientSecret: z.ZodOptional<z.ZodString>;
|
|
143
|
+
callbackPort: z.ZodOptional<z.ZodNumber>;
|
|
144
|
+
callbackUrl: z.ZodOptional<z.ZodString>;
|
|
145
|
+
}, z.core.$strip>;
|
|
146
|
+
export declare const McpServerConfigSchema: z.ZodPreprocess<z.ZodPipe<z.ZodObject<{
|
|
141
147
|
type: z.ZodOptional<z.ZodEnum<{
|
|
142
148
|
stdio: "stdio";
|
|
143
149
|
http: "http";
|
|
@@ -160,6 +166,13 @@ export declare const McpServerConfigSchema: z.ZodPipe<z.ZodObject<{
|
|
|
160
166
|
bearerTokenEnvVar: z.ZodOptional<z.ZodString>;
|
|
161
167
|
keepAliveIntervalMs: z.ZodOptional<z.ZodNumber>;
|
|
162
168
|
keepAliveTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
169
|
+
oauth: z.ZodOptional<z.ZodObject<{
|
|
170
|
+
clientId: z.ZodString;
|
|
171
|
+
clientSecret: z.ZodOptional<z.ZodString>;
|
|
172
|
+
callbackPort: z.ZodOptional<z.ZodNumber>;
|
|
173
|
+
callbackUrl: z.ZodOptional<z.ZodString>;
|
|
174
|
+
}, z.core.$strip>>;
|
|
175
|
+
scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
163
176
|
}, z.core.$strip>, z.ZodTransform<{
|
|
164
177
|
transport: "stdio" | "http";
|
|
165
178
|
command?: string | undefined;
|
|
@@ -176,6 +189,13 @@ export declare const McpServerConfigSchema: z.ZodPipe<z.ZodObject<{
|
|
|
176
189
|
bearerTokenEnvVar?: string | undefined;
|
|
177
190
|
keepAliveIntervalMs?: number | undefined;
|
|
178
191
|
keepAliveTimeoutMs?: number | undefined;
|
|
192
|
+
oauth?: {
|
|
193
|
+
clientId: string;
|
|
194
|
+
clientSecret?: string | undefined;
|
|
195
|
+
callbackPort?: number | undefined;
|
|
196
|
+
callbackUrl?: string | undefined;
|
|
197
|
+
} | undefined;
|
|
198
|
+
scopes?: string[] | undefined;
|
|
179
199
|
}, {
|
|
180
200
|
type?: "stdio" | "http" | undefined;
|
|
181
201
|
transport?: "stdio" | "http" | undefined;
|
|
@@ -193,7 +213,14 @@ export declare const McpServerConfigSchema: z.ZodPipe<z.ZodObject<{
|
|
|
193
213
|
bearerTokenEnvVar?: string | undefined;
|
|
194
214
|
keepAliveIntervalMs?: number | undefined;
|
|
195
215
|
keepAliveTimeoutMs?: number | undefined;
|
|
196
|
-
|
|
216
|
+
oauth?: {
|
|
217
|
+
clientId: string;
|
|
218
|
+
clientSecret?: string | undefined;
|
|
219
|
+
callbackPort?: number | undefined;
|
|
220
|
+
callbackUrl?: string | undefined;
|
|
221
|
+
} | undefined;
|
|
222
|
+
scopes?: string[] | undefined;
|
|
223
|
+
}>>>;
|
|
197
224
|
export declare const HookDefConfigSchema: z.ZodObject<{
|
|
198
225
|
event: z.ZodString;
|
|
199
226
|
matcher: z.ZodOptional<z.ZodString>;
|
|
@@ -297,7 +324,7 @@ export declare const AgentFrameworkConfigSchema: z.ZodObject<{
|
|
|
297
324
|
high: "high";
|
|
298
325
|
}>>;
|
|
299
326
|
}, z.core.$strip>>;
|
|
300
|
-
mcpServers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodPipe<z.ZodObject<{
|
|
327
|
+
mcpServers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodPreprocess<z.ZodPipe<z.ZodObject<{
|
|
301
328
|
type: z.ZodOptional<z.ZodEnum<{
|
|
302
329
|
stdio: "stdio";
|
|
303
330
|
http: "http";
|
|
@@ -320,6 +347,13 @@ export declare const AgentFrameworkConfigSchema: z.ZodObject<{
|
|
|
320
347
|
bearerTokenEnvVar: z.ZodOptional<z.ZodString>;
|
|
321
348
|
keepAliveIntervalMs: z.ZodOptional<z.ZodNumber>;
|
|
322
349
|
keepAliveTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
350
|
+
oauth: z.ZodOptional<z.ZodObject<{
|
|
351
|
+
clientId: z.ZodString;
|
|
352
|
+
clientSecret: z.ZodOptional<z.ZodString>;
|
|
353
|
+
callbackPort: z.ZodOptional<z.ZodNumber>;
|
|
354
|
+
callbackUrl: z.ZodOptional<z.ZodString>;
|
|
355
|
+
}, z.core.$strip>>;
|
|
356
|
+
scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
323
357
|
}, z.core.$strip>, z.ZodTransform<{
|
|
324
358
|
transport: "stdio" | "http";
|
|
325
359
|
command?: string | undefined;
|
|
@@ -336,6 +370,13 @@ export declare const AgentFrameworkConfigSchema: z.ZodObject<{
|
|
|
336
370
|
bearerTokenEnvVar?: string | undefined;
|
|
337
371
|
keepAliveIntervalMs?: number | undefined;
|
|
338
372
|
keepAliveTimeoutMs?: number | undefined;
|
|
373
|
+
oauth?: {
|
|
374
|
+
clientId: string;
|
|
375
|
+
clientSecret?: string | undefined;
|
|
376
|
+
callbackPort?: number | undefined;
|
|
377
|
+
callbackUrl?: string | undefined;
|
|
378
|
+
} | undefined;
|
|
379
|
+
scopes?: string[] | undefined;
|
|
339
380
|
}, {
|
|
340
381
|
type?: "stdio" | "http" | undefined;
|
|
341
382
|
transport?: "stdio" | "http" | undefined;
|
|
@@ -353,7 +394,14 @@ export declare const AgentFrameworkConfigSchema: z.ZodObject<{
|
|
|
353
394
|
bearerTokenEnvVar?: string | undefined;
|
|
354
395
|
keepAliveIntervalMs?: number | undefined;
|
|
355
396
|
keepAliveTimeoutMs?: number | undefined;
|
|
356
|
-
|
|
397
|
+
oauth?: {
|
|
398
|
+
clientId: string;
|
|
399
|
+
clientSecret?: string | undefined;
|
|
400
|
+
callbackPort?: number | undefined;
|
|
401
|
+
callbackUrl?: string | undefined;
|
|
402
|
+
} | undefined;
|
|
403
|
+
scopes?: string[] | undefined;
|
|
404
|
+
}>>>>>;
|
|
357
405
|
hooks: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
358
406
|
event: z.ZodString;
|
|
359
407
|
matcher: z.ZodOptional<z.ZodString>;
|
|
@@ -382,6 +430,7 @@ export type PermissionConfig = z.infer<typeof PermissionConfigSchema>;
|
|
|
382
430
|
export type LoopControl = z.infer<typeof LoopControlSchema>;
|
|
383
431
|
export type ThinkingConfig = z.infer<typeof ThinkingConfigSchema>;
|
|
384
432
|
export type McpServerConfig = z.infer<typeof McpServerConfigSchema>;
|
|
433
|
+
export type McpOAuthClientConfig = z.infer<typeof McpOAuthClientConfigSchema>;
|
|
385
434
|
export type HookDefConfig = z.infer<typeof HookDefConfigSchema>;
|
|
386
435
|
export type PluginRef = z.infer<typeof PluginRefSchema>;
|
|
387
436
|
export type AgentFrameworkConfig = z.infer<typeof AgentFrameworkConfigSchema>;
|
package/dist/config/schema.js
CHANGED
|
@@ -68,7 +68,55 @@ export const ThinkingConfigSchema = z.object({
|
|
|
68
68
|
mode: z.enum(["auto", "on", "off"]),
|
|
69
69
|
effort: z.enum(["low", "medium", "high"]).optional(),
|
|
70
70
|
});
|
|
71
|
-
|
|
71
|
+
// A pre-registered OAuth client for an MCP server (Codex `.mcp.json` `oauth` block). When set, the
|
|
72
|
+
// login flow uses this client instead of dynamic client registration — for providers that don't
|
|
73
|
+
// support DCR (GitHub, Slack) and publish a public client for local agents.
|
|
74
|
+
export const McpOAuthClientConfigSchema = z.object({
|
|
75
|
+
clientId: z.string().min(1),
|
|
76
|
+
clientSecret: z.string().min(1).optional(),
|
|
77
|
+
// Fixed loopback port for the callback listener (the provider registered it). Random when unset.
|
|
78
|
+
callbackPort: z.number().int().min(1).max(65535).optional(),
|
|
79
|
+
// Exact redirect URI the provider registered; its port and path drive the callback listener.
|
|
80
|
+
callbackUrl: z.string().url().optional(),
|
|
81
|
+
});
|
|
82
|
+
// Codex writes `.mcp.json` in snake_case (`bearer_token_env_var`, `oauth.client_id`, …). Rename
|
|
83
|
+
// those keys to the camelCase config spelling before validation so a plugin's server config keeps
|
|
84
|
+
// them instead of having zod strip them as unknown keys.
|
|
85
|
+
const MCP_SNAKE_CASE_KEYS = {
|
|
86
|
+
bearer_token_env_var: "bearerTokenEnvVar",
|
|
87
|
+
allowed_tools: "allowedTools",
|
|
88
|
+
blocked_tools: "blockedTools",
|
|
89
|
+
startup_timeout_ms: "startupTimeoutMs",
|
|
90
|
+
tool_timeout_ms: "toolTimeoutMs",
|
|
91
|
+
};
|
|
92
|
+
const MCP_OAUTH_SNAKE_CASE_KEYS = {
|
|
93
|
+
client_id: "clientId",
|
|
94
|
+
client_secret: "clientSecret",
|
|
95
|
+
callback_port: "callbackPort",
|
|
96
|
+
callback_url: "callbackUrl",
|
|
97
|
+
};
|
|
98
|
+
function renameKeys(value, keys) {
|
|
99
|
+
const out = {};
|
|
100
|
+
for (const [key, v] of Object.entries(value)) {
|
|
101
|
+
const renamed = keys[key];
|
|
102
|
+
// An explicit camelCase key wins over its snake_case twin.
|
|
103
|
+
if (renamed !== undefined && renamed in value)
|
|
104
|
+
continue;
|
|
105
|
+
out[renamed ?? key] = v;
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
function normalizeMcpServerKeys(value) {
|
|
110
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
111
|
+
return value;
|
|
112
|
+
const out = renameKeys(value, MCP_SNAKE_CASE_KEYS);
|
|
113
|
+
const oauth = out["oauth"];
|
|
114
|
+
if (typeof oauth === "object" && oauth !== null && !Array.isArray(oauth)) {
|
|
115
|
+
out["oauth"] = renameKeys(oauth, MCP_OAUTH_SNAKE_CASE_KEYS);
|
|
116
|
+
}
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
119
|
+
const McpServerConfigObjectSchema = z.object({
|
|
72
120
|
// spelling. Accept both, but normalise output to `transport`.
|
|
73
121
|
type: z.enum(["stdio", "http"]).optional(),
|
|
74
122
|
transport: z.enum(["stdio", "http"]).optional(),
|
|
@@ -87,6 +135,9 @@ export const McpServerConfigSchema = z.object({
|
|
|
87
135
|
bearerTokenEnvVar: z.string().min(1).optional(),
|
|
88
136
|
keepAliveIntervalMs: z.number().int().min(1).optional(),
|
|
89
137
|
keepAliveTimeoutMs: z.number().int().min(1).optional(),
|
|
138
|
+
oauth: McpOAuthClientConfigSchema.optional(),
|
|
139
|
+
// OAuth scopes to request. Overrides what the server's protected-resource metadata advertises.
|
|
140
|
+
scopes: z.array(z.string().min(1)).optional(),
|
|
90
141
|
}).superRefine((value, ctx) => {
|
|
91
142
|
if (value.type !== undefined && value.transport !== undefined && value.type !== value.transport) {
|
|
92
143
|
ctx.addIssue({
|
|
@@ -99,6 +150,7 @@ export const McpServerConfigSchema = z.object({
|
|
|
99
150
|
...rest,
|
|
100
151
|
transport: transport ?? type ?? "stdio",
|
|
101
152
|
}));
|
|
153
|
+
export const McpServerConfigSchema = z.preprocess(normalizeMcpServerKeys, McpServerConfigObjectSchema);
|
|
102
154
|
export const HookDefConfigSchema = z.object({
|
|
103
155
|
event: z.string(),
|
|
104
156
|
matcher: z.string().optional(),
|
package/dist/mcp/auth-tool.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { type Tool } from "../index.ts";
|
|
2
|
-
import { type McpOAuthService } from "./oauth/index.ts";
|
|
2
|
+
import { type McpOAuthClientSettings, type McpOAuthService } from "./oauth/index.ts";
|
|
3
3
|
export declare const MCP_OAUTH_AUTHORIZATION_URL_UPDATE = "mcp_oauth_authorization_url";
|
|
4
4
|
export interface CreateMcpAuthToolOptions {
|
|
5
5
|
readonly serverName: string;
|
|
6
6
|
readonly serverUrl: string;
|
|
7
7
|
readonly oauthService: McpOAuthService;
|
|
8
|
+
/** The server's pre-registered client / scopes, from its config. */
|
|
9
|
+
readonly oauthSettings?: McpOAuthClientSettings;
|
|
8
10
|
readonly reconnect: (signal?: AbortSignal) => Promise<void>;
|
|
9
11
|
readonly timeoutMs?: number;
|
|
10
12
|
}
|
package/dist/mcp/auth-tool.js
CHANGED
|
@@ -14,7 +14,7 @@ This server requires an OAuth login that has not yet been completed. Calling thi
|
|
|
14
14
|
|
|
15
15
|
Takes no arguments. Treat the URL as sensitive — do not modify it or strip query parameters.`;
|
|
16
16
|
export function createMcpAuthTool(options) {
|
|
17
|
-
const { serverName, serverUrl, oauthService, reconnect, timeoutMs } = options;
|
|
17
|
+
const { serverName, serverUrl, oauthService, oauthSettings, reconnect, timeoutMs } = options;
|
|
18
18
|
const name = qualifyMcpToolName(serverName, "authenticate");
|
|
19
19
|
return {
|
|
20
20
|
schema: {
|
|
@@ -32,7 +32,7 @@ export function createMcpAuthTool(options) {
|
|
|
32
32
|
onUpdate?.({ kind: "status", text: `Discovering OAuth metadata for ${serverName}…` });
|
|
33
33
|
let flow;
|
|
34
34
|
try {
|
|
35
|
-
flow = await oauthService.beginAuthorization(serverName, serverUrl);
|
|
35
|
+
flow = await oauthService.beginAuthorization(serverName, serverUrl, oauthSettings ?? {});
|
|
36
36
|
}
|
|
37
37
|
catch (error) {
|
|
38
38
|
if (error instanceof AlreadyAuthorizedError) {
|
package/dist/mcp/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export { convertMcpContentBlock, mcpResultToContent, MCP_MAX_OUTPUT_CHARS, MCP_M
|
|
|
8
8
|
export { mcpToolProvider, wrapMcpTool } from "./provider.ts";
|
|
9
9
|
export { mcpCapability } from "./capability.ts";
|
|
10
10
|
export type { MCPCapabilityOptions } from "./capability.ts";
|
|
11
|
-
export { serverFromConfig, mcpServersCapability, createMcpServers, DEFAULT_RECONNECT_POLICY, McpTransportNotPermittedError } from "./manager.ts";
|
|
11
|
+
export { serverFromConfig, mcpOAuthSettings, mcpServersCapability, createMcpServers, DEFAULT_RECONNECT_POLICY, McpTransportNotPermittedError } from "./manager.ts";
|
|
12
12
|
export type { McpServerStatus, McpTransportKind, McpServerView, McpServersHandle, McpServersCapabilityOptions, ServerFromConfigOptions, McpTransportFactory, McpStatusListener, ReconnectPolicy, KeepAlivePolicy, McpTimer, } from "./manager.ts";
|
|
13
13
|
export { createMcpAuthTool, MCP_OAUTH_AUTHORIZATION_URL_UPDATE } from "./auth-tool.ts";
|
|
14
14
|
export type { CreateMcpAuthToolOptions } from "./auth-tool.ts";
|
|
@@ -19,5 +19,5 @@ export type { MCPStdioConfig, MCPHttpConfig } from "./sdk-transport.ts";
|
|
|
19
19
|
export { loadProjectMcpServers, loadMcpServers } from "./config-loader.ts";
|
|
20
20
|
export type { McpConfigTier, McpConfigLayerOptions, McpConfigLayer, LoadedMcpServers } from "./config-loader.ts";
|
|
21
21
|
export { McpOAuthService, McpOAuthClientProvider, AlreadyAuthorizedError, JsonFileStore, MemoryMcpCredentialStore, startCallbackServer, frameworkHomeDir, mcpCredentialsDir, defaultMcpCredentialsDir, mcpOAuthStoreKey, } from "./oauth/index.ts";
|
|
22
|
-
export type { McpOAuthServiceOptions, BeginAuthorizationOptions, BeginAuthorizationResult, McpOAuthProviderOptions, McpCredentialStore, CallbackServer, CallbackResult, } from "./oauth/index.ts";
|
|
22
|
+
export type { McpOAuthServiceOptions, BeginAuthorizationOptions, BeginAuthorizationResult, McpOAuthProviderOptions, McpOAuthClientSettings, McpCredentialStore, CallbackServerOptions, CallbackServer, CallbackResult, } from "./oauth/index.ts";
|
|
23
23
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/mcp/index.js
CHANGED
|
@@ -4,7 +4,7 @@ export { qualifyMcpToolName, sanitizeMcpNamePart, isMcpToolName } from "./tool-n
|
|
|
4
4
|
export { convertMcpContentBlock, mcpResultToContent, MCP_MAX_OUTPUT_CHARS, MCP_MAX_IMAGE_PART_BYTES } from "./output.js";
|
|
5
5
|
export { mcpToolProvider, wrapMcpTool } from "./provider.js";
|
|
6
6
|
export { mcpCapability } from "./capability.js";
|
|
7
|
-
export { serverFromConfig, mcpServersCapability, createMcpServers, DEFAULT_RECONNECT_POLICY, McpTransportNotPermittedError } from "./manager.js";
|
|
7
|
+
export { serverFromConfig, mcpOAuthSettings, mcpServersCapability, createMcpServers, DEFAULT_RECONNECT_POLICY, McpTransportNotPermittedError } from "./manager.js";
|
|
8
8
|
export { createMcpAuthTool, MCP_OAUTH_AUTHORIZATION_URL_UPDATE } from "./auth-tool.js";
|
|
9
9
|
export { MockMCPTransport } from "./mock-transport.js";
|
|
10
10
|
export { mcpStdioTransport, mcpStreamableHttpTransport, mergeStdioEnv, isTerminalTransportError, buildMcpHttpHeaders, } from "./sdk-transport.js";
|
package/dist/mcp/manager.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TransportMCPServer } from "./server.ts";
|
|
2
2
|
import type { MCPTool, MCPTransport } from "./types.ts";
|
|
3
|
-
import type { McpOAuthService } from "./oauth/index.ts";
|
|
3
|
+
import type { McpOAuthClientSettings, McpOAuthService } from "./oauth/index.ts";
|
|
4
4
|
import type { Capability, ToolProvider } from "../index.ts";
|
|
5
5
|
import type { EventSink } from "../events/index.ts";
|
|
6
6
|
import type { McpServerConfig } from "../config/schema.ts";
|
|
@@ -67,6 +67,8 @@ export interface ServerFromConfigOptions {
|
|
|
67
67
|
readonly transport?: MCPTransport;
|
|
68
68
|
}
|
|
69
69
|
export declare function serverFromConfig(name: string, config: McpServerConfig, opts?: ServerFromConfigOptions): TransportMCPServer;
|
|
70
|
+
/** The OAuth client/scopes a server config pins (Codex `.mcp.json` `oauth` / `scopes`). */
|
|
71
|
+
export declare function mcpOAuthSettings(config: McpServerConfig): McpOAuthClientSettings;
|
|
70
72
|
export interface McpServersCapabilityOptions {
|
|
71
73
|
readonly oauthService?: McpOAuthService;
|
|
72
74
|
/**
|
package/dist/mcp/manager.js
CHANGED
|
@@ -120,7 +120,14 @@ function resolveOAuthProvider(name, config, oauthService) {
|
|
|
120
120
|
return undefined;
|
|
121
121
|
if (!oauthService.hasTokens(name, config.url))
|
|
122
122
|
return undefined;
|
|
123
|
-
return oauthService.getProvider(name, config.url);
|
|
123
|
+
return oauthService.getProvider(name, config.url, mcpOAuthSettings(config));
|
|
124
|
+
}
|
|
125
|
+
/** The OAuth client/scopes a server config pins (Codex `.mcp.json` `oauth` / `scopes`). */
|
|
126
|
+
export function mcpOAuthSettings(config) {
|
|
127
|
+
return {
|
|
128
|
+
...(config.oauth !== undefined ? { client: config.oauth } : {}),
|
|
129
|
+
...(config.scopes !== undefined ? { scopes: config.scopes } : {}),
|
|
130
|
+
};
|
|
124
131
|
}
|
|
125
132
|
function isUnauthorizedLikeError(error) {
|
|
126
133
|
if (!(error instanceof Error))
|
|
@@ -313,6 +320,7 @@ class McpServerController {
|
|
|
313
320
|
serverName: this.name,
|
|
314
321
|
serverUrl: this.config.url,
|
|
315
322
|
oauthService: this.oauthService,
|
|
323
|
+
oauthSettings: mcpOAuthSettings(this.config),
|
|
316
324
|
reconnect: () => this.reconnect(),
|
|
317
325
|
});
|
|
318
326
|
}
|
|
@@ -10,5 +10,14 @@ export interface CallbackServer {
|
|
|
10
10
|
}): Promise<CallbackResult>;
|
|
11
11
|
close(): Promise<void>;
|
|
12
12
|
}
|
|
13
|
-
export
|
|
13
|
+
export interface CallbackServerOptions {
|
|
14
|
+
/** Listen on this loopback port instead of a random one (a pre-registered redirect URI). */
|
|
15
|
+
readonly port?: number;
|
|
16
|
+
/**
|
|
17
|
+
* The exact redirect URI to advertise. Its port (when present) and path drive the listener;
|
|
18
|
+
* wins over `port`. Must be an http loopback URL.
|
|
19
|
+
*/
|
|
20
|
+
readonly redirectUri?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function startCallbackServer(options?: CallbackServerOptions): Promise<CallbackServer>;
|
|
14
23
|
//# sourceMappingURL=callback-server.d.ts.map
|
|
@@ -48,7 +48,8 @@ function errorHtml(detail) {
|
|
|
48
48
|
detail,
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
|
-
export async function startCallbackServer() {
|
|
51
|
+
export async function startCallbackServer(options = {}) {
|
|
52
|
+
const fixed = resolveFixedRedirect(options);
|
|
52
53
|
let resolveCode;
|
|
53
54
|
let rejectCode;
|
|
54
55
|
let settled = false;
|
|
@@ -74,7 +75,7 @@ export async function startCallbackServer() {
|
|
|
74
75
|
res.writeHead(404).end();
|
|
75
76
|
return;
|
|
76
77
|
}
|
|
77
|
-
if (url.pathname !==
|
|
78
|
+
if (url.pathname !== fixed.path) {
|
|
78
79
|
res.writeHead(404).end();
|
|
79
80
|
return;
|
|
80
81
|
}
|
|
@@ -107,13 +108,13 @@ export async function startCallbackServer() {
|
|
|
107
108
|
}
|
|
108
109
|
await new Promise((resolve, reject) => {
|
|
109
110
|
server.once("error", reject);
|
|
110
|
-
server.listen(0,
|
|
111
|
+
server.listen(fixed.port ?? 0, fixed.host, () => {
|
|
111
112
|
server.off("error", reject);
|
|
112
113
|
resolve();
|
|
113
114
|
});
|
|
114
115
|
});
|
|
115
116
|
const port = server.address().port;
|
|
116
|
-
const redirectUri = `http://127.0.0.1:${port}
|
|
117
|
+
const redirectUri = fixed.redirectUri ?? `http://127.0.0.1:${port}${fixed.path}`;
|
|
117
118
|
let closed = false;
|
|
118
119
|
const close = async () => {
|
|
119
120
|
if (closed)
|
|
@@ -162,4 +163,26 @@ export async function startCallbackServer() {
|
|
|
162
163
|
};
|
|
163
164
|
return { redirectUri, waitForCode, close };
|
|
164
165
|
}
|
|
166
|
+
function resolveFixedRedirect(options) {
|
|
167
|
+
if (options.redirectUri === undefined) {
|
|
168
|
+
return { host: "127.0.0.1", ...(options.port !== undefined ? { port: options.port } : {}), path: "/callback" };
|
|
169
|
+
}
|
|
170
|
+
let url;
|
|
171
|
+
try {
|
|
172
|
+
url = new URL(options.redirectUri);
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
throw new Error(`invalid OAuth callback URL "${options.redirectUri}"`);
|
|
176
|
+
}
|
|
177
|
+
if (url.protocol !== "http:" || !LOOPBACK_HOSTS.has(url.hostname)) {
|
|
178
|
+
throw new Error(`OAuth callback URL must be an http loopback URL (got "${options.redirectUri}")`);
|
|
179
|
+
}
|
|
180
|
+
const port = url.port !== "" ? Number(url.port) : options.port;
|
|
181
|
+
if (port === undefined) {
|
|
182
|
+
throw new Error(`OAuth callback URL "${options.redirectUri}" has no port`);
|
|
183
|
+
}
|
|
184
|
+
const host = url.hostname === "[::1]" ? "::1" : "127.0.0.1";
|
|
185
|
+
return { host, port, path: url.pathname, redirectUri: options.redirectUri };
|
|
186
|
+
}
|
|
187
|
+
const LOOPBACK_HOSTS = new Set(["127.0.0.1", "localhost", "[::1]"]);
|
|
165
188
|
//# sourceMappingURL=callback-server.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { startCallbackServer } from "./callback-server.ts";
|
|
2
|
-
export type { CallbackServer, CallbackResult } from "./callback-server.ts";
|
|
2
|
+
export type { CallbackServer, CallbackResult, CallbackServerOptions } from "./callback-server.ts";
|
|
3
3
|
export { McpOAuthClientProvider } from "./provider.ts";
|
|
4
|
-
export type { McpOAuthProviderOptions } from "./provider.ts";
|
|
4
|
+
export type { McpOAuthProviderOptions, McpOAuthClientSettings } from "./provider.ts";
|
|
5
5
|
export { McpOAuthService, AlreadyAuthorizedError, } from "./service.ts";
|
|
6
6
|
export type { McpOAuthServiceOptions, BeginAuthorizationOptions, BeginAuthorizationResult, } from "./service.ts";
|
|
7
7
|
export { JsonFileStore, MemoryMcpCredentialStore, frameworkHomeDir, mcpCredentialsDir, defaultMcpCredentialsDir, sanitizeStoreKey, canonicalMcpOAuthResource, mcpOAuthStoreKey, } from "./store.ts";
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import type { OAuthClientProvider, OAuthDiscoveryState } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
2
2
|
import type { OAuthClientInformationMixed, OAuthClientMetadata, OAuthTokens } from "@modelcontextprotocol/sdk/shared/auth.js";
|
|
3
|
+
import type { McpOAuthClientConfig } from "../../config/schema.ts";
|
|
3
4
|
import { type McpCredentialStore } from "./store.ts";
|
|
4
5
|
export interface McpOAuthProviderOptions {
|
|
5
6
|
readonly serverName: string;
|
|
6
7
|
readonly serverUrl: string | URL;
|
|
7
8
|
readonly store: McpCredentialStore;
|
|
8
9
|
readonly clientLabel?: string;
|
|
10
|
+
/** A pre-registered client (skips dynamic client registration). */
|
|
11
|
+
readonly client?: McpOAuthClientConfig;
|
|
12
|
+
/** Scopes to request; also the DCR metadata scope. */
|
|
13
|
+
readonly scopes?: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
/** Server-config-derived OAuth settings a provider can be (re)configured with. */
|
|
16
|
+
export interface McpOAuthClientSettings {
|
|
17
|
+
readonly client?: McpOAuthClientConfig;
|
|
18
|
+
readonly scopes?: readonly string[];
|
|
9
19
|
}
|
|
10
20
|
export declare class McpOAuthClientProvider implements OAuthClientProvider {
|
|
11
21
|
readonly storeKey: string;
|
|
@@ -16,7 +26,15 @@ export declare class McpOAuthClientProvider implements OAuthClientProvider {
|
|
|
16
26
|
private _codeVerifier;
|
|
17
27
|
private _state;
|
|
18
28
|
private _lastAuthorizationUrl;
|
|
29
|
+
private _client;
|
|
30
|
+
private _scopes;
|
|
19
31
|
constructor(options: McpOAuthProviderOptions);
|
|
32
|
+
/** Apply the server's configured client/scopes. Called on every lookup, so config edits land. */
|
|
33
|
+
configure(settings: McpOAuthClientSettings): void;
|
|
34
|
+
/** The pre-registered client, when the server config names one. */
|
|
35
|
+
get staticClient(): McpOAuthClientConfig | undefined;
|
|
36
|
+
/** Configured scopes as an OAuth `scope` string, when any. */
|
|
37
|
+
get scope(): string | undefined;
|
|
20
38
|
setRedirectUrl(url: URL): void;
|
|
21
39
|
takeAuthorizationUrl(): URL | undefined;
|
|
22
40
|
expectedState(): string | undefined;
|
|
@@ -15,11 +15,27 @@ export class McpOAuthClientProvider {
|
|
|
15
15
|
_codeVerifier;
|
|
16
16
|
_state;
|
|
17
17
|
_lastAuthorizationUrl;
|
|
18
|
+
_client;
|
|
19
|
+
_scopes;
|
|
18
20
|
constructor(options) {
|
|
19
21
|
this.serverUrl = canonicalMcpOAuthResource(options.serverUrl);
|
|
20
22
|
this.storeKey = mcpOAuthStoreKey(options.serverName, this.serverUrl);
|
|
21
23
|
this.store = options.store;
|
|
22
24
|
this.clientLabel = options.clientLabel ?? `Operon (${options.serverName})`;
|
|
25
|
+
this.configure(options);
|
|
26
|
+
}
|
|
27
|
+
/** Apply the server's configured client/scopes. Called on every lookup, so config edits land. */
|
|
28
|
+
configure(settings) {
|
|
29
|
+
this._client = settings.client;
|
|
30
|
+
this._scopes = settings.scopes !== undefined && settings.scopes.length > 0 ? settings.scopes : undefined;
|
|
31
|
+
}
|
|
32
|
+
/** The pre-registered client, when the server config names one. */
|
|
33
|
+
get staticClient() {
|
|
34
|
+
return this._client;
|
|
35
|
+
}
|
|
36
|
+
/** Configured scopes as an OAuth `scope` string, when any. */
|
|
37
|
+
get scope() {
|
|
38
|
+
return this._scopes?.join(" ");
|
|
23
39
|
}
|
|
24
40
|
setRedirectUrl(url) {
|
|
25
41
|
this._redirectUrl = url;
|
|
@@ -48,6 +64,7 @@ export class McpOAuthClientProvider {
|
|
|
48
64
|
grant_types: ["authorization_code", "refresh_token"],
|
|
49
65
|
response_types: ["code"],
|
|
50
66
|
client_name: this.clientLabel,
|
|
67
|
+
...(this.scope !== undefined ? { scope: this.scope } : {}),
|
|
51
68
|
};
|
|
52
69
|
}
|
|
53
70
|
state() {
|
|
@@ -55,9 +72,18 @@ export class McpOAuthClientProvider {
|
|
|
55
72
|
return this._state;
|
|
56
73
|
}
|
|
57
74
|
clientInformation() {
|
|
75
|
+
if (this._client !== undefined) {
|
|
76
|
+
return {
|
|
77
|
+
client_id: this._client.clientId,
|
|
78
|
+
...(this._client.clientSecret !== undefined ? { client_secret: this._client.clientSecret } : {}),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
58
81
|
return this.store.read(`${this.storeKey}${CLIENT_SUFFIX}`);
|
|
59
82
|
}
|
|
60
83
|
saveClientInformation(info) {
|
|
84
|
+
// A pre-registered client is never persisted — the server config stays the source of truth.
|
|
85
|
+
if (this._client !== undefined)
|
|
86
|
+
return;
|
|
61
87
|
this.store.write(`${this.storeKey}${CLIENT_SUFFIX}`, info);
|
|
62
88
|
}
|
|
63
89
|
tokens() {
|
|
@@ -108,6 +134,10 @@ export class McpOAuthClientProvider {
|
|
|
108
134
|
if (this._redirectUrl !== undefined) {
|
|
109
135
|
return this._redirectUrl.toString();
|
|
110
136
|
}
|
|
137
|
+
if (this._client?.callbackUrl !== undefined)
|
|
138
|
+
return this._client.callbackUrl;
|
|
139
|
+
if (this._client?.callbackPort !== undefined)
|
|
140
|
+
return `http://127.0.0.1:${this._client.callbackPort}/callback`;
|
|
111
141
|
const registered = registeredRedirectUri(this.clientInformation());
|
|
112
142
|
return registered ?? PASSIVE_REDIRECT_URI;
|
|
113
143
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { McpOAuthClientProvider } from "./provider.ts";
|
|
1
|
+
import { McpOAuthClientProvider, type McpOAuthClientSettings } from "./provider.ts";
|
|
2
2
|
import { type McpCredentialStore } from "./store.ts";
|
|
3
3
|
export interface McpOAuthServiceOptions {
|
|
4
4
|
/** Where credentials live. Defaults to a `JsonFileStore` (local disk); inject a
|
|
@@ -7,7 +7,7 @@ export interface McpOAuthServiceOptions {
|
|
|
7
7
|
readonly homeDir?: string;
|
|
8
8
|
readonly clientLabel?: string;
|
|
9
9
|
}
|
|
10
|
-
export interface BeginAuthorizationOptions {
|
|
10
|
+
export interface BeginAuthorizationOptions extends McpOAuthClientSettings {
|
|
11
11
|
readonly clientLabel?: string;
|
|
12
12
|
}
|
|
13
13
|
export interface BeginAuthorizationResult {
|
|
@@ -23,7 +23,13 @@ export declare class McpOAuthService {
|
|
|
23
23
|
private readonly clientLabel;
|
|
24
24
|
private readonly providers;
|
|
25
25
|
constructor(options?: McpOAuthServiceOptions);
|
|
26
|
-
|
|
26
|
+
/**
|
|
27
|
+
* The cached provider for one server identity. Pass the server's OAuth `settings` (its
|
|
28
|
+
* pre-registered client / scopes) whenever you have its config — they're re-applied on every
|
|
29
|
+
* call so the provider always matches the current config. Omit them only for store-level
|
|
30
|
+
* queries (`hasTokens`, invalidation) that never talk to the authorization server.
|
|
31
|
+
*/
|
|
32
|
+
getProvider(serverName: string, serverUrl: string | URL, settings?: McpOAuthClientSettings): McpOAuthClientProvider;
|
|
27
33
|
hasTokens(serverName: string, serverUrl: string | URL): boolean;
|
|
28
34
|
beginAuthorization(serverName: string, serverUrl: string | URL, options?: BeginAuthorizationOptions): Promise<BeginAuthorizationResult>;
|
|
29
35
|
invalidate(serverName: string, serverUrl: string | URL, scope?: "all" | "client" | "tokens" | "discovery"): void;
|
|
@@ -12,7 +12,13 @@ export class McpOAuthService {
|
|
|
12
12
|
new JsonFileStore(options.homeDir === undefined ? undefined : mcpCredentialsDir(options.homeDir));
|
|
13
13
|
this.clientLabel = options.clientLabel;
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* The cached provider for one server identity. Pass the server's OAuth `settings` (its
|
|
17
|
+
* pre-registered client / scopes) whenever you have its config — they're re-applied on every
|
|
18
|
+
* call so the provider always matches the current config. Omit them only for store-level
|
|
19
|
+
* queries (`hasTokens`, invalidation) that never talk to the authorization server.
|
|
20
|
+
*/
|
|
21
|
+
getProvider(serverName, serverUrl, settings) {
|
|
16
22
|
const storeKey = mcpOAuthStoreKey(serverName, serverUrl);
|
|
17
23
|
let provider = this.providers.get(storeKey);
|
|
18
24
|
if (provider === undefined) {
|
|
@@ -21,22 +27,35 @@ export class McpOAuthService {
|
|
|
21
27
|
serverUrl,
|
|
22
28
|
store: this.store,
|
|
23
29
|
...(this.clientLabel !== undefined ? { clientLabel: this.clientLabel } : {}),
|
|
30
|
+
...settings,
|
|
24
31
|
});
|
|
25
32
|
this.providers.set(provider.storeKey, provider);
|
|
26
33
|
}
|
|
34
|
+
else if (settings !== undefined) {
|
|
35
|
+
provider.configure(settings);
|
|
36
|
+
}
|
|
27
37
|
return provider;
|
|
28
38
|
}
|
|
29
39
|
hasTokens(serverName, serverUrl) {
|
|
30
40
|
return this.getProvider(serverName, serverUrl).tokens() !== undefined;
|
|
31
41
|
}
|
|
32
42
|
async beginAuthorization(serverName, serverUrl, options = {}) {
|
|
43
|
+
// Callers that don't pass settings keep whatever the provider was last configured with (e.g.
|
|
44
|
+
// by the MCP manager connecting this server from its config).
|
|
45
|
+
const settings = options.client === undefined && options.scopes === undefined
|
|
46
|
+
? undefined
|
|
47
|
+
: {
|
|
48
|
+
...(options.client !== undefined ? { client: options.client } : {}),
|
|
49
|
+
...(options.scopes !== undefined ? { scopes: options.scopes } : {}),
|
|
50
|
+
};
|
|
33
51
|
const provider = options.clientLabel === undefined
|
|
34
|
-
? this.getProvider(serverName, serverUrl)
|
|
52
|
+
? this.getProvider(serverName, serverUrl, settings)
|
|
35
53
|
: new McpOAuthClientProvider({
|
|
36
54
|
serverName,
|
|
37
55
|
serverUrl,
|
|
38
56
|
store: this.store,
|
|
39
57
|
clientLabel: options.clientLabel,
|
|
58
|
+
...settings,
|
|
40
59
|
});
|
|
41
60
|
if (options.clientLabel !== undefined) {
|
|
42
61
|
this.providers.set(provider.storeKey, provider);
|
|
@@ -44,7 +63,12 @@ export class McpOAuthService {
|
|
|
44
63
|
provider.resetFlow();
|
|
45
64
|
let callbackServer;
|
|
46
65
|
try {
|
|
47
|
-
|
|
66
|
+
// A pre-registered client only accepts the redirect URI it was registered with.
|
|
67
|
+
const client = provider.staticClient;
|
|
68
|
+
callbackServer = await startCallbackServer({
|
|
69
|
+
...(client?.callbackPort !== undefined ? { port: client.callbackPort } : {}),
|
|
70
|
+
...(client?.callbackUrl !== undefined ? { redirectUri: client.callbackUrl } : {}),
|
|
71
|
+
});
|
|
48
72
|
}
|
|
49
73
|
catch (error) {
|
|
50
74
|
throw wrapAuthError("failed to start OAuth callback listener", error);
|
|
@@ -52,7 +76,8 @@ export class McpOAuthService {
|
|
|
52
76
|
provider.setRedirectUrl(new URL(callbackServer.redirectUri));
|
|
53
77
|
let authorizationUrl;
|
|
54
78
|
try {
|
|
55
|
-
const
|
|
79
|
+
const scope = provider.scope;
|
|
80
|
+
const result = await auth(provider, { serverUrl, ...(scope !== undefined ? { scope } : {}) });
|
|
56
81
|
if (result !== "REDIRECT") {
|
|
57
82
|
// Tokens already valid (e.g. unexpired refresh). Nothing to do.
|
|
58
83
|
await callbackServer.close();
|