内容
# CSE MCP 服务器
科伦坡证券交易所公共 API 端点的 MCP 服务器,详见 `res/API_REFERENCE.md`。
## 已实现工具
- `scan_market`
- `get_sectors`
- `get_market_status`
- `get_market_summary`
- `get_top_gainers`
- `get_order_book`
- `get_stock_snapshot`
- `get_chart_data`
- `get_detailed_trades`
- `get_company_profile`
- `tradingView`
- `financials`
- `get_financial_reports`
- `get_noncompliance_list`
## 要求
- Node.js 18+(推荐 Node 20+)
## 安装
```bash
npm install
```
## 运行
```bash
npm start
```
服务器使用 stdio 传输,旨在由 MCP 客户端启动。
## 使用 MCP Inspector 运行
1. 安装依赖:
```bash
npm install
```
2. 启动 MCP Inspector 并附加此服务器:
```bash
npx @modelcontextprotocol/inspector node src/index.js
```
3. 在 Inspector 中,打开 `Tools` 选项卡并点击 `List Tools`。
4. 运行快速烟雾测试:
- `get_market_status` with `{}`
- `get_sectors` with `{}`
- `get_top_gainers` with `{}`
5. 对于基于符号的工具,尝试:
- `get_stock_snapshot` with `{"symbol":"JKH.N0000"}`
- `get_order_book` with `{"symbol":"JKH.N0000"}`
6. 在终端中使用 `Ctrl + C` 停止 inspector/服务器。
## 示例 MCP 客户端配置
```json
{
"mcpServers": {
"cse": {
"command": "node",
"args": ["/absolute/path/to/CSEMCPServer/src/index.js"]
}
}
}
```
## 可选环境变量
- `CSE_API_BASE_URL`(默认:`https://www.cse.lk/api`)
- `CSE_USER_AGENT`
- `CSE_ORIGIN`
- `CSE_REFERER`
## 备注
- 为以下内容实现 30 秒缓存:
- `tradeSummary`
- `allSectors`
- `dailyMarketSummery`
- `topGainers`
- 将类似数字的字符串(包括逗号分隔的值)转换为数字。
- 通过 `tradeSummary` 为接受 `symbol` 或 `stockId` 的工具解析 `symbol -> stockId`。