Guide · Agent builders

MCP server for finance — how to give your AI agent stock pattern intelligence.

If you’re building an AI agent that needs to reason about stocks, you’ve probably hit the wall: LLMs hallucinate prices and trends, finance APIs return raw bars not insights, and there’s no canonical way to wire calibrated stock analysis into Claude or Cursor.

An MCP (Model Context Protocol) server for finance is the answer. Chart Library’s MCP server exposes 20 tools for cohort intelligence, regime tracking, and historical pattern analysis. Install once via pip, configure your MCP client, and your agent has the right primitives wired in.

This guide covers what MCP is, why it matters for finance agents specifically, the 20 tools available, and the exact configuration for Claude Desktop and Cursor.

What MCP is (and why finance is a good fit)

MCP — Model Context Protocol — is Anthropic’s open standard for connecting LLM agents to external tools and data sources. An MCP client (Claude Desktop, Cursor, custom builds) talks to MCP servers using a defined JSON-RPC protocol. Each server exposes a list of tools the agent can call.

The advantages over baking tool definitions into your prompt:

  • Discoverable — the agent introspects the tool list at runtime
  • Composable — multiple MCP servers can be attached to one agent
  • Updateable — server-side tool changes propagate automatically without redeploying the agent
  • Deterministic — tool inputs/outputs are typed schemas, not freeform text

Finance is a particularly strong MCP use case because the alternative (LLM-only stock analysis) is dangerous: LLMs hallucinate prices, fabricate news, and make up patterns that don’t exist. An MCP server backed by real data eliminates all of those failure modes — the agent can’t hallucinate what the cohort_analyze tool returns, because the tool returns real numbers from a real database.

What chartlibrary-mcp gives you

Twenty tools spanning cohort intelligence, agent surfaces, regime tracking, narrative-change alerts, and learning memory. The most important ones:

  • cohort_analyze — full-distribution cohort intelligence for a (symbol, date, timeframe) anchor. Returns 300 historical analogs, forward-return distribution at 1d/5d/10d, feature attribution, and regime stratification.
  • get_daily_setups — single-call brief: top picks pre-enriched with full-cohort statistics, top features, yesterday’s calibration recap. The canonical agent entrypoint.
  • discover_picks — daily scanner: top patterns ranked by cohort_score with full-cohort enrichment.
  • regime_tracker — current SPY/QQQ/sector regime context.
  • narrative_alerts — realtime news anomaly detection across the market.
  • get_pattern_degradation — are signals losing accuracy recently?
  • get_risk_adjusted_picks — Sharpe-like scoring.

Each tool returns structured JSON the agent can reason about. No hallucination surface — the data is the data.

Install in 30 seconds

The package is on PyPI:

pip install chartlibrary-mcp

That installs the executable chartlibrary-mcp.

Configure Claude Desktop

Edit your Claude Desktop config (location varies by OS — Settings → Developer → Edit Config opens it):

{
  "mcpServers": {
    "chartlibrary": {
      "command": "chartlibrary-mcp",
      "env": {
        "CHARTLIBRARY_API_KEY": "cl_your_key_here"
      }
    }
  }
}

The API key is optional — without it, the server uses the free Sandbox tier (200 calls/day). With a Builder ($29) or Scale ($99) key, you get higher limits and priority queue.

Restart Claude Desktop. The chartlibrary tools appear in the tool picker. Try:

> What's NVDA's historical pattern look like right now?

# Claude calls cohort_analyze with anchor=(NVDA, today, 1h)
# Returns: cohort of 300 analogs, full distribution, top features
# Claude summarizes the result honestly

Configure Cursor

Cursor’s MCP support uses the same protocol. Add to your Cursor settings:

{
  "mcp.servers": {
    "chartlibrary": {
      "command": "chartlibrary-mcp",
      "env": {
        "CHARTLIBRARY_API_KEY": "cl_your_key_here"
      }
    }
  }
}

Useful in Cursor when you’re writing trading-research code and want the IDE’s AI to reason about real cohort statistics rather than fabricated examples.

Configure custom MCP clients (Python, TypeScript)

If you’re building a custom agent that talks to MCP servers directly:

# Python — using mcp.client
from mcp.client.stdio import stdio_client
from mcp import ClientSession, StdioServerParameters

async def main():
    server_params = StdioServerParameters(
        command="chartlibrary-mcp",
        env={"CHARTLIBRARY_API_KEY": "cl_..."}
    )
    async with stdio_client(server_params) as (read, write):
        async with ClientSession(read, write) as session:
            await session.initialize()
            tools = await session.list_tools()
            # Call cohort_analyze
            result = await session.call_tool(
                "cohort_analyze",
                {"symbol": "NVDA", "date": "2024-08-05", "timeframe": "1h"}
            )
            print(result)
// TypeScript — using @modelcontextprotocol/sdk
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";

const transport = new StdioClientTransport({
  command: "chartlibrary-mcp",
  env: { CHARTLIBRARY_API_KEY: "cl_..." }
});
const client = new Client({ name: "my-agent", version: "1.0" }, {});
await client.connect(transport);

const result = await client.callTool({
  name: "cohort_analyze",
  arguments: { symbol: "NVDA", date: "2024-08-05", timeframe: "1h" }
});

The right way to use these tools in an agent

Three usage patterns we’ve seen work well:

1. Single-call brief at the start of a research session

When the user asks “what setups look interesting today,” call get_daily_setups once. It returns the top 3 picks pre-enriched with full-cohort stats and yesterday’s calibration recap. One tool call, complete answer.

2. Drill-down on a specific symbol

When the user asks about a specific ticker, call cohort_analyze with the (symbol, date, timeframe) anchor. Optionally apply filters for vol_regime or days_since_earnings to narrow the cohort to comparable historical situations.

3. Regime context as a wrapper

For any market analysis question, prepend a call to regime_tracker to get current SPY/QQQ/sector context. Then condition the cohort_analyze interpretation on the regime. Same cohort + low-vol regime tells a different story than same cohort + high-vol regime.

What you should NOT use these tools for

  • Live trade execution. The MCP server returns analysis, not orders. Connect to a broker SDK separately if you need execution.
  • Single-shot point predictions. If your agent asks “will NVDA go up tomorrow,” cohort_analyze returns a distribution, not a yes/no. Coerce the agent into presenting probabilities, not predictions.
  • High-frequency querying. The Sandbox tier is 200 calls/day. Builder is rate-limited. For agent loops that want to call cohort_analyze 1,000 times a minute, you want a higher-tier subscription or a different architecture.

Frequently asked questions

Is this open source?
The MCP server (chartlibrary-mcp on PyPI) is open source on GitHub at grahammccain/chart-library-mcp. The backend it talks to is closed source but accessible via free API tier.
Can I run this offline?
No. The MCP server is a thin client that calls the Chart Library API; data and computation live on our servers. Offline use would require shipping ~427GB of pgvector data.
Does this work with ChatGPT or Gemini?
Anthropic created MCP and Claude Desktop has first-class support. Cursor (which uses Claude under the hood by default) also supports MCP. ChatGPT doesn't natively speak MCP yet — there are unofficial bridges. For ChatGPT, the alternative is the OpenAPI Action approach (see our ChatGPT GPT submission spec).
How do I rate-limit my agent?
Free Sandbox is 200 calls/day per IP. Builder ($29/mo) is 5,000/day with priority queue. Scale ($99/mo) is 50,000/day. Enterprise is custom. The MCP server itself doesn't rate-limit — it relays to the API which enforces the limit.
What about other MCP finance servers?
Some MCP servers wrap raw market data APIs (Polygon, Alpha Vantage). Those are useful but they don't give you cohort intelligence — they give you raw bars. Chart Library's MCP gives you the calibrated, methodology-honest analysis layer on top of the raw data.
Try it

Install the MCP server now.

pip install chartlibrary-mcp — works with free Sandbox tier (no API key needed for first 200 calls/day).

Related