get_portfolio_summary
Retrieve the authenticated user's MTG portfolio summary: current value, total invested, and for premium users, unrealized P&L and ROI.
Instructions
Get the authenticated user's portfolio summary - current value, total invested, unrealized P&L, ROI, card/unit counts. Free tier sees current value + total invested only; Premium gets the full P&L set. Requires IWMM_API_KEY.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/portfolio.ts:4-9 (handler)The handler function for get_portfolio_summary. It calls apiFetch with path '/api/v1/portfolio' and authenticated=true, returning the portfolio summary data from the IWMM API.
export const getPortfolioSummaryTool = { name: "get_portfolio_summary", description: "Get the authenticated user's portfolio summary - current value, total invested, unrealized P&L, ROI, card/unit counts. Free tier sees current value + total invested only; Premium gets the full P&L set. Requires IWMM_API_KEY.", inputSchema: z.object({}), handler: () => apiFetch({ path: "/api/v1/portfolio", authenticated: true }), - src/tools/portfolio.ts:8-8 (schema)The input schema for get_portfolio_summary — an empty Zod object (no parameters required).
inputSchema: z.object({}), - src/tools/index.ts:71-71 (registration)The tool is registered in the tools array and toolsByName lookup map (line 90-92), making it available to the MCP server.
getPortfolioSummaryTool, - src/api-client.ts:26-66 (handler)The apiFetch helper used by the handler. It constructs a URL, adds auth headers if authenticated, makes the HTTP request, and returns parsed JSON.
export async function apiFetch<T = unknown>(req: ApiRequest): Promise<T> { const url = new URL(req.path, config.baseUrl); if (req.query) { for (const [k, v] of Object.entries(req.query)) { if (v !== undefined && v !== null && v !== "") { url.searchParams.set(k, String(v)); } } } const headers: Record<string, string> = { Accept: "application/json", "User-Agent": "iwantmymtg-mcp/0.0.1", }; if (req.authenticated) { const { requireApiKey } = await import("./config.js"); headers["Authorization"] = `Bearer ${requireApiKey()}`; } if (req.body !== undefined) { headers["Content-Type"] = "application/json"; } const res = await fetch(url, { method: req.method ?? "GET", headers, body: req.body !== undefined ? JSON.stringify(req.body) : undefined, }); if (!res.ok) { const text = await res.text(); throw new ApiError(res.status, text, { limit: res.headers.get("X-RateLimit-Limit") ?? undefined, remaining: res.headers.get("X-RateLimit-Remaining") ?? undefined, reset: res.headers.get("X-RateLimit-Reset") ?? undefined, }); } if (res.status === 204) return undefined as T; return (await res.json()) as T;