Skip to main content
Glama

Bybit MCP Server (Node.js)

A Model Context Protocol (MCP) server for Bybit trading operations, built with Node.js and TypeScript.

Features

  • ✅ Perfect Authentication - Uses exact Cloud Functions signature logic

  • ✅ Smart Position Validation - Automatic validation against Bybit trading rules

  • ✅ Position Mode Detection - Automatically detects one-way vs hedge mode

  • ✅ 16 Trading Tools - Complete market data, account, and trading operations

  • ✅ Demo Mode Support - Safe testing environment

Related MCP server: bybit-mcp-server

Installation

  1. Build the server:

    cd /Users/rkondis/personalwork/mcp-bybit-node
    npm install
    npm run build
  2. Configure environment:

    • Copy .env file with your Bybit API credentials

    • Set DEMO=true for safe testing

Claude MCP Integration

Step 1: Ensure your .env file exists with your API keys:

# Check if .env file exists
ls -la /Users/rkondis/personalwork/mcp-bybit-node/.env

# If it doesn't exist, create it:
cat > /Users/rkondis/personalwork/mcp-bybit-node/.env << EOF
ACCESS_KEY=your_access_key_here
SECRET_KEY=your_secret_key_here
DEMO=true
EOF

Step 2: Add to Claude MCP:

claude mcp add-json bybit-node '{
  "type": "stdio",
  "command": "/Users/rkondis/personalwork/mcp-bybit-node/start-server.sh",
  "args": []
}'

The startup script automatically loads API keys from the .env file.

Method 2: Direct node execution with environment variables

claude mcp add-json bybit-node '{
  "type": "stdio",
  "command": "node",
  "args": ["/Users/rkondis/personalwork/mcp-bybit-node/dist/index.js"],
  "env": {
    "ACCESS_KEY": "your_access_key_here",
    "SECRET_KEY": "your_secret_key_here",
    "DEMO": "true"
  }
}'

Method 3: Using working directory (reads .env automatically)

claude mcp add-json bybit-node '{
  "type": "stdio",
  "command": "node",
  "args": ["dist/index.js"],
  "cwd": "/Users/rkondis/personalwork/mcp-bybit-node",
  "env": {
    "DEMO": "true"
  }
}'

This method uses the existing .env file in the working directory.

Available Tools

  1. Market Data:

    • get_tickers - Get ticker information

    • get_orderbook - Get orderbook data

    • get_kline - Get K-line (candlestick) data

    • get_instruments_info - Get exchange information

  2. Account Management:

    • get_wallet_balance - Get wallet balance

    • get_positions - Get position information

    • get_api_key_information - Get API key information

  3. Trading Operations:

    • validate_order_quantity - Validate order quantity against trading rules

    • calculate_position_size - Calculate optimal position size based on risk management

    • calculate_trailing_stop - Calculate trailing stop loss with breakeven and profit protection

    • detect_position_mode - Detect position mode and get recommended positionIdx

    • place_order - Execute order with automatic position mode detection

    • place_order_with_trailing_stop - Place order with built-in trailing stop loss

    • cancel_order - Cancel order

    • get_order_history - Get order history

    • get_open_orders - Get open orders

  4. Position Management:

    • set_leverage - Set leverage for a specific symbol

    • set_trading_stop - Set trading stop

    • set_margin_mode - Set margin mode

  5. Utility:

    • get_access_key - Get access key from environment

    • get_secret_key - Get secret key from environment

Testing

Test the MCP server:

cd /Users/rkondis/personalwork/mcp-bybit-node
node test-mcp.js

Test trade execution:

cd /Users/rkondis/personalwork/mcp-bybit-node
node test-order.js

Usage Examples

Validate order before placing:

// Check if $80 worth of ETHUSDT is valid
validate_order_quantity("linear", "ETHUSDT", 80)
// Returns: { validatedQty: "0.02", estimatedCost: "73.18", adjustments: [] }

Place a validated order:

// Place market buy order for ETHUSDT
place_order("linear", "ETHUSDT", "Buy", "Market", "0.02", positionIdx="0")

Calculate position size with risk management:

// Calculate position size for 2% risk with $1000 balance
calculate_position_size("linear", "ETHUSDT", 1000, 2, 3500, 3600, 10)
// Returns: {
//   recommendedQty: "0.57",
//   riskAmount: 20,
//   positionValue: 2052,
//   takeProfitSuggestion: 3800,
//   warnings: []
// }

Calculate trailing stop loss with profit protection:

// Calculate trailing stop for a long position
calculate_trailing_stop("linear", "ETHUSDT", 3600, 3750, "Buy", 3500, 50)
// Returns: {
//   newStopLoss: 3700,
//   trailingActivated: true,
//   breakevenProtection: true,
//   profitProtected: 0,
//   recommendations: {
//     shouldUpdateStop: true,
//     protectionLevel: "breakeven",
//     reasoning: "Breakeven protection activated - stop moved to entry price"
//   }
// }

Place order with trailing stop loss:

// Place market buy order with 50 USDT trailing stop
place_order_with_trailing_stop("linear", "ETHUSDT", "Buy", "Market", "0.02", null, "50")
// Returns: Order placed with automatic trailing stop that follows price movement

Set leverage:

// Set 10x leverage for ETHUSDT
set_leverage("linear", "ETHUSDT", "10", "10")

Check positions:

// Get all linear positions
get_positions("linear")

Key Improvements Over Python Version

  • ✅ No signature errors - Perfect authentication with Bybit API

  • ✅ Smart validation - Automatic position size and mode validation

  • ✅ Better error handling - Comprehensive error messages and recovery

  • ✅ TypeScript support - Full type safety and IntelliSense

Troubleshooting

If Claude MCP fails to start:

  1. Check file permissions:

    ls -la /Users/rkondis/personalwork/mcp-bybit-node/dist/index.js
    # Should show: -rwxr-xr-x (executable)
  2. Test server directly:

    cd /Users/rkondis/personalwork/mcp-bybit-node
    node dist/index.js
    # Should show: "Bybit MCP Server (Node.js) running on stdio"
  3. Check environment variables:

    cat /Users/rkondis/personalwork/mcp-bybit-node/.env
  4. Use the startup script:

    /Users/rkondis/personalwork/mcp-bybit-node/start-server.sh

Security Notes

  • Always use DEMO=true for testing

  • Never commit API keys to version control

  • Use environment variables for sensitive data

  • Test thoroughly in demo mode before production use

Support

The server includes comprehensive logging and error handling. Check the console output for detailed information about any issues.

Available Tools

21 tools
calculate_position_sizeC

Calculate optimal position size based on risk management principles

Inputs: category (required), symbol (required), accountBalance (required), riskPercentage (required), +3 more.

calculate_trailing_stopC

Calculate trailing stop loss with breakeven and profit protection

Inputs: category (required), symbol (required), entryPrice (required), currentPrice (required), +5 more.

cancel_orderD

Cancel order

Inputs: category (required), symbol (required), orderId, orderLinkId, +1 more.

detect_position_modeC

Detect current position mode (one-way vs hedge) and get recommended positionIdx for orders

Inputs: category (required), symbol.

get_access_keyB

Get access key from environment variables

Inputs: no named parameters.

get_api_key_informationC

Get API key information

Inputs: no named parameters.

get_instruments_infoC

Get exchange information

Inputs: category (required), symbol (required), status, baseCoin.

get_klineC

Get K-line (candlestick) data

Inputs: category (required), symbol (required), interval (required), start, +2 more.

get_open_ordersC

Get open orders

Inputs: category (required), symbol, orderId, orderLinkId, +2 more.

get_orderbookC

Get orderbook data for a specific symbol

Inputs: category (required), symbol (required), limit.

get_order_historyC

Get order history

Inputs: category (required), symbol, orderId, orderLinkId, +5 more.

get_positionsC

Get position information

Inputs: category (required), symbol.

get_secret_keyB

Get secret key from environment variables

Inputs: no named parameters.

get_tickersC

Get ticker information

Inputs: category (required), symbol (required).

get_wallet_balanceD

Get wallet balance

Inputs: accountType (required), coin.

place_orderD

Execute order

Inputs: category (required), symbol (required), side (required), orderType (required), +18 more.

place_order_with_trailing_stopC

Place order with trailing stop loss

Inputs: category (required), symbol (required), side (required), orderType (required), +7 more.

set_leverageC

Set leverage for a specific symbol

Inputs: category (required), symbol (required), buyLeverage (required), sellLeverage (required).

set_margin_modeD

Set margin mode

Inputs: category (required), symbol (required), tradeMode (required), buyLeverage (required), +1 more.

set_trading_stopD

Set trading stop

Inputs: category (required), symbol (required), takeProfit, stopLoss, +2 more.

validate_order_quantityC

Validate order quantity against Bybit trading rules and get properly formatted quantity

Inputs: category (required), symbol (required), targetAmount (required), currentPrice.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    C2.8/5.0

    Scored across 21 tools

    Disambiguation4/5

    Most tools have distinct purposes, but some overlap exists. For example, 'place_order' and 'place_order_with_trailing_stop' are clearly related, and 'set_trading_stop' might overlap with trailing stop calculations. However, descriptions help clarify differences, preventing major confusion.

    Naming Consistency5/5

    Tool names follow a consistent verb_noun pattern throughout, such as 'get_orderbook', 'set_leverage', and 'calculate_position_size'. There are no deviations in naming conventions, making the set predictable and readable.

    Tool Count4/5

    With 21 tools, the count is slightly high but reasonable for a comprehensive trading server. It covers key areas like orders, positions, and risk management without being overly bloated, though it borders on the heavy side.

    Completeness5/5

    The tool set provides complete coverage for trading operations, including order placement, cancellation, position management, risk calculations, and account information. No obvious gaps exist; agents can handle full trading workflows without dead ends.

    Maintenance

    ActivityInactive
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      Enables AI assistants to interact with Bitget cryptocurrency exchange for spot and futures trading. Supports real-time market data, order management, account balances, leverage control, and position tracking with demo trading capabilities.
      17
      6
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Enables AI assistants to interact with the Bybit cryptocurrency exchange via the V5 API, supporting market data, trading, and account management with both local and remote OAuth-authenticated connections.
      28
      1
      MIT
    • A
      license
      C
      quality
      B
      maintenance
      A production-ready MCP server for Bybit — 206 tools covering market data, trading, positions, account management, assets, and real-time WebSocket streams. Enables AI assistants to interact directly with the Bybit cryptocurrency exchange through natural language.
      403
      1,095 npm
      45
      MIT