Skip to main content
Glama
Fintech MCP Server

Fintech MCP Server

Fintech MCP Server Blueprint

CI License: Apache-2.0 Python 3.11+

A production-oriented reference blueprint for customer-facing financial & trading MCP servers (Streamable HTTP + stdio JSON-RPC 2.0).

Most MCP demos stop at wrapping three REST endpoints and trusting the system prompt to behave. In real brokerage, trading, and portfolio platforms, the hard 80% lives in the control layer between the model and your execution API:

  • OAuth 2.1 + RFC 9728 Protected Resource Metadata: Bearer token verification with RFC 8707 audience binding, least-privilege scopes (portfolio:read, market:read, orders:propose, orders:execute), and per-user account isolation (IDOR prevention).

  • Strict Pydantic v2 Tool Contracts (extra="forbid"): Rejects hallucinated or prompt-injected fields before business logic ever runs, with explicit token-budget pagination caps.

  • Deterministic Decimal Risk & Sizing Engine: Zero binary floats. The model passes an intent (account_id, symbol, side, quantity); deterministic Python computes exact notional, buying power, short-sale checks, and post-trade single-name concentration limits, emitting an immutable SHA-256 proposal_hash.

  • Non-Bypassable Ed25519 Human Confirmation Gate: Execution accepts only an approved proposal_hash signed out-of-band on an operator channel. The MCP server holds only the reviewer's public key and exposes no approval tool—rejecting unapproved calls, forged signatures, failed risk checks, expired TTLs (>15 min), live price drift (>50 bps), and replays.

  • Tamper-Evident Signed Audit Log: Append-only SHA-256 hash-chained, Ed25519-signed JSONL log written and verified before routing any order to the broker adapter.

  • Automated CI Eval Suite: Runs adversarial security, isolation, arithmetic, and gate regression cases on every push via GitHub Actions.


Architecture

flowchart LR
    Client["MCP Client\n(Claude / ChatGPT / Cursor)"] -->|Bearer JWT + RFC 8707 aud| Auth["OAuth 2.1 Middleware\nScopes + Account Isolation"]
    Auth -->|Validated JSON-RPC 2.0| Router["Typed Tool Router\nPydantic v2 · extra=forbid"]
    Router -->|Read tools| Broker["Broker Adapter\n(IBKR / Alpaca / Sandbox)"]
    Router -->|evaluate_order_risk| Risk["Deterministic Risk Engine\nPython Decimal · SHA-256 hash"]
    Risk --> Gate["Ed25519 Approval Gate\nTTL · Drift · Replay Guard"]
    Operator["Human Reviewer\n(Out-of-Band UI / Key)"] -.->|Signed ApprovalRecord| Gate
    Gate -->|Append & Verify FIRST| Audit["Hash-Chained Audit Log\nSHA-256 + Ed25519 JSONL"]
    Audit -->|Authorized only| Broker

Related MCP server: IBKR Agent Harness MCP Server

Tool Surface

Tool

Required OAuth Scope

Behavior

get_account_balances

portfolio:read

Exact Decimal cash, buying power, and NAV for authorized accounts only

get_positions

portfolio:read

Holdings, market values, and weights with bounded pagination

get_market_quote

market:read

Bid / ask / last quote snapshot

evaluate_order_risk

orders:propose

Computes exact notional & risk checks server-side; returns immutable proposal_hash

execute_approved_order

orders:execute

Enforces Ed25519 approval, TTL, drift, replay & audit verification before broker routing

verify_audit_log

portfolio:read

Independently validates full hash chain and Ed25519 signatures


Quick Start

uv sync --all-extras

# Run unit & integration test suite
uv run pytest -v

# Run automated security & contract CI evals
uv run python -m evals.run_evals

# Lint
uv run ruff check src tests evals

Run the Streamable HTTP MCP Server locally

uv run python -c "
import uvicorn
from fintech_mcp.http_app import create_demo_app
app, verifier, _, _ = create_demo_app()
uvicorn.run(app, host='127.0.0.1', port=8080)
"

Inspect OAuth 2.1 discovery metadata at GET http://127.0.0.1:8080/.well-known/oauth-protected-resource and send authenticated JSON-RPC 2.0 requests to POST http://127.0.0.1:8080/mcp.


Repository Structure

src/fintech_mcp/
  auth.py        # OAuth 2.1 bearer verification, RFC 8707 aud, scope & account checks
  schemas.py     # Strict Pydantic v2 tool contracts and response models
  risk.py        # Deterministic Decimal sizing, concentration & pre-trade risk engine
  gate.py        # Out-of-band Ed25519 confirmation gate (TTL, drift, replay guards)
  audit.py       # SHA-256 hash-chained & Ed25519-signed append-only audit log
  broker.py      # BrokerAdapter protocol + deterministic SandboxBrokerAdapter
  router.py      # Transport-agnostic JSON-RPC 2.0 MCP router
  http_app.py    # FastAPI Streamable HTTP transport + RFC 9728 metadata
  server.py      # Stdio JSON-RPC 2.0 MCP transport
tests/
  test_server.py # Unit & HTTP integration tests
evals/
  run_evals.py   # Automated adversarial & contract CI evaluation harness

Author & Consulting

Built by Ahmed Khattab — AI Agents & MCP Infrastructure Engineer for Finance (Philips, ASML via ICT Group, Valeo; previously led a ~20-tool brokerage MCP server over IBKR, Alpaca, and Binance).

Published as-is under Apache-2.0 as an architectural reference blueprint. For fixed-price production MCP servers, broker/market-data agent integrations, or CI evaluation harnesses, visit ahmedkhattab.io or email ahmed@ahmedkhattab.io.

Engineering reference only. Uses an in-memory sandbox broker adapter and does not connect to live accounts or give investment advice.

Available Tools

5 tools
evaluate_order_riskA

Compute deterministic Decimal sizing, post-trade concentration, and pre-trade risk checks for an order intent. Emits an immutable SHA-256 proposal_hash; never executes.

Inputs: side (required), symbol (required), quantity (required), rationale (required), +3 more.

get_account_balancesB
Read-only

Read cash, buying power, and NAV for an authorized brokerage account.

Inputs: account_id (required).

get_market_quoteA
Read-only

Read latest bid/ask/last market quote for an equity or ETF symbol.

Inputs: symbol (required).

get_positionsB
Read-only

Read current holdings, market values, and portfolio weights (Decimal exact).

Inputs: account_id (required), limit.

verify_audit_logA
Read-only

Verify the SHA-256 hash chain and Ed25519 signatures across the audit log.

Inputs: no named parameters.

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    A3.7/5.0

    Scored across 5 tools

    Disambiguation5/5

    Each tool targets a distinct resource and action: account balances, market quote, positions, order risk evaluation, and audit log verification. The only near-neighbors, get_account_balances and get_positions, are clearly separated by their descriptions (cash/NAV vs. holdings/weights).

    Naming Consistency5/5

    All five tools follow the same verb_noun snake_case convention (get_*, evaluate_*, verify_*). Names are readable and predictably structured across resources.

    Tool Count5/5

    Five tools is a tight, well-scoped surface for a read-only brokerage and risk layer, with each tool earning a clear place. Nothing redundant and nothing padding the list.

    Completeness4/5

    The read-and-verify surface is coherent, and risk evaluation explicitly stops at a proposal hash, handing execution off elsewhere. Minor gaps remain: no account/authorization enumeration, no order status or trade history lookup to close the post-submission loop.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI agents to execute stock trading operations with built-in risk controls and human approval workflows. Supports paper trading simulation, real brokerage integration (Alpaca, Tradier), backtesting, sentiment analysis, and portfolio management while maintaining strict separation between AI intelligence and trade execution.
      MIT
    • A
      license
      B
      quality
      B
      maintenance
      Enables LLM clients to query Interactive Brokers portfolio data and run deterministic policy, valuation, risk, tax, and options analytics through read-only tools, with dual-plane DLP isolation for local or public-only cloud research and human-approved stateful workflows.
      21
      1
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI clients to author and backtest trading strategies, paper trade, and execute orders across supported venues with built-in circuit breakers, risk-based position sizing, automatic stop-loss and take-profit orders, and a local audit trail.
      9
      MIT
    • A
      license
      B
      quality
      B
      maintenance
      Enables AI agents to access Charles Schwab market data, account information, and risk-guarded trading through official APIs with OAuth authentication and configurable safety controls.
      30
      MIT