fidelity_transfer
Transfer cash between two Fidelity accounts after validating the source account balance to prevent failed transactions.
Instructions
Transfer cash between two Fidelity accounts. Validates available balance before submitting.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from_account | Yes | Source account number. | |
| to_account | Yes | Destination account number. | |
| amount | Yes | Dollar amount to transfer. |
Implementation Reference
- src/index.ts:357-396 (registration)Registration of the fidelity_transfer MCP tool with Zod schema validation for from_account, to_account, and amount. Imports and delegates to the transfer() function from ./accounts.js.
server.tool( "fidelity_transfer", "Transfer cash between two Fidelity accounts. Validates available balance before submitting.", { from_account: z .string() .describe("Source account number."), to_account: z .string() .describe("Destination account number."), amount: z .number() .positive() .describe("Dollar amount to transfer."), }, async ({ from_account, to_account, amount }) => { try { const result = await transfer(from_account, to_account, amount); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], isError: !result.success, }; } catch (e) { return { content: [ { type: "text", text: `Transfer failed: ${e instanceof Error ? e.message : String(e)}`, }, ], isError: true, }; } } ); - src/accounts.ts:82-182 (handler)Core handler for fidelity_transfer. Navigates to Fidelity transfer page, selects from/to accounts, validates balance, fills amount, submits and confirms the transfer.
export async function transfer( fromAccount: string, toAccount: string, amount: number ): Promise<{ success: boolean; message: string }> { const page = await getPage(); await page.goto(TRANSFERS_URL, { waitUntil: "domcontentloaded" }); await waitForLoadingComplete(page); // Select "From" account const fromDropdown = page.getByLabel("From"); await fromDropdown.waitFor({ state: "visible", timeout: 15000 }); const fromOptions = await fromDropdown.locator("option").all(); let fromFound = false; for (const option of fromOptions) { const text = (await option.textContent()) ?? ""; if (text.includes(fromAccount)) { await fromDropdown.selectOption({ label: text.trim() }); fromFound = true; break; } } if (!fromFound) { return { success: false, message: `Source account ${fromAccount} not found.`, }; } await page.waitForTimeout(500); await waitForLoadingComplete(page); // Check available balance try { const balanceCell = page.locator( "tr.pvd-table__row:nth-child(2) > td:nth-child(2)" ); const balanceText = await balanceCell.textContent({ timeout: 5000 }); if (balanceText) { const available = parseFloat(balanceText.replace(/[$,]/g, "")); if (amount > available) { return { success: false, message: `Insufficient funds. Available: $${available.toFixed(2)}, Requested: $${amount.toFixed(2)}`, }; } } } catch { // Continue anyway } // Select "To" account const toDropdown = page.getByLabel("To", { exact: true }); const toOptions = await toDropdown.locator("option").all(); let toFound = false; for (const option of toOptions) { const text = (await option.textContent()) ?? ""; if (text.includes(toAccount)) { await toDropdown.selectOption({ label: text.trim() }); toFound = true; break; } } if (!toFound) { return { success: false, message: `Destination account ${toAccount} not found.`, }; } await page.waitForTimeout(500); // Fill amount const amountInput = page.locator("#transfer-amount"); await amountInput.fill(amount.toFixed(2)); // Submit await page.getByRole("button", { name: "Continue" }).click(); await waitForLoadingComplete(page); // Confirm try { await page.getByRole("button", { name: "Submit" }).click(); await waitForLoadingComplete(page); const successText = page.getByText("Request submitted"); await successText.waitFor({ state: "visible", timeout: 15000 }); return { success: true, message: `Successfully transferred $${amount.toFixed(2)} from ${fromAccount} to ${toAccount}.`, }; } catch (e) { return { success: false, message: `Transfer failed: ${e instanceof Error ? e.message : String(e)}`, }; } } - src/types.ts:60-69 (helper)Type definitions TransferRequest and TransferResult used by the transfer functionality.
export interface TransferRequest { fromAccount: string; toAccount: string; amount: number; } export interface TransferResult { success: boolean; message: string; }