generate_key
Create a new Bitcoin key pair and address using the Bitcoin MCP Server for secure and direct interaction with the Bitcoin network.
Instructions
Generate a new Bitcoin key pair and address
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/server/tools.ts:52-62 (handler)MCP tool handler function for 'generate_key' that invokes the BitcoinService generateKey method and formats the response as MCP TextContent.export async function handleGenerateKey(bitcoinService: BitcoinService) { const key = await bitcoinService.generateKey(); return { content: [ { type: "text", text: `Generated new Bitcoin key pair:\nAddress: ${key.address}\nPrivate Key (WIF): ${key.privateKey}\nPublic Key: ${key.publicKey}`, }, ] as TextContent[], }; }
- src/server/base.ts:200-202 (registration)Registration and dispatch logic in the CallToolRequest handler switch statement that routes 'generate_key' calls to handleGenerateKey.case "generate_key": { return handleGenerateKey(this.bitcoinService); }
- src/server/base.ts:116-120 (schema)Tool schema definition including name, description, and empty input schema for 'generate_key' in the ListToolsRequest handler.{ name: "generate_key", description: "Generate a new Bitcoin key pair and address", inputSchema: { type: "object", properties: {}, required: [] }, } as Tool,
- src/services/bitcoin.ts:79-103 (helper)Core implementation of key generation using bitcoinjs-lib ECPair and p2pkh address derivation in BitcoinService.async generateKey(): Promise<GeneratedKey> { try { const keyPair = ECPair.makeRandom({ rng }); const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey, network: this.network, }); if (!address) { throw new Error("Failed to generate address"); } return { address, privateKey: keyPair.toWIF(), publicKey: keyPair.publicKey.toString("hex"), }; } catch (error) { logger.error({ error }, "Failed to generate key"); throw new BitcoinError( "Failed to generate key pair", BitcoinErrorCode.KEY_GENERATION_ERROR ); } }