# Bybit MCP Server

**Trade Bybit perpetual futures from any AI agent. No API keys to manage, no infrastructure to run.**

**0.014% maker fees on futures. Isolated sub-accounts. Works in 30 seconds.**

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Bybit](https://img.shields.io/badge/Exchange-Bybit-orange)](https://www.bybit.com)
[![MCP Protocol](https://img.shields.io/badge/Protocol-MCP-blue)](https://modelcontextprotocol.io)

**Powered by [Eterna MCP Gateway](https://github.com/eterna-exchange/eterna-mcp)**

---

## 30-Second Setup

```json
{
  "mcpServers": {
    "bybit-trading": {
      "type": "streamable-http",
      "url": "https://mcp.eterna.exchange/mcp"
    }
  }
}
```

Ask your AI to call `register_agent`. It gets an API key. Add the key to the config, restart, trade.

---

## Why Managed Over Self-Hosted?

| | Eterna (managed) | Self-hosted Bybit MCP | Direct Bybit API |
|---|---|---|---|
| **Setup** | 30 seconds | 15-30 min | 2-4 hours |
| **Bybit API keys** | Auto-provisioned | You create & rotate | You create & rotate |
| **Agent isolation** | Dedicated sub-account | Shared account | Shared account |
| **Risk management** | Built-in | None | Build your own |
| **Key security** | Argon2-hashed | Plaintext env vars | Plaintext env vars |
| **Futures fees** | 0.014% / 0.035% | 0.02% / 0.055% (default) | 0.02% / 0.055% (default) |
| **Spot fees** | 0.065% / 0.0775% | 0.1% / 0.1% (default) | 0.1% / 0.1% (default) |
| **Transport** | HTTP (works remotely) | stdio (local only) | HTTP |
| **Maintenance** | Zero | You manage updates | You manage |

For detailed comparisons with specific self-hosted alternatives, see [docs/vs-self-hosted.md](docs/vs-self-hosted.md).

---

## Works With Your Stack

No pre-existing API key needed. Your agent connects, registers itself, and starts trading.

### LangChain

```python
from langchain_mcp_adapters.client import MultiServerMCPClient

# 1. Connect without auth -- agent calls register_agent to get a key
async with MultiServerMCPClient({
    "trading": {
        "url": "https://mcp.eterna.exchange/mcp",
        "transport": "streamable_http",
    }
}) as client:
    tools = client.get_tools()  # includes register_agent

# 2. Reconnect with the key
async with MultiServerMCPClient({
    "trading": {
        "url": "https://mcp.eterna.exchange/mcp",
        "transport": "streamable_http",
        "headers": {"Authorization": f"Bearer {api_key}"},
    }
}) as client:
    tools = client.get_tools()  # all trading tools
```

### AutoGen

```python
from autogen_ext.tools.mcp import McpWorkbench, StreamableHttpParams

# 1. Register (no auth needed)
async with McpWorkbench(StreamableHttpParams(url=MCP_URL)) as wb:
    tools = await wb.list_tools()  # includes register_agent

# 2. Trade with the key
async with McpWorkbench(StreamableHttpParams(
    url=MCP_URL,
    headers={"Authorization": f"Bearer {api_key}"},
)) as wb:
    tools = await wb.list_tools()  # all trading tools
```

### CrewAI

```python
from crewai_tools.mcp import MCPServerAdapter

# After registration (see examples/ for full flow)
server = MCPServerAdapter(
    server_url="https://mcp.eterna.exchange/mcp",
    headers={"Authorization": f"Bearer {api_key}"},
)
tools = server.tools
```

Full working examples: [`examples/`](examples/)

---

## Available Tools

| Category | Tool | Description |
|---|---|---|
| **Registration** | `register_agent` | Register a new trading agent and receive an API key |
| **Market Data** | `get_tickers` | Current prices and 24h stats for Bybit linear perpetuals |
| | `get_instruments` | Contract specs: tick size, lot size, leverage limits |
| | `get_orderbook` | Live order book (bids and asks) up to 200 levels |
| **Account** | `get_balance` | USDT equity, available balance, and margin usage |
| | `get_positions` | Open positions with entry price, PnL, and leverage |
| | `get_orders` | Active and recent order history with fill info |
| **Trading** | `place_order` | Place market or limit orders with optional TP/SL and leverage |
| | `close_position` | Close an entire position at market price |
| **Funding** | `get_deposit_address` | Get deposit address for a coin and chain |
| | `get_deposit_records` | View deposit transaction history |
| | `transfer_to_trading` | Move funds from Funding wallet to Trading wallet |

---

## Examples

- [LangChain agent](examples/langchain_agent.py) -- Full ReAct agent with trading tools
- [AutoGen trader](examples/autogen_trader.py) -- AutoGen agent with risk management
- [CrewAI trading crew](examples/crewai_trading_crew.py) -- Multi-agent crew (analyst + risk manager)
- [Python (raw MCP SDK)](examples/python/bybit-trading-bot.py) -- Direct MCP client usage
- [Claude Code config](examples/claude-code/.mcp.json)
- [Cursor config](examples/cursor/.cursor/mcp.json)
- [Claude Code skill for Bybit](skills/claude-code/bybit-trading/SKILL.md)

---

## Coming Soon

- 130+ additional Bybit API endpoints (order management, position controls, kline data)
- Code execution sandbox -- submit TypeScript strategies for isolated execution
- Strategy runtime -- deploy strategies on cron, zero LLM at runtime
- Backtesting engine with historical data replay

See the full [roadmap](https://github.com/eterna-exchange/eterna-mcp/blob/main/ROADMAP.md).

---

## Ecosystem

| Repository | Description |
|---|---|
| [eterna-mcp](https://github.com/eterna-exchange/eterna-mcp) | Eterna MCP Gateway -- full documentation and protocol reference |
| [bybit-mcp-server](https://github.com/eterna-exchange/bybit-mcp-server) | This repository -- Bybit-focused entry point |
| [mcp-trading-agent](https://github.com/eterna-exchange/mcp-trading-agent) | IDE configs and trading strategies |
| [awesome-mcp-trading](https://github.com/eterna-exchange/awesome-mcp-trading) | Curated list of MCP trading resources |

---

## Contact

Questions, feedback, or partnership inquiries: **hello@eterna.exchange**

---

## License

MIT License. See [LICENSE](LICENSE) for details.
