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 a composite toolset 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 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

Nine canonical tools backed by a full-cohort handover surface. The core loop is search cohort_analyzecohort_introspect; the rest cover single-metric checks, market context, prose, and portfolio exposure. The most important ones:

  • search — entry point. Find the cohort of historically similar setups for a (symbol, date, timeframe) anchor; returns a cohort_id you can chain.
  • cohort_analyze — full-distribution cohort intelligence for the anchor. Returns 300 historical analogs, forward-return distribution at 1d/5d/10d, feature attribution, and regime stratification.
  • cohort_introspect — slice the cohort you just built with a where filter to see how a sub-cohort behaved, without re-searching.
  • symbol_intelligence — per-symbol track record plus the learning-memory layer.
  • analyze — single-metric checks via metric=: volume, earnings reaction, correlation shift, pattern degradation, regime accuracy.
  • context — market overview, ticker metadata, sector/regime, DB status (target=).
  • explain — prose narrative, filter importance, exit guidance, risk ranking (style=).
  • portfolio — multi-holding weighted cohort exposure.

Hand the cohort back to your own logic with the handover surface — cohort_members, cohort_groupby, cohort_rerank — to bucket, aggregate, or re-sort by your own objective. 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": {
        "CHART_LIBRARY_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": {
        "CHART_LIBRARY_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={"CHART_LIBRARY_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: { CHART_LIBRARY_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. Anchor and analyze — the core loop

When the user asks about a specific ticker, call search to anchor the cohort for the (symbol, date, timeframe), then cohort_analyze for the full forward-return distribution, feature attribution, and regime stratification. Two calls, complete picture.

2. Slice the cohort without re-searching

Pass the cohort_id from step 1 to cohort_introspect with a where filter (e.g. vol_regime=high or days_since_earnings<5) to see how the comparable sub-cohort behaved. Same cohort, conditioned distribution, no second search.

3. Condition on market context

For any market-analysis question, prepend a call to context (target=market) to get current SPY/QQQ/sector regime. Then interpret the cohort against it — 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 50K calls/month with priority queue. Scale ($99/mo) is 500K calls/month. Agent ($299/mo) is 2M calls/month. Enterprise (from $2K/mo) is unlimited/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