TA-Lib MCP Server

TA-Lib MCP Server

Provides technical analysis indicators like SMA, EMA, RSI, MACD, Bollinger Bands, and Stochastic through MCP, enabling AI assistants to perform financial market analysis and calculations on price data.

Category
访问服务器

README

TA-Lib MCP Server

Technical analysis indicators MCP server and HTTP API for the Model Context Protocol.

Quick Start

# Install dependencies
uv sync --dev

# Copy logging configuration
cp logging.conf.example logging.conf

# Run MCP server with STDIO transport (default)
uv run python -m mcp_talib.cli --mode mcp --transport stdio

# Run MCP server with HTTP transport
uv run python -m mcp_talib.cli --mode mcp --transport http --port 8000

# Run HTTP API server only
uv run python -m mcp_talib.cli --mode api --port 8001

# Run CLI tools directly
uv run python -m mcp_talib.cli_tools list
uv run python -m mcp_talib.cli_tools call sma --close '[1,2,3,4,5]' --timeperiod 3

Architecture

This project provides three independent access methods:

1. MCP Server (--mode mcp)

  • Pure MCP protocol implementation exposing all TA-Lib indicators as MCP tools
  • Supports both STDIO and HTTP transports
  • For use with MCP clients (Claude Desktop, MCP Inspector, MCP.js, etc.)
  • No REST endpoints

Run with STDIO (for Claude Desktop):

uv run python -m mcp_talib.cli --mode mcp --transport stdio

Run with HTTP (for MCP Inspector or web clients):

uv run python -m mcp_talib.cli --mode mcp --transport http --port 8000
# Then connect MCP Inspector to http://localhost:8000/mcp

2. HTTP API Server (--mode api)

  • Pure REST API with /api/tools/* JSON endpoints
  • For programmatic HTTP access to indicators
  • No MCP protocol, just clean REST

Run HTTP API:

uv run python -m mcp_talib.cli --mode api --port 8001

Example request:

curl -X POST http://localhost:8001/api/tools/sma \
  -H 'Content-Type: application/json' \
  -d '{"close": [1,2,3,4,5], "timeperiod": 3}'

3. CLI Tools

Direct command-line access to all indicators via Typer:

uv run python -m mcp_talib.cli_tools list
uv run python -m mcp_talib.cli_tools call sma --close '[1,2,3,4,5]' --timeperiod 3

Features

  • All TA-Lib Overlap Studies: BBANDS, DEMA, EMA, HT_TRENDLINE, KAMA, MA, MAMA, MAVP, MIDPOINT, MIDPRICE, SAR, SAREXT, SMA, T3, TEMA, TRIMA, WMA
  • Three Access Methods: MCP, HTTP REST, CLI
  • Dual Transport: STDIO and HTTP for MCP
  • Cross-platform: Works on Linux, macOS, Windows
  • Comprehensive Testing: 26+ unit and integration tests
  • Error Handling: Detailed error messages and validation

Logging Configuration

The server requires a logging.conf file for configuration. Copy the example:

cp logging.conf.example logging.conf

Customize logging levels, format, and output file in logging.conf. The server logs to console.log to maintain MCP protocol compliance.

Client Configuration

Claude Desktop Integration

  1. Create a configuration file at ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or appropriate location for your OS.

  2. Add the MCP server configuration:

{
  "mcpServers": {
    "talib": {
      "command": "uv",
      "args": [
        "run",
        "python",
        "-m",
        "mcp_talib.cli",
        "--mode",
        "mcp",
        "--transport",
        "stdio"
      ],
      "cwd": "/path/to/mcp-talib"
    }
  }
}
  1. Restart Claude Desktop to load the TA-Lib server.

  2. Verify installation by asking Claude: "What technical analysis tools do you have?"

MCP Inspector (HTTP)

For HTTP transport, configure MCP Inspector to connect to:

http://localhost:8000/mcp

Run the MCP server with HTTP:

uv run python -m mcp_talib.cli --mode mcp --transport http --port 8000

Important: The HTTP transport includes CORS middleware to support browser-based MCP clients like MCP Inspector. If you're behind a reverse proxy or need to restrict access, update the allow_origins setting in transport/http.py.

MCP.js Client Example

import { MCPServerClient } from '@modelcontextprotocol/client';

const client = new MCPServerClient({
  name: 'talib',
  command: 'uv',
  args: ['run', 'python', '-m', 'mcp_talib.cli', '--mode', 'mcp', '--transport', 'stdio'],
  cwd: process.cwd()
});

// List available tools
const tools = await client.listTools();
console.log('Available tools:', tools.map(t => t.name));

// Calculate SMA
const smaResult = await client.callTool('calculate_sma', {
  close_prices: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
  timeperiod: 5
});
console.log('SMA result:', smaResult);

HTTP API Client (Python)

import requests

# List available tools
response = requests.get('http://localhost:8001/api/tools')
tools = response.json()['tools']
print('Available tools:', tools)

# Calculate SMA
payload = {
    'close': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
    'timeperiod': 5
}
response = requests.post('http://localhost:8001/api/tools/sma', json=payload)
result = response.json()
print('SMA result:', result['values'])

Available Tools

The server provides MCP tools and HTTP endpoints for all TA-Lib overlap studies:

  • calculate_sma - Simple Moving Average
  • calculate_ema - Exponential Moving Average
  • calculate_rsi - Relative Strength Index
  • calculate_bbands - Bollinger Bands
  • calculate_dema - Double Exponential Moving Average
  • calculate_ht_trendline - Hilbert Transform Trendline
  • calculate_kama - Kaufman Adaptive Moving Average
  • calculate_ma - Moving Average (with matype)
  • calculate_mama - MESA Adaptive Moving Average
  • calculate_mavp - Moving Average Variable Period
  • calculate_midpoint - Midpoint
  • calculate_midprice - Midpoint Price
  • calculate_sar - Parabolic SAR
  • calculate_sarext - Parabolic SAR Extended
  • calculate_t3 - T3 Moving Average
  • calculate_tema - Triple Exponential Moving Average
  • calculate_trima - Triangular Moving Average
  • calculate_wma - Weighted Moving Average

Development

# Run all tests
uv run pytest

# Run specific test file
uv run pytest tests/unit/test_sma.py -v

# Run with coverage
uv run pytest --cov=src/mcp_talib

# Format code
uv run black src/ tests/
uv run isort src/ tests/

# Lint code
uv run ruff check src/ tests/

TA-Lib Platform Requirements

This project uses the ta-lib Python bindings which require the native TA-Lib C library. On CI or developer machines, you must install the system TA-Lib library before installing Python dependencies.

Links and notes:

  • TA-Lib (C library): https://ta-lib.org/ (download and build instructions)
  • ta-lib-python (Python bindings): https://github.com/TA-Lib/ta-lib-python

Example (Ubuntu) CI steps:

# Install build dependencies
sudo apt-get update && sudo apt-get install -y build-essential wget

# Download and build TA-Lib C library
wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
tar -xzf ta-lib-0.4.0-src.tar.gz
cd ta-lib
./configure --prefix=/usr
make
sudo make install

# Then install Python package
pip install TA-Lib

If you prefer not to build the C library, use pre-built wheels where available or run tests in an environment that provides TA-Lib (e.g., manylinux CI images).

HTTP API & CLI

This project exposes the same MCP tools as both HTTP JSON endpoints and a Typed CLI (Typer).

HTTP Endpoint

POST /api/tools/{tool_name}

Request JSON: { "close": [..], ...params } (e.g., timeperiod)

Response JSON: { "success": true, "values": [...], "metadata": {...} }

Example:

curl -X POST http://localhost:8000/api/tools/sma \
  -H 'Content-Type: application/json' \
  -d '{"close": [1,2,3,4,5], "timeperiod": 3}'

MCP Endpoint

The MCP endpoint remains at /mcp for MCP clients (MCP Inspector, MCP.js, etc.). The HTTP API mounts the MCP app so both APIs coexist.

CLI (Typer)

Access tools from the command line via src/mcp_talib/cli_tools.py:

List available tools:

uv run python -m mcp_talib.cli_tools list

Call a tool:

uv run python -m mcp_talib.cli_tools call sma --close '[1,2,3,4,5]' --timeperiod 3

Implementation Notes

  • Requests are validated using Pydantic
  • The underlying indicator implementations are the single source of truth (registered in the MCP registry)
  • HTTP API and CLI call the same code so results match exactly
  • For browser clients, CORS is enabled and mcp-session-id is exposed in responses

License

MIT

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选