Skip to content

fix(mcp): make mainnet key optional and explicit opt-in - #554

Open
esanbasirat wants to merge 1 commit into
Divinity-Labs:mainfrom
esanbasirat:fix/issue-412-testnet-optional-mainnet-key
Open

esanbasirat wants to merge 1 commit into
Divinity-Labs:mainfrom
esanbasirat:fix/issue-412-testnet-optional-mainnet-key

Conversation

@esanbasirat

Copy link
Copy Markdown

Summary

This PR addresses #412 by removing the requirement to configure a mainnet secret key when running the MCP server against testnet, making mainnet payment signing an explicit opt-in, enabling read-only startup when no keys are present, and cleanly reporting missing network signer errors without ever leaking secret keys.

What is included:

  • src/mcp/paymentConfig.ts:
    • Implements setupMcpPayment() to configure payment schemes dynamically based on available keys.
    • Supports running with testnet key only.
    • Enforces explicit opt-in for mainnet (enableMainnet: true via MCP_ENABLE_MAINNET=true, MCP_ALLOW_MAINNET=true, or --allow-mainnet); ignores mainnet key if not opted in and emits informational guidance.
    • Logs a visible warning at startup when mainnet is active: ⚠️ WARNING: Mainnet (stellar:pubnet) is enabled! Real funds are reachable.
    • Supports keyless startup in read-only mode.
    • Ensures secret key values are never logged, printed, or leaked in error messages.
  • src/mcp/server.ts:
    • Made fetchWithPayment optional in McpServerConfig and BazaarMcpServer.
    • Refuses paid_call gracefully when payment is disabled or unconfigured (ERR_PAYMENT_REJECTED).
    • Improved handlePaidCallError so missing network scheme errors (No network/scheme registered for <network>) map to ERR_PAYMENT_REJECTED and explicitly name the required network.
  • examples/mcp-server/run.ts:
    • Wired to setupMcpPayment().
  • examples/mcp-server/README.md:
    • Updated configuration table and safe setup guide.
  • tests/mcp.test.ts:
    • Added unit test suite covering:
      • Server starting with only testnet key.
      • Mainnet explicit opt-in verification.
      • Server starting with no keys and paid_call refusing.
      • Error response naming the missing network.
      • Zero key leakage on invalid key errors.

Closes #412

@drips-wave

drips-wave Bot commented Oct 19, 2026

Copy link
Copy Markdown

@esanbasirat Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Running on testnet requires a mainnet key

2 participants