Skip to main content
Glama

list-accounts

Retrieve all cryptocurrency wallet accounts stored in the keys folder for managing tokens on the Pump.fun platform.

Instructions

List all accounts in the keys folder

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core handler function that scans the .keys directory for .json keypair files (excluding mint-), parses them into Solana Keypairs, and returns a list of account names and public keys. Handles missing folder by creating it.
    export async function listAccounts() { try { console.error("Starting listAccounts function"); const keysFolder = path.resolve(rootDir, ".keys"); console.error(`Using keys folder path: ${keysFolder}`); console.error( `Checking if keys folder exists: ${fs.existsSync(keysFolder)}` ); if (!fs.existsSync(keysFolder)) { console.error(`Creating keys folder: ${keysFolder}`); try { fs.mkdirSync(keysFolder, { recursive: true }); console.error(`Keys folder created successfully`); return { success: true, message: `No accounts found. Keys folder created at ${keysFolder}. Use the create-token or buy-token tools to create an account.`, accounts: [], }; } catch (mkdirError: any) { console.error(`Error creating keys folder:`, mkdirError); return { success: false, error: `Error creating keys folder: ${ mkdirError.message || JSON.stringify(mkdirError) }`, accounts: [], }; } } console.error(`Reading files from keys folder: ${keysFolder}`); const files = fs.readdirSync(keysFolder); console.error(`Found ${files.length} files in keys folder`); const accounts = files .filter((file) => !file.startsWith("mint-") && file.endsWith(".json")) .map((file) => { const name = file.replace(".json", ""); console.error(`Processing account file: ${file}`); try { const keypairData = JSON.parse( fs.readFileSync(path.join(keysFolder, file), "utf-8") ); const keypair = Keypair.fromSecretKey(new Uint8Array(keypairData)); return { name, publicKey: keypair.publicKey.toString() }; } catch (error: any) { console.error(`Error processing account file ${file}:`, error); return { name, publicKey: "Error reading keypair" }; } }); console.error(`Found ${accounts.length} accounts`); if (accounts.length === 0) { return { success: true, message: `No accounts found in ${keysFolder}. Use the create-token or buy-token tools to create an account.`, accounts: [], }; } return { success: true, message: `Accounts in ${keysFolder}:`, accounts, }; } catch (error: any) { console.error("Error listing accounts:", error); console.error("Error stack:", error.stack); let errorMessage = "Unknown error"; if (error) { if (typeof error === "object") { if (error.message) { errorMessage = error.message; } else { try { errorMessage = JSON.stringify(error); } catch (e) { errorMessage = "Error object could not be stringified"; } } } else { errorMessage = String(error); } } return { success: false, error: errorMessage, accounts: [] }; } }
  • src/index.ts:245-273 (registration)
    MCP tool registration for 'list-accounts'. Defines empty input schema ({}), thin wrapper handler that calls listAccounts() and formatListAccountsResult(), wraps in MCP response.
    server.tool( "list-accounts", "List all accounts in the keys folder", {}, async () => { try { console.error("Listing accounts"); const result = await listAccounts(); const formattedResult = formatListAccountsResult(result); return createMcpResponse( formattedResult || "Error: No account information available" ); } catch (error: any) { console.error("Error listing accounts:", error); return { content: [ { type: "text" as const, text: `Error listing accounts: ${ error?.message || "Unknown error" }`, }, ], }; } } );
  • Helper function to format the listAccounts result into a human-readable string, handling success/error and empty list cases.
    export function formatListAccountsResult( result: ReturnType<typeof listAccounts> extends Promise<infer T> ? T : never ) { if (!result.success) { return `Error listing accounts: ${result.error}`; } if (result.accounts.length === 0) { return result.message; } const accountsText = result.accounts .map((account) => `${account.name}: ${account.publicKey}`) .join("\n"); return `${result.message}\n\n${accountsText}`; }

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/dexoryn/pumpfun-mcp-server'

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