get_all_crypto
Retrieve all cryptocurrency assets from your LunchMoney account to view your complete crypto portfolio holdings and track digital asset investments.
Instructions
Get a list of all cryptocurrency assets associated with the user
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/crypto.ts:11-42 (handler)The handler function that fetches the user's cryptocurrency assets from the LunchMoney API endpoint `/crypto`, handles errors, and returns the assets as a JSON string in the MCP response format.async () => { const { baseUrl, lunchmoneyApiToken } = getConfig(); const response = await fetch(`${baseUrl}/crypto`, { headers: { Authorization: `Bearer ${lunchmoneyApiToken}`, }, }); if (!response.ok) { return { content: [ { type: "text", text: `Failed to get crypto assets: ${response.statusText}`, }, ], }; } const data = await response.json(); const cryptoAssets: Crypto[] = data.crypto; return { content: [ { type: "text", text: JSON.stringify(cryptoAssets), }, ], }; }
- src/tools/crypto.ts:8-43 (registration)Registers the 'get_all_crypto' tool on the MCP server with its description, empty input schema, and inline handler function."get_all_crypto", "Get a list of all cryptocurrency assets associated with the user", {}, async () => { const { baseUrl, lunchmoneyApiToken } = getConfig(); const response = await fetch(`${baseUrl}/crypto`, { headers: { Authorization: `Bearer ${lunchmoneyApiToken}`, }, }); if (!response.ok) { return { content: [ { type: "text", text: `Failed to get crypto assets: ${response.statusText}`, }, ], }; } const data = await response.json(); const cryptoAssets: Crypto[] = data.crypto; return { content: [ { type: "text", text: JSON.stringify(cryptoAssets), }, ], }; } );
- src/index.ts:31-31 (registration)Invokes the registration of crypto tools, including 'get_all_crypto', on the main MCP server instance.registerCryptoTools(server);
- src/tools/crypto.ts:6-100 (helper)Helper function that registers both crypto-related tools on the MCP server.export function registerCryptoTools(server: McpServer) { server.tool( "get_all_crypto", "Get a list of all cryptocurrency assets associated with the user", {}, async () => { const { baseUrl, lunchmoneyApiToken } = getConfig(); const response = await fetch(`${baseUrl}/crypto`, { headers: { Authorization: `Bearer ${lunchmoneyApiToken}`, }, }); if (!response.ok) { return { content: [ { type: "text", text: `Failed to get crypto assets: ${response.statusText}`, }, ], }; } const data = await response.json(); const cryptoAssets: Crypto[] = data.crypto; return { content: [ { type: "text", text: JSON.stringify(cryptoAssets), }, ], }; } ); server.tool( "update_manual_crypto", "Update a manually-managed cryptocurrency asset balance", { input: z.object({ crypto_id: z .number() .describe("ID of the crypto asset to update"), balance: z .number() .optional() .describe("Updated balance of the crypto asset"), }), }, async ({ input }) => { const { baseUrl, lunchmoneyApiToken } = getConfig(); const body: any = {}; if (input.balance !== undefined) { body.balance = input.balance.toString(); } const response = await fetch(`${baseUrl}/crypto/manual/${input.crypto_id}`, { method: "PUT", headers: { Authorization: `Bearer ${lunchmoneyApiToken}`, "Content-Type": "application/json", }, body: JSON.stringify(body), }); if (!response.ok) { return { content: [ { type: "text", text: `Failed to update crypto asset: ${response.statusText}`, }, ], }; } const result = await response.json(); return { content: [ { type: "text", text: JSON.stringify(result), }, ], }; } ); }