kookmin-stock
Kookmin MCP 股票代理
国民大学作业 · “用 Hermes + MCP 自制服务器提升影响力”
在上一个作业中制作的韩国股票推荐 Hermes 代理的基础上,挂载自制 MCP 服务器,并通过 3 个实验证明工作质量的变化。
🎯 包含内容
产出物 | 路径 | 说明 |
MCP 服务器 (正常) |
| FastMCP stdio, 6 种工具 |
MCP 服务器 (损坏版本) |
| 错误的 description / 超时 / 空响应 |
30秒动作演示 |
| 录制用序列输出 |
实验 ② 结果对比 |
| NO MCP / GOOD / BROKEN 对比 |
实验 ③ 模式对比 |
| Single / Planner+Executor / Parallel |
演示文稿(spec) |
| 直接粘贴给其他 AI 生成 PPT |
结果产出物 |
| 自动生成的表格·CSV·日志 |
Related MCP server: pykrx-mcp
⚙️ 安装
Python 3.10+ (测试环境 3.13)。
python -m venv .venv
source .venv/bin/activate
pip install -e .▶️ 运行
# 1) MCP 서버 검증 (서버는 stdio라 호스트가 붙어야 의미 있음 — Ctrl+C로 종료)
python -m mcp_stock.server
# 2) 30초 동작 데모 (실제로 돌려서 녹화)
python -m experiments.exp1_demo
# 또는 ./demo/record_demo.sh
# 3) 실험 ② 성공/실패 비교 → results/exp2_* 자동 생성
python -m experiments.exp2_quality
# 4) 실험 ③ Orchestration 토큰 비교 → results/exp3_* 자동 생성
python -m experiments.exp3_orchestration🎥 30秒演示录制
demo/demo_script.md 中整理了按时间码的操作。
最简单的路径:
./demo/record_demo.sh # QuickTime/Cmd+Shift+5 로 화면 녹화하면서 실행
./demo/record_demo.sh --asciinema # 텍스트 캡처 (asciinema 필요)🧪 实验 ① — MCP 服务器 (6 种工具)
工具 | 输入 | 输出 |
| 'today' / YYYY-MM-DD |
|
| KOSPI/KOSDAQ, 1..50 | 前 N 名股票 |
| 代码或韩文名称 | close / changePct / volume / per / pbr |
| 关键词或股票名称 | 标题 + |
| 代码或韩文名称 | per / pbr / eps / bps / roe |
| KOSPI/KOSDAQ | scoreBreakdown + rationale |
数据:Naver Finance 爬虫单一来源 (src/mcp_stock/sources/naver.py)。免费,无需 Key。
指数:
polling.finance.naver.com/api/realtime/domestic/index/{KOSPI|KOSDAQ}JSON涨跌幅前列:
finance.naver.com/sise/sise_rise.naver?sosok={0|1}HTML股票详情 / PER·EPS·PBR·分红:
finance.naver.com/item/main.naver?code=...(稳定的id="_per"等 emphasis 标签)个股新闻:
finance.naver.com/item/news_news.naver?code=...休市日 / Naver 页面变更时自动 fallback 快照,安全运行。
🧪 实验 ② — 工具成功/失败结果质量对比
exp2_quality.py 在三种环境下运行相同的用户提问,并自动生成表格和失败日志。
(a) NO MCP — 0 个工具。LLM 仅凭训练数据回答 → 幻觉·缺乏依据。
(b) GOOD MCP — 正常的自制服务器。调用工具 12 次,引用 4 个利好关键词。
(c) BROKEN MCP — 根据
server_broken.py定义:将
get_top_gainers的 description 错误写为“跌幅前列” → 模型误选get_recent_news在time.sleep(5)后发生TimeoutErrorget_fundamentals返回空 dict
结果:
results/exp2_quality_table.md— 对比表格results/exp2_failure_logs.md— 失败调用追踪 + 回答正文results/exp2_summary.json— 原始统计数据
🧪 实验 ③ — 编排 3 种模式
模式 | 说明 | Token 特性 | 响应时间特性 |
Single | 在一个循环内累积工具结果 | 输入 Token ↑↑ | 最慢 |
Planner + Executor | Planner 只制定调用序列,Executor 只总结结果 | 输入 Token ↓ | 中等 |
Parallel sub-agents | KOSPI / KOSDAQ / NEWS 子代理同时执行 | 输入 Token ↓↓ | 最快 |
结果:
results/exp3_benchmark.csv— 用于制作柱状图的 wide CSVresults/exp3_pattern_table.md— 表格 + 回顾results/exp3_summary.json— 各模式的完整追踪
🤖 LLM 联动 — Hermes / 其他主机
本仓库即使没有 LLM API Key,也能通过确定性模拟得出 Token 和追踪记录。 若要挂载到实际的 Hermes / Claude Desktop / Cursor:
1) 作为 Hermes 主机使用 (用真实 LLM 运行实验 ②③)
只需填充 src/experiments/runner/hermes_runner.py 中的 _callHermes()。
# TODO(user): replace this body with the real Hermes call.
import httpx
response = httpx.post(self.endpoint, headers=..., json=...)
return response.json()设置环境变量 HERMES_ENDPOINT, HERMES_API_KEY 后,
将 AgentRunner 实例替换为 HermesRunner()。
2) 在 Claude Desktop / Cursor 中仅使用工具
添加到 Claude Desktop 的 claude_desktop_config.json 或 Cursor MCP 设置中:
{
"mcpServers": {
"kookmin-stock": {
"command": "python",
"args": ["-m", "mcp_stock.server"],
"cwd": "/path/to/Kookmin-University-MCP",
"env": { "PYTHONPATH": "/path/to/Kookmin-University-MCP/src" }
}
}
}📑 制作 PPT
将 slides/slides.md 直接粘贴给其他 AI 即可。示例提示词:
以下 markdown 是 5 分钟演讲用的 12 页幻灯片 spec。 请以
# Slide N标题为单位制作 PowerPoint 幻灯片。### Visual块尽量用 mermaid 图表或表格直接表现,### Speaker Notes放入幻灯片备注区域。
📤 提交流程
通过
python -m experiments.exp2_quality && python -m experiments.exp3_orchestration更新结果通过
./demo/record_demo.sh录制 30 秒演示 →demo/demo.movGitHub push (在 README 和 slide 6 中记录仓库 URL)
发送邮件至
kts123@kookmin.ac.kr,包含 GitHub URL + slides + demo 视频 (截止日期 5/14 23:59:59)
📁 目录树
.
├── README.md
├── pyproject.toml / requirements.txt
├── demo/
│ ├── demo_script.md
│ └── record_demo.sh
├── results/ # 자동 생성
├── slides/slides.md
└── src/
├── mcp_stock/
│ ├── server.py
│ ├── server_broken.py
│ ├── data/ticker_map.py
│ ├── sources/naver.py # 네이버 금융 크롤러 (단일 데이터 소스)
│ └── tools/{market, quote, news, fundamentals, recommend}.py
├── experiments/
│ ├── exp1_demo.py
│ ├── exp2_quality.py
│ ├── exp3_orchestration.py
│ └── runner/{agent_base, mock_runner, hermes_runner}.py
└── utils/{logger, token_counter}.py🛟 故障排除
症状 | 原因 | 应对 |
| Naver 页面上没有该股票或结构变更 | 使用自动 fallback 快照 — 正常运行 |
| 网络离线 | 所有工具均通过 fallback 快照安全运行 |
韩文乱码 | 终端字体 | 推荐 D2 Coding / Pretendard / SF Mono |
休市日/周末调用 | 非营业日 | 轮询 API 会原样返回最后收盘价 |
Available Tools
6 toolsget_fundamentalsB
Return PER, PBR, EPS, BPS, ROE and dividend yield for a ticker.
Inputs: ticker (required).
get_market_overviewA
Return KOSPI and KOSDAQ index close, daily change percent, and trading value.
Args: date: 'today' or YYYY-MM-DD. Non-business days fall back to the most recent trading day automatically. Returns: {asOf, kospi:{close, changePct, tradingValueKrw}, kosdaq:{...}, source}
Inputs: date.
get_recent_newsA
Return recent Naver finance news headlines about a ticker or keyword.
Each item carries a positivityScore (sum of catalyst-keyword matches
minus negative-keyword matches) plus the matched keywords.
Args: query: ticker code, Korean stock name, or free-text keyword. top_n: 1..20.
Inputs: query (required), top_n. Returns: result
get_stock_quoteB
Return the most recent close, change percent, volume, PER and PBR for a ticker.
Args: ticker: 6-digit code (e.g. '005930') or Korean name (e.g. '삼성전자').
Inputs: ticker (required).
get_top_gainersA
Return the top N stocks ranked by daily change percent (descending).
Args: market: 'KOSPI' or 'KOSDAQ'. top_n: 1..50. Returns: List of {ticker, name, changePct, close, asOf}.
Inputs: market, top_n. Returns: result
recommend_buysA
Composite buy-recommendation tool.
Combines top gainers + per-ticker quote, news positivity, and fundamentals
into a ranked list. Each entry includes a transparent scoreBreakdown and
a Korean-language rationale so the LLM can quote the reasoning.
Args: market: 'KOSPI' or 'KOSDAQ'. top_n: 1..10. criteria: optional override of {minPositivityScore, maxPer, minRoe}.
Inputs: market, top_n, criteria. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool has a clearly distinct purpose: fundamentals, market overview, news, stock quote, top gainers, and a composite recommendation. No overlap or ambiguity.
Most tools follow a 'get_' prefix verb_noun pattern (e.g., get_fundamentals, get_market_overview). The exception is recommend_buys, which is still verb_noun but lacks the prefix, creating a minor inconsistency.
With 6 tools covering fundamental data, market overview, news, quotes, top gainers, and a recommend feature, the count is well-scoped for a stock information server.
The tool surface covers core stock information needs (fundamentals, quotes, news, top gainers, overview, and a composite recommendation). Minor gaps like historical prices or sector data are not critical for the stated purpose.
Maintenance
Related MCP Connectors
Financial data MCP server for global quotes, news, financials, funds, bonds, IPOs and macro data.
A Model Context Protocol server exposing real-time and historical Colombo Stock Exchange (CSE) data to AI agents and LLM applications. Provides quotes and OHLCV price history, full financial statements (income, balance sheet, cash flow), pre-computed technicals (moving averages, RS ratings, volume signals), macroeconomic indicators, corporate actions, and rule-based screening across CSE stocks and sector indices, everything needed to build CSE-aware trading assistants, research tools, and market-analysis agents. This is the official MCP server of www.ceyloncharts.com
Official Intrinio MCP server. US stock prices, options and fundamentals for AI agents.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to query real-time and historical Korean stock market data from KRX (Korea Exchange) including indices, stocks, ETFs, bonds, derivatives, and commodities via MCP tools and resources.49 npm1MIT

pykrx-mcpofficial
AlicenseNot gradedqualityDmaintenanceProvides Korean stock market data (KOSPI, KOSDAQ, KONEX) including prices, fundamentals, investor trading, short selling, and indices via MCP protocol, enabling natural language queries from AI agents like ChatGPT and Claude.66 PyPI3MIT- AlicenseAqualityDmaintenanceProvides Korean stock market data, including DART electronic disclosures and KRX trading information, enabling users to query company profiles, financial statements, and stock trade details via MCP clients.9MIT
- AlicenseNot gradedqualityDmaintenanceAn MCP server that retrieves Korean stock fundamentals and financial data from OpenDART, enabling LLMs to access corporate disclosures, financial statements, and dividend information.Apache 2.0