Skip to content

Support account API keys across MCP tools - #136

Closed
KillerQueen-Z wants to merge 2 commits into
BlockRunAI:mainfrom
KillerQueen-Z:feat/account-api-key
Closed

KillerQueen-Z wants to merge 2 commits into
BlockRunAI:mainfrom
KillerQueen-Z:feat/account-api-key

Conversation

@KillerQueen-Z

Copy link
Copy Markdown
Contributor

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.

VickyXAI added a commit that referenced this pull request Sep 5, 2026
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>
@VickyXAI

VickyXAI commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

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 @blockrun/llm #36 being published ("must be updated from ^3.8.4 before MCP release"). That gate lifted this morning when the SDK went out as 3.14.3. In parallel, and without checking for an open PR first — my miss — the same feature was built and shipped as 0.46.0 and 0.47.0. By the time the gate lifted, main had moved past this branch: it is now unmergeable, and CI is red on a typecheck error in test/account-api.test.ts plus the stale ^3.8.4 pin it was waiting to replace.

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:

  • ~/.blockrun/.api-key. The shipped implementation read only BLOCKRUN_API_KEY. Reading a file too is the better call, and for the reason the wallet already has ~/.blockrun/.session: a stdio MCP server is launched by its client, and several clients make setting an environment variable awkward. Precedence is env-then-file, mirroring BLOCKRUN_WALLET_KEY over .session. Four tests cover it.
  • Retry-After on a 429. Surfaced rather than buried in the body — the one part of a rate-limit response a caller can act on.

Not carried over, for the record: accountJson duplicates polling and origin-pinning that utils/api-key-call.ts and utils/wallet.ts:resolveGatewayUrl now do with test coverage, and requirements-api-preview.txt was a note for the unpublished SDK and is obsolete.

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.

@VickyXAI VickyXAI closed this Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants