TWSEMCPServer CLAUDE.md

TWSEMCPServer CLAUDE.md is an instructions file for coding agents from twjackysu/TWSEMCPServer. It costs 3,379 tokens per session, scanned A, original, MIT.

Repository instructions for a Python server that provides Taiwan stock-market data through the Model Context Protocol, a standard way for AI tools to call external data services.

In plain words
What is it for?
Use it when adding or fixing tools for Taiwan stocks, exchange-traded funds, futures, options, company reports, trading data, or market indicators.
Why use it?
They document the available market-data sources, their limits, and which endpoints support historical or current information, reducing incorrect data requests.

Instructions file

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add instructions/twjackysu/twsemcpserver/claude-md
Clone the repo
git clone --depth 1 https://github.com/twjackysu/TWSEMCPServer

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for TWSEMCPServer CLAUDE.md

README.md
[![agentmods](https://agentmods.dev/badge/instructions/twjackysu/twsemcpserver/claude-md.svg)](https://agentmods.dev/instructions/twjackysu/twsemcpserver/claude-md)
Your own site
<a href="https://agentmods.dev/instructions/twjackysu/twsemcpserver/claude-md"><img src="https://agentmods.dev/badge/instructions/twjackysu/twsemcpserver/claude-md.svg" alt="Measured on agentmods" height="20"></a>
Per session 3,379 This file is loaded in full into every session.
When invoked 3,379 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.03379 $0.03379
Opus 5 $0.01690 $0.01690
Sonnet 5 $0.00676 $0.00676
Haiku 4.5 $0.00338 $0.00338

Measured 5d ago against content hash 77bb77a5d377, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

TWSEMCPServer CLAUDE.md scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

CLAUDE.md · 161 lines

How it starts

The opening of the file, as written. The whole thing — 161 lines — stays where its author put it; the contents beside it link to each section on GitHub.

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

TWStockMCPServer is a Model Context Protocol (MCP) server for Taiwan stock market data analysis. Built with FastMCP (Python) and requests. Data sources:

  • TWSE OpenAPI (openapi.twse.com.tw) — 143 tools: 公司治理、ESG、財報、交易、指數、券商
  • TWSE Web API (twse.com.tw) — 16 tools: 歷史日K、月均價、融資融券(/exchangeReport);估值(/rwd/zh/afterTrading/BWIBBU_d —— /exchangeReport/BWIBBU_ALL 會忽略 date 參數,只回最新交易日,不可用於歷史查詢);三大法人買賣超日報、個股明細(/rwd/zh/fund/T86);三大法人買賣金額、全市場收盤行情、市場成交量值、加權指數歷史、外資持股歷史(/rwd/zh/...,可查任意過去日期,與同名 openapi.twse.com.tw 端點僅回傳最近約12個交易日不同);個股月/年成交彙總、鉅額交易明細(無伺服器端股票篩選,本地端過濾)、融券借券餘額/成交(/rwd/zh/...)(legacy JSON,非 Swagger)
  • MIS 即時報價 (mis.twse.com.tw) — 1 tool: 盤中多股即時報價
  • TPEx OpenAPI (tpex.org.tw/openapi) — 3 tools: 上櫃日收盤、三大法人、本益比
  • TAIFEX OpenAPI (openapi.taifex.com.tw) — 16 tools: 三大法人系列、大額交易人部位、每日行情、選擇權分析(Delta/OI增減)、保證金、年月統計
  • TAIFEX 網站下載 (www.taifex.com.tw) — 9 tools: 期貨每日OHLC歷史、三大法人期貨部位歷史、Put/Call Ratio歷史、三大法人選擇權買賣權分計歷史、大額交易人未沖銷部位歷史(無伺服器端契約篩選,本地端過濾)、選擇權每日OHLC歷史、三大法人期貨+選擇權總表歷史、三大法人期貨/選擇權分計歷史、三大法人各選擇權契約歷史(HTML表單下載頁面,非 openapi.taifex.com.tw;後者無任何歷史查詢功能,僅回傳最新一個交易日)

Development Commands

Task Command
Install dependencies uv sync
Install with test deps uv sync --extra dev
Run server (dev) uv run fastmcp dev server.py
Run server (prod) uv run fastmcp run server.py
Run all tests uv run pytest
Run specific test file uv run pytest tests/e2e/test_history_api.py -v
Run tests by category python run_tests.py history (also: realtime, otc, taifex, institutional, e2e)
Quick test (fail fast) python run_tests.py quick
Tests with coverage python run_tests.py cov (opens HTML report)
Run server directly python server.py (HTTP on port 8000)

Code Architecture

High-Level Structure

server.py                     # Thin entrypoint: FastMCP init, prompt registration, tool registration
models/                       # Pydantic-style data models (MarketInfo, BrokerInfo, RealTimeStats)
utils/
├── api_client.py             # TWSEAPIClient - all TWSE HTTP calls
├── config.py                 # APIConfig, DisplayConfig, TestConfig (env var overrides)
├── constants.py              # Localized message templates (Chinese)
├── decorators.py             # @handle_api_errors
├── formatters.py             # Data → string formatting functions
├── tool_factory.py           # create_company_tool() for dynamically named tools
└── types.py                  # TWSEDataItem TypedDict, DataFormatter Protocol
tools/
├── __init__.py               # register_all_tools() - auto-discovers and registers all tool modules
├── broker.py                 # Broker data tools (top-level module)
├── other.py                  # Misc tools: funds, bonds, holidays (top-level module)
├── company/                  # Company tools: basic_info, financials, esg, listing, news
├── trading/                  # Trading tools: daily, periodic, valuation, dividend_schedule, etf, market, warrants
├── market/                   # Market tools: indices, statistics, foreign
├── history/                  # TWSE legacy: stock_day, stock_day_avg, margin_balance (exchangeReport); bwibbu_all (rwd/*);
                              #   institutional (T86);
                              #   institutional_amounts, all_stocks_daily_close, market_turnover, taiex_index_history,
                              #   foreign_holdings_history, stock_monthly_yearly_history, block_trades_detail,
                              #   short_sale_lending (rwd/* endpoints — accept arbitrary past dates, unlike the
                              #   openapi.twse.com.tw equivalents which only return a rolling ~12-day window)
├── realtime/                 # MIS real-time quotes: stock_info
├── otc/                      # TPEx OTC market: daily_close, institutional, peratio
└── taifex/                   # TAIFEX derivatives: futures_position, put_call_ratio, institutional_general,
                              #   institutional_details, daily_market_report, large_traders_oi,
                              #   options_analytics, margin, trading_statistics, futures_daily_history,
                              #   institutional_futures_history, put_call_ratio_history,
                              #   options_institutional_history, large_traders_futures_history,
                              #   options_daily_history, institutional_total_history,
                              #   institutional_fut_opt_split_history,
                              #   options_institutional_by_contract_history (latter nine scrape
                              #   www.taifex.com.tw's HTML-form download endpoints for multi-day
                              #   history; openapi.taifex.com.tw has no historical query support —
                              #   every openapi endpoint returns only the latest trading day,
                              #   confirmed by testing all 135 of its endpoints)
prompts/                      # 9 prompt templates registered in server.py

Read the full file on GitHub · 161 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 161 lines · 3,379 tokens per session scan A 77bb77a5d377

Subscribe to this mod's changes

TWSEMCPServer CLAUDE.md is an instructions file published in the GitHub repository twjackysu/TWSEMCPServer (159 stars, last pushed 7d ago), licensed MIT. It adds 3,379 tokens to every session, about $0.0169 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.