Support account API keys across MCP tools - #136
KillerQueen-Z wants to merge 2 commits into
Conversation
Both carried over from @KillerQueen-Z's PR #136, which implemented account-key support in parallel and had these two details the shipped version did not. ~/.blockrun/.api-key is read when BLOCKRUN_API_KEY is unset. A stdio MCP server is launched by its client, and several clients make setting an environment variable awkward or impossible — which is why the wallet has always had ~/.blockrun/.session. The key needs the same escape hatch. Precedence is env then file, mirroring BLOCKRUN_WALLET_KEY over .session: an explicitly exported key is a deliberate override and must not be shadowed by whatever is left on disk from an earlier account. An empty or unreadable file falls through to wallet mode rather than taking the server down. A malformed one still fails loudly, and the message now names which source it came from, so "invalid key" does not send someone to check an env var they never set. A 429 from the account API now surfaces Retry-After instead of burying it in the body. It is the one part of a rate-limit response a caller can act on; an agent told only "rate limited" retries immediately and is refused again. Verified with no environment variable set at all, against a temp HOME holding only the key file: the server reports account mode and reads the live balance. Tests 458 -> 462. Claude-Session: https://claude.ai/code/session_0116SvLAGyzJ4SYKBvAE2DTc Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Closing as superseded — but the good parts of this are shipped, with credit. What happened. This PR was opened 2026-09-04 and explicitly gated on There is no path where this merges. But it had two things the shipped version did not, and both are now on main in 0.48.0 (#139) with attribution:
Not carried over, for the record: Sorry for the duplicated effort — that was avoidable and the fault was mine for not looking for an open PR before starting. Thank you for the two details that made the shipped version better. |
MCP previously selected or provisioned a wallet before model and data tools, while music, speech, video and RealFace also maintained independent x402 code paths. Add shared account-key resolution and use it across chat/native Anthropic, catalog, image, media polling, prices and other SDK-backed data tools, including the independent music/speech/video/RealFace flows.
Account mode reads BLOCKRUN_API_KEY or the shared ~/.blockrun/.api-key, validates it, binds Bearer credentials to the configured account origin, refuses redirects/cross-origin polls and fails closed without wallet fallback. Wallet-owned assets, Polymarket trading, transfers, deposits, withdrawals and signing remain explicit wallet operations. Account calls skip x402 settlement counters and point billing to the credits portal. New wallet users default to Solana while prior selections and Base-only users remain compatible.
Validation: 434 tests pass; typecheck and production build (including MCP apps and DTS bundle) pass. Live temporary-key validation starts the real MCP stdio server, initializes the protocol, lists tools, fetches the account model catalog and completes a chat request. Account media/polling and 401/402/429 behavior are covered deterministically; paid live media was not repeated.
Release gate: TypeScript SDK #36 must be published and package.json must be updated from ^3.8.4 before MCP release. Local tests used the tarball built from exact commit 7a61b57. Responses SSE/video production completion remains dependent on Enterprise #10 deployment/configuration; native Gemini account availability is unverified.