Skip to main content
Glama
kookmin-stock

kookmin-stock

Kookmin MCP Stock Agent

Kookmin University Assignment Β· "Boosting Impact with Hermes + Custom MCP Server"

We prove how work quality changes through 3 experiments by attaching a custom MCP server to the domestic stock recommendation Hermes agent created in the previous assignment.

🎯 What's Included

Output

Path

Description

MCP Server (Normal)

src/mcp_stock/server.py

FastMCP stdio, 6 tools

MCP Server (Broken Version)

src/mcp_stock/server_broken.py

Incorrect description / Timeout / Empty response

30-second Demo

src/experiments/exp1_demo.py

Sequence output for recording

Experiment β‘‘ Result Comparison

src/experiments/exp2_quality.py

NO MCP / GOOD / BROKEN comparison

Experiment β‘’ Pattern Comparison

src/experiments/exp3_orchestration.py

Single / Planner+Executor / Parallel

Presentation Slides (spec)

slides/slides.md

Paste into another AI to generate PPT

Result Outputs

results/exp2_*, results/exp3_*

Auto-generated tables, CSVs, logs

Related MCP server: pykrx-mcp

βš™οΈ Installation

Python 3.10+ (Test environment 3.13).

python -m venv .venv
source .venv/bin/activate
pip install -e .

▢️ Execution

# 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-Second Demo Recording

Actions by timecode are organized in demo/demo_script.md. The simplest path:

./demo/record_demo.sh         # QuickTime/Cmd+Shift+5 둜 ν™”λ©΄ λ…Ήν™”ν•˜λ©΄μ„œ μ‹€ν–‰
./demo/record_demo.sh --asciinema   # ν…μŠ€νŠΈ 캑처 (asciinema ν•„μš”)

πŸ§ͺ Experiment β‘  β€” MCP Server (6 Tools)

Tool

Input

Output

get_market_overview(date)

'today' / YYYY-MM-DD

{kospi:{close, changePct, tradingValueKrw}, kosdaq:{...}}

get_top_gainers(market, top_n)

KOSPI/KOSDAQ, 1..50

Top N stocks

get_stock_quote(ticker)

Code or Korean name

close / changePct / volume / per / pbr

get_recent_news(query, top_n)

Keyword or stock name

Headline + positivityScore

get_fundamentals(ticker)

Code or Korean name

per / pbr / eps / bps / roe

recommend_buys(market, top_n, criteria)

KOSPI/KOSDAQ

scoreBreakdown + rationale

Data: Naver Finance crawling single source (src/mcp_stock/sources/naver.py). Free, no key required.

  • Indices: polling.finance.naver.com/api/realtime/domestic/index/{KOSPI|KOSDAQ} JSON

  • Top Gainers: finance.naver.com/sise/sise_rise.naver?sosok={0|1} HTML

  • Stock Details / PERΒ·EPSΒ·PBRΒ·Dividends: finance.naver.com/item/main.naver?code=... (Stable emphasis tags like id="_per")

  • News by Stock: finance.naver.com/item/news_news.naver?code=...

  • Safe operation with automatic fallback snapshots during market holidays or Naver page changes.

πŸ§ͺ Experiment β‘‘ β€” Tool Success/Failure Quality Comparison

exp2_quality.py runs the same user questions across three environments and auto-generates tables and failure logs.

  • (a) NO MCP β€” 0 tools. LLM answers only with training data β†’ Hallucinations, lack of evidence.

  • (b) GOOD MCP β€” Normal custom server. 12 tool calls, cites 4 positive keywords.

  • (c) BROKEN MCP β€” As defined in server_broken.py:

    • get_top_gainers description incorrectly written as "Top losers" β†’ Model misselection

    • get_recent_news triggers TimeoutError after time.sleep(5)

    • get_fundamentals returns an empty dict

Results:

  • results/exp2_quality_table.md β€” Comparison table

  • results/exp2_failure_logs.md β€” Failed call traces + response body

  • results/exp2_summary.json β€” Original statistics

πŸ§ͺ Experiment β‘’ β€” 3 Orchestration Patterns

Pattern

Description

Token Characteristics

Response Time Characteristics

Single

Accumulate tool results in one loop

Input tokens ↑↑

Slowest

Planner + Executor

Planner creates sequence, executor summarizes results

Input tokens ↓

Medium

Parallel sub-agents

KOSPI / KOSDAQ / NEWS sub-agents run simultaneously

Input tokens ↓↓

Fastest

Results:

  • results/exp3_benchmark.csv β€” Wide CSV for bar charts

  • results/exp3_pattern_table.md β€” Table + Retrospective

  • results/exp3_summary.json β€” Full trace per pattern

πŸ€– LLM Integration β€” Hermes / Other Hosts

This repository is designed to produce tokens and traces via deterministic simulation even without LLM API keys. To attach to actual Hermes / Claude Desktop / Cursor:

1) Use as Hermes Host (Running experiments β‘‘β‘’ with a real LLM)

Simply fill in _callHermes() in src/experiments/runner/hermes_runner.py.

# TODO(user): replace this body with the real Hermes call.
import httpx
response = httpx.post(self.endpoint, headers=..., json=...)
return response.json()

After setting environment variables HERMES_ENDPOINT, HERMES_API_KEY, replace the AgentRunner instance with HermesRunner().

2) Use only tools in Claude Desktop / Cursor

Add to Claude Desktop's claude_desktop_config.json or Cursor MCP settings:

{
  "mcpServers": {
    "kookmin-stock": {
      "command": "python",
      "args": ["-m", "mcp_stock.server"],
      "cwd": "/path/to/Kookmin-University-MCP",
      "env": { "PYTHONPATH": "/path/to/Kookmin-University-MCP/src" }
    }
  }
}

πŸ“‘ Creating PPT

Paste slides/slides.md directly into another AI. Example prompt:

The following markdown is a 12-slide spec for a 5-minute presentation. Please create PowerPoint slides based on the # Slide N headers. Represent ### Visual blocks as mermaid diagrams or tables if possible, and put ### Speaker Notes into the slide notes area.

πŸ“€ Submission Flow

  1. Update results with python -m experiments.exp2_quality && python -m experiments.exp3_orchestration

  2. Record 30-second demo with ./demo/record_demo.sh β†’ demo/demo.mov

  3. GitHub push (Record repository URL in README and slide 6)

  4. Send GitHub URL + slides + demo video to kts123@kookmin.ac.kr (Deadline 5/14 23:59:59)

πŸ“ Directory Tree

.
β”œβ”€β”€ 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

πŸ›Ÿ Troubleshooting

Symptom

Cause

Response

naver detail fetch failed for XXXXXX

Stock not on Naver page or structure changed

Uses automatic fallback snapshot β€” operates normally

httpx.ConnectError

Network offline

All tools operate safely with fallback snapshots

Korean characters broken

Terminal font

D2 Coding / Pretendard / SF Mono recommended

Call on holiday/weekend

Not a business day

Polling API returns the last closing price as is

Available Tools

6 tools
get_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

    A3.8/5.0

    Scored across 6 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose: fundamentals, market overview, news, stock quote, top gainers, and a composite recommendation. No overlap or ambiguity.

    Naming Consistency4/5

    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.

    Tool Count5/5

    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.

    Completeness4/5

    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.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables 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.
      27 npm
      1
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides 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.
      57 PyPI
      3
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Provides 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.
      9
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      An 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