Luno MCP Server

Luno MCP Server

A Model Context Protocol server that provides a standardized interface for AI models and applications to interact with the Luno cryptocurrency exchange API for trading operations.

Category
访问服务器

README

Luno MCP Server

A Model Context Protocol (MCP) server for the Luno cryptocurrency exchange API. This server provides a standardized interface for AI models and applications to interact with the Luno API for cryptocurrency trading.

<!-- A text-based header instead of potentially broken image link -->

 _                        __  __  ____ ____   
| |    _   _ _ __   ___  |  \/  |/ ___|  _ \  
| |   | | | | '_ \ / _ \ | |\/| | |   | |_) | 
| |___| |_| | | | | (_) || |  | | |___|  __/  
|_____|\__,_|_| |_|\___/ |_|  |_|\____|_|     

Features

  • Real-time cryptocurrency price information via Luno API
  • Market overview for all trading pairs
  • Account balance queries
  • Order management (place, cancel, status)
  • Transaction history retrieval
  • Fee information
  • Standardized JSON-RPC 2.0 interface
  • Simple integration with AI applications

Prerequisites

  • Python 3.8+ (Python 3.9+ recommended)
  • uv for package management
  • Luno account with API keys (for full functionality)

Installation

  1. Clone this repository
git clone https://github.com/amanasmuei/mcp-luno.git
cd mcp-luno
  1. Create a virtual environment using uv
uv venv
source .venv/bin/activate  # On macOS/Linux
# On Windows use: .venv\Scripts\activate
  1. Install dependencies
uv pip install -r requirements.txt
  1. Configure your Luno API credentials (choose one method):

Docker Support

You can run the MCP server using Docker for easier deployment and consistent environment across different platforms.

Using Docker Compose (Recommended)

  1. Copy the example environment file and configure your credentials:
cp .env.example .env
# Edit .env file with your Luno API credentials
  1. Start the server:
docker compose up -d

The server will be available at ws://localhost:8765 in WebSocket mode.

  1. View logs:
docker compose logs -f
  1. Stop the server:
docker compose down

Using Docker Directly

Build the image:

docker build -t mcp-luno .

Run the container:

docker run -d \
  -p 8765:8765 \
  -e LUNO_API_KEY=your_api_key_here \
  -e LUNO_API_SECRET=your_api_secret_here \
  -e MCP_TRANSPORT=websocket \
  -e MCP_HOST=0.0.0.0 \
  -v ./certs:/app/certs \
  --name mcp-luno \
  mcp-luno

Using with AI Assistants

After starting the Docker container, you can connect various AI assistants to use the Luno MCP server:

Cursor

Add the following to your Cursor configuration:

{
  "mcp_servers": {
    "luno": {
      "type": "websocket",
      "url": "ws://localhost:8765"
    }
  }
}

Claude Desktop

In Claude Desktop settings, you have two options for configuring the MCP server:

Option 1: Using Docker (Recommended)
{
  "mcpServers": {
    "luno": {
      "command": "docker",
      "args": ["compose", "up"],
      "cwd": "/path/to/mcp-luno",
      "transport": "websocket",
      "url": "ws://localhost:8765",
      "env": {
        "LUNO_API_KEY": "your_api_key_here",
        "LUNO_API_SECRET": "your_api_secret_here"
      }
    }
  }
}

This configuration starts the server in a Docker container and connects via WebSocket.

Option 2: Using Direct Python Execution
{
  "mcpServers": {
    "luno": {
      "command": "python",
      "args": ["-m", "src.main", "--transport", "stdio"],
      "cwd": "/path/to/mcp-luno",
      "transport": "stdio",
      "env": {
        "PYTHONPATH": "${workspaceFolder}",
        "LUNO_API_KEY": "your_api_key_here",
        "LUNO_API_SECRET": "your_api_secret_here"
      }
    }
  }
}

This configuration runs the Python server directly using STDIO transport.

Note: Replace /path/to/mcp-luno with the actual path where you cloned the repository.

Cline

Add the following to your Cline configuration file:

{
  "mcp": {
    "servers": {
      "luno": {
        "transport": "websocket",
        "url": "ws://localhost:8765"
      }
    }
  }
}

SSL Support with Docker

To use SSL with the Docker container:

  1. Generate certificates using the provided script:
./generate_certificates.sh
  1. Mount the certificates directory when running the container:
docker run -d \
  -p 8765:8765 \
  -e LUNO_API_KEY=your_api_key_here \
  -e LUNO_API_SECRET=your_api_secret_here \
  -e MCP_TRANSPORT=websocket \
  -e MCP_HOST=0.0.0.0 \
  -v ./certs:/app/certs \
  --name mcp-luno \
  mcp-luno

Manual Installation

Option A: Using .env file

cp .env.example .env

Then edit the .env file to add your Luno API credentials:

LUNO_API_KEY=your_api_key_here
LUNO_API_SECRET=your_api_secret_here

Option B: Using VS Code MCP configuration

Edit the .vscode/mcp.json file and add your credentials to the env section:

"env": {
  "PYTHONPATH": "${workspaceFolder}",
  "LUNO_API_KEY": "your_api_key_here",
  "LUNO_API_SECRET": "your_api_secret_here",
  "LOG_LEVEL": "INFO"
}

Note: Without valid API credentials, only public endpoints will be available. Recommendation: For security, prefer environment variables when sharing code.

Running the Server

You can run the MCP server in two different transport modes:

STDIO Transport (Default, Single Client)

This is the default mode, which supports a single client connection via standard input/output:

python -m src.main --transport stdio

WebSockets Transport (Multiple Clients)

For supporting multiple client connections simultaneously, run the server in WebSocket mode:

python -m src.main --transport websocket [--host HOST] [--port PORT]

The WebSocket server will start at ws://localhost:8765 by default.

Testing the WebSocket Server

You can test the WebSocket server using the included test client:

python test_websocket_client.py

This helps verify that the server is correctly handling WebSocket connections and responding to requests.

Command Line Options

  • --transport {stdio,websocket}: Transport mechanism to use (default: stdio)
  • --host HOST: Host to bind to when using WebSocket transport (default: localhost)
  • --port PORT: Port to bind to when using WebSocket transport (default: 8765)

Environment Variables

You can also configure the transport using environment variables:

  • MCP_TRANSPORT: Transport mechanism ("stdio" or "websocket")
  • MCP_HOST: Host to bind to for WebSocket transport
  • MCP_PORT: Port to bind to for WebSocket transport

Testing with the Standard Client

For testing the STDIO transport, use the included test client:

python test_client.py

MCP Protocol Integration

This server implements the Model Context Protocol, which allows AI models to interact with it via standardized JSON-RPC 2.0 messages. The server operates over STDIO by default, making it easy to integrate with VS Code extensions and other MCP-compatible clients.

VS Code Integration

The .vscode/mcp.json file configures the server for use with VS Code. Two server configurations are provided:

  1. luno-mcp-server-stdio - Uses the STDIO transport (default MCP behavior)
  2. luno-mcp-server-websocket - Uses the WebSocket transport for multiple client support

VS Code Configuration

To use the WebSocket transport with VS Code, the mcp.json file includes a process-type configuration:

"luno-mcp-server-websocket": {
  "type": "process",
  "command": "python",
  "args": ["-m", "src.main", "--transport", "websocket"],
  "env": {
    // environment variables
  }
}

When using the WebSocket transport, VS Code will start the server as a background process rather than communicating via STDIO.

Configuring the MCP Server in VS Code

You can configure the server directly from the .vscode/mcp.json file:

{
  "servers": {
    "luno-mcp-server": {
      "type": "stdio",
      "command": "python",
      "args": ["-m", "src.main"],
      "env": {
        "PYTHONPATH": "${workspaceFolder}",
        "LUNO_API_KEY": "your_api_key_here",
        "LUNO_API_SECRET": "your_api_secret_here",
        "LOG_LEVEL": "INFO"
      }
    }
  }
}

This configuration will be used by VS Code extensions that support the MCP protocol, making it easy to integrate with AI models and other tools.

Available Methods

Method Description Authentication Required
describe_capabilities Return information about server capabilities No
get_crypto_price Get current price for a specific trading pair No
get_market_overview Get an overview of all available markets No
get_account_balance Get the balance of all accounts Yes
place_order Place a new order Yes
cancel_order Cancel an existing order Yes
get_order_status Get the status of an order Yes
get_transaction_history Get transaction history for an account Yes
get_fees Get fee information for a trading pair Yes

Example Requests

Get server capabilities:

{
  "jsonrpc": "2.0",
  "method": "describe_capabilities",
  "params": {},
  "id": 1
}

Get Bitcoin-ZAR price:

{
  "jsonrpc": "2.0",
  "method": "get_crypto_price",
  "params": {"pair": "XBTZAR"},
  "id": 2
}

Development

Project Structure

├── .env                 # Environment variables (API credentials)
├── .gitignore           # Git ignore configuration
├── .vscode/             # VS Code specific settings
│   └── mcp.json         # MCP configuration for VS Code
├── src/                 # Source code
│   ├── main.py          # Entry point
│   └── luno_mcp_server/ # MCP server implementation
│       ├── luno_client.py # Luno API client
│       └── server.py    # MCP server core
├── tests/               # Test suite
├── test_client.py       # Simple test client for the MCP server
├── requirements.txt     # Project dependencies
└── setup.py             # Package setup

Running Tests

python -m pytest tests/

Adding New Features

To add new Luno API capabilities:

  1. Extend the LunoClient class in src/luno_mcp_server/luno_client.py with new API methods
  2. Add corresponding methods in the LunoMCPServer class in src/luno_mcp_server/server.py
  3. Update the MCP_METHODS list in server.py and register your methods in the _register_methods function
  4. Add tests in the tests/ directory

Architecture

The MCP server uses a simple architecture:

  • JSON-RPC 2.0 for communication
  • Standard input/output (STDIO) for transport
  • Luno API client for cryptocurrency operations

Troubleshooting

Common Issues

  • API Authentication Errors: Ensure your Luno API keys are correctly set in either the .env file or in .vscode/mcp.json
  • Import Errors: Make sure you've activated the virtual environment
  • Rate Limiting: The Luno API has rate limits - implement retry logic for production use

Configuration Priority

When starting the server, configuration values are loaded in this order of priority:

  1. Environment variables passed through MCP configuration (highest priority)
  2. Values in the .env file
  3. Default values in code (lowest priority)

This means you can set values in the MCP configuration to override any existing values in your .env file.

Multi-Client Support

This MCP server supports multiple client connections simultaneously via WebSockets. For detailed information, see MULTI_CLIENT_SUPPORT.md.

Transport Options

The server supports two transport mechanisms:

  1. STDIO (Default): Standard input/output - single client, used by VS Code MCP
  2. WebSockets: Network transport - multiple clients with security features

Running with WebSockets Transport

Basic usage:

python -m src.main --transport websocket --host localhost --port 8765

With security options:

python -m src.main --transport websocket --host localhost --port 8765 \
  --max-connections 50 --max-message-size 1048576 --rate-limit 100

With SSL/TLS encryption:

# First generate certificates
./generate_certificates.sh

# Then run with SSL support
python -m src.main --transport websocket --ssl-cert ./certs/server.crt --ssl-key ./certs/server.key

WebSocket Client Tools

The repository includes two client tools:

  1. test_websocket_client.py: Simple test client

    python test_websocket_client.py
    
  2. enhanced_websocket_client.py: Advanced client with multi-client simulation

    # Single client mode
    python enhanced_websocket_client.py --mode single
    
    # Multi-client simulation (3 clients)
    python enhanced_websocket_client.py --mode multi --clients 3
    

License

MIT License

Copyright (c) 2025

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选