Skip to main content
Glama
Financial Risk MCP Server

Financial Risk MCP Server

High-Performance Financial Risk & Quantitative Analytics MCP Server

CI Suite Python 3.10+ C++17/20 MCP Specification License: MIT

An enterprise-grade Model Context Protocol (MCP) server bridging institutional quantitative risk analytics to autonomous AI agents (Claude, Cursor, Devin, Copilot).

Designed and engineered by Shelendra Jain (Technical Architect & Hands-on Tech Lead, 19+ years experience in low-latency systems and investment banking trading platforms).


๐Ÿ›๏ธ Architectural Overview

Regulated financial institutions (Tier-1 banks, hedge funds, prime brokers) possess mission-critical quantitative engines written in C++ and distributed microservices. However, connecting these engines to modern Large Language Models (LLMs) requires strict adherence to security boundaries, deterministic arithmetic, and formal protocol standards.

This repository provides a production-hardened reference implementation of an MCP Server exposing quantitative risk functions over standard JSON-RPC 2.0:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚           Autonomous AI Agents / Front-Office UI       โ”‚
โ”‚         (Claude Desktop, Cursor, Devin, Copilot)       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                            โ”‚ Standard JSON-RPC 2.0 (stdio / TCP)
                            โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚               Financial Risk MCP Server                โ”‚
โ”‚    โ€ข Tools Registry        โ€ข Dynamic Resource Provider โ”‚
โ”‚    โ€ข Prompt Templates      โ€ข Protocol Handshake (v1.0) โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
              โ”‚                           โ”‚
              โ–ผ                           โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Python Analytics Core   โ”‚ โ”‚   High-Performance C++   โ”‚
โ”‚  โ€ข BCBS 279 SA-CCR Engine โ”‚ โ”‚  โ€ข Multithreaded Engine  โ”‚
โ”‚  โ€ข Parametric VaR / CVaR  โ”‚ โ”‚  โ€ข Monte Carlo PFE Sim   โ”‚
โ”‚  โ€ข Options Greeks (Delta, โ”‚ โ”‚  โ€ข 6.8M Valuations/Sec   โ”‚
โ”‚    Gamma, Vega, Theta)    โ”‚ โ”‚  โ€ข Zero-Allocation Pools โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Related MCP server: PA MCP Server

โšก Key Capabilities & Quantitative Formulations

1. Basel III / BCBS 279 SA-CCR Engine

Computes Exposure at Default (EAD) under the Standardized Approach for Counterparty Credit Risk: $$\text{EAD} = \alpha \times (\text{RC} + \text{PFE})$$ where $\alpha = 1.4$.

  • Replacement Cost (RC):

    • Unmargined: $\text{RC} = \max(V - C, 0)$

    • Margined (CSA): $\text{RC} = \max(V - C, \text{Threshold} + \text{MTA} - \text{NICA}, 0)$

  • Potential Future Exposure (PFE): $$\text{PFE} = \text{Multiplier} \times \text{AddOn}^{\text{aggregate}}$$ $$\text{Multiplier} = \min\left(1.0, 0.05 + 0.95 \cdot \exp\left(\frac{V - C}{2 \times 0.95 \times \text{AddOn}^{\text{aggregate}}}\right)\right)$$

  • Supervisory Duration: $$\text{SD}_i = \frac{\exp(-0.05 \cdot S_i) - \exp(-0.05 \cdot E_i)}{0.05}$$

2. Multithreaded Monte Carlo Peak Forward Exposure (PFE)

  • Simulates stochastic rate paths across tenors from 0.25 years to 30 years using mean-reverting Ornstein-Uhlenbeck / Hull-White state diffusion.

  • Aggregates distribution profiles to calculate Expected Exposure (EE), PFE 95%, PFE 97.5%, and PFE 99% quantiles.

  • Automatically identifies the Peak Forward Exposure point along the tenor curve.

3. Value-at-Risk (VaR) & Expected Shortfall (CVaR)

  • Calculates regulatory holding-period VaR (10-day 99% confidence interval) and Conditional VaR (Expected Shortfall) using variance-covariance analytical scaling: $$\text{VaR}\alpha = \text{PV} \cdot Z\alpha \cdot \sigma_{\text{daily}} \sqrt{T}$$

4. Derivative Sensitivities (Greeks)

  • Real-time analytical first- and second-order Greeks:

    • Delta ($\Delta$): First-order directional sensitivity.

    • Gamma ($\Gamma$): Second-order underlying convexity.

    • Vega ($\nu$): Volatility surface exposure.

    • Theta ($\Theta$): Calendar time decay.

    • Rho ($\rho$): Risk-free interest rate sensitivity.


๐Ÿ“Š Benchmark Performance (C++20 Engine)

Executed on an Intel x86_64 host (2 worker threads, 100,000 paths across 11 tenors):

Metric

Measured Value

Total Simulated Paths

100,000

Tenor Discretization

11 steps (0.25y โ€“ 30.0y)

Total Valuation Events

1,100,000

Execution Time

161.8 ms

Simulation Throughput

6,797,363 valuations / second


๐Ÿ› ๏ธ MCP Primitives Exposed

Tools

  1. calculate_sacr_exposure: Basel III counterparty credit risk capital calculation.

  2. simulate_monte_carlo_pfe: Vectorized multi-path Monte Carlo PFE simulation across 30y tenors.

  3. compute_portfolio_var: Parametric and regulatory Value-at-Risk and Expected Shortfall.

  4. calculate_portfolio_greeks: Multi-asset portfolio Greeks aggregation (Delta, Gamma, Vega, Theta, Rho).

Resources

  • financial://portfolio/citi-benchmark-01: Standardized institutional benchmark portfolio with Rates, FX, and Equity options.

  • financial://regulatory/bcbs279-factors: Regulatory reference lookup table for BCBS 279 supervisory parameters.

Prompts

  • audit_counterparty_risk: Guided LLM agent workflow for credit risk auditing, EAD verification, and margin adequacy analysis.

  • stress_test_scenario: Guided agent workflow for applying macroeconomic rate shocks and volatility spikes.


๐Ÿš€ Quickstart Guide

1. Prerequisites

  • Python 3.10 or higher

  • GCC / G++ with C++17 support (optional for C++ benchmark)

  • pip install numpy

2. Verify Installation

git clone https://github.com/shelendra/financial-risk-mcp.git
cd financial-risk-mcp

# Run unit tests
make test

# Run C++ high-performance benchmark
make bench-cpp

# Run end-to-end sample client
make run-demo

๐Ÿ”Œ Integration with AI Development Environments

A. Claude Desktop

Add to your claude_desktop_config.json:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

  • Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "financial-risk-engine": {
      "command": "python3",
      "args": ["-m", "fin_risk_mcp.server"],
      "cwd": "/path/to/financial-risk-mcp",
      "env": {
        "PYTHONPATH": "src"
      }
    }
  }
}

B. Cursor IDE

Create or update .cursor/mcp.json in your workspace:

{
  "mcpServers": {
    "financial-risk-engine": {
      "command": "python3",
      "args": ["-m", "fin_risk_mcp.server"],
      "cwd": "/path/to/financial-risk-mcp",
      "env": {
        "PYTHONPATH": "src"
      }
    }
  }
}

๐Ÿงช Testing Suite

The repository includes comprehensive unit tests verifying math accuracy against standard quantitative tables and testing full JSON-RPC protocol compliance:

$ make test

test_saccr_unmargined (test_engines.TestRiskEngines) ... ok
test_saccr_margined (test_engines.TestRiskEngines) ... ok
test_monte_carlo_pfe (test_engines.TestRiskEngines) ... ok
test_parametric_var (test_engines.TestRiskEngines) ... ok
test_greeks_calculation (test_engines.TestRiskEngines) ... ok
test_initialize (test_mcp_server.TestFinancialRiskMCPServer) ... ok
test_tools_list (test_mcp_server.TestFinancialRiskMCPServer) ... ok
test_call_calculate_sacr_exposure (test_mcp_server.TestFinancialRiskMCPServer) ... ok
test_call_simulate_monte_carlo_pfe (test_mcp_server.TestFinancialRiskMCPServer) ... ok
test_resources_read (test_mcp_server.TestFinancialRiskMCPServer) ... ok
test_prompts_get (test_mcp_server.TestFinancialRiskMCPServer) ... ok

----------------------------------------------------------------------
Ran 11 tests in 0.035s

OK

๐Ÿ‘จโ€๐Ÿ’ป Author

Shelendra Jain
Senior Vice President โ€“ Technical Architect & Tech Lead

๐Ÿ“„ License

This project is open-sourced under the MIT License.

Available Tools

4 tools
calculate_portfolio_greeksC

Aggregates first- and second-order derivatives sensitivities: Delta, Gamma, Vega, Theta, and Rho across a book of positions.

Inputs: trades (required).

calculate_sacr_exposureB

Calculates Basel III / BCBS 279 Standardized Approach for Counterparty Credit Risk (SA-CCR) metrics: Replacement Cost (RC), Potential Future Exposure (PFE), Supervisory Add-on, Multiplier, and Exposure at Default (EAD = 1.4 * (RC + PFE)).

Inputs: trades (required), netting_set_id (required), counterparty_id (required), threshold, +3 more.

compute_portfolio_varA

Computes regulatory Value-at-Risk (VaR) and Expected Shortfall (CVaR) for market risk across specified holding periods and confidence intervals.

Inputs: portfolio_value (required), daily_volatility (required), horizon_days, confidence_level.

simulate_monte_carlo_pfeC

Executes high-performance Monte Carlo simulation (using native C++20 multithreaded core) to project Potential Future Exposure (PFE) profiles and Peak Forward Exposure across multi-year tenors (0.25y to 30y).

Inputs: trades (required), portfolio_id (required), volatility, mean_reversion, +1 more.

Tool Schema Changelog

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

Loading tool schema changelogโ€ฆ

    TDQS

    B3.2/5.0

    Scored across 4 tools

    Disambiguation4/5

    Each tool targets a distinct risk metric: regulatory SA-CCR exposure, Monte Carlo PFE profiles, portfolio VaR/CVaR, and Greeks. The only mild overlap is between calculate_sacr_exposure and simulate_monte_carlo_pfe, since both address counterparty exposure, but the standardized-formula vs simulation distinction is clear enough to distinguish them.

    Naming Consistency4/5

    All names use snake_case with a verb_noun structure (calculate_sacr_exposure, simulate_monte_carlo_pfe, compute_portfolio_var, calculate_portfolio_greeks), which is easily predictable. The verb choices vary (calculate/simulate/compute) but all are equally readable and follow the same pattern.

    Tool Count4/5

    Four tools is a focused, well-scoped set that avoids redundancy for a risk analytics server. It is on the lean side, but each tool clearly earns its place.

    Completeness3/5

    The core measures are covered: exposure, PFE, VaR/CVaR, and Greeks. However, notable counterparty-risk operations are absent, including CVA/credit valuation adjustment, stress testing, and scenario or backtesting tools, leaving some obvious gaps in a full risk workflow.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables MCP-compatible AI agents to retrieve quantum-computed portfolio optimisation, VaR simulations, AI-enhanced sentiment and regime detection, and cross-asset risk signals through simple metric tools.
      47 npm
      MIT
    • F
      license
      Not graded
      quality
      B
      maintenance
      Enables AI agents to run probabilistic portfolio analysis workflows, including input validation, instrument verification, simulation preparation, and approved interactive reporting.
      -
    • A
      license
      Not graded
      quality
      B
      maintenance
      Equips AI agents with institutional risk management and execution tools for Solana and Hyperliquid, enabling Kelly-criterion position sizing, VaR/CVaR analysis, Monte Carlo simulations, circuit breaker checks, and wallet/funding data queries through standardized MCP tools.
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables quantitative portfolio tail-risk analysis, option Greeks, Monte Carlo stochastic simulations, fixed-income duration/convexity, and Nelson-Siegel yield-curve interpolation through MCP tools.
      7
      MIT