fetch_etoro_portfolio
Retrieve a user's eToro portfolio by username using the eToro MCP Server, enabling access to portfolio data without CORS restrictions.
Instructions
Fetch an eToro user's portfolio using their username
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "fetch_etoro_portfolio"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- dist/index.js:52-52 (registration)Registration of the fetch_etoro_portfolio tool using server.tool with name, description, input schema, and inline handler function.
server.tool("fetch_etoro_portfolio", "Fetch an eToro user's portfolio using their username", { - dist/index.js:53-54 (schema)Input schema definition using Zod for the tool parameters: username (string) and optional authToken (string).
username: z.string().describe("The eToro username"), authToken: z.string().optional().describe("Optional: Authorization token for authenticated requests") - dist/index.js:55-134 (handler)The core handler function that implements the tool logic: converts eToro username to CID using an external API, generates a client request ID, fetches portfolio data from eToro's API with specific headers mimicking a browser, and returns formatted JSON response.
}, async (params) => { const { username, authToken = "" } = params; try { // First, convert username to CID const cidResponse = await fetch(`https://helpers.bullsheet.me/api/cid?username=${encodeURIComponent(username)}`, { method: 'GET', headers: { 'accept': '*/*', 'accept-language': 'en-US,en;q=0.9', 'cache-control': 'no-cache', 'pragma': 'no-cache', 'priority': 'u=1, i', 'referer': 'https://helpers.bullsheet.me/', 'sec-ch-ua': '"Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"Windows"', 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'same-origin', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36' } }); if (!cidResponse.ok) { throw new Error(`Failed to convert username to CID: ${cidResponse.statusText}`); } const cidData = await cidResponse.json(); const cid = cidData.cid; if (!cid) { throw new Error(`Failed to retrieve CID for username: ${username}`); } // Generate a client request ID (UUID-like format) const clientRequestId = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { const r = Math.random() * 16 | 0; const v = c === 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); // Now fetch the portfolio using the retrieved CID const response = await fetch(`https://www.etoro.com/sapi/trade-data-real/live/public/portfolios?cid=${cid}&client_request_id=${clientRequestId}`, { method: 'GET', headers: { 'accept': 'application/json, text/plain, */*', 'accept-language': 'en-US,en;q=0.9', 'accounttype': 'Real', 'applicationidentifier': 'ReToro', 'applicationversion': 'v651.621.3', 'cache-control': 'no-cache', 'pragma': 'no-cache', 'priority': 'u=1, i', 'sec-ch-ua': '"Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"Windows"', 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'same-origin', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36', ...(authToken ? { 'authorization': authToken } : {}) } }); if (!response.ok) { throw new Error(`Failed to fetch portfolio data: ${response.statusText}`); } const portfolioData = await response.json(); return { content: [{ type: "text", text: JSON.stringify({ username, cid, portfolio: portfolioData }, null, 2) }], }; } catch (error) { if (error instanceof Error) { throw new Error(`Failed to fetch portfolio data: ${error.message}`); } throw error; } });