getKeypairInfo
Retrieve keypair details, including public key and balance, by providing the base58 encoded secret key using the Solana MCP Server tool.
Instructions
Get information about a keypair from its secret key
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| secretKey | Yes | Base58 encoded secret key or array of bytes |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"secretKey": {
"description": "Base58 encoded secret key or array of bytes",
"type": "string"
}
},
"required": [
"secretKey"
],
"type": "object"
}
Implementation Reference
- src/index.ts:96-139 (handler)The handler function that implements the core logic of the getKeypairInfo tool: parses secretKey into Keypair, fetches balance and account info from Solana, formats and returns the information.async ({ secretKey }) => { try { // Handle both base58 encoded strings and byte arrays let keypair: Keypair; try { // First try parsing as comma-separated string const decoded = Uint8Array.from(secretKey.split(',').map(num => parseInt(num.trim()))); keypair = Keypair.fromSecretKey(decoded); } catch { // If that fails, try as a byte array string keypair = Keypair.fromSecretKey(Uint8Array.from(JSON.parse(secretKey))); } // Get account info and balance const publicKey = keypair.publicKey; const balance = await connection.getBalance(publicKey); const accountInfo = await connection.getAccountInfo(publicKey); return { content: [ { type: "text", text: `Keypair Information: Public Key: ${publicKey.toBase58()} Balance: ${balance / LAMPORTS_PER_SOL} SOL Account Program Owner: ${accountInfo?.owner?.toBase58() || 'N/A'} Account Size: ${accountInfo?.data.length || 0} bytes Is Executable: ${accountInfo?.executable || false} Rent Epoch: ${accountInfo?.rentEpoch || 0}`, }, ], }; } catch (err) { const error = err as Error; return { content: [ { type: "text", text: `Failed to retrieve keypair information: ${error.message}`, }, ], }; } }
- src/index.ts:93-95 (schema)The input schema for the getKeypairInfo tool, defining the secretKey parameter using Zod.{ secretKey: z.string().describe("Base58 encoded secret key or array of bytes"), },
- src/index.ts:90-140 (registration)The registration of the getKeypairInfo tool using server.tool(), including name, description, schema, and inline handler.server.tool( "getKeypairInfo", "Get information about a keypair from its secret key", { secretKey: z.string().describe("Base58 encoded secret key or array of bytes"), }, async ({ secretKey }) => { try { // Handle both base58 encoded strings and byte arrays let keypair: Keypair; try { // First try parsing as comma-separated string const decoded = Uint8Array.from(secretKey.split(',').map(num => parseInt(num.trim()))); keypair = Keypair.fromSecretKey(decoded); } catch { // If that fails, try as a byte array string keypair = Keypair.fromSecretKey(Uint8Array.from(JSON.parse(secretKey))); } // Get account info and balance const publicKey = keypair.publicKey; const balance = await connection.getBalance(publicKey); const accountInfo = await connection.getAccountInfo(publicKey); return { content: [ { type: "text", text: `Keypair Information: Public Key: ${publicKey.toBase58()} Balance: ${balance / LAMPORTS_PER_SOL} SOL Account Program Owner: ${accountInfo?.owner?.toBase58() || 'N/A'} Account Size: ${accountInfo?.data.length || 0} bytes Is Executable: ${accountInfo?.executable || false} Rent Epoch: ${accountInfo?.rentEpoch || 0}`, }, ], }; } catch (err) { const error = err as Error; return { content: [ { type: "text", text: `Failed to retrieve keypair information: ${error.message}`, }, ], }; } } );