Spaces:
Running
Running
smolagents + copy.top MCP tutorial
Browse files- README.md +12 -6
- index.html +91 -18
- smol_copytop.py +53 -0
README.md
CHANGED
|
@@ -1,10 +1,16 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
colorTo: green
|
| 6 |
sdk: static
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
| 1 |
---
|
| 2 |
+
title: smolagents + a remote MCP server
|
| 3 |
+
colorFrom: blue
|
| 4 |
+
colorTo: gray
|
|
|
|
| 5 |
sdk: static
|
| 6 |
+
app_file: index.html
|
| 7 |
+
short_description: Tested tutorial, smolagents MCPClient on copy.top/mcp
|
| 8 |
+
tags:
|
| 9 |
+
- smolagents
|
| 10 |
+
- mcp
|
| 11 |
+
- agents
|
| 12 |
+
- tutorial
|
| 13 |
+
- crypto
|
| 14 |
---
|
| 15 |
|
| 16 |
+
Tutorial: load the tools of the remote MCP server https://copy.top/mcp into smolagents, call them directly, then give them to a CodeAgent. Code in `smol_copytop.py`, tested on 2026-11-25. Setup for other clients: https://copy.top/agents
|
index.html
CHANGED
|
@@ -1,19 +1,92 @@
|
|
| 1 |
<!doctype html>
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
</
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
<!doctype html>
|
| 2 |
+
<html lang="en"><head><meta charset="utf-8">
|
| 3 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 4 |
+
<title>Plug a remote MCP server into smolagents: crypto trader data in a CodeAgent</title>
|
| 5 |
+
<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.">
|
| 6 |
+
<style>
|
| 7 |
+
body { margin: 0; background: #0d1117; color: #e6edf3; font: 17px/1.65 -apple-system, "Segoe UI", Roboto, sans-serif; }
|
| 8 |
+
main { max-width: 760px; margin: 0 auto; padding: 40px 22px 80px; }
|
| 9 |
+
h1 { font-size: 32px; line-height: 1.25; } h2 { margin-top: 36px; color: #9ecbff; }
|
| 10 |
+
a { color: #79b8ff; } code { background: #161b22; padding: 2px 5px; border-radius: 4px; font-size: 15px; }
|
| 11 |
+
pre { background: #161b22; padding: 14px 18px; border-radius: 8px; overflow-x: auto; } pre code { padding: 0; }
|
| 12 |
+
.dl { margin-top: 40px; color: #8b949e; font-size: 15px; }
|
| 13 |
+
</style></head><body><main>
|
| 14 |
+
<h1>Plug a remote MCP server into smolagents: crypto trader data in a CodeAgent</h1>
|
| 15 |
+
<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>
|
| 16 |
+
<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>
|
| 17 |
+
<h2>The server</h2>
|
| 18 |
+
<ul>
|
| 19 |
+
<li>URL: <code>https://copy.top/mcp</code> (streamable HTTP)</li>
|
| 20 |
+
<li>No key, no account, 20 calls a minute</li>
|
| 21 |
+
<li>16 tools: leaderboards, a trader's profile, live trades, coins tracked traders are buying, alerts, Hyperliquid perps</li>
|
| 22 |
+
</ul>
|
| 23 |
+
<p>Setup for Claude, Cursor, VS Code and the rest: <a href="https://copy.top/agents">https://copy.top/agents</a></p>
|
| 24 |
+
<h2>Install, and the version trap</h2>
|
| 25 |
+
<pre><code class="language-bash">pip install "smolagents[mcp]" "mcp<2" websockets
|
| 26 |
+
</code></pre>
|
| 27 |
+
<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>
|
| 28 |
+
<h2>Load the tools and call them directly</h2>
|
| 29 |
+
<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>
|
| 30 |
+
<pre><code class="language-python">import json
|
| 31 |
+
from smolagents import MCPClient
|
| 32 |
+
|
| 33 |
+
SERVER = {"url": "https://copy.top/mcp", "transport": "streamable-http"}
|
| 34 |
+
|
| 35 |
+
def as_data(result):
|
| 36 |
+
# tools return text; this server puts JSON inside it
|
| 37 |
+
try:
|
| 38 |
+
return json.loads(result)
|
| 39 |
+
except (TypeError, ValueError):
|
| 40 |
+
return result
|
| 41 |
+
|
| 42 |
+
with MCPClient(SERVER, structured_output=False) as tools:
|
| 43 |
+
by_name = {t.name: t for t in tools}
|
| 44 |
+
print(len(by_name), "tools")
|
| 45 |
+
|
| 46 |
+
board = as_data(by_name["get_leaderboard"](platform="pumpfun", limit=5))
|
| 47 |
+
for row in board["traders"]:
|
| 48 |
+
print(row["handle"], row["pnl"], row["fairPlay"])
|
| 49 |
+
|
| 50 |
+
hot = as_data(by_name["get_hot_coins"](limit=5))
|
| 51 |
+
for c in hot["coins"]:
|
| 52 |
+
mcap = c.get("mcap")
|
| 53 |
+
print(c["symbol"], c["chain"], c["traders"],
|
| 54 |
+
f"${mcap:,.0f}" if isinstance(mcap, (int, float)) else "n/a")
|
| 55 |
+
</code></pre>
|
| 56 |
+
<p>What it printed for me (trimmed):</p>
|
| 57 |
+
<pre><code class="language-text">16 tools
|
| 58 |
+
pf_5ae8d0344ba0 1261819 flagged
|
| 59 |
+
pf_c311d04abf73 737798 flagged
|
| 60 |
+
pf_93ec43d90703 270206 flagged
|
| 61 |
+
pf_2ccf3a09cd0e 254988 flagged
|
| 62 |
+
gtsb 244849 watch
|
| 63 |
+
</code></pre>
|
| 64 |
+
<p>Two details are worth handling in your own code:</p>
|
| 65 |
+
<ol>
|
| 66 |
+
<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>
|
| 67 |
+
<li>Look at the <code>fairPlay</code> column before anything else.</li>
|
| 68 |
+
</ol>
|
| 69 |
+
<h2>The leaderboard trap</h2>
|
| 70 |
+
<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>
|
| 71 |
+
<h2>Give the same tools to a CodeAgent</h2>
|
| 72 |
+
<pre><code class="language-python">from smolagents import CodeAgent, InferenceClientModel
|
| 73 |
+
|
| 74 |
+
with MCPClient(SERVER, structured_output=False) as tools:
|
| 75 |
+
agent = CodeAgent(tools=list(tools), model=InferenceClientModel())
|
| 76 |
+
agent.run(
|
| 77 |
+
"Which coins did at least 3 tracked traders buy recently, under $5m market cap? "
|
| 78 |
+
"Skip traders whose fair play is flagged. Answer in 5 lines."
|
| 79 |
+
)
|
| 80 |
+
</code></pre>
|
| 81 |
+
<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>
|
| 82 |
+
<p>Prompts that use the tools well:</p>
|
| 83 |
+
<ul>
|
| 84 |
+
<li>"Who are the 5 best pump.fun traders this week, and which of them are clean on fair play?"</li>
|
| 85 |
+
<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>
|
| 86 |
+
<li>"Every minute, check <code>get_alerts</code> for new confluence events and keep the cursor"</li>
|
| 87 |
+
</ul>
|
| 88 |
+
<h2>Before you rely on it</h2>
|
| 89 |
+
<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>
|
| 90 |
+
<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>
|
| 91 |
+
<p class="dl">Script used for this post: <a href="smol_copytop.py">smol_copytop.py</a>.</p>
|
| 92 |
+
</main></body></html>
|
smol_copytop.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Load the copy.top MCP tools into smolagents and call them.
|
| 2 |
+
|
| 3 |
+
pip install "smolagents[mcp]"
|
| 4 |
+
python smol_copytop.py # direct tool calls, no model needed
|
| 5 |
+
python smol_copytop.py --agent # same tools behind a CodeAgent (needs HF_TOKEN)
|
| 6 |
+
"""
|
| 7 |
+
import json
|
| 8 |
+
import sys
|
| 9 |
+
|
| 10 |
+
from smolagents import MCPClient
|
| 11 |
+
|
| 12 |
+
SERVER = {"url": "https://copy.top/mcp", "transport": "streamable-http"}
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def as_data(result):
|
| 16 |
+
# tools return text; copy.top sends JSON inside it
|
| 17 |
+
if isinstance(result, str):
|
| 18 |
+
try:
|
| 19 |
+
return json.loads(result)
|
| 20 |
+
except ValueError:
|
| 21 |
+
return result
|
| 22 |
+
return result
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def main():
|
| 26 |
+
with MCPClient(SERVER, structured_output=False) as tools:
|
| 27 |
+
by_name = {t.name: t for t in tools}
|
| 28 |
+
print(len(by_name), "tools:", ", ".join(sorted(by_name)))
|
| 29 |
+
|
| 30 |
+
board = as_data(by_name["get_leaderboard"](platform="pumpfun", limit=5))
|
| 31 |
+
print("\ntop pump.fun traders (realized pnl)")
|
| 32 |
+
for row in board.get("traders", []):
|
| 33 |
+
print(f" {row.get('handle', '?'):<24} pnl {row.get('pnl')} fair play {row.get('fairPlay')}")
|
| 34 |
+
|
| 35 |
+
hot = as_data(by_name["get_hot_coins"](limit=5))
|
| 36 |
+
print("\ncoins tracked traders are buying")
|
| 37 |
+
for c in hot.get("coins", []):
|
| 38 |
+
mcap = c.get("mcap")
|
| 39 |
+
mcap = f"${mcap:,.0f}" if isinstance(mcap, (int, float)) else "n/a"
|
| 40 |
+
print(f" {c.get('symbol', '?'):<12} {c.get('chain', '?'):<8} traders {c.get('traders')} mcap {mcap}")
|
| 41 |
+
|
| 42 |
+
if "--agent" in sys.argv:
|
| 43 |
+
from smolagents import CodeAgent, InferenceClientModel
|
| 44 |
+
|
| 45 |
+
agent = CodeAgent(tools=list(tools), model=InferenceClientModel())
|
| 46 |
+
print(agent.run(
|
| 47 |
+
"Which coins did at least 3 tracked traders buy recently, under $5m market cap? "
|
| 48 |
+
"Skip traders whose fair play is flagged. Answer in 5 lines."
|
| 49 |
+
))
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
if __name__ == "__main__":
|
| 53 |
+
main()
|