Skip to main content
Glama

Binance MCP Server

ARCHITECTURE.md6.19 kB
# Binance MCP Server Architecture ## System Components ``` +-----------------------+ +------------------+ +----------------+ | | | | | | | Binance Exchange | <---> | Binance MCP | <---> | LLM Agent | | API Endpoints | | Server | | (Claude/GPT) | | | | | | | +-----------------------+ +------------------+ +----------------+ ^ | | | v v +------------------------+ +------------------+ | | | | | WebSocket Data | | MCP Client | | Streams | | Applications | | | | | +------------------------+ +------------------+ ``` ## Internal Structure ``` +----------------------------------------------------+ | Binance MCP Server | | | | +----------------+ +---------------------+ | | | | | | | | | REST API | | WebSocket API | | | | (binance_api) | | (binance_ws_api) | | | | | | | | | +-------+--------+ +----------+----------+ | | ^ ^ | | | | | | v v | | +-------+------------------------+-+----------+ | | | | | | | Command Modules | | | | | | | | +-------------+ +-------------+ +-----+ | | | | | market_data | | market_info | | ws | | | | | +-------------+ +-------------+ +-----+ | | | | | | | +---------------------+---------------------+-- | | ^ | | | | | v | | +------------------------------------------+ | | | | | | | MCP Server Interface | | | | (FastMCP) | | | | | | | +------------------------------------------+ | | | +----------------------------------------------------+ ``` ## Data Flow ``` +----------------+ HTTP GET +---------------------------+ | MCP Client | -------------> | Binance Exchange REST API | | (Tool Request) | +---------------------------+ +----------------+ | | v | +---------------------------+ | | Process & Format Response | | +---------------------------+ v | +----------------+ v | MCP Server | <----- JSON Response ----+ | (Tool Result) | +----------------+ ``` WebSocket Data Flow: ``` +-------------------+ Subscribe +-------------------------+ | | ----------------> | | | WebSocket Command | | Binance WebSocket API | | | <---------------- | | +--------+----------+ Stream Open +-------------------------+ | | | v | +-------------------------+ v | WebSocket Message | +--------+----------+ | Processing & Queueing | | | +-------------------------+ | WebSocket Result | | | Queue | | | | <---- Real-time Updates --------+ +-------------------+ ``` ## Component Responsibilities ### binance_api.py - Provides functions for accessing REST API endpoints - Handles HTTP request/response cycle - Encapsulates error handling and data formatting - Converts data types (string to numeric) ### binance_ws_api.py - Manages WebSocket connections - Handles subscription management - Processes incoming messages - Maintains connection state and handles reconnects ### commands/market_data.py - Defines MCP tools for market data - Maps tool parameters to API function calls - Formats responses for MCP protocol ### commands/market_info.py - Defines MCP tools for exchange information - Provides metadata about symbols, markets, and exchange rules ### commands/websocket_streams.py - Defines MCP tools for WebSocket interactions - Manages subscription lifecycles - Provides access to real-time data queues ### server.py - Initializes FastMCP server - Registers all command modules - Configures server parameters and dependencies ## Authentication Flow Future implementation: ``` +-------------+ +------------+ +----------------+ | | | | | | | API Key | --> | HMAC-SHA | --> | Request with | | Secret Key | | Signature | | Authentication | | | | | | | +-------------+ +------------+ +-------+--------+ | v +------------------+ | | | Authenticated | | Binance API | | | +------------------+ ```

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tienan92it/binance-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server