Skip to main content

An MCP server implementation for Kalshi prediction market endpoints

Project description

MCP Server Kalshi

An MCP server that gives Claude Code and other agent harnesses a first-class interface to Kalshi. It is built for end-to-end trading: browse markets, research them, read the exact settlement rules (including pulling the contract-terms PDFs), and execute trades — all through MCP tools.

Highlights

  • Discoverylist_markets, get_market, list_events, get_event, list_series, get_series. (Kalshi has no free-text search; list_markets filters are the search.)
  • Researchget_market_orderbook, get_market_candlesticks, get_market_trades.
  • Deep rulesget_market_rules consolidates a market's rules_primary/rules_secondary, early-close conditions, settlement sources, and series prohibitions; fetch_rules_pdf downloads and extracts the text of the actual legal contract PDF so the agent can read it.
  • Exchangeget_exchange_status, get_exchange_schedule (is the market open, and its hours).
  • Portfolioget_balance, get_positions, get_fills, get_settlements.
  • Tradingcreate_order, cancel_order, amend_order, decrease_order, plus list_orders / get_order.

Safety by default

  • The server targets Kalshi's demo (sandbox) environment unless you explicitly set KALSHI_ENV=prod.
  • Order-placing tools (create_order, amend_order) require confirm=true. Without it they return a preview — a human-readable summary and the exact payload — and place nothing.
  • Credentials are optional: all market/rules tools work unauthenticated. Only portfolio and order tools need an API key + RSA private key.

Intuitive order model

Kalshi's V2 order API quotes everything from the YES leg (bid/ask in fixed-point dollars). This server exposes the natural model instead — action (buy/sell) + side (yes/no) + a whole cents limit price — and translates it (including the buy-NO ⇄ sell-YES price inversion).

Configuration

Variable Default Purpose
KALSHI_ENV demo demo (sandbox) or prod (real money). Derives the base URL.
KALSHI_API_KEY (none) Kalshi API key ID. Required only for authenticated tools.
KALSHI_PRIVATE_KEY_PATH (none) Path to your RSA private key .pem. Required for authenticated tools.
BASE_URL (derived) Optional explicit REST base override (must include /trade-api/v2).

See .env-example. Get API credentials at docs.kalshi.com/getting_started/api_keys and a demo account via the demo environment guide.

Claude Desktop (uvx)

"mcpServers": {
  "kalshi": {
    "command": "uvx",
    "args": ["mcp-server-kalshi"],
    "env": {
      "KALSHI_ENV": "demo",
      "KALSHI_API_KEY": "<YOUR KALSHI API KEY>",
      "KALSHI_PRIVATE_KEY_PATH": "PATH TO YOUR RSA KEY FILE"
    }
  }
}

Claude Desktop (Docker)

"mcpServers": {
  "kalshi": {
    "command": "docker",
    "args": ["run", "--rm", "-i",
      "--mount", "type=bind,src=/Users/username,dst=/Users/username",
      "-e", "KALSHI_ENV", "-e", "KALSHI_API_KEY", "-e", "KALSHI_PRIVATE_KEY_PATH",
      "mcp-server-kalshi"],
    "env": {
      "KALSHI_ENV": "demo",
      "KALSHI_API_KEY": "<YOUR KALSHI API KEY>",
      "KALSHI_PRIVATE_KEY_PATH": "PATH TO YOUR RSA KEY FILE"
    }
  }
}

Local Development

  1. Create a .env file (see .env-example).
  2. Install deps: uv sync (add --extra dev for dev tools). Requires Python 3.10+.
  3. Run: uv run start.
  4. Test: uv run pytest.

MCP Inspector

npx @modelcontextprotocol/inspector uv --directory /path/to/mcp-server-kalshi run start

Testing & code quality

uv sync --extra dev              # install dev tools (ruff, mypy, pytest, ...)
uv run pytest                    # run the test suite
uv run pytest --cov              # tests with a coverage report
uv run ruff check src tests      # lint
uv run black src tests           # format (add --check to verify only)
uv run mypy                      # type check
uv run pre-commit install        # (once) run ruff + black on every commit

Tests are pure/offline — they exercise the order translation and confirm-gate, the HTTP client (via an injected httpx.MockTransport), the MCP tool registry, config, and PDF extraction, all without touching the live Kalshi API. CI (.github/workflows/ci.yml) runs ruff + black + mypy + pytest across Python 3.10–3.13 on every push/PR, and releases are gated on that same suite.

Authentication

Requests are signed with RSA-PSS (MGF1-SHA256, max salt). Each authenticated request sends KALSHI-ACCESS-KEY, KALSHI-ACCESS-TIMESTAMP, and KALSHI-ACCESS-SIGNATURE, where the signed message is timestamp_ms + METHOD + path (path includes /trade-api/v2, excludes the query string).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_server_kalshi-0.2.2.tar.gz (27.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_server_kalshi-0.2.2-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file mcp_server_kalshi-0.2.2.tar.gz.

File metadata

  • Download URL: mcp_server_kalshi-0.2.2.tar.gz
  • Upload date:
  • Size: 27.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mcp_server_kalshi-0.2.2.tar.gz
Algorithm Hash digest
SHA256 aa8c2a3fece49fda1fa58b5a4dd7d3a0ca9271899ef54ff2232aeedd2a87719b
MD5 209443b21e7393807aa29b775c5e4d1b
BLAKE2b-256 a9600f38a3aed5d00054b5a47bc59be6aeb9c9bebba619d8dfa77bd6e50b0772

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_server_kalshi-0.2.2.tar.gz:

Publisher: deploy.yml on 9crusher/mcp-server-kalshi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mcp_server_kalshi-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_server_kalshi-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 83f43c6e930c1506133bc3d7d626a05735fbb721b58bf6ec84a0d15f9b1631ab
MD5 cddd4893b3dfd8feddc86fc90df0502b
BLAKE2b-256 24784d6ac959fbf3772af57e73a3b1703d1dba412242729ec6beaf42e699130b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_server_kalshi-0.2.2-py3-none-any.whl:

Publisher: deploy.yml on 9crusher/mcp-server-kalshi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page