Skip to main content
Glama

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

NameRequiredDescriptionDefault
secretKeyYesBase58 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

  • 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}`, }, ], }; } }
  • 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}`, }, ], }; } } );

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/akc2267/solana-mcp-server'

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