Longbridge MCP Server Official MCP server for the Longbridge brokerage. 145 tools across real-time quotes, options, order routing, fundamentals, analyst ratings, calendars, IPO, price alerts, DCA plans, portfolio analytics and community sharelists — covering US and HK markets. Built with Rust using rmcp and axum. - 145 MCP tools across 13 categories: quotes, trading, fundamentals, screener, market
Add this skill
npx mdskills install longbridge/longbridge-mcpComprehensive financial trading server with 145 tools across 13 categories, excellent OAuth architecture
1<p align="center">2 <img src="https://raw.githubusercontent.com/longbridge/longbridge-mcp/main/docs/logo.png" alt="Longbridge" width="120" height="120">3</p>45<h1 align="center">Longbridge MCP Server</h1>67<p align="center">8 <a href="https://registry.modelcontextprotocol.io/v0/servers/com.longbridge%2Fmcp/versions"><img alt="Official MCP Registry" src="https://img.shields.io/badge/MCP%20Registry-com.longbridge%2Fmcp-0a66c2"></a>9 <a href="https://smithery.ai/servers/longbridge-official/longbridge-mcp"><img alt="Smithery" src="https://smithery.ai/badge/longbridge-official/longbridge-mcp"></a>10 <a href="https://lobehub.com/mcp/longbridge-longbridge-mcp"><img alt="LobeHub" src="https://lobehub.com/badge/mcp/longbridge-longbridge-mcp"></a>11 <a href="https://glama.ai/mcp/servers/longbridge/longbridge-mcp"><img alt="longbridge-mcp MCP server" src="https://glama.ai/mcp/servers/longbridge/longbridge-mcp/badges/score.svg"></a>12 <a href="https://github.com/longbridge/longbridge-mcp/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/badge/license-MIT-blue"></a>13 <a href="https://longbridge.com"><img alt="Longbridge" src="https://img.shields.io/badge/brokerage-Longbridge-ffe000?labelColor=000"></a>14</p>1516Official MCP server for the [Longbridge](https://longbridge.com) brokerage. **145 tools** across real-time quotes, options, order routing, fundamentals, analyst ratings, calendars, IPO, price alerts, DCA plans, portfolio analytics and community sharelists — covering **US and HK markets**. Built with Rust using [rmcp](https://github.com/anthropics/rmcp) and [axum](https://github.com/tokio-rs/axum).1718## Features1920- **145 MCP tools** across 13 categories: quotes, trading, fundamentals, screener, market data, calendars, IPO, portfolio, alerts, content, account statements, DCA, and community sharelists21- **Stateless architecture** -- each request carries a Bearer token forwarded directly to the Longbridge SDK; no server-side sessions or database22- **OAuth 2.1 resource metadata** compliant with RFC 9728, pointing clients to Longbridge OAuth for authorization23- **JSON response transformation** -- field names normalized to snake_case, timestamps converted to RFC 3339, internal counter_id values mapped to human-readable symbols24- **Prometheus metrics** for monitoring tool calls, latency, and errors25- **Configurable** via CLI arguments or a JSON config file (CLI takes precedence)2627## Connect from an MCP client2829Longbridge operates a hosted endpoint at `https://openapi.longbridge.com/mcp`, so most users don't need to run their own server — just point your MCP client at it and complete OAuth when prompted. Authorization is auto-discovered via RFC 9728.3031### Claude Desktop3233Add to `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or the equivalent on your OS:3435```json36{37 "mcpServers": {38 "longbridge": {39 "url": "https://openapi.longbridge.com/mcp"40 }41 }42}43```4445Restart Claude Desktop. On first tool invocation it will open a browser to complete the Longbridge OAuth flow.4647### Claude Code4849```bash50claude mcp add --transport http longbridge https://openapi.longbridge.com/mcp51```5253### Zed5455Add to your Zed `settings.json` (open with `zed: open settings`):5657```json58{59 "context_servers": {60 "longbridge": {61 "url": "https://openapi.longbridge.com/mcp"62 }63 }64}65```6667On first use, Zed will open a browser to complete the Longbridge OAuth flow.6869### Cursor / Cline / Windsurf / other MCP clients7071Point the client at `https://openapi.longbridge.com/mcp` using transport `streamable-http`. OAuth is auto-discovered via RFC 9728; no manual token required.7273---7475## Self-hosting7677Prefer running your own instance? Use Docker or build from source.7879### Docker (recommended)8081```bash82docker run -p 8443:8443 \83 -v /path/to/certs:/certs:ro \84 ghcr.io/longbridge/longbridge-mcp \85 --bind 0.0.0.0:8443 \86 --base-url https://mcp.example.com \87 --tls-cert /certs/cert.pem \88 --tls-key /certs/key.pem89```9091> **Important:** When deploying to a public network, you **must** set `--base-url` to the externally reachable URL of your server (e.g. `https://mcp.example.com`). This URL is returned in the OAuth protected resource metadata and used by MCP clients to discover the authorization server. If not set, it defaults to `http://localhost:{port}` which will not work for remote clients.9293### Build from source9495```bash96cargo build --release97./target/release/longbridge-mcp98```99100### Configure101102Create a config file at `~/.longbridge/mcp/config.json` (optional):103104```json105{106 "bind": "127.0.0.1:8000",107 "base_url": "https://mcp.example.com",108 "log_dir": "/var/log/longbridge-mcp"109}110```111112## Configuration113114| Option | Config Key | CLI Flag | Default | Description |115|--------|-----------|----------|---------|-------------|116| Bind address | `bind` | `--bind` | `127.0.0.1:8000` | HTTP server listen address |117| Base URL | `base_url` | `--base-url` | auto | Public base URL for resource metadata |118| Log directory | `log_dir` | `--log-dir` | *(stderr)* | Directory for rolling log files |119| TLS certificate | `tls_cert` | `--tls-cert` | *(none)* | PEM certificate file for HTTPS |120| TLS private key | `tls_key` | `--tls-key` | *(none)* | PEM private key file for HTTPS |121122CLI arguments override config file values. The config file is read from `~/.longbridge/mcp/config.json` (override with `LONGBRIDGE_MCP_CONFIG_DIR`).123124When `tls_cert` and `tls_key` are both set, the server runs HTTPS. Otherwise it falls back to HTTP. The `base_url` defaults to `https://localhost:{port}` with TLS or `http://localhost:{port}` without.125126### Environment Variables127128These are **advanced settings** — most users do not need to change them. They are primarily useful for connecting to non-production Longbridge environments or debugging SDK internals.129130| Variable | Default | Description |131|----------|---------|-------------|132| `LONGBRIDGE_MCP_CONFIG_DIR` | `~/.longbridge/mcp` | Config file directory |133| `LONGBRIDGE_HTTP_URL` | `https://openapi.longbridge.com` | Longbridge API base URL (also used for OAuth metadata) |134| `LONGBRIDGE_QUOTE_WS_URL` | `wss://openapi-quote.longbridge.com/v2` | Quote WebSocket endpoint |135| `LONGBRIDGE_TRADE_WS_URL` | `wss://openapi-trade.longbridge.com/v2` | Trade WebSocket endpoint |136| `LONGBRIDGE_LOG_PATH` | *(none)* | SDK internal log path |137138## Authentication139140The server expects a Longbridge OAuth access token in the `Authorization: Bearer <token>` header. On missing or invalid auth, it returns 401 with a `WWW-Authenticate` header pointing to the protected resource metadata endpoint, which in turn directs MCP clients to the Longbridge OAuth authorization server.141142## Claude Code integration143144The one-liner in [Connect → Claude Code](#claude-code) gets you connected. Below are the extra commands you'll reach for while developing against this server.145146```bash147# Hosted — use this unless you have a reason not to148claude mcp add --transport http longbridge https://openapi.longbridge.com/mcp149150# Local self-hosted instance (see Self-hosting above)151claude mcp add --transport http longbridge-local http://localhost:8000/mcp152153# Inspect154claude mcp list # registered servers155claude mcp get longbridge # config + auth status of one server156claude mcp remove longbridge # unregister157158# Re-trigger OAuth (e.g. after token revocation on the Longbridge side)159claude mcp logout longbridge160```161162On the first tool invocation, Claude Code reads the `WWW-Authenticate` challenge from the server, fetches `/.well-known/oauth-protected-resource` (RFC 9728), and opens your browser for the Longbridge OAuth flow. Access tokens are cached per-session and refreshed automatically.163164## API Endpoints165166| Method | Path | Description |167|--------|------|-------------|168| GET | `/.well-known/oauth-protected-resource` | Protected Resource Metadata (RFC 9728) |169| GET | `/metrics` | Prometheus metrics |170| POST/GET/DELETE | `/mcp` | MCP Streamable HTTP endpoint (requires Bearer token) |171172## Tool Categories173174| Category | Count | Description |175|----------|-------|-------------|176| **Quote** | 32 | Real-time and historical quotes, candlesticks, depth, brokers, options, warrants, watchlists, capital flow, market temperature, short positions, option volume |177| **Trade** | 14 | Order submission/cancellation/replacement, positions, balance, executions, cash flow, margin |178| **Fundamental** | 19 | Financial statements, business segments, institutional views, industry peers, earnings snapshot, dividends, EPS forecasts, valuations, company info, shareholders, corporate actions |179| **Market** | 10 | Market status, industry rank, broker holdings, A/H premium, trade statistics, anomalies, index constituents |180| **IPO** | 8 | IPO subscriptions, calendar, listed stocks, order detail, profit/loss analysis |181| **Content** | 8 | News, discussion topics, filing details |182| **DCA** | 9 | Dollar-cost averaging plan create/update/pause/resume/stop, execution history, statistics, and support check |183| **Sharelist** | 8 | Community sharelist CRUD, member add/remove/sort, popular lists |184| **Alert** | 5 | Price alert CRUD (add, delete, enable, disable, list) |185| **ATM** | 3 | Bank cards, withdrawal records, deposit records |186| **Portfolio** | 3 | Exchange rates, profit/loss analysis with optional date range |187| **Search** | 2 | News search, community topic search |188| **Statement** | 2 | Account statement listing and export |189| **Calendar** | 1 | Finance calendar events (earnings, dividends, IPOs, macro data, market closures) |190| **Utility** | 1 | Current UTC time |191192## Prometheus Metrics193194| Metric | Type | Description |195|--------|------|-------------|196| `mcp_tool_calls_total` | Counter | Total tool invocations (label: `tool_name`) |197| `mcp_tool_call_duration_seconds` | Histogram | Tool call latency (label: `tool_name`) |198| `mcp_tool_call_errors_total` | Counter | Tool call error count (label: `tool_name`) |199200## Project Structure201202```203src/204 main.rs CLI args, config loading, axum server setup205 auth/206 mod.rs Router composition, MCP service wiring207 metadata.rs Protected Resource Metadata (RFC 9728)208 middleware.rs Bearer token extraction middleware209 tools/210 mod.rs MCP tool definitions and ServerHandler impl211 quote.rs Quote tools (SDK QuoteContext)212 trade.rs Trade tools (SDK TradeContext)213 fundamental.rs Fundamental data, business segments, industry peers (HTTP API)214 market.rs Market data, industry rank, broker holdings, anomalies (HTTP API)215 ipo.rs IPO subscriptions, calendar, orders, profit/loss (HTTP API)216 search.rs News and topic search (HTTP API)217 atm.rs Bank cards, withdrawals, deposits (HTTP API)218 calendar.rs Finance calendar (HTTP API)219 portfolio.rs Portfolio analytics (HTTP API)220 dca.rs Dollar-cost averaging / recurring investment (HTTP API)221 sharelist.rs Community sharelist management (HTTP API)222 alert.rs Price alerts (HTTP API)223 content.rs News, topics, filings (SDK ContentContext + HTTP)224 statement.rs Account statements (HTTP API)225 http_client.rs Shared HTTP client helpers226 parse.rs Parameter parsing helpers227 serialize/ JSON transformation (snake_case, timestamps, counter_id -> symbol)228 counter.rs Symbol <-> counter_id bidirectional conversion (ST/ETF/IX/BK)229 metrics.rs Prometheus metric definitions and /metrics handler230 error.rs Unified error type (thiserror)231```232233## Development234235```bash236# Format237cargo +nightly fmt238239# Lint240cargo clippy241242# Test243cargo test244```245246## License247248See [LICENSE](LICENSE) for details.249
Full transparency — inspect the skill content before installing.