validate_address
Verify Bitcoin address validity to prevent errors in transactions and ensure proper format before use.
Instructions
Validate a Bitcoin address
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | The Bitcoin address to validate |
Implementation Reference
- src/server/tools.ts:73-96 (handler)The main handler function for the 'validate_address' tool. It parses input arguments using ValidateAddressSchema, calls bitcoinService.validateAddress, and returns a text response indicating validity.export async function handleValidateAddress( bitcoinService: BitcoinService, args: unknown ) { const result = ValidateAddressSchema.safeParse(args); if (!result.success) { throw new McpError( ErrorCode.InvalidParams, `Invalid parameters: ${result.error.message}` ); } const isValid = bitcoinService.validateAddress(result.data.address); return { content: [ { type: "text", text: isValid ? `Address ${result.data.address} is valid` : `Address ${result.data.address} is invalid`, }, ] as TextContent[], }; }
- src/types.ts:118-120 (schema)Zod schema defining the input for the validate_address tool: an object with a required 'address' string.export const ValidateAddressSchema = z.object({ address: z.string().min(1, "Address is required"), });
- src/server/base.ts:122-134 (registration)Tool registration in the MCP server's listTools response, specifying name 'validate_address', description, and input schema.name: "validate_address", description: "Validate a Bitcoin address", inputSchema: { type: "object", properties: { address: { type: "string", description: "The Bitcoin address to validate", }, }, required: ["address"], } as any, } as Tool,
- src/server/base.ts:203-205 (registration)Dispatch logic in the callTool request handler that routes 'validate_address' calls to handleValidateAddress.case "validate_address": { return handleValidateAddress(this.bitcoinService, args); }
- src/services/bitcoin.ts:114-121 (helper)Core helper method in BitcoinService that performs the actual address validation using bitcoinjs-lib's toOutputScript.validateAddress(address: string): boolean { try { bitcoin.address.toOutputScript(address, this.network); return true; } catch { return false; } }