Content
# A-Share MCP Server
Based on the free API of East Fortune, providing a full-dimensional A-share market MCP server, with 22 tools covering six scenarios: market trends, capital flows, fundamentals, sectors, anomalies, and risk control. No API key required, compile and use.
## Quick Start
### Build
```bash
cd stock
go mod tidy
go build -o stock .
```
### Configure Claude Desktop
Edit the configuration file:
- macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
- Windows: `%APPDATA%\Claude\claude_desktop_config.json`
- Linux: `~/.config/Claude/claude_desktop_config.json`
```json
{
"mcpServers": {
"a-stock": {
"command": "/absolute/path/to/stock"
}
}
}
```
Restart Claude Desktop, and the hammer icon appears in the bottom left corner, indicating a successful connection.
### Configure Claude Code
```bash
claude mcp add a-stock /absolute/path/to/stock
```
## Project Structure
```
stock/
├── go.mod
├── README.md
├── main.go # Entry: server initialization + tool registration
├── handlers.go # All handler functions + parameter parsing assistance
└── eastmoney/ # East Fortune API client (split by domain)
├── client.go # HTTP client + 6 general query functions + URL constants + parsing assistance
├── quote.go # Market trends: search, real-time quotes, K-line, index
├── flow.go # Capital flows: individual stock capital flows, northbound funds, margin trading
├── fundamental.go # Fundamentals: financial indicators, top shareholders, dividend history, research reports
├── market.go # Market: sectors, rankings, limit up/down, dragon and tiger list, block trades, lockup expiry
├── news.go # News: individual stock news
└── eastmoney_test.go # Full integration test (22 tools)
```
**Design Principles:**
- `main.go` only handles server startup and tool metadata registration, without business logic
- `handlers.go` is responsible for MCP protocol layer parameter parsing and result serialization, calling the `eastmoney` package
- `eastmoney/` is a pure API client, independent of MCP, and can be reused
- `eastmoney/` is split into files by domain, with each file having a single responsibility
- API URL, parameter construction, and response parsing are all concentrated in `client.go`, with business functions only declaring query parameters and field mappings
## Tool List
### Basic Market Trends
| Tool | Function | Required Parameters | Optional Parameters |
|------|----------|---------|---------|
| `search_stock` | Fuzzy search stocks | `keyword` | — |
| `get_quote` | Real-time market trends (price/涨跌/PE/PB/market value) | `code` | — |
| `get_kline` | K-line historical data (前复权) | `code` | `period`(daily/weekly/monthly), `limit` |
| `get_index` | Major index market trends + number of rising and falling stocks | — | — |
### Capital Flows
| Tool | Function | Required Parameters | Optional Parameters |
|------|----------|---------|---------|
| `get_money_flow` | Individual stock capital flows (主力/大单/中单/小单) | `code` | — |
| `get_money_flow_history` | Individual stock capital flow trends over the past N days | `code` | `limit` |
| `get_north_flow` | Northbound funds daily net purchases | — | `limit` |
| `get_north_holdings` | Northbound funds individual stock holdings ranking | — | `market`(sh/sz), `limit` |
| `get_margin_data` | Two-city margin trading balance summary | — | `limit` |
| `get_stock_margin` | Individual stock margin trading data | `code` | `limit` |
### Fundamentals
| Tool | Function | Required Parameters | Optional Parameters |
|------|----------|---------|---------|
| `get_financial` | Core financial indicators (ROE/毛利率/净利率/营收增速) | `code` | — |
| `get_top_holders` | Top ten circulating shareholders (持股/占比/增减/性质) | `code` | — |
| `get_dividend_history` | Dividend history | `code` | `limit` |
| `get_analyst_ratings` | Institutional ratings/research reports (券商/目标价) | `code` | `limit` |
### Sectors
| Tool | Function | Required Parameters | Optional Parameters |
|------|----------|---------|---------|
| `get_sectors` | Industry/concept sector rise and fall ranking | `type`(industry/concept) | `limit` |
| `get_sector_stocks` | Sector constituent stock list | `sector_code` | `limit` |
> Usage process: First call `get_sectors` to obtain sector codes, then use `get_sector_stocks` to query constituent stocks.
### Rankings and Anomalies
| Tool | Function | Required Parameters | Optional Parameters |
|------|----------|---------|---------|
| `get_ranking` | Rise/fall/volume rankings | `type`(top/bottom/volume/amount/turnover) | `limit` |
| `get_limit_stocks` | Limit up/down analysis (连板/封板/题材) | `type`(up/down) | `limit` |
| `get_dragon_tiger` | Dragon and tiger list (净买入/上榜原因) | — | `limit` |
### Leverage and Risk Control
| Tool | Function | Required Parameters | Optional Parameters |
|------|----------|---------|---------|
| `get_block_trades` | Block trades (折溢价/买卖方) | — | `limit` |
| `get_lockup_expiry` | Lockup expiry calendar | — | `limit` |
### News
| Tool | Function | Required Parameters | Optional Parameters |
|------|----------|---------|---------|
| `get_stock_news` | Individual stock related news | `code` | `limit` |
## Usage Examples
Talk to Claude in natural language, and it will automatically combine and call the appropriate tools.
### Query Class
**Search Stocks**
```
"Help me find stocks related to lithium batteries"
→ search_stock("锂电池")
```
**Real-time Market Trends**
```
"What is the current price of Maotai?"
→ search_stock("Maotai") → get_quote("600519")
Return: price, rise and fall, trading volume, turnover rate, PE, PB, total market value, circulating market value
```
**K-line Trend**
```
"Check the daily K-line of BYD for the past month"
→ get_kline("002594", period="daily", limit=22)
"Cherish the weekly K-line trend of CATL"
→ get_kline("300750", period="weekly", limit=20)
"Guizhou Maotai's monthly K-line for the past year"
→ get_kline("600519", period="monthly", limit=12)
```
**Major Index**
```
"How is the market today?"
→ get_index()
Return: Shanghai Composite Index, Shenzhen Component Index, ChiNext Index, Science and Technology Innovation 50, Shanghai and Shenzhen 300, CSI 500, including the number of rising and falling stocks
```
### Capital Flows
**Individual Stock Capital Flows**
```
"What is the capital flow of CATL today?"
→ get_money_flow("300750")
Return: main force/super large single/large single/medium single/small single inflow and outflow and net amount
"Trend of Ping An Bank's capital flows over the past 10 days"
→ get_money_flow_history("000001", limit=10)
```
**Northbound Funds**
```
"What are northbound funds buying recently?"
→ get_north_flow(limit=10) → get_north_holdings(market="sh") → get_north_holdings(market="sz")
"Northbound funds net inflow for the past 5 days"
→ get_north_flow(limit=5)
Return: Shanghai Stock Connect/Shenzhen Stock Connect daily net purchase, cumulative net purchase
```
**Margin Trading**
```
"How is the recent leverage fund sentiment?"
→ get_margin_data(limit=10)
Return: two-city margin trading balance summary trend
"Check Ping An Bank's margin trading data"
→ get_stock_margin("000001", limit=10)
Return: financing purchase amount/balance, securities lending sales volume/balance
```
### Fundamental Analysis
**Financial Indicators**
```
"How is BYD's financial situation?"
→ get_financial("002594")
Return: ROE, gross margin, net profit margin, revenue growth rate, net profit growth rate, asset-liability ratio, EPS
```
**Shareholder Analysis**
```
"Who are the top ten circulating shareholders of CATL?"
→ get_top_holders("300750")
Return: shareholder name, holding quantity, proportion, increase/decrease, shareholder nature (fund/personal/QFII)
```
**Dividend History**
```
"Maotai's historical dividend situation"
→ get_dividend_history("600519", limit=10)
Return: distribution plan, ex-rights and ex-dividend date, dividend rate
```
**Institutional Ratings**
```
"What do securities firms think of CATL?"
→ get_analyst_ratings("300750", limit=10)
Return: securities firm, analyst, rating (buy/增持/中性), target price, research report title
```
### Sector Analysis
**Sector Ranking**
```
"Which industry sectors rose well today?"
→ get_sectors(type="industry", limit=20)
"What are the popular concepts recently?"
→ get_sectors(type="concept", limit=20)
Return: sector name, rise and fall amplitude, main capital net inflow, leading stock
```
**Sector Constituent Stocks**
```
"Which stocks are worth paying attention to in the solid-state battery sector?"
→ get_sectors(type="concept") → find sector code → get_sector_stocks("BK0477", limit=20)
Return: constituent stock list, including price, rise and fall amplitude, trading volume, main capital
```
### Rankings and Anomalies
**Rise and Fall Ranking**
```
"Which stocks rose the most today?"
→ get_ranking(type="top", limit=20)
"Which stocks fell the most today?"
→ get_ranking(type="bottom", limit=20)
"Which stocks had the largest trading volume today?"
→ get_ranking(type="amount", limit=20)
"Which stocks had the highest turnover rate today?"
→ get_ranking(type="turnover", limit=20)
```
**Limit Up/Down**
```
"Which stocks hit the limit up today?"
→ get_limit_stocks(type="up", limit=30)
Return: limit up stock list, including consecutive board days, sealing time, opening times, industry
"Which stocks hit the limit down today?"
→ get_limit_stocks(type="down", limit=30)
```
**Dragon and Tiger List**
```
"What is on the dragon and tiger list today?"
→ get_dragon_tiger(limit=20)
Return: listed stocks, net purchase, buying and selling total, listed reasons, turnover rate
```
### Risk Control and Inspection
**Block Trades**
```
"Recent block trades?"
→ get_block_trades(limit=20)
Return: transaction price, discount rate, trading volume, buying and selling party
```
**Lockup Expiry**
```
"Recent lockup expiry?"
→ get_lockup_expiry(limit=20)
Return: lockup expiry date, lockup quantity, proportion of total share capital, lockup type
```
### News
**Individual Stock News**
```
"What are the recent news about Ping An Bank?"
→ get_stock_news("000001", limit=10)
Return: title, source, date, summary
```
### Comprehensive Scenarios
**Individual Stock Comprehensive Analysis**
```
"Help me comprehensively analyze CATL"
→ search_stock → get_quote → get_financial → get_money_flow → get_kline
→ get_top_holders → get_analyst_ratings → get_stock_news
```
**Market Sentiment Judgment**
```
"How is the market sentiment today?"
→ get_index → get_north_flow → get_margin_data → get_limit_stocks(up) → get_sectors(concept)
```
**Short-term Opportunity Scanning**
```
"What are the short-term opportunities today?"
→ get_limit_stocks(up) → get_dragon_tiger → get_ranking(turnover) → get_sectors(concept)
```
**Individual Stock Risk Warning**
```
"Help me check if this stock has risks"
→ get_lockup_expiry → get_stock_margin → get_top_holders → get_block_trades → get_dividend_history
```
## Parameter Description
| Parameter | Format | Description |
|------|------|------|
| `code` | 6-digit number | stock code, such as `600519`(Maotai), `300750`(CATL) |
| `keyword` | string | supports name, code, and pinyin initial letter fuzzy matching |
| `period` | enumeration | K-line cycle: `daily` / `weekly` / `monthly` |
| `limit` | positive integer | return quantity, each interface has a different upper limit, exceeding automatic truncation |
| `sector_code` | string | sector code (such as `BK0477`), obtained from `get_sectors` return value |
| `market` | enumeration | northbound holdings market: `sh`(Shanghai Stock Connect) / `sz`(Shenzhen Stock Connect) |
| `type` | enumeration | each tool has different enumeration values, see the above table |
## Data Source
All data comes from East Fortune's public market interface, free and no registration required. Domain name and base URL are uniformly defined in `client.go`:
| Domain | Purpose | Corresponding Query Function |
|------|------|-------------|
| `push2.eastmoney.com` | real-time market trends, capital flows, sectors, rankings, financial indicators | `Push2StockGet` / `ClistGet` / `Push2DiffGet` |
| `push2his.eastmoney.com` | historical K-line, historical capital flows | `Push2HisGet` |
| `push2ex.eastmoney.com` | limit up/down stock pool | `basePush2Ex` constant |
| `searchapi.eastmoney.com` | stock search | `baseSearch` constant |
| `datacenter-web.eastmoney.com` | data center (dragon and tiger list/margin trading/block trades/lockup expiry/northbound holdings/shareholders/dividends) | `DatacenterGet` |
| `reportapi.eastmoney.com` | institutional ratings/research reports | `baseReport` constant |
| `search-api-web.eastmoney.com` | news search | `baseNews` constant |
**Known Limitations:**
- after-hours data usually updated by 15:30
- financial indicators only updated after financial report release
- high-frequency calls may trigger current limiting, recommend controlling reasonable frequency
- data only for reference, not constituting investment advice
## Extension Guide
**Adding New Tools in Three Steps:**
1. add API function in corresponding file under `eastmoney/` (struct definition + general query + field mapping)
2. add handler function in `handlers.go` (parameter parsing → call API → return JSON)
3. add `s.AddTool(...)` registration in `main.go`'s `registerTools()`
**`client.go` General Query Function:**
| Function | Purpose | Applicable Interface |
|------|------|---------|
| `DatacenterGet` | datacenter-web report query | dragon and tiger list, block trades, lockup expiry, northbound holdings, margin trading, shareholders, dividends, etc. |
| `ClistGet` | push2 list ranking query | sector ranking, constituent stocks, rise and fall ranking |
| `Push2StockGet` | push2 single stock data query | real-time market trends, financial indicators, capital flows |
| `Push2DiffGet` | push2 multi-target diff query | index market trends |
| `Push2HisGet` | push2his K-line class query | K-line, historical capital flows |
Adding new datacenter-like interfaces only requires declaring `DatacenterQuery`, no need to write URL manually:
```go
data, err := DatacenterGet(DatacenterQuery{
ReportName: "RPT_SOME_REPORT",
SortColumns: "TRADE_DATE",
SortTypes: "-1",
PageSize: limit,
Filter: fmt.Sprintf(`(SECURITY_CODE="%s")`, code),
})
```
**Extensible Directions:**
- financial report details (balance sheet/income statement/cash flow statement)
- ETF/convertible bond market trends
- Hong Kong Stock Connect target market trends
- futures/options data
- Level 2 disk data (requires paid data source)
## License
MIT
MCP Config
Below is the configuration for this MCP Server. You can copy it directly to Cursor or other MCP clients.
mcp.json
Connection Info
You Might Also Like
No recommendations available