mirror of
https://github.com/nightly-labs/openbot.git
synced 2026-12-03 02:00:16 +08:00
* Make MCP work on a clean machine: report every drop, ship Bun, close the second config door, sign in natively An MCP server that OpenBot could not hand over used to disappear without a word, and on a machine with no Node none of them could start at all. Four stages, each shippable alone. 1. Every drop is now a shape, not a `continue`. The three adapters return `McpHandoff<T>` with the servers they left out, and `AgentService` reports each new one once: a warning in the log and one deduped `mcp_server_not_started` toast with no `agentId`, because the MCP list is machine-scoped. `resolveMcpCommand` is memoized per `PATH` and command, so a thread start no longer runs one login shell per stdio server, and the Test button clears that cache because it asks about now. 2. Bun 1.4.2 ships as a managed tool runtime, downloaded and sha256-verified by the existing runtime manager under its own id space (`toolRuntimes`), not as a fifth provider. Its bin directory is appended *last* to the lookup and launch `PATH`, so a user's own Node still wins and no machine that works today changes behaviour. `bun run pin:bun-runtime` refreshes the pin at release prep. 3. The panel is authoritative. Claude gets `strictMcpConfig: true`, which drops project `.mcp.json`, user settings, plugins and agent frontmatter for MCP only, and the Codex disabled-name sweep moves into every thread. Those names join the manifest fingerprint and `CODEX_MCP_ADAPTER_VERSION` is 3, so a stale session is replaced once rather than resumed with tools the panel does not show. 4. OpenBot holds the OAuth client itself. A `safeStorage`-encrypted store, an `OAuthClientProvider` on the pinned SDK, and a third `openbot://mcp-auth` deep-link variant replace `mcp-remote`, whose refresh tokens sat outside `safeStorage` and outside redaction. The token is injected at hand-off and never written to a row, and it is recorded in `McpHandoffLog`, which is the point: a CLI that quotes the request it failed on no longer prints it. All six bridge listings are now `transport: "http"`; Linear's address is corrected to `/mcp`. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * Close four MCP hand-off gaps the review found Serialize the OAuth store's read-modify-write, so two servers refreshing in one hand-off cannot write each other's rotated token away or race the same temporary file. Keep the inherited PATH when the managed runtime directory is appended and there is no login shell to ask. Windows is always that case, and the user's own npx, python and uvx would otherwise disappear behind the managed one. Give the OpenCode driver mcpAuthorization, which every other driver already had: without it a completed native sign-in reached OpenCode with no token. Redact the token a probe mints between its two attempts. It is on no row, so only the sign-in provider can name it, and a server that quotes the credential it refused would otherwise put it on the panel. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * Keep one refresh per server, and never delete a sign-in file this build cannot read A refresh token is single use where the authorization server rotates it, so two hand-offs refreshing the same server side by side spend the same one twice and can lose the whole grant. Callers now wait on the exchange already running. A `clear` while the envelope is unreadable committed an empty map, and an empty map is a delete: one keychain refusal plus one removed row cost the user every sign-in on the machine. Both changes now read the file again first, and a clear that still cannot read it leaves the file alone. The provider runtime snapshot carries the tool runtimes, so the preload decoder test has to send them. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * Refuse an MCP registration while encrypted sign-ins cannot be read saveClientInformation runs before the user signs in and carries no tokens. When the envelope holds records this build cannot decrypt, storing it replaced the file and deleted unrelated credentials even if the user cancelled. The store now keeps the raw encrypted records from a failed read and refuses the write, so the file stays as it is until the keychain answers again. A corrupt file still takes the replacement path, since it holds nothing worth keeping. * Fix the four remaining review findings on MCP setup Migrate catalog bridge rows: rows that still match the six shipped mcp-remote definitions become native http rows on startup. Exact matches only; renamed rows and edited arguments stay untouched, and every other column is kept. The next Test on a converted row signs in through the browser like a new installation. Wait for the runtime download in the connection test: the local stdio test path now awaits ensureToolRuntimesReady before probing, so a first plugin no longer answers Command not found on a machine that only needs the Bun download. A failed download still runs the probe. Spend stored OAuth tokens in remote tests: the Team API route passes storedCredentials, and the service builds a silent authority whose signIn stays null. A remote administrator gets the host's working token instead of a false 401, and no browser opens on the host. Fold tool runtimes into the Codex fingerprint: a session started before Bun was ready no longer reads as current once its servers can start, so the next turn replaces it. Adapter version rides to 4. * Fix the three new review findings on MCP setup Bound the OAuth exchanges: a silent refresh now waits at most MCP_TOKEN_TIMEOUT_MS for the authorization server, then the stored token answers instead of the thread start or test hanging with it. The token trade after a browser grant gets the same bound and reports a timeout instead of holding the test past its deadline. Both bounds are injectable as refreshTimeoutMs, like signInTimeoutMs. Launch with the looked-up PATH: mcpLaunchEnvironment applies the resolved server.path after the configured pairs, so the managed directories the lookup appended survive into the spawn. The user's own directories still come first, and a configured PATH still stands when the lookup answered nothing. Match the rendered note in the MCP story: the play queries read Claude only, like mcpProviderLimitNote renders. * Fix the two new review findings on MCP setup Wait for Bun only when the test needs it: the local stdio test resolves the configured command first and downloads only when nothing names it, so installed interpreters and the user's own npx probe at once. The wait is bounded at sixty seconds; a stalled transfer keeps downloading for the next attempt while the probe reports what this machine starts. Refuse writes from forgotten OAuth runs: forget counts a generation per server, and every provider built from then on carries it. A refresh or sign-in already running when the row is removed finishes with a refused write instead of restoring the account, so removal reads complete and re-adding the URL cannot reuse it. * Fix the three review findings on MCP setup Wait for the download only when the command needs it: the local test resolves the configured command first and downloads only when nothing names it, so installed commands and the user's own npx probe at once. The wait is bounded at sixty seconds, and failure reaches the probe instead of replacing it: the download rejection is caught before the race, so a failed transfer still tests the command on its own merits. Compare normalized URLs before deleting shared credentials: removing a row forgets its sign-in only when no remaining http row normalizes to the same resource, so https://mcp.stripe.com and https://mcp.stripe.com/ keep sharing one credential until the last row goes. Refresh loaded sessions when Bun becomes ready: the tool runtime's ready event marks every agent for a runtime refresh, spent through the existing deferred mechanism before each agent's next turn. Only Codex needed the fingerprint; Claude, OpenCode and Grok sessions now pick up newly resolvable servers the same way. * Share the runtime preparation with the remote MCP routes The host's Team API routes called AgentService directly and bypassed every runtime preparation the local branches do: on a host with no Node, a first server saved, enabled, or tested remotely left npx unavailable. The IPC handlers' preparation now travels as one shape, McpToolRuntimePreparation, through the host into the Team API options, and the save, enable, and test routes share it: fire and forget on save and enable, the bounded wait for a command nothing names on test. * Cover the host preparation in the remote test deadline The host may wait out the bounded runtime download before its own probe deadline even starts, so a remote Test carries an explicit deadline of preparation plus probe plus margin. Without it the caller's 15-second request limit reported a timeout for a download that was still running, before the host probed anything. * Fix the three OAuth review findings on MCP setup Open the browser only for web pages: the authorization endpoint arrives in the server's own discovery document, and the SDK accepts more than web pages, so redirectToAuthorization now requires https (loopback http for a sign-in server on the user's own machine) and refuses anything else before openExternal. A file or installed protocol handler named by a malicious metadata document no longer opens. Retain the discovered authorization server: the client provider now implements the SDK discovery-state members per resource, so a refresh or a later sign-in reuses the authorization server a previous exchange found instead of rediscovering at the default locations and falling back to the MCP origin's token endpoint. Invalidation clears the retained state with the credentials it belongs to. Never open a browser for an abandoned sign-in: abandon marks the run, and a discovery slow enough to outlast the probe finds no browser to open and no grant to wait out when it finishes. * Persist OAuth discovery and bound stalled refreshes Persist the authorization server a sign-in found with the encrypted credentials: the client provider keeps the server and metadata URLs in the record, so a refresh or sign-in after a restart reuses them instead of rediscovering at the default locations and falling back to the MCP origin's token endpoint. Invalidation clears the retained state with the credentials it belongs to. Bound stalled refreshes: the exchange carries an abort tied to the same deadline as the wait, and a cancelled entry is cleared, so the next caller starts a fresh exchange instead of joining a request that never answers and receiving the expired token again. * Keep OAuth discovery across the sign-in and cancel timed-out trades Keep discovery-only records: the SDK saves discovery state before it registers, when the record holds no client and no tokens yet. The store no longer deletes that write, so the code exchange reuses the advertised authorization server instead of falling back to default discovery. An actually empty record still deletes. Cancel a token trade that outlasts its deadline: the code exchange carries an abort tied to the same bound as its wait, and writes from an abandoned run are refused, so a late response cannot store credentials a later sign-in already replaced. * Keep OAuth credentials on TLS and out of the failures they cause Send a credential only over https, or to loopback. `normalizeResource` cleared the MCP server's own address and `isAuthorizationUrlSafe` cleared where the browser goes, but neither covered where the code, the PKCE verifier and the refresh token are posted: discovery names that endpoint, and an https server naming `http://auth.example.com/token` put all three in clear text. One fetch guard now covers the refresh and the code exchange, and checks every redirect hop rather than the first address alone, so a redirect cannot reach what the document could not name. Redact every secret an attempt spent, not only its access token. A token endpoint states a refusal in `error_description`, the SDK makes that text the error it throws, and the probe puts that text on the panel - so a server quoting back the code, the verifier, the refresh token or the client secret leaked it. The sign-in keeps a ledger of what it handled as it goes, because reading the store after the failure is too late: a recoverable refusal has already cleared the value that was spent. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * Guard the transport's own OAuth, its redirects, and its removals Give the probe transport the same fetch. A 401 on a stored token the probe believed was still valid makes the transport call `auth()` itself, through a fetch of its own - so the refresh token and the client secret went to the discovered token endpoint unchecked, including a plain-text one. A provider is only attached to a URL that already passed `normalizeResource`, so the guard refuses nothing the probe could otherwise reach. Drop the credentials when a redirect leaves the origin. Following redirects by hand took over a job `fetch` had been doing: it strips `Authorization` across origins, and the SDK sends `Authorization: Basic` for a client with a secret. A token endpoint redirecting elsewhere would have handed that origin the secret, and the body holding the code or the refresh token with it. Discovery carries neither, so an issuer may still point at the server that answers for it. Guard removals as writes are guarded. The SDK answers `invalid_client` by invalidating everything, and `clear` had neither the generation nor the abandonment check - so a refusal arriving after a probe timed out could delete the account a later sign-in had already stored. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>