list-accounts
Retrieve and display all accounts stored in the keys folder for managing token transactions on the Pump.fun platform via the MCP server.
Instructions
List all accounts in the keys folder
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/list-accounts.ts:10-101 (handler)Core handler function that scans the .keys directory for .json keypair files (excluding mint- files), loads them, extracts public keys using Solana Keypair, and returns a list of accounts with names and public keys, or handles folder creation/errors.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' with no input parameters (empty schema), thin wrapper handler calling listAccounts() and formatListAccountsResult(), returning MCP-formatted 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" }`, }, ], }; } } );
- src/list-accounts.ts:103-119 (helper)Formats the listAccounts result into a human-readable string, listing account names and public keys or error/no accounts messages.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}`; }
- src/index.ts:248-248 (schema)Input schema for the list-accounts tool: empty object, no parameters required.{},