Skip to content

JohnnyWic/bybit-mcp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🟑 Bybit MCP Server

License: MIT Python 3.13+ MCP Tools Bybit V5 API

The most comprehensive MCP server for Bybit β€” 246 tools covering the entire Bybit V5 API

Quick Start β€’ Features β€’ Configuration β€’ Tools Reference β€’ Troubleshooting β€’ Contributing


🎯 Overview

Bybit MCP Server enables AI assistants like Claude, Cursor, ChatGPT, and other MCP-compatible clients to interact directly with the Bybit cryptocurrency exchange. Execute trades, manage portfolios, analyze markets, and automate strategies β€” all through natural language.

Why Bybit MCP?

  • πŸ”₯ Complete Coverage β€” 246 tools spanning every Bybit V5 API endpoint
  • πŸ” Secure by Design β€” API credentials never leave your machine
  • πŸ‘οΈ Read-Only Mode β€” Use all market tools without any API key
  • πŸ“‘ Triple Transport β€” STDIO, SSE, and Streamable HTTP
  • πŸ”Œ Universal Compatibility β€” Works with Claude Desktop, Cursor, ChatGPT, and any MCP client
  • ⚑ Zero Config Start β€” Just uv run bybit.py and go

✨ Features

πŸ“ˆ Trading & Markets

  • Spot Trading β€” Market & limit orders, batch operations
  • Derivatives β€” Linear & inverse perpetuals
  • Order Management β€” Amend, cancel, batch, DCP
  • Market Data β€” Klines, orderbook, tickers, funding rates
  • Open Interest β€” Long/short ratio, ADL alerts

πŸ’° Earn & Lending

  • Simple Earn β€” Stake, redeem, yield tracking
  • Crypto Loans β€” Old & new (fixed + flexible)
  • Leveraged Tokens β€” Subscribe & redeem
  • Spot Margin β€” Cross-margin trading
  • OTC Lending β€” Institutional loan management

🏦 Account & Assets

  • Wallet β€” Deposits, withdrawals, transfers
  • Multi-Account β€” Sub-accounts, universal transfers
  • Asset Convert β€” Crypto-to-crypto, small balance, fiat
  • Margin Modes β€” Cross, isolated, portfolio margin
  • Risk Management β€” MMP, leverage, TP/SL

πŸ› οΈ Advanced

  • Spread Trading β€” Spread instruments & orders
  • Block Trading (RFQ) β€” Request for quote workflow
  • Broker β€” Earnings, rate limits, vouchers
  • Strategy β€” Built-in arbitrage detection
  • Announcements β€” Exchange news & system status

πŸš€ Quick Start

Method 1: Ask AI to Install (Recommended)

Simply tell your AI assistant:

"Help me install the Bybit MCP server from https://github.com/JohnnyWic/bybit-mcp"

Your AI will clone the repo, install dependencies, and configure everything automatically. Works with Claude Code, Cursor, and other MCP-compatible clients.

Method 2: Manual Setup

1. Install

git clone https://github.com/JohnnyWic/bybit-mcp.git
cd bybit-mcp
uv sync

Requires Python β‰₯ 3.13 and uv.

2. Add to Your MCP Client

Add the following to your MCP config file:

Client Config File
Claude Desktop claude_desktop_config.json
Cursor ~/.cursor/mcp.json
Claude Code Run claude mcp add (see below)

JSON config (Claude Desktop / Cursor):

{
  "mcpServers": {
    "bybit-mcp": {
      "command": "uv",
      "args": ["--directory", "/path/to/bybit-mcp", "run", "bybit.py"]
    }
  }
}

Claude Code CLI:

claude mcp add bybit-mcp -- uv --directory /path/to/bybit-mcp run bybit.py

3. Configure API Key (Optional)

Create a .env file in the project root:

cp .env.example .env
BYBIT_API_KEY=your_api_key_here
BYBIT_SECRET_KEY=your_secret_key_here
BYBIT_TESTNET=false

Or pass credentials inline in the MCP config:

{
  "mcpServers": {
    "bybit-mcp": {
      "command": "uv",
      "args": [
        "--directory", "/path/to/bybit-mcp", "run", "bybit.py",
        "--bybit-api-key", "YOUR_API_KEY",
        "--bybit-secret-key", "YOUR_SECRET_KEY"
      ]
    }
  }
}

πŸ’‘ No API key? No problem! All 23 market data tools work without authentication.

πŸ”’ Security Note: Never commit your .env file. It's already in .gitignore.

Transport Modes

uv run bybit.py                                        # STDIO (default)
uv run bybit.py --transport sse --port 8000             # SSE
uv run bybit.py --transport streamable-http --port 8000 # Streamable HTTP

πŸ’¬ Usage Examples

Check Market Price

"What's the current price of BTC?"

Place a Trade

"Buy 0.01 BTC at market price on spot"

Analyze Funding Rates

"Show me the funding rate history for ETHUSDT over the last 24 hours"

Manage Positions

"What are my open positions? Set a stop loss at 95000 for my BTCUSDT long"

Portfolio Overview

"Show my unified account balance and all open orders"

πŸ“Š Available Tools (246)

Module Tools Description
Market 23 Prices, klines, orderbook, funding rates, open interest, tickers (no API key needed)
Trade 15 Market/limit orders, amend, cancel, batch operations, DCP
Account 25 Balance, fee rates, margin mode, collateral, MMP, transaction log
Position 11 Positions, leverage, TP/SL, auto-margin, move positions
Asset 41 Deposits, withdrawals, transfers, convert, fiat, address management
Lending 39 Crypto loans β€” legacy + new (fixed & flexible)
User 15 Sub-accounts, API key management, affiliate
RFQ 15 Block trading β€” create/cancel RFQ, quotes, executions
Spot Margin 12 Spot margin trading, borrow, repay, collateral
Spread 11 Spread instruments, orderbook, trading
Broker 10 Broker earnings, rate limits, vouchers
OTC 7 Institutional OTC lending
Pre-Upgrade 6 Pre-upgrade historical data queries
Earn 6 Staking, redemption, yield tracking
Leveraged Token 5 Leveraged token subscribe/redeem
Announcement 2 Exchange announcements, system status
Strategy 2 Built-in arbitrage pair detection

Total: 246 tools

πŸ“‹ View all tool names
uv run python -c "
import src.tools
from src import mcp
for name in sorted(mcp._tool_manager._tools):
    print(name)
"

πŸ—οΈ Project Structure

bybit-mcp/
β”œβ”€β”€ bybit.py                    # Entry point (backward compatible)
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ __init__.py             # Shared FastMCP instance
β”‚   β”œβ”€β”€ main.py                 # CLI: dotenv + argparse + logging + mcp.run()
β”‚   β”œβ”€β”€ client.py               # Config singleton + HMAC signing + HTTP methods
β”‚   └── tools/
β”‚       β”œβ”€β”€ __init__.py         # Auto-imports all tool modules
β”‚       β”œβ”€β”€ market.py           # 23 tools β€” public market data
β”‚       β”œβ”€β”€ trade.py            # 15 tools β€” order management
β”‚       β”œβ”€β”€ account.py          # 25 tools β€” account operations
β”‚       β”œβ”€β”€ position.py         # 11 tools β€” position management
β”‚       β”œβ”€β”€ asset.py            # 41 tools β€” wallet & transfers
β”‚       β”œβ”€β”€ lending.py          # 39 tools β€” crypto loans
β”‚       β”œβ”€β”€ earn.py             #  6 tools β€” staking & yield
β”‚       β”œβ”€β”€ leveraged_token.py  #  5 tools β€” leveraged tokens
β”‚       β”œβ”€β”€ spot_margin.py      # 12 tools β€” spot margin
β”‚       β”œβ”€β”€ user.py             # 15 tools β€” sub-accounts & API keys
β”‚       β”œβ”€β”€ broker.py           # 10 tools β€” broker services
β”‚       β”œβ”€β”€ otc.py              #  7 tools β€” OTC lending
β”‚       β”œβ”€β”€ spread.py           # 11 tools β€” spread trading
β”‚       β”œβ”€β”€ rfq.py              # 15 tools β€” block trading RFQ
β”‚       β”œβ”€β”€ pre_upgrade.py      #  6 tools β€” pre-upgrade data
β”‚       β”œβ”€β”€ announcement.py     #  2 tools β€” announcements
β”‚       └── strategy.py         #  2 tools β€” arbitrage strategies
β”œβ”€β”€ .env.example                # Environment variable template
β”œβ”€β”€ pyproject.toml              # Project config & dependencies
└── LICENSE                     # MIT License

πŸ”§ Troubleshooting

MCP Server Not Loading / "No MCP servers configured"

If you've configured the server but /mcp shows no tools or "No MCP servers configured":

1. Check the correct configuration file

Claude Code reads MCP server config from ~/.claude.json (per-project), not from ~/.claude/settings.json. The recommended way to add the server is via CLI:

claude mcp add bybit-mcp -- uv --directory /path/to/bybit-mcp run bybit.py

This writes the config to the correct location. If you manually edited ~/.claude/settings.json, the server won't be found.

2. Use the full path to uv

Claude Code spawns MCP server subprocesses without loading your shell profile (.zshrc / .zprofile), so PATH may not include ~/.local/bin. Use the absolute path:

# Find your uv path
which uv
# Example output: /Users/yourname/.local/bin/uv

# Add with full path
claude mcp add bybit-mcp -- /Users/yourname/.local/bin/uv --directory /path/to/bybit-mcp run bybit.py

3. Restart Claude Code after configuration changes

MCP servers connect at session startup. After adding or changing config, you must exit and restart Claude Code for changes to take effect.

4. Verify the server starts correctly

Test that the server can start and respond to MCP protocol:

# Test import
uv run python -c "from src.main import main; print('Import OK')"

# Test MCP initialize handshake
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"0.1"}}}' | uv run bybit.py

If the import fails, run uv sync to install dependencies.

5. Don't run the server manually

Claude Code manages the MCP server process itself via stdio. A manually started server instance is completely separate β€” Claude Code won't connect to it. Let Claude Code handle the lifecycle automatically.

Quick Diagnosis Checklist

Symptom Cause Fix
/mcp shows "No MCP servers configured" Config in wrong file (settings.json instead of .claude.json) Use claude mcp add CLI command
Config exists but tools don't load uv not found (PATH issue) Use absolute path to uv
Tools loaded before but not now Session not restarted after config change Restart Claude Code
Server works manually but not in Claude Code Manual server is a separate process Don't start manually; let Claude Code manage it
Import errors on startup Dependencies not installed Run uv sync

⚠️ Disclaimer

This software is provided for educational and informational purposes only.

  • Not Financial Advice β€” This tool does not provide financial, investment, or trading advice
  • Use at Your Own Risk β€” Cryptocurrency trading involves substantial risk of loss
  • API Security β€” Protect your API credentials; use IP restrictions and disable withdrawal permissions
  • Test First β€” Always test on Bybit Testnet before using real funds (--testnet flag)
  • No Warranty β€” The software is provided "as is" without warranty of any kind

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Adding New Tools

  1. Add your tool function in the appropriate src/tools/*.py module
  2. Decorate with @mcp.tool()
  3. Use _public_get for unauthenticated or _signed_get/_signed_post for authenticated endpoints
  4. That's it β€” tools are auto-registered on import

πŸ“š Resources

Resource Description
Bybit V5 API Docs Official Bybit API documentation
Bybit Testnet Practice trading with test funds
MCP Specification Model Context Protocol spec
uv Package Manager Fast Python package manager

πŸ“„ License

This project is licensed under the MIT License β€” see the LICENSE file for details.


Built with ❀️ for the Bybit trading community

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages