🦀 ☁️ - Real-time stock market data, analysis and trading via the LongPort OpenAPI
LongPort MCP Server
以下摘录自该仓库的 README(片段) · 在 GitHub 读完整 README →
Official MCP server for the LongPort 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.
Features
- **145 MCP tools** across 13 categories: quotes, trading, fundamentals, screener, market data, calendars, IPO, portfolio, alerts, content, account statements, DCA, and community sharelists
- **Stateless architecture** -- each request carries a Bearer token forwarded directly to the LongPort SDK; no server-side sessions or database
- **OAuth 2.1 resource metadata** compliant with RFC 9728, pointing clients to LongPort OAuth for authorization
- **JSON response transformation** -- field names normalized to snake_case, timestamps converted to RFC 3339, internal counter_id values mapped to human-readable symbols
- **Prometheus metrics** for monitoring tool calls, latency, and errors
- **Configurable** via CLI arguments or a JSON config file (CLI takes precedence)
Connect from an MCP client
LongPort operates a hosted endpoint at https://mcp.longportapp.com, 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.
Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or the equivalent on your OS:
Restart Claude Desktop. On first tool invocation it will open a browser to complete the LongPort OAuth flow.
Claude Code
Zed
Add to your Zed settings.json (open with zed: open settings):
On first use, Zed will open a browser to complete the LongPort OAuth flow.
Cursor / Cline / Windsurf / other MCP clients
Point the client at https://mcp.longportapp.com using transport streamable-http. OAuth is auto-discovered via RFC 9728; no manual token required.
---
Self-hosting
Prefer running your own instance? Use Docker or build from source.
Docker (recommended)
> **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.
Build from source
Configure
Create a config file at ~/.longport/mcp/config.json (optional):
Configuration
| Option | Config Key | CLI Flag | Default | Description |
|--------|-----------|----------|---------|-------------|
| Bind address | bind | --bind | 127.0.0.1:8000 | HTTP server listen address |
| Base URL | base_url | --base-url | auto | Public base URL for resource metadata |
| Log directory | log_dir | --log-dir | *(stderr)* | Directory for rolling log files |
| TLS certificate | tls_cert | --tls-cert | *(none)* | PEM certificate file for HTTPS |
| TLS private key | tls_key | --tls-key | *(none)* | PEM private key file for HTTPS |
CLI arguments override config file values. The config file is read from ~/.longport/mcp/config.json (override with LONGPORT_MCP_CONFIG_DIR).
When 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.
Environment Variables
These are **advanced settings** — most users do not need to change them. They are primarily useful for connecting to non-production LongPort environments or debugging SDK internals.
| Variable | Default | Description |