Skip to content

feat: Integrate TWSE market data tools via MCP bridge#110

Open
JasonWang1124 wants to merge 6 commits intoTraderAlice:masterfrom
JasonWang1124:feat/twstock-tools
Open

feat: Integrate TWSE market data tools via MCP bridge#110
JasonWang1124 wants to merge 6 commits intoTraderAlice:masterfrom
JasonWang1124:feat/twstock-tools

Conversation

@JasonWang1124
Copy link
Copy Markdown

Summary

Closes #109

Adds 29 Taiwan Stock Exchange (TWSE) tools to OpenAlice, bridging the TWSEMCPServer into the existing tool system via MCP HTTP transport.

  • New: src/domain/twstock/client.ts — MCP client with lazy-connect (connects on first tool call)
  • New: src/domain/twstock/config.ts — Config reader for data/config/twstock.json (gitignored)
  • New: src/tool/twstock.ts — 29 tool definitions using existing Zod + factory pattern
  • Modified: src/main.ts — Conditional registration + shutdown hook
  • Modified: .gitignore — Add services/ for local MCP server clones

Tools added

Category Count Examples
Company Info 6 Profile, balance sheet, income statement, revenue, dividends, news
ESG & Governance 5 Governance, climate, risk, security, supply chain
Trading Data 6 Daily/monthly/yearly OHLCV, monthly average, P/E ratio, real-time stats
Market Indices 2 Index info (major/sector/ESG/thematic), historical TAIEX
Foreign Investment 2 Top holdings, by industry
Margin Trading 1 Margin/short balances
Dividends & ETF 2 Ex-dividend schedule, ETF regular investment ranking
TWSE News 2 Official news, events
Warrants 3 Basic info, daily trading, trader count

Design choices

  • Opt-in: No config file or empty mcpUrl → zero tools registered, zero impact
  • No hardcoded URLs: Endpoint read from gitignored data/config/twstock.json
  • Lazy connection: OpenAlice starts normally even if TWSE server is unavailable
  • Follows existing patterns: Identical structure to equity.ts, market.ts, etc.
  • Minimal existing code changes: Only main.ts touched (3 imports + 6 lines registration + 1 line shutdown)

Setup

# 1. Clone and start TWSEMCPServer locally
git clone https://github.com/twjackysu/TWSEMCPServer.git services/twstock-mcp
cd services/twstock-mcp && uv sync
uv run fastmcp run server.py --transport streamable-http --port 3010

# 2. Create config
echo '{"enabled": true, "mcpUrl": "http://localhost:3010/mcp"}' > data/config/twstock.json

# 3. Start OpenAlice
pnpm dev

Test plan

  • TypeScript compiles with zero errors (npx tsc --noEmit)
  • OpenAlice starts and registers 71 tools (42 existing + 29 twstock)
  • Tested 13 tools across all categories via direct MCP client calls — all returned correct data
  • End-to-end test via chat API — AI successfully calls twstockGetCompanyProfile and returns formatted TSMC data
  • Verified opt-in: without config, tool count stays at 42
  • Benchmarked local vs remote: local HTTP is ~5-7x faster for most endpoints

🤖 Generated with Claude Code

TBD-JasonWang and others added 6 commits April 8, 2026 17:53
Add 29 Taiwan Stock Exchange tools covering company fundamentals,
trading data, market indices, foreign investment, ESG, warrants,
and more. Tools connect to a local TWSEMCPServer instance via MCP
HTTP transport, with lazy-connect and opt-in config gating.

Closes TraderAlice#109

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add twstockGetStockRealtimeQuote for live intraday data via TWSE
matching system API. Updates get_stock_daily_trading description
to clarify it only updates after market close.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add KlineChart component using lightweight-charts (TradingView) that
renders candlestick charts with MA5/MA20/MA60 and volume histogram.
ChatMessage detects ```kline code blocks and renders them inline.
Supports both daily (YYYY-MM-DD) and intraday (ISO datetime) data.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add twstockGetStockKlineData for historical OHLCV chart data
- Fix inherited CLAUDECODE env var causing nested session crash
- Update daily trading description to reference realtime alternative

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add 7 Fugle tools for intraday candles (1/3/5/10/15/30/60 min),
real-time quotes, tick-by-tick trades, price-volume distribution,
historical candles (D/W/M), and historical stats. Connects to
local Fugle MCP server via HTTP for fast response (~100-400ms).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fugleCheckVolumeSpikes scans multiple stocks in one call, comparing
latest candle volume against previous average. Can be scheduled via
cron for continuous intraday monitoring during market hours.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Integrate TWSE (Taiwan Stock Exchange) market data tools

2 participants