operon-agents-core 0.1.0-alpha.2 → 0.1.0-alpha.21

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 (289) hide show
  1. package/dist/agent/agent.d.ts +8 -7
  2. package/dist/agent/compose-hooks.d.ts +10 -1
  3. package/dist/agent/compose-hooks.js +61 -6
  4. package/dist/agent/concurrency.js +1 -1
  5. package/dist/agent/context-report.d.ts +2 -2
  6. package/dist/agent/durable-state.d.ts +22 -0
  7. package/dist/agent/durable-state.js +54 -0
  8. package/dist/agent/index.d.ts +2 -2
  9. package/dist/agent/index.js +1 -1
  10. package/dist/agent/instruction-context.d.ts +6 -6
  11. package/dist/agent/instruction-context.js +23 -23
  12. package/dist/agent/profile-builtins.js +1 -1
  13. package/dist/agent/run-support.d.ts +1 -1
  14. package/dist/agent/run-support.js +6 -5
  15. package/dist/agent/runner.d.ts +25 -22
  16. package/dist/agent/runner.js +217 -121
  17. package/dist/agent/session.d.ts +262 -156
  18. package/dist/agent/session.js +590 -418
  19. package/dist/agent/subagent-tools.js +3 -3
  20. package/dist/agent/subagent.js +28 -13
  21. package/dist/agent/toolset.d.ts +1 -0
  22. package/dist/agent/toolset.js +13 -7
  23. package/dist/agent/workflow/journal.d.ts +2 -2
  24. package/dist/agent/workflow/journal.js +2 -2
  25. package/dist/agent/workflow/manager.d.ts +1 -1
  26. package/dist/agent/workflow/manager.js +1 -1
  27. package/dist/agent/workflow/prompt.js +2 -2
  28. package/dist/agent/workflow/sandbox.d.ts +1 -1
  29. package/dist/agent/workflow/sandbox.js +1 -1
  30. package/dist/agent/workflow/tool.js +30 -43
  31. package/dist/agent/worktree.d.ts +8 -8
  32. package/dist/agent/worktree.js +15 -15
  33. package/dist/capabilities/assembler.d.ts +29 -5
  34. package/dist/capabilities/assembler.js +85 -9
  35. package/dist/capabilities/background/code-task.d.ts +43 -0
  36. package/dist/capabilities/background/code-task.js +75 -0
  37. package/dist/capabilities/background/command-task.d.ts +9 -2
  38. package/dist/capabilities/background/command-task.js +22 -6
  39. package/dist/capabilities/background/index.d.ts +6 -1
  40. package/dist/capabilities/background/index.js +26 -20
  41. package/dist/capabilities/background/manager.d.ts +57 -1
  42. package/dist/capabilities/background/manager.js +210 -45
  43. package/dist/capabilities/background/persist-disk.d.ts +1 -1
  44. package/dist/capabilities/background/persist-disk.js +1 -1
  45. package/dist/capabilities/background/persist.js +4 -2
  46. package/dist/capabilities/background/projections.d.ts +16 -0
  47. package/dist/capabilities/background/projections.js +86 -0
  48. package/dist/capabilities/background/stall-watchdog.d.ts +41 -0
  49. package/dist/capabilities/background/stall-watchdog.js +85 -0
  50. package/dist/capabilities/background/task.d.ts +8 -7
  51. package/dist/capabilities/background/tools.js +33 -7
  52. package/dist/capabilities/capability-data.d.ts +52 -0
  53. package/dist/capabilities/capability-data.js +88 -0
  54. package/dist/capabilities/capability-state.d.ts +2 -4
  55. package/dist/capabilities/capability-state.js +5 -23
  56. package/dist/capabilities/capability.d.ts +203 -38
  57. package/dist/capabilities/compaction/index.js +10 -4
  58. package/dist/capabilities/compaction/service.d.ts +20 -5
  59. package/dist/capabilities/compaction/service.js +27 -11
  60. package/dist/capabilities/goal/goal-store.d.ts +76 -12
  61. package/dist/capabilities/goal/goal-store.js +137 -53
  62. package/dist/capabilities/goal/index.d.ts +1 -1
  63. package/dist/capabilities/goal/index.js +30 -7
  64. package/dist/capabilities/index.d.ts +9 -6
  65. package/dist/capabilities/index.js +4 -3
  66. package/dist/capabilities/plan/index.js +22 -5
  67. package/dist/capabilities/plan/plan-mode.d.ts +30 -9
  68. package/dist/capabilities/plan/plan-mode.js +57 -32
  69. package/dist/capabilities/plan/tools.js +1 -1
  70. package/dist/capabilities/skills/flow-provider.js +3 -3
  71. package/dist/capabilities/skills/index.d.ts +13 -1
  72. package/dist/capabilities/skills/index.js +30 -21
  73. package/dist/capabilities/skills/parser.d.ts +2 -2
  74. package/dist/capabilities/skills/parser.js +3 -3
  75. package/dist/capabilities/skills/registry.d.ts +5 -6
  76. package/dist/capabilities/skills/registry.js +6 -9
  77. package/dist/capabilities/skills/scanner.d.ts +3 -3
  78. package/dist/capabilities/skills/scanner.js +14 -14
  79. package/dist/capabilities/skills/service.d.ts +2 -1
  80. package/dist/capabilities/skills/service.js +3 -3
  81. package/dist/capabilities/skills/skill-tool.d.ts +2 -0
  82. package/dist/capabilities/skills/skill-tool.js +1 -1
  83. package/dist/capabilities/task/index.js +2 -1
  84. package/dist/capabilities/task/persist-disk.d.ts +1 -1
  85. package/dist/capabilities/task/persist-disk.js +1 -1
  86. package/dist/capabilities/task/persist.js +1 -1
  87. package/dist/capabilities/todo/index.js +11 -6
  88. package/dist/capabilities/todo/injector.js +2 -1
  89. package/dist/capabilities/todo/todo-store.d.ts +28 -7
  90. package/dist/capabilities/todo/todo-store.js +44 -11
  91. package/dist/capabilities/todo/tools.js +8 -3
  92. package/dist/capabilities/tool-provider.d.ts +3 -3
  93. package/dist/capabilities/user-hooks/engine.d.ts +3 -3
  94. package/dist/capabilities/user-hooks/engine.js +7 -7
  95. package/dist/capabilities/user-hooks/index.js +2 -1
  96. package/dist/capabilities/workflow/index.d.ts +5 -3
  97. package/dist/capabilities/workflow/index.js +3 -2
  98. package/dist/commands/index.js +34 -32
  99. package/dist/config/index.d.ts +1 -1
  100. package/dist/config/provider-manager.js +0 -28
  101. package/dist/config/schema.d.ts +53 -4
  102. package/dist/config/schema.js +53 -1
  103. package/dist/events/events.d.ts +43 -11
  104. package/dist/events/events.js +1 -0
  105. package/dist/events/index.d.ts +2 -2
  106. package/dist/events/index.js +1 -1
  107. package/dist/events/projection.d.ts +49 -1
  108. package/dist/events/projection.js +144 -19
  109. package/dist/events/publisher.js +2 -21
  110. package/dist/home.d.ts +1 -1
  111. package/dist/home.js +1 -1
  112. package/dist/index.d.ts +3 -2
  113. package/dist/index.js +2 -1
  114. package/dist/internal.d.ts +5 -2
  115. package/dist/internal.js +5 -2
  116. package/dist/llm/define-model.d.ts +4 -0
  117. package/dist/llm/define-model.js +63 -25
  118. package/dist/llm/index.d.ts +1 -0
  119. package/dist/llm/index.js +1 -0
  120. package/dist/llm/model.d.ts +2 -0
  121. package/dist/llm/provider.d.ts +17 -0
  122. package/dist/llm/provider.js +14 -0
  123. package/dist/llm/retry.js +1 -1
  124. package/dist/loop/context.d.ts +21 -1
  125. package/dist/loop/context.js +47 -9
  126. package/dist/loop/events.d.ts +5 -1
  127. package/dist/loop/index.d.ts +2 -2
  128. package/dist/loop/index.js +1 -1
  129. package/dist/loop/interruption.d.ts +9 -4
  130. package/dist/loop/interruption.js +11 -25
  131. package/dist/loop/run-turn.d.ts +16 -3
  132. package/dist/loop/run-turn.js +13 -4
  133. package/dist/loop/steer.d.ts +78 -12
  134. package/dist/loop/steer.js +101 -38
  135. package/dist/loop/tool-call.d.ts +13 -2
  136. package/dist/loop/tool-call.js +135 -5
  137. package/dist/loop/turn-step.d.ts +13 -2
  138. package/dist/loop/turn-step.js +29 -7
  139. package/dist/loop/types.d.ts +6 -0
  140. package/dist/mcp/auth-tool.d.ts +3 -1
  141. package/dist/mcp/auth-tool.js +2 -2
  142. package/dist/mcp/capability.d.ts +13 -0
  143. package/dist/mcp/capability.js +36 -17
  144. package/dist/mcp/config-loader.d.ts +5 -5
  145. package/dist/mcp/config-loader.js +17 -17
  146. package/dist/mcp/credentials.d.ts +35 -0
  147. package/dist/mcp/credentials.js +2 -0
  148. package/dist/mcp/filter.d.ts +2 -2
  149. package/dist/mcp/index.d.ts +4 -3
  150. package/dist/mcp/index.js +1 -1
  151. package/dist/mcp/manager.d.ts +108 -6
  152. package/dist/mcp/manager.js +262 -18
  153. package/dist/mcp/oauth/callback-server.d.ts +10 -1
  154. package/dist/mcp/oauth/callback-server.js +82 -16
  155. package/dist/mcp/oauth/index.d.ts +2 -2
  156. package/dist/mcp/oauth/provider.d.ts +18 -0
  157. package/dist/mcp/oauth/provider.js +31 -1
  158. package/dist/mcp/oauth/service.d.ts +9 -3
  159. package/dist/mcp/oauth/service.js +29 -4
  160. package/dist/mcp/sdk-transport.js +1 -1
  161. package/dist/mcp/server.js +1 -1
  162. package/dist/permission/auto-approver/prompts-data.d.ts +1 -1
  163. package/dist/permission/auto-approver/prompts-data.js +1 -1
  164. package/dist/permission/manager.d.ts +5 -3
  165. package/dist/permission/manager.js +7 -3
  166. package/dist/permission/policies.d.ts +2 -2
  167. package/dist/permission/policies.js +4 -4
  168. package/dist/plugins/fields.d.ts +14 -0
  169. package/dist/plugins/fields.js +30 -0
  170. package/dist/plugins/hooks.d.ts +2 -2
  171. package/dist/plugins/hooks.js +12 -12
  172. package/dist/plugins/index.js +1 -0
  173. package/dist/plugins/manager.d.ts +8 -3
  174. package/dist/plugins/manager.js +18 -7
  175. package/dist/plugins/manifest.d.ts +2 -2
  176. package/dist/plugins/manifest.js +101 -91
  177. package/dist/plugins/marketplace.js +76 -57
  178. package/dist/plugins/store.d.ts +3 -3
  179. package/dist/plugins/store.js +6 -6
  180. package/dist/protocol/index.d.ts +1 -1
  181. package/dist/store/catalog-store.d.ts +4 -1
  182. package/dist/store/catalog-store.js +5 -1
  183. package/dist/store/checkpointing-store.d.ts +41 -0
  184. package/dist/store/checkpointing-store.js +86 -0
  185. package/dist/store/disk-store.d.ts +8 -0
  186. package/dist/store/disk-store.js +127 -5
  187. package/dist/store/index.d.ts +3 -2
  188. package/dist/store/index.js +2 -1
  189. package/dist/store/log-store.d.ts +9 -1
  190. package/dist/store/log-store.js +68 -4
  191. package/dist/store/migrate.d.ts +8 -2
  192. package/dist/store/migrate.js +9 -2
  193. package/dist/store/origin.d.ts +31 -6
  194. package/dist/store/origin.js +0 -14
  195. package/dist/store/pg.d.ts +1 -0
  196. package/dist/store/pg.js +37 -2
  197. package/dist/store/redis.d.ts +1 -0
  198. package/dist/store/redis.js +30 -0
  199. package/dist/store/repository.d.ts +13 -1
  200. package/dist/store/repository.js +45 -2
  201. package/dist/store/session-catalog.d.ts +4 -0
  202. package/dist/store/session-catalog.js +6 -0
  203. package/dist/store/storage.js +3 -0
  204. package/dist/store/store.d.ts +97 -34
  205. package/dist/store/store.js +64 -10
  206. package/dist/telemetry/appender.d.ts +43 -0
  207. package/dist/telemetry/appender.js +46 -0
  208. package/dist/telemetry/events.d.ts +142 -0
  209. package/dist/telemetry/events.js +141 -0
  210. package/dist/telemetry/index.d.ts +10 -0
  211. package/dist/telemetry/index.js +6 -0
  212. package/dist/telemetry/projection.d.ts +23 -0
  213. package/dist/telemetry/projection.js +185 -0
  214. package/dist/telemetry/redact.d.ts +20 -0
  215. package/dist/telemetry/redact.js +40 -0
  216. package/dist/telemetry/service.d.ts +49 -0
  217. package/dist/telemetry/service.js +137 -0
  218. package/dist/testing.d.ts +58 -0
  219. package/dist/testing.js +123 -0
  220. package/dist/tool/background.d.ts +9 -6
  221. package/dist/tool/background.js +7 -1
  222. package/dist/tool/builtin/ask-user-question.js +6 -5
  223. package/dist/tool/builtin/bash.d.ts +6 -0
  224. package/dist/tool/builtin/bash.js +79 -42
  225. package/dist/tool/builtin/edit.js +82 -109
  226. package/dist/tool/builtin/glob.js +13 -13
  227. package/dist/tool/builtin/grep.js +13 -13
  228. package/dist/tool/builtin/read.js +25 -15
  229. package/dist/tool/builtin/write.js +49 -33
  230. package/dist/tool/define.d.ts +14 -8
  231. package/dist/tool/define.js +8 -2
  232. package/dist/tool/{machine-base.d.ts → environment-base.d.ts} +37 -37
  233. package/dist/tool/{machine-base.js → environment-base.js} +45 -119
  234. package/dist/tool/{machine-local.d.ts → environment-local.d.ts} +9 -8
  235. package/dist/tool/{machine-local.js → environment-local.js} +60 -81
  236. package/dist/tool/{machine-null.d.ts → environment-null.d.ts} +9 -9
  237. package/dist/tool/{machine-null.js → environment-null.js} +9 -9
  238. package/dist/tool/{machine-ssh.d.ts → environment-ssh.d.ts} +33 -18
  239. package/dist/tool/{machine-ssh.js → environment-ssh.js} +118 -149
  240. package/dist/tool/{machine.d.ts → environment.d.ts} +53 -82
  241. package/dist/tool/environment.js +2 -0
  242. package/dist/tool/file-freshness.d.ts +33 -19
  243. package/dist/tool/file-freshness.js +39 -30
  244. package/dist/tool/filesystem-tools.d.ts +1 -1
  245. package/dist/tool/filesystem-tools.js +1 -1
  246. package/dist/tool/git-context.d.ts +2 -2
  247. package/dist/tool/git-context.js +8 -8
  248. package/dist/tool/index.d.ts +12 -12
  249. package/dist/tool/index.js +12 -10
  250. package/dist/tool/policies/path-access.d.ts +4 -4
  251. package/dist/tool/policies/path-access.js +12 -12
  252. package/dist/tool/questions.d.ts +8 -0
  253. package/dist/tool/search/catalog.d.ts +37 -0
  254. package/dist/tool/search/catalog.js +182 -0
  255. package/dist/tool/search/deferral.d.ts +3 -2
  256. package/dist/tool/search/loaded.d.ts +32 -0
  257. package/dist/tool/search/loaded.js +96 -0
  258. package/dist/tool/search/search-tool.d.ts +2 -6
  259. package/dist/tool/search/search-tool.js +16 -15
  260. package/dist/tool/shell-env.js +4 -0
  261. package/dist/tool/support/bash-paths.js +38 -7
  262. package/dist/tool/support/{machine-ops.d.ts → environment-ops.d.ts} +12 -14
  263. package/dist/tool/support/{machine-ops.js → environment-ops.js} +21 -2
  264. package/dist/tool/support/git-worktree.d.ts +3 -3
  265. package/dist/tool/support/git-worktree.js +6 -6
  266. package/dist/tool/support/rg-locator.d.ts +6 -6
  267. package/dist/tool/support/rg-locator.js +6 -6
  268. package/dist/tool/support/ripgrep-run.d.ts +5 -5
  269. package/dist/tool/support/ripgrep-run.js +3 -3
  270. package/dist/tool/support/tool-path.d.ts +3 -3
  271. package/dist/tool/support/tool-path.js +7 -7
  272. package/dist/tool/types.d.ts +54 -10
  273. package/dist/tool/web/fetch-url.js +1 -1
  274. package/dist/tool/web/web-search.js +1 -1
  275. package/dist/tool/workspace-spec.d.ts +3 -3
  276. package/dist/tool/workspace-spec.js +27 -27
  277. package/dist/tracing/bridge.d.ts +9 -1
  278. package/dist/tracing/bridge.js +307 -77
  279. package/dist/tracing/index.d.ts +2 -2
  280. package/dist/tracing/otel.d.ts +28 -1
  281. package/dist/tracing/otel.js +150 -38
  282. package/dist/tracing/processor.d.ts +22 -0
  283. package/dist/tracing/processor.js +2 -0
  284. package/dist/tracing/spans.d.ts +54 -0
  285. package/dist/tracing/spans.js +5 -0
  286. package/package.json +6 -2
  287. package/dist/tool/machine.js +0 -15
  288. package/dist/tool/search/activation.d.ts +0 -13
  289. package/dist/tool/search/activation.js +0 -31
@@ -3,6 +3,53 @@ import { mcpStdioTransport, mcpStreamableHttpTransport } from "./sdk-transport.j
3
3
  import { mcpToolProvider } from "./provider.js";
4
4
  import { qualifyMcpToolName } from "./tool-naming.js";
5
5
  import { createMcpAuthTool } from "./auth-tool.js";
6
+ /**
7
+ * Raised when a configured server asks for a transport its host does not offer.
8
+ *
9
+ * The case this exists for is `stdio` on a server host. An stdio server is not reached over a
10
+ * wire at all: it is spawned as a child of whatever process holds the MCP client — the harness —
11
+ * and so it stays on THAT process's environment even when every tool the session runs has been
12
+ * pushed out to a sandbox. On a single-tenant local host that is exactly right. On a server it
13
+ * is four problems at once:
14
+ *
15
+ * - LIFECYCLE. `HarnessParts.mcpServers` is "one set of connections per process", which holds
16
+ * inside one process and stops holding the moment the server runs as more than one replica:
17
+ * each replica spawns its own children, and a rolling restart takes them with it.
18
+ * - FAULT DOMAIN. A leaking or crashing `npx`-launched server takes down a process that is
19
+ * carrying every other tenant's sessions.
20
+ * - CREDENTIALS. stdio secrets travel in `config.env` — process environment, which has no
21
+ * tenant boundary. The http path has `McpOAuthService` and a swappable credential store
22
+ * precisely because it was designed for that boundary; stdio has no counterpart.
23
+ * - ISOLATION. A host that moved execution into a sandbox did so to contain it. An stdio
24
+ * server reopens an unsandboxed execution surface beside it, one that reads the HOST's disk
25
+ * rather than the workspace the agent's own tools operate on.
26
+ *
27
+ * So this is a host-declared admission rule, not a kernel prohibition. A single-tenant
28
+ * self-deployment is a legitimate case, and there stdio is no worse than it is in a CLI. The
29
+ * host states which transports it is willing to run; core refuses the rest, by name.
30
+ */
31
+ export class McpTransportNotPermittedError extends Error {
32
+ serverName;
33
+ transport;
34
+ allowed;
35
+ constructor(serverName, transport, allowed) {
36
+ super(`MCP server "${serverName}" asks for the "${transport}" transport, which this host does not ` +
37
+ `run (allowed: ${allowed.join(", ")}). ` +
38
+ (transport === "stdio"
39
+ ? `An stdio server is spawned as a child of this process, on this machine — and "stdio" ` +
40
+ `is also what a config with no \`transport\` field defaults to. Point it at an http ` +
41
+ `server, disable it with \`enabled: false\`, or leave it out of this host's configuration.`
42
+ : `Configure it with one of the allowed transports.`));
43
+ this.name = "McpTransportNotPermittedError";
44
+ this.serverName = serverName;
45
+ this.transport = transport;
46
+ this.allowed = allowed;
47
+ }
48
+ }
49
+ /** The `ToolProvider.id` a server's provider carries — `mcp:<server name>`, unsanitized. */
50
+ function mcpProviderId(serverName) {
51
+ return `mcp:${serverName}`;
52
+ }
6
53
  export const DEFAULT_RECONNECT_POLICY = {
7
54
  maxRetries: 5,
8
55
  initialDelayMs: 1000,
@@ -15,7 +62,7 @@ const REAL_TIMER = {
15
62
  };
16
63
  const DEFAULT_CACHE_TOOLS = true;
17
64
  export function serverFromConfig(name, config, opts = {}) {
18
- const transport = opts.transport ?? transportFromConfig(name, config, opts.oauthService);
65
+ const transport = opts.transport ?? transportFromConfig(name, config, opts.oauthService, opts.credential);
19
66
  const filter = staticFilterFromConfig(config);
20
67
  return new TransportMCPServer({
21
68
  name,
@@ -35,7 +82,7 @@ function staticFilterFromConfig(config) {
35
82
  ...(blocked !== undefined ? { blockedToolNames: blocked } : {}),
36
83
  };
37
84
  }
38
- function transportFromConfig(name, config, oauthService) {
85
+ function transportFromConfig(name, config, oauthService, credential) {
39
86
  if (config.transport === "stdio") {
40
87
  if (config.command === undefined)
41
88
  throw new Error(`MCP server "${name}": stdio transport requires "command".`);
@@ -50,11 +97,12 @@ function transportFromConfig(name, config, oauthService) {
50
97
  }
51
98
  if (config.url === undefined)
52
99
  throw new Error(`MCP server "${name}": http transport requires "url".`);
53
- const oauthProvider = resolveOAuthProvider(name, config, oauthService);
100
+ const oauthProvider = credential === undefined ? resolveOAuthProvider(name, config, oauthService) : undefined;
101
+ const headers = config.headers ?? (credential !== undefined ? { ...credential.headers } : undefined);
54
102
  return mcpStreamableHttpTransport({
55
103
  name,
56
104
  url: config.url,
57
- ...(config.headers !== undefined ? { headers: config.headers } : {}),
105
+ ...(headers !== undefined ? { headers } : {}),
58
106
  ...(config.bearerTokenEnvVar !== undefined ? { bearerTokenEnvVar: config.bearerTokenEnvVar } : {}),
59
107
  ...(config.toolTimeoutMs !== undefined ? { toolTimeoutMs: config.toolTimeoutMs } : {}),
60
108
  ...(oauthProvider !== undefined ? { oauthProvider } : {}),
@@ -73,7 +121,14 @@ function resolveOAuthProvider(name, config, oauthService) {
73
121
  return undefined;
74
122
  if (!oauthService.hasTokens(name, config.url))
75
123
  return undefined;
76
- return oauthService.getProvider(name, config.url);
124
+ return oauthService.getProvider(name, config.url, mcpOAuthSettings(config));
125
+ }
126
+ /** The OAuth client/scopes a server config pins (Codex `.mcp.json` `oauth` / `scopes`). */
127
+ export function mcpOAuthSettings(config) {
128
+ return {
129
+ ...(config.oauth !== undefined ? { client: config.oauth } : {}),
130
+ ...(config.scopes !== undefined ? { scopes: config.scopes } : {}),
131
+ };
77
132
  }
78
133
  function isUnauthorizedLikeError(error) {
79
134
  if (!(error instanceof Error))
@@ -91,6 +146,7 @@ class McpServerController {
91
146
  name;
92
147
  config;
93
148
  oauthService;
149
+ credentials;
94
150
  cacheToolsList;
95
151
  transportFactory;
96
152
  onStatusChange;
@@ -99,7 +155,7 @@ class McpServerController {
99
155
  timer;
100
156
  server;
101
157
  authTool;
102
- ctx;
158
+ session;
103
159
  _status = "pending";
104
160
  _error;
105
161
  reconnectAttempts = 0;
@@ -110,6 +166,7 @@ class McpServerController {
110
166
  this.name = opts.name;
111
167
  this.config = opts.config;
112
168
  this.oauthService = opts.oauthService;
169
+ this.credentials = opts.credentials;
113
170
  this.cacheToolsList = opts.cacheToolsList;
114
171
  this.transportFactory = opts.transportFactory;
115
172
  this.onStatusChange = opts.onStatusChange;
@@ -135,25 +192,41 @@ class McpServerController {
135
192
  async connect(ctx) {
136
193
  if (this.disposed)
137
194
  return;
138
- this.ctx = ctx;
195
+ this.session = { events: ctx.events, sessionId: ctx.sessionId };
139
196
  if (this.config.enabled === false) {
140
197
  this.setStatus("disabled");
141
198
  return;
142
199
  }
143
200
  await this.attempt();
144
201
  }
145
- async attempt() {
202
+ /** The provider's request for this server, when the provider is the one to ask: an http
203
+ * server whose config carries no credential of its own. */
204
+ credentialRequest() {
205
+ if (this.credentials === undefined)
206
+ return undefined;
207
+ if (this.config.transport !== "http" || this.config.url === undefined)
208
+ return undefined;
209
+ if (this.config.headers !== undefined || this.config.bearerTokenEnvVar !== undefined)
210
+ return undefined;
211
+ return { serverName: this.name, url: this.config.url, sessionId: this.session?.sessionId ?? "" };
212
+ }
213
+ async attempt(retriedAuth = false) {
146
214
  // Attempts can overlap: a manual reconnect() can fire while an in-flight attempt is still
147
215
  // awaiting connect(). Every mutation of the shared `this.server` slot is therefore guarded
148
216
  // by identity — an attempt only ever publishes/retracts the server IT created, never a
149
217
  // sibling's. Without this, a losing attempt's cleanup would tear down the winner's live
150
218
  // connection (and a stale connect() success would leak an orphaned server/child process).
151
219
  let server;
220
+ const request = this.credentialRequest();
221
+ let credential;
152
222
  try {
223
+ if (request !== undefined)
224
+ credential = await this.credentials.credentialsFor(request);
153
225
  server = serverFromConfig(this.name, this.config, {
154
226
  ...(this.oauthService !== undefined ? { oauthService: this.oauthService } : {}),
155
227
  cacheToolsList: this.cacheToolsList,
156
- ...(this.transportFactory !== undefined ? { transport: this.transportFactory(this.name, this.config) } : {}),
228
+ ...(credential !== undefined ? { credential } : {}),
229
+ ...(this.transportFactory !== undefined ? { transport: this.transportFactory(this.name, this.config, credential) } : {}),
157
230
  });
158
231
  const mine = server;
159
232
  this.server = mine;
@@ -176,6 +249,15 @@ class McpServerController {
176
249
  catch (error) {
177
250
  // React only if we're still the current attempt; a superseding attempt owns the state.
178
251
  const current = this.server === server || this.server === undefined;
252
+ // The provider's credential was refused: let it refresh, then try once more with whatever
253
+ // it hands out next. Once only — a credential that is still refused is a failure.
254
+ if (current && !retriedAuth && credential !== undefined && this.credentials?.invalidate !== undefined && isUnauthorizedLikeError(error)) {
255
+ await server?.close().catch(() => undefined);
256
+ if (this.server === server)
257
+ this.server = undefined;
258
+ await Promise.resolve(this.credentials.invalidate(request)).catch(() => undefined);
259
+ return this.attempt(true);
260
+ }
179
261
  if (current) {
180
262
  this.cancelKeepAlive();
181
263
  if (this.shouldMarkNeedsAuth(error)) {
@@ -220,9 +302,23 @@ class McpServerController {
220
302
  this.disposed = true;
221
303
  await this.close();
222
304
  }
305
+ /**
306
+ * What this server offers, for a host that wants to SHOW it rather than call it.
307
+ *
308
+ * Separate from `toolProvider().listTools`, which exists to hand the model runnable
309
+ * tools: that one substitutes an auth tool while a server is stuck on OAuth, and it
310
+ * namespaces every name. This returns the server's own list, unwrapped, and an empty
311
+ * one whenever the server is not connected — a disconnected server has no tools to
312
+ * describe, and asking is not worth an exception.
313
+ */
314
+ async listTools() {
315
+ if (this._status !== "connected" || this.server === undefined)
316
+ return [];
317
+ return await this.server.listTools().catch(() => []);
318
+ }
223
319
  toolProvider() {
224
320
  return {
225
- id: `mcp:${this.name}`,
321
+ id: mcpProviderId(this.name),
226
322
  listTools: async (ctx) => {
227
323
  if (this._status === "needs-auth")
228
324
  return [this.authToolInstance()];
@@ -252,6 +348,7 @@ class McpServerController {
252
348
  serverName: this.name,
253
349
  serverUrl: this.config.url,
254
350
  oauthService: this.oauthService,
351
+ oauthSettings: mcpOAuthSettings(this.config),
255
352
  reconnect: () => this.reconnect(),
256
353
  });
257
354
  }
@@ -345,7 +442,7 @@ class McpServerController {
345
442
  emitWarning(message) {
346
443
  if (message === undefined)
347
444
  return;
348
- this.ctx?.events.emit({ type: "warning", address: "main", sessionId: this.ctx.sessionId, message });
445
+ this.session?.events?.emit({ type: "warning", address: "main", sessionId: this.session.sessionId, message });
349
446
  }
350
447
  }
351
448
  function keepAliveOptions(config, defaults) {
@@ -355,7 +452,38 @@ function keepAliveOptions(config, defaults) {
355
452
  const timeoutMs = config.keepAliveTimeoutMs ?? defaults?.timeoutMs;
356
453
  return { keepAlivePolicy: timeoutMs === undefined ? { intervalMs } : { intervalMs, timeoutMs } };
357
454
  }
358
- export function mcpServersCapability(configs, options = {}) {
455
+ /**
456
+ * Refuse, up front, any server this host does not offer a transport for.
457
+ *
458
+ * A server switched off in configuration is none of this rule's business: `enabled: false` is
459
+ * how one configuration file serves both a laptop and a server, and rejecting it would take
460
+ * that away for no gain — a disabled server spawns nothing.
461
+ */
462
+ function assertTransportsPermitted(configs, allowed) {
463
+ if (allowed === undefined)
464
+ return;
465
+ for (const [name, config] of Object.entries(configs)) {
466
+ if (config.enabled === false)
467
+ continue;
468
+ if (!allowed.includes(config.transport)) {
469
+ throw new McpTransportNotPermittedError(name, config.transport, allowed);
470
+ }
471
+ }
472
+ }
473
+ /**
474
+ * The controller set behind a group of configured servers — buildable on its own so a HARNESS
475
+ * can hold one set of connections for every session it serves (`HarnessParts.mcpServers`), or a session can
476
+ * own a private set (`mcpServersCapability`). Nothing connects until `handle.connect()`.
477
+ *
478
+ * Transport admission is checked HERE, while the set is being built, and not where the
479
+ * transport is actually constructed. That is deliberate: `transportFromConfig` runs inside
480
+ * `attempt()`, whose whole job is to be fault-isolated — it turns a throw into a `failed`
481
+ * status and a warning, which is right for "the server is down" and wrong for "this host will
482
+ * not run that". A misconfiguration should be a startup error the deployer cannot miss, not one
483
+ * more warning in a stream, so it is raised before a single controller exists.
484
+ */
485
+ export function createMcpServers(configs, options = {}) {
486
+ assertTransportsPermitted(configs, options.allowedTransports);
359
487
  const listeners = new Set();
360
488
  const notify = (view) => {
361
489
  for (const listener of listeners)
@@ -365,6 +493,7 @@ export function mcpServersCapability(configs, options = {}) {
365
493
  name,
366
494
  config,
367
495
  ...(options.oauthService !== undefined ? { oauthService: options.oauthService } : {}),
496
+ ...(options.credentials !== undefined ? { credentials: options.credentials } : {}),
368
497
  cacheToolsList: options.cacheToolsList ?? DEFAULT_CACHE_TOOLS,
369
498
  ...(options.transportFactory !== undefined ? { transportFactory: options.transportFactory } : {}),
370
499
  ...(options.reconnectPolicy !== undefined ? { reconnectPolicy: options.reconnectPolicy } : {}),
@@ -384,8 +513,10 @@ export function mcpServersCapability(configs, options = {}) {
384
513
  })();
385
514
  return shuttingDown;
386
515
  };
516
+ const providers = controllers.map((c) => c.toolProvider());
387
517
  const handle = {
388
518
  list: () => controllers.map((c) => c.view()),
519
+ listTools: async (name) => (await byName.get(name)?.listTools()) ?? [],
389
520
  reconnect: async (name) => {
390
521
  const controller = byName.get(name);
391
522
  if (controller === undefined)
@@ -396,17 +527,130 @@ export function mcpServersCapability(configs, options = {}) {
396
527
  listeners.add(listener);
397
528
  return () => listeners.delete(listener);
398
529
  },
530
+ toolProviders: () => providers,
531
+ connect: async (ctx) => {
532
+ await Promise.all(controllers.map((c) => c.connect(ctx)));
533
+ },
399
534
  shutdown,
400
535
  };
536
+ return handle;
537
+ }
538
+ /**
539
+ * The session-tier MCP capability. It covers both topologies, deciding between them from what the
540
+ * host handed it rather than from which function the caller picked:
541
+ *
542
+ * - The host passed shared servers (`options.sharedServers`)? This is a VIEW over them. It
543
+ * connects nothing and shuts nothing down — the harness owns those connections; this
544
+ * capability only hands the model their tools, publishes them as its `mcp` service (so `session.mcp?.list() ?? []` and friends work) and mirrors status changes into this
545
+ * session's event stream as warnings.
546
+ * - It didn't? Then `configs` is all this session sees, and those controllers are built,
547
+ * connected and shut down with the session, owned by it outright.
548
+ *
549
+ * Both at once is the interesting case: `configs` (from `SessionCapabilityContext.mcpServers` — a
550
+ * REPL kernel keyed by conversation id, say) is then an OVERLAY on the shared set. A name in
551
+ * `configs` SHADOWS the shared server of the same name for this session — the two would
552
+ * otherwise produce identical `mcp__<name>__<tool>` tool names. Shadowing is a view-level
553
+ * decision: the shared connection itself keeps running for every other session.
554
+ *
555
+ * Either way only what this session OWNS is connected and shut down here; see `merge` below.
556
+ */
557
+ export function mcpServersCapability(configs = {}, options = {}) {
558
+ /** The host's set, if it gave this session one. Undefined = this session views only its own. */
559
+ let shared = options.sharedServers;
560
+ const ownNames = new Set(Object.keys(configs));
561
+ const ownProviderIds = new Set([...ownNames].map(mcpProviderId));
562
+ const own = ownNames.size > 0 ? createMcpServers(configs, options) : undefined;
563
+ let unsubscribe;
564
+ const providers = [
565
+ ...(own?.toolProviders() ?? []),
566
+ {
567
+ id: "mcp:shared",
568
+ listTools: async (ctx) => {
569
+ // The set bound at provision time, not a fresh lookup: which servers this session views
570
+ // was decided once, by its configuration, and must not drift mid-run.
571
+ if (shared === undefined)
572
+ return [];
573
+ const tools = [];
574
+ for (const provider of shared.toolProviders()) {
575
+ // Skip a shared server this session overlays: same name, same qualified tool names.
576
+ if (ownProviderIds.has(provider.id))
577
+ continue;
578
+ tools.push(...(await provider.listTools(ctx)));
579
+ }
580
+ return tools;
581
+ },
582
+ },
583
+ ];
584
+ /** The merged view: this session's own servers first, the shared set for what they don't name. */
585
+ const merge = (shared, overlay) => ({
586
+ list: () => [...overlay.list(), ...shared.list().filter((v) => !ownNames.has(v.name))],
587
+ listTools: (name) => (ownNames.has(name) ? overlay.listTools(name) : shared.listTools(name)),
588
+ reconnect: (name) => (ownNames.has(name) ? overlay.reconnect(name) : shared.reconnect(name)),
589
+ onStatusChange: (listener) => {
590
+ const offOwn = overlay.onStatusChange(listener);
591
+ const offShared = shared.onStatusChange((view) => {
592
+ if (!ownNames.has(view.name))
593
+ listener(view);
594
+ });
595
+ return () => {
596
+ offOwn();
597
+ offShared();
598
+ };
599
+ },
600
+ toolProviders: () => providers,
601
+ // Only the overlay is this session's to run: the shared half is already connected, and
602
+ // outlives the session.
603
+ connect: (ctx) => overlay.connect(ctx),
604
+ shutdown: () => overlay.shutdown(),
605
+ });
606
+ /**
607
+ * What `openSession` does: bind the shared set for this
608
+ * session's view, connect what this session OWNS, and subscribe for the rest.
609
+ */
610
+ const open = async (ctx) => {
611
+ const events = ctx.events;
612
+ // Nothing shared and nothing of its own means this capability should never have been
613
+ // assembled — diagnose rather than hand back an empty handle.
614
+ if (shared === undefined && own === undefined) {
615
+ throw new Error("mcpServersCapability was given no servers of its own and no shared set to view.");
616
+ }
617
+ // Session-owned controllers emit their own warnings once connected (they hold the
618
+ // session); the shared ones have no session, so this session subscribes for them.
619
+ if (own !== undefined)
620
+ await own.connect({ sessionId: ctx.sessionId, events });
621
+ if (shared !== undefined) {
622
+ const warn = (view) => {
623
+ if (ownNames.has(view.name))
624
+ return;
625
+ if (view.status !== "failed" || view.error === undefined)
626
+ return;
627
+ events?.emit({ type: "warning", address: "main", sessionId: ctx.sessionId, message: `MCP server "${view.name}" failed: ${view.error}` });
628
+ };
629
+ // Servers that failed before this session existed: tell it once at open.
630
+ for (const view of shared.list())
631
+ warn(view);
632
+ unsubscribe = shared.onStatusChange(warn);
633
+ }
634
+ handle = shared === undefined ? own : own === undefined ? shared : merge(shared, own);
635
+ };
636
+ /** The merged view handed out as the session's service; bound by `open`. */
637
+ let handle;
638
+ const dispose = async () => {
639
+ unsubscribe?.();
640
+ unsubscribe = undefined;
641
+ shared = undefined;
642
+ await own?.shutdown();
643
+ };
401
644
  return {
402
645
  name: "mcp",
403
- toolProviders: controllers.map((c) => c.toolProvider()),
404
- service: handle,
405
- // Session-tier: connect all servers in parallel, fault-isolated (attempt() never throws).
406
- openSession: async (ctx) => {
407
- await Promise.all(controllers.map((c) => c.connect(ctx)));
646
+ contract: "detachable",
647
+ toolProviders: providers,
648
+ /** The merged view (shared ∪ own), bound at open. */
649
+ get service() {
650
+ return handle;
408
651
  },
409
- closeSession: shutdown,
652
+ openSession: open,
653
+ closeSession: dispose,
410
654
  };
411
655
  }
412
656
  //# sourceMappingURL=manager.js.map
@@ -10,5 +10,14 @@ export interface CallbackServer {
10
10
  }): Promise<CallbackResult>;
11
11
  close(): Promise<void>;
12
12
  }
13
- export declare function startCallbackServer(): Promise<CallbackServer>;
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
@@ -1,15 +1,55 @@
1
1
  import { createServer } from "node:http";
2
- const SUCCESS_HTML = '<!doctype html><html><head><meta charset="utf-8"><title>Authorized</title></head>' +
3
- '<body style="font-family:system-ui,sans-serif;padding:2rem;">' +
4
- "<h1>Sign-in complete</h1>" +
5
- "<p>You can close this tab and return to agent-framework.</p>" +
6
- "</body></html>";
7
- const ERROR_HTML = '<!doctype html><html><head><meta charset="utf-8"><title>OAuth error</title></head>' +
8
- '<body style="font-family:system-ui,sans-serif;padding:2rem;">' +
9
- "<h1>Sign-in failed</h1>" +
10
- "<p>The authorization server reported an error. Return to agent-framework for details.</p>" +
11
- "</body></html>";
12
- export async function startCallbackServer() {
2
+ const PAGE_STYLE = `
3
+ :root{color-scheme:light dark;--bg:#fafafa;--card:#ffffff;--border:rgba(223,227,235,.9);--fg:#18181b;--muted:#71717a;--ok:#15803d;--ok-bg:rgba(21,128,61,.1);--err:#b91c1c;--err-bg:rgba(185,28,28,.08);--code:#f4f4f5;--shadow:0 1px 2px rgba(15,23,42,.04),0 8px 24px rgba(15,23,42,.05)}
4
+ @media (prefers-color-scheme:dark){:root{--bg:#0b0b0d;--card:#141417;--border:rgba(63,63,70,.55);--fg:#f4f4f5;--muted:#a1a1aa;--ok:#4ade80;--ok-bg:rgba(74,222,128,.1);--err:#fca5a5;--err-bg:rgba(248,113,113,.1);--code:#1d1d21;--shadow:0 1px 2px rgba(0,0,0,.4),0 12px 32px rgba(0,0,0,.35)}}
5
+ *{box-sizing:border-box}
6
+ body{margin:0;min-height:100vh;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:20px;padding:24px 16px;background:var(--bg);color:var(--fg);font:14px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",system-ui,sans-serif;-webkit-font-smoothing:antialiased}
7
+ .card{width:100%;max-width:400px;padding:32px 28px 28px;border:1px solid var(--border);border-radius:12px;background:var(--card);box-shadow:var(--shadow);text-align:center}
8
+ .icon{width:44px;height:44px;margin:0 auto 16px;display:flex;align-items:center;justify-content:center;border-radius:9999px}
9
+ .icon svg{width:22px;height:22px}
10
+ .ok .icon{background:var(--ok-bg);color:var(--ok)}
11
+ .err .icon{background:var(--err-bg);color:var(--err)}
12
+ h1{margin:0 0 6px;font-size:16px;font-weight:600;letter-spacing:-.01em}
13
+ p{margin:0;color:var(--muted)}
14
+ .detail{margin-top:16px;padding:10px 12px;border-radius:8px;background:var(--code);color:var(--fg);font:12px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;text-align:left;word-break:break-word}
15
+ .brand{display:flex;align-items:center;gap:6px;color:var(--muted);font-size:12px;font-weight:500;letter-spacing:.02em}
16
+ .brand span{width:6px;height:6px;border-radius:9999px;background:currentColor;opacity:.6}
17
+ `;
18
+ const CHECK_ICON = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg>';
19
+ const CROSS_ICON = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12"/></svg>';
20
+ function escapeHtml(value) {
21
+ return value
22
+ .replaceAll("&", "&amp;")
23
+ .replaceAll("<", "&lt;")
24
+ .replaceAll(">", "&gt;")
25
+ .replaceAll('"', "&quot;")
26
+ .replaceAll("'", "&#39;");
27
+ }
28
+ function renderPage(opts) {
29
+ const detail = opts.detail ? `<div class="detail">${escapeHtml(opts.detail)}</div>` : "";
30
+ return ('<!doctype html><html lang="en"><head><meta charset="utf-8">' +
31
+ '<meta name="viewport" content="width=device-width,initial-scale=1">' +
32
+ `<title>${escapeHtml(opts.title)} · Operon</title><style>${PAGE_STYLE}</style></head>` +
33
+ `<body><main class="card ${opts.ok ? "ok" : "err"}">` +
34
+ `<div class="icon">${opts.ok ? CHECK_ICON : CROSS_ICON}</div>` +
35
+ `<h1>${escapeHtml(opts.title)}</h1><p>${escapeHtml(opts.message)}</p>${detail}</main>` +
36
+ '<div class="brand"><span></span>Operon</div></body></html>');
37
+ }
38
+ const SUCCESS_HTML = renderPage({
39
+ ok: true,
40
+ title: "Sign-in complete",
41
+ message: "You can close this tab and return to Operon.",
42
+ });
43
+ function errorHtml(detail) {
44
+ return renderPage({
45
+ ok: false,
46
+ title: "Sign-in failed",
47
+ message: "Return to Operon and try connecting again.",
48
+ detail,
49
+ });
50
+ }
51
+ export async function startCallbackServer(options = {}) {
52
+ const fixed = resolveFixedRedirect(options);
13
53
  let resolveCode;
14
54
  let rejectCode;
15
55
  let settled = false;
@@ -35,14 +75,16 @@ export async function startCallbackServer() {
35
75
  res.writeHead(404).end();
36
76
  return;
37
77
  }
38
- if (url.pathname !== "/callback") {
78
+ if (url.pathname !== fixed.path) {
39
79
  res.writeHead(404).end();
40
80
  return;
41
81
  }
42
82
  const errorParam = url.searchParams.get("error");
43
83
  if (errorParam !== null) {
44
84
  const description = url.searchParams.get("error_description") ?? "";
45
- res.writeHead(400, { "content-type": "text/html; charset=utf-8" }).end(ERROR_HTML);
85
+ res
86
+ .writeHead(400, { "content-type": "text/html; charset=utf-8" })
87
+ .end(errorHtml(description ? `${errorParam}: ${description}` : errorParam));
46
88
  settle(() => {
47
89
  rejectCode?.(new Error(`OAuth error: ${errorParam}${description ? ` — ${description}` : ""}`));
48
90
  });
@@ -50,7 +92,9 @@ export async function startCallbackServer() {
50
92
  }
51
93
  const code = url.searchParams.get("code");
52
94
  if (code === null || code.length === 0) {
53
- res.writeHead(400, { "content-type": "text/html; charset=utf-8" }).end(ERROR_HTML);
95
+ res
96
+ .writeHead(400, { "content-type": "text/html; charset=utf-8" })
97
+ .end(errorHtml("The authorization server did not return an authorization code."));
54
98
  settle(() => {
55
99
  rejectCode?.(new Error("OAuth callback missing authorization code"));
56
100
  });
@@ -64,13 +108,13 @@ export async function startCallbackServer() {
64
108
  }
65
109
  await new Promise((resolve, reject) => {
66
110
  server.once("error", reject);
67
- server.listen(0, "127.0.0.1", () => {
111
+ server.listen(fixed.port ?? 0, fixed.host, () => {
68
112
  server.off("error", reject);
69
113
  resolve();
70
114
  });
71
115
  });
72
116
  const port = server.address().port;
73
- const redirectUri = `http://127.0.0.1:${port}/callback`;
117
+ const redirectUri = fixed.redirectUri ?? `http://127.0.0.1:${port}${fixed.path}`;
74
118
  let closed = false;
75
119
  const close = async () => {
76
120
  if (closed)
@@ -119,4 +163,26 @@ export async function startCallbackServer() {
119
163
  };
120
164
  return { redirectUri, waitForCode, close };
121
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]"]);
122
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;