Purpose: LongPort MCP Server is the official MCP server for LongPort broker, allowing MCP clients (such as Claude Desktop, Zed, Cursor, Cline, Windsurf, etc.) to access market data, trading, and account data for the US and Hong Kong stock markets through standardized tool calls.
Main capabilities: Provides 145 MCP tools, divided into 13 categories: quotes, trading, fundamentals, screeners, market data, calendar, IPO, portfolio, alerts, content, account statements, dollar-cost averaging (DCA), and community watchlists. Written in Rust, based on rmcp and axum. The architecture is stateless; each request carries a Bearer token that is forwarded directly to the LongPort SDK, with no server-side session or database. Responses are JSON-converted: field names are normalized to snake_case, timestamps are converted to RFC 3339, and internal counter_id values are mapped to readable codes. Supports Prometheus metrics for monitoring tool calls, latency, and errors, and can be configured via CLI arguments or a JSON configuration file (CLI takes precedence).
Usage: LongPort provides a hosted endpoint https://mcp.longportapp.com,多数用户无需自建服务器,只需将 Point the MCP client to this address and complete OAuth authorization when prompted; authorization is automatically discovered via RFC 9728. For Claude Desktop, you can write it into claude_desktop_config.json and restart; the first time a tool is called, a browser will open to complete OAuth. For Zed, configure it in settings.json; the first use will likewise open a browser for authorization. Clients such as Cursor, Cline, and Windsurf use the streamable-http transport pointed at this endpoint, with OAuth automatically discovered and no manual token required. You can also use Docker or build your own instance from source; when deploying to the public internet, you must set --base-url to an externally accessible URL, otherwise the default http://localhost:{port} is invalid for remote clients. The configuration file is located at ~/.longport/mcp/config.json (can be overridden with LONGPORT_MCP_CONFIG_DIR). HTTPS is enabled when both tls_cert and tls_key are set, otherwise it falls back to HTTP.
Limitations and security: The server requires a LongPort OAuth access token in the Authorization: Bearer <token> header; if missing or invalid, it returns 401 with a WWW-Authenticate header pointing to the protected resource metadata endpoint. Requests and responses contain customer data (cash balances, positions, order history), and upstream SDK frames contain access tokens; the server caps log targets that might print this content, independently of RUST_LOG, so raising the log level (such as debug, trace) is safe. LONGPORT_MCP_LOG_PAYLOADS=1 removes the cap and is recommended only for use with local test accounts; LONGPORT_LOG_PATH causes the SDK to install a private subscriber that writes INFO events containing request and response bodies, and the server will warn at startup. Environment variables are advanced settings that most users do not need to change.