Spaces:
Running
Running
Download index.html from copytop/smolagents-mcp-tutorial: direct link, hf CLI and curl.
- Browser
- Download file 6.75 kB
-
https://huggingface.co/spaces/copytop/smolagents-mcp-tutorial/resolve/main/index.html
- Command line
-
hf download hf://spaces/copytop/smolagents-mcp-tutorial/index.html
-
curl -L -o index.html https://huggingface.co/spaces/copytop/smolagents-mcp-tutorial/resolve/main/index.html
6.75 kB
| <html lang="en"><head><meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <title>Plug a remote MCP server into smolagents: crypto trader data in a CodeAgent</title> | |
| <meta name="description" content="Load every tool of a remote MCP server into smolagents in one line, call them directly, then hand them to a CodeAgent. Tested code, version trap included."> | |
| <style> | |
| body { margin: 0; background: #0d1117; color: #e6edf3; font: 17px/1.65 -apple-system, "Segoe UI", Roboto, sans-serif; } | |
| main { max-width: 760px; margin: 0 auto; padding: 40px 22px 80px; } | |
| h1 { font-size: 32px; line-height: 1.25; } h2 { margin-top: 36px; color: #9ecbff; } | |
| a { color: #79b8ff; } code { background: #161b22; padding: 2px 5px; border-radius: 4px; font-size: 15px; } | |
| pre { background: #161b22; padding: 14px 18px; border-radius: 8px; overflow-x: auto; } pre code { padding: 0; } | |
| .dl { margin-top: 40px; color: #8b949e; font-size: 15px; } | |
| </style></head><body><main> | |
| <h1>Plug a remote MCP server into smolagents: crypto trader data in a CodeAgent</h1> | |
| <p>smolagents can load every tool of a remote MCP server in one line. This post wires it to a free, read-only server that tracks what top traders buy and sell on pump.fun, fomo and Hyperliquid, then shows the two traps I hit on the way: a version clash in the <code>mcp</code> package, and a leaderboard where the biggest winners are not the ones you want to follow.</p> | |
| <p>I'm the founder of copy.top, the service behind the server, so take the choice of example with that in mind. The code below was run against the live server on 2026-11-25.</p> | |
| <h2>The server</h2> | |
| <ul> | |
| <li>URL: <code>https://copy.top/mcp</code> (streamable HTTP)</li> | |
| <li>No key, no account, 20 calls a minute</li> | |
| <li>16 tools: leaderboards, a trader's profile, live trades, coins tracked traders are buying, alerts, Hyperliquid perps</li> | |
| </ul> | |
| <p>Setup for Claude, Cursor, VS Code and the rest: <a href="https://copy.top/agents">https://copy.top/agents</a></p> | |
| <h2>Install, and the version trap</h2> | |
| <pre><code class="language-bash">pip install "smolagents[mcp]" "mcp<2" websockets | |
| </code></pre> | |
| <p>With a fresh <code>pip install "smolagents[mcp]"</code> I got <code>mcp</code> 2.3.0, and the first connection failed with <code>ImportError: cannot import name 'streamablehttp_client'</code>. The adapter smolagents uses (<code>mcpadapt</code> 0.1.20) still imports the 1.x name. Pinning <code>mcp<2</code> fixed it, and the adapter then also wanted <code>websockets</code>. Tested with Python 3.14, smolagents 1.26.0, mcp 1.30.0. If a newer mcpadapt is out when you read this, try without the pin first.</p> | |
| <h2>Load the tools and call them directly</h2> | |
| <p><code>MCPClient</code> is a context manager. Inside it you get a list of ordinary smolagents tools, and each one can be called like a function, with no model involved.</p> | |
| <pre><code class="language-python">import json | |
| from smolagents import MCPClient | |
| SERVER = {"url": "https://copy.top/mcp", "transport": "streamable-http"} | |
| def as_data(result): | |
| # tools return text; this server puts JSON inside it | |
| try: | |
| return json.loads(result) | |
| except (TypeError, ValueError): | |
| return result | |
| with MCPClient(SERVER, structured_output=False) as tools: | |
| by_name = {t.name: t for t in tools} | |
| print(len(by_name), "tools") | |
| board = as_data(by_name["get_leaderboard"](platform="pumpfun", limit=5)) | |
| for row in board["traders"]: | |
| print(row["handle"], row["pnl"], row["fairPlay"]) | |
| hot = as_data(by_name["get_hot_coins"](limit=5)) | |
| for c in hot["coins"]: | |
| mcap = c.get("mcap") | |
| print(c["symbol"], c["chain"], c["traders"], | |
| f"${mcap:,.0f}" if isinstance(mcap, (int, float)) else "n/a") | |
| </code></pre> | |
| <p>What it printed for me (trimmed):</p> | |
| <pre><code class="language-text">16 tools | |
| pf_5ae8d0344ba0 1261819 flagged | |
| pf_c311d04abf73 737798 flagged | |
| pf_93ec43d90703 270206 flagged | |
| pf_2ccf3a09cd0e 254988 flagged | |
| gtsb 244849 watch | |
| </code></pre> | |
| <p>Two details are worth handling in your own code:</p> | |
| <ol> | |
| <li><code>mcap</code> can be <code>null</code> for a coin that just launched, so format it only when it is a number.</li> | |
| <li>Look at the <code>fairPlay</code> column before anything else.</li> | |
| </ol> | |
| <h2>The leaderboard trap</h2> | |
| <p>The top four pump.fun accounts by realized pnl were all <code>flagged</code> that day. Fair play is a verdict built from a trader's own trades: <code>clean</code>, <code>watch</code> (many positions sold within 10 minutes, or selling into the people copying them) or <code>flagged</code>. A ranking by profit alone rewards exactly the behaviour you don't want to copy. So the first thing an agent should learn is to drop flagged rows, and to treat <code>watch</code> with care.</p> | |
| <h2>Give the same tools to a CodeAgent</h2> | |
| <pre><code class="language-python">from smolagents import CodeAgent, InferenceClientModel | |
| with MCPClient(SERVER, structured_output=False) as tools: | |
| agent = CodeAgent(tools=list(tools), model=InferenceClientModel()) | |
| agent.run( | |
| "Which coins did at least 3 tracked traders buy recently, under $5m market cap? " | |
| "Skip traders whose fair play is flagged. Answer in 5 lines." | |
| ) | |
| </code></pre> | |
| <p><code>InferenceClientModel</code> reads your <code>HF_TOKEN</code>; any smolagents model class works. To be clear about what I tested: the direct tool calls above were run against the live server, the agent step depends on the model you plug in and I'm not showing its output.</p> | |
| <p>Prompts that use the tools well:</p> | |
| <ul> | |
| <li>"Who are the 5 best pump.fun traders this week, and which of them are clean on fair play?"</li> | |
| <li>"Show the live trades of these three handles since my last check" (the agent should pass a <code>since</code> cursor to <code>get_live_trades</code>)</li> | |
| <li>"Every minute, check <code>get_alerts</code> for new confluence events and keep the cursor"</li> | |
| </ul> | |
| <h2>Before you rely on it</h2> | |
| <p>The data says what traders did, not what they will do. Memecoins are very risky and most traders lose money; following a strong trader does not remove that risk. Nothing here is financial advice.</p> | |
| <p>Full script, plus setup for other clients: <a href="https://copy.top/agents">https://copy.top/agents</a> · MCP endpoint: <a href="https://copy.top/mcp">https://copy.top/mcp</a></p> | |
| <p class="dl">Script used for this post: <a href="smol_copytop.py">smol_copytop.py</a>.</p> | |
| </main></body></html> | |