Skip to main content
Glama
freddyhaddad

finnhub-mcp-server

by freddyhaddad

finnhub-mcp-server

A small, production-shaped remote MCP server that lets Claude.ai query live stock-market data from the Finnhub REST API.

It is the reference pattern for "connect a third-party REST API to Claude":

Claude.ai  ──MCP over HTTPS──▶  finnhub-mcp-server  ──REST + X-Finnhub-Token header──▶  Finnhub
  • Upstream auth: Finnhub API key sent in a request header. The key lives only in a server-side environment variable.

  • Downstream auth: Claude must present a bearer token. Constant-time comparison. Refuses to boot without one unless you opt out explicitly.

  • Transport: MCP Streamable HTTP, stateless. Works with Claude.ai custom connectors, Claude Desktop, Claude Code, and any MCP client.

  • Hosting: one-click on Railway or Render. Health endpoint included.

  • Tests: 18 end-to-end tests run a real MCP client against the server with a mocked Finnhub. No key or network needed.

Tools

Tool

What it does

get_quote

Current price, change, open, high, low, previous close for a ticker

get_company_profile

Name, exchange, country, currency, industry, market cap, IPO date, website

search_symbol

Find tickers by company name or partial symbol, optionally per exchange

get_company_news

Recent articles for a ticker, default last 7 days, capped and trimmed for the model

get_market_news

General, forex, crypto, or merger headlines

Every tool is declared read-only and returns both human-readable text and structuredContent JSON.

Related MCP server: Yahoo Finance MCP Server

Quick start (local)

git clone https://github.com/freddyhaddad/finnhub-mcp-server.git
cd finnhub-mcp-server
npm install
cp .env.example .env
# edit .env: paste your Finnhub key, and generate a token with:  openssl rand -hex 32
npm run dev

Then in another terminal:

npm run smoke            # lists tools and calls each one for AAPL
npm run smoke -- NVDA    # any ticker

Requires Node 22.6 or newer (runs TypeScript directly, no build step for dev).

Run the tests

npm test

The suite spins up a fake Finnhub, starts the server, and drives it with the official MCP client. It checks that the API key travels in the X-Finnhub-Token header, that requests without a bearer token get 401, that bad input never reaches Finnhub, and that upstream failures come back as clean tool errors without leaking the key.

Deploy

Railway

  1. Fork or push this repo to GitHub.

  2. In Railway: New Project → Deploy from GitHub repo. railway.json sets the start command and health check.

  3. Under Variables add FINNHUB_API_KEY and MCP_AUTH_TOKEN. Railway sets PORT for you.

  4. Under Settings → Networking, generate a public domain. Your MCP URL is https://<domain>/mcp.

Render

  1. New → Blueprint, point it at the repo. render.yaml defines the service and auto-generates MCP_AUTH_TOKEN.

  2. Add FINNHUB_API_KEY when prompted.

  3. Copy the generated token from the service's environment page. Your MCP URL is https://<service>.onrender.com/mcp.

Optional hardening: set ALLOWED_HOSTS to your public hostname so the server rejects requests with any other Host header (DNS-rebinding protection). If you put a firewall in front, Anthropic's egress range is 160.79.104.0/21.

Connect it to Claude

Claude.ai (web, desktop, mobile)

Settings → Connectors → Add custom connector. Paste the MCP URL.

For the bearer token, use the request headers option and add Authorization: Bearer <your MCP_AUTH_TOKEN>. Static request-header auth on custom connectors is in beta and is configured by an organization admin. If your account does not show the option yet, two fallbacks:

  • Claude Desktop or Claude Code send headers today (see below).

  • Run with ALLOW_UNAUTHENTICATED=true behind an unguessable URL. Not recommended for anything beyond a demo, since anyone with the URL can spend your Finnhub quota. Adding OAuth is the proper next step and is a natural Phase 2.

Claude Code

claude mcp add --transport http finnhub https://<domain>/mcp \
  --header "Authorization: Bearer <your MCP_AUTH_TOKEN>"

Then ask: "What's NVDA trading at, and what's the latest news on it?"

Configuration

Variable

Required

Default

Purpose

FINNHUB_API_KEY

yes

Finnhub key, sent as X-Finnhub-Token

MCP_AUTH_TOKEN

yes*

Bearer token Claude must send. Min 16 chars

PORT

no

3000

Listen port. Hosts inject this

ALLOWED_HOSTS

no

Comma-separated hostnames to accept

RATE_LIMIT_PER_MINUTE

no

60

Per-IP limit on /mcp

UPSTREAM_TIMEOUT_MS

no

10000

Finnhub request timeout

FINNHUB_BASE_URL

no

https://finnhub.io/api/v1

Override for tests or proxies

ALLOW_UNAUTHENTICATED

no

false

*Set to true to run without MCP_AUTH_TOKEN

Security notes

  • The Finnhub key never appears in tool output, error messages, or logs.

  • Tool inputs are validated with Zod before any upstream call. Tickers are restricted to [A-Z0-9.\-:], dates to YYYY-MM-DD, list sizes to 1–20.

  • User input only ever reaches Finnhub through URL-encoded query parameters. It can never change which endpoint is called.

  • Upstream 401/403/429/5xx are mapped to short, safe messages. Upstream bodies are never forwarded on failure.

  • Request bodies are capped at 100 KB. Responses are trimmed (news summaries to 300 chars, lists to 20 items) so Claude's context stays small.

  • GET and DELETE on /mcp return 405. The server is stateless: nothing is stored between requests.

  • Rotate either secret by changing the environment variable and redeploying. Revoke Claude's access by deleting the connector.

Adapting this to another API

The whole point of the pattern is that swapping Finnhub for any other key-authenticated REST API is mechanical:

  1. Replace src/finnhub.ts with a client for the new API. Keep the header-auth and error-mapping shape.

  2. Replace the tool definitions in src/server.ts. One registerTool per endpoint.

  3. Update test/mock-finnhub.ts fixtures and the assertions in test/e2e.test.ts.

src/app.ts, src/auth.ts, and src/config.ts do not need to change.

Project layout

src/
  index.ts      entrypoint: load config, listen
  app.ts        Express app: health, rate limit, bearer auth, /mcp handler
  auth.ts       bearer-token and host-allowlist middleware
  config.ts     environment parsing and startup guards
  finnhub.ts    Finnhub REST client (header auth, timeouts, sanitised errors)
  server.ts     MCP tool definitions
test/
  mock-finnhub.ts   fake upstream used by the tests
  e2e.test.ts       end-to-end suite using the official MCP client
scripts/
  smoke.ts      manual check against a running server
railway.json, render.yaml   one-click deploy configs

License

MIT. Built by Frederic Haddad.

Related MCP Connectors

  • Finnhub MCP — wraps Finnhub Stock API (finnhub.io)

  • A Model Context Protocol server exposing real-time and historical Colombo Stock Exchange (CSE) data to AI agents and LLM applications. Provides quotes and OHLCV price history, full financial statements (income, balance sheet, cash flow), pre-computed technicals (moving averages, RS ratings, volume signals), macroeconomic indicators, corporate actions, and rule-based screening across CSE stocks and sector indices, everything needed to build CSE-aware trading assistants, research tools, and market-analysis agents. This is the official MCP server of www.ceyloncharts.com

  • Market Data App MCP — wraps the Market Data App API (marketdata.app)

  • Your agent needs markets — prices and fundamentals for listed companies, the filings behind them, crypto, and what the prediction markets put the odds at. **What you can ask for** • "Pull this company's income statement, cash flow and balance sheet for the last 8 quarters." • "What did insiders buy or sell, and when?" • "Snapshot prices for these 50 tickers, then the OHLC history for the three that moved." • "What are the current odds on this event across Kalshi and Polymarket?" • "Screen for companies matching these financial criteria." **How to use it** Point any MCP client at https://mcp.aisa.one/finance/mcp and sign in with OAuth — there is no key to create or paste. 49 tools: prices and snapshots, income statements, balance sheets and cash flows, metrics and ratios, earnings and analyst estimates, filings and line-item search, insider trades, macro interest rates, news, a screener; CoinGecko spot prices, market tables, OHLC, per-venue tickers and trending; Kalshi and Polymarket markets and trades; plus EDINET filings for Japan. **Why this rather than the source** Equities, crypto and event markets behind one account, so a cross-asset question is one conversation. **It is also a door to the rest** The same login reaches 26 sources and 580+ operations. Read the number here, then ask the same agent what X is saying about the ticker today — without adding a second server. **What it costs** Finding and inspecting an operation is free. Running one is billed per call at API prices, with no seat and no monthly minimum, and every call takes max_price_usd so an agent cannot overspend by accident. **Where else it reaches** https://mcp.aisa.one/marketpulse/mcp · /crypto-market-data/mcp · /prediction-market-data/mcp · /stock-pulse/mcp for one slice each.

Related MCP Servers

  • A
    license
    B
    quality
    D
    maintenance
    MCP server providing comprehensive access to Finnhub financial market data API for AI assistants like Claude Desktop.
    15
    10
    MIT
  • A
    license
    Not graded
    quality
    A
    maintenance
    Provides real-time stock market data for Claude Desktop and MCP-compatible clients, enabling natural language queries for quotes, historical prices, company profiles, financial statements, analyst ratings, comparisons, news, options, holdings, dividends, estimates, symbol search, and market status.
    168 npm
    21
    MIT
  • F
    license
    A
    quality
    C
    maintenance
    Connects Claude Desktop to real-time stock market data via Finnhub API, enabling company profiles, stock quotes, market news, and a customizable watchlist.
    3
    -
  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables AI models to access real-time financial market data including stock quotes, fundamentals, daily prices, symbol search, and market status via the Alpha Vantage API. Works with any MCP-compatible client like Claude Desktop for natural language interaction.
    -