Skip to main content
Glama

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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[], }; }
  • Registration and dispatch logic in the CallToolRequest handler switch statement that routes 'generate_key' calls to handleGenerateKey.
    case "generate_key": { return handleGenerateKey(this.bitcoinService); }
  • 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,
  • 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 ); } }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/AbdelStark/bitcoin-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server