Build a Pear Protocol DeFi trading agent with MCP A developer built a DeFi trading agent for Pear Protocol using the Model Context Protocol (MCP). The agent, powered by the open-source mcp-pear server, can browse pair markets, read positions and portfolio, and execute leveraged pair trades on Hyperliquid. The MCP server wraps Pear Protocol's API, allowing the agent to call tools like open_position and close_position via a uniform interface. If you want an AI agent that can actually trade , not just chat about charts, the Model Context Protocol MCP is the cleanest way to wire a model to a real exchange. This post builds a Pear Protocol DeFi trading agent: one that can browse pair markets, read your positions and portfolio, and when you turn it on open and close leveraged pair trades on Hyperliquid . We'll use mcp-pear https://github.com/MarvelNwachukwu/mcp-pear , an open-source MCP server that wraps Pear Protocol's API. Pear Protocol https://pearprotocol.io is a Hyperliquid-backed platform for pair trading . You go long one basket and short another in a single position, and profit from the ratio between them moving your way, regardless of overall market direction. Classic example: long ETH, short BTC if you think ETH outperforms, without betting on crypto as a whole. Pear settles on Hyperliquid, so every pair position is really a pair of perp legs executed on-chain. The Model Context Protocol is an open standard that lets an LLM call external tools through one uniform interface. Instead of gluing Pear's REST API to your model by hand, you run an MCP server that describes its tools to the model, and any MCP client Claude Desktop, Cursor, Cline, or your own agent can use them. mcp-pear exposes Pear as a set of MCP tools: list markets , get active markets , get pair ratio , get health get open positions , get open orders , get portfolio , get trade history , get account summary open position , close position , adjust position , adjust leverage , set risk parameters , cancel order No install needed. npx fetches it: npx -y @marvelcodes/mcp-pear@latest The public tools work with zero config, so your agent can browse markets and pair ratios right away. Add this to your Claude Desktop MCP config: { "mcpServers": { "pear": { "command": "npx", "args": "-y", "@marvelcodes/mcp-pear@latest" } } } Restart Claude and ask: "What are the top gaining pair markets on Pear right now?" It calls get active markets and answers from live data. To read your positions and portfolio, mint a Pear API key: npx -y @marvelcodes/mcp-pear@latest setup This opens a browser, asks you to sign once with your wallet, and writes PEAR API KEY + PEAR ADDRESS . Add them to the config: { "mcpServers": { "pear": { "command": "npx", "args": "-y", "@marvelcodes/mcp-pear@latest" , "env": { "PEAR API KEY": "your key", "PEAR ADDRESS": "0xyour address" } } } } Now "How's my portfolio doing this week?" works. It calls get portfolio with your real PnL. Trade execution is off by default . You opt in on purpose: "env": { "PEAR API KEY": "your key", "PEAR ADDRESS": "0xyour address", "PEAR TRADE ENABLED": "true" } With that flag set, the agent can call open position . A pair trade looks like this: long ETH, short BTC, 3x, $100 notional. { "executionType": "MARKET", "leverage": 3, "usdValue": 100, "slippage": 0.01, "longAssets": { "asset": "ETH", "weight": 1 } , "shortAssets": { "asset": "BTC", "weight": 1 } } open position also takes TRIGGER , TWAP , and LADDER execution types, plus attached stopLoss / takeProfit . Pear signs the trade server-side, so the MCP server never holds your private keys . Two Hyperliquid gotchas worth knowing: open position fails with insufficient margin.Here's the shape of an agent loop that uses it: get active markets to find pairs with strong momentum get pair ratio to check the current ratio and funding open position with a stop-loss attached get open positions , then close position when the thesis plays outEverything is a tool call, so the model reasons over live data and acts. No custom API glue. PEAR TRADE ENABLED off until you've tested read-only behaviour. mcp-pear is an independent, open-source community project, not affiliated with Pear Protocol. PRs and issues welcome.