Skip to main content
Glama
TA-Lib MCP Server

TA-Lib MCP Server

by phuihock

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

Related MCP server: mcp-tradingview-server

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:

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

Available Tools

18 tools
calculate_bbandsD

Calculate Bollinger Bands (BBANDS).

Inputs: kwargs (required). Returns: result

calculate_demaC

Calculate Double Exponential Moving Average (DEMA).

Inputs: kwargs (required). Returns: result

calculate_emaC

Calculate Exponential Moving Average (EMA).

Inputs: kwargs (required). Returns: result

calculate_ht_trendlineD

Calculate Hilbert Transform Trendline.

Inputs: kwargs (required). Returns: result

calculate_kamaC

Calculate Kaufman Adaptive Moving Average (KAMA).

Inputs: kwargs (required). Returns: result

calculate_maD

Calculate Moving Average (MA).

Inputs: kwargs (required). Returns: result

calculate_mamaC

Calculate MESA Adaptive Moving Average (MAMA).

Inputs: kwargs (required). Returns: result

calculate_mavpD

Calculate Moving Average Variable Period (MAVP).

Inputs: kwargs (required). Returns: result

calculate_midpointD

Calculate Midpoint (MIDPOINT).

Inputs: kwargs (required). Returns: result

calculate_midpriceD

Calculate Midpoint Price (MIDPRICE).

Inputs: kwargs (required). Returns: result

calculate_rsiC

Calculate Relative Strength Index (RSI).

Inputs: kwargs (required). Returns: result

calculate_sarD

Calculate Parabolic SAR.

Inputs: kwargs (required). Returns: result

calculate_sarextD

Calculate Parabolic SAR Extended (SAREXT).

Inputs: kwargs (required). Returns: result

calculate_smaC

Calculate Simple Moving Average (SMA).

Inputs: kwargs (required). Returns: result

calculate_t3D

Calculate T3 Moving Average.

Inputs: kwargs (required). Returns: result

calculate_temaC

Calculate Triple Exponential Moving Average (TEMA).

Inputs: kwargs (required). Returns: result

calculate_trimaC

Calculate Triangular Moving Average (TRIMA).

Inputs: kwargs (required). Returns: result

calculate_wmaC

Calculate Weighted Moving Average (WMA).

Inputs: kwargs (required). Returns: result

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    C2.7/5.0

    Scored across 18 tools

    Disambiguation5/5

    Every tool has a clearly distinct purpose, each calculating a specific technical indicator or moving average type with no overlap. The descriptions explicitly name the unique algorithm (e.g., BBANDS, DEMA, RSI), making it impossible to confuse one tool for another.

    Naming Consistency5/5

    All tools follow a perfect verb_noun pattern with 'calculate_' as the consistent prefix, followed by the indicator acronym or name in snake_case. There are no deviations in naming style or structure across the entire set.

    Tool Count4/5

    With 18 tools, the count is slightly high but reasonable for a technical analysis library covering various moving averages and indicators. It aligns well with the domain's scope, though it might feel heavy compared to simpler servers.

    Completeness5/5

    The tool set provides comprehensive coverage for calculating technical indicators, including multiple moving average types (e.g., SMA, EMA, WMA) and key indicators like RSI and Bollinger Bands. There are no obvious gaps for a TA-Lib server, as it covers the core functionality expected in this domain.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Provides stock market data and computes technical indicators like EMA, MACD, and RSI across multiple timeframes using the LongPort API and TA-Lib. It enables users to perform detailed financial analysis and multi-timeframe market reviews through standard MCP tools.
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides comprehensive stock market data and technical analysis tools via the MCP protocol, enabling real-time quotes, historical data, and professional indicators like RSI and MACD for Claude Desktop and other clients.
      5
      Apache 2.0
    • A
      license
      B
      quality
      D
      maintenance
      Provides real-time market data, technical analysis, screeners, and backtesting for stocks, crypto, forex, and futures to AI assistants via MCP.
      37
      1
      MIT