TWSE MCP Server

TWSE MCP Server

台灣證交所MCPServer

Category
Visit Server

README

🚀 TWStockMCPServer

License: MIT Python MCP

一個全面的模型上下文協議 (MCP) 伺服器,專為台灣證券交易所 (TWSE) 數據分析設計,提供即時股票資訊、財務報表、ESG 數據和趨勢分析功能。

<a href="https://glama.ai/mcp/servers/@twjackysu/TWSEMCPServer"> <img width="380" height="200" src="https://glama.ai/mcp/servers/@twjackysu/TWSEMCPServer/badge" /> </a>

🎬 示範影片

股票趨勢分析示範

觀看 TWStockMCPServer 功能展示

✨ 主要功能

📊 技術分析工具

  • 每日交易數據:即時股價、成交量和交易統計
  • 價格趨勢:每日收盤價和月平均價格計算
  • 估值指標:本益比、股利殖利率和股價淨值比
  • 歷史數據:月份和年度交易資訊

💰 基本面分析

  • 財務報表:綜合損益表和資產負債表
  • 營收報告:月營收追蹤和成長分析
  • 股利資訊:配息記錄和股利政策
  • 公司治理:ESG 數據和治理指標

🏛️ 市場情報

  • 市場指數:即時台股指數資訊
  • 法人動態:融資融券和借貸數據
  • 市場統計:每日市場摘要和趨勢

🌱 ESG 與永續經營

  • 氣候管理:氣候相關風險評估
  • 風險管理:企業風險管理政策
  • 供應鏈:供應鏈管理透明度
  • 資訊安全:網路安全事件報告

⚙️ 安裝說明

使用者快速安裝

# 直接從 GitHub 安裝
pip install git+https://github.com/twjackysu/TWSEMCPServer.git

# 然後設定您的 MCP 客戶端(詳見下方完整指南)

📋 完整安裝指南 - 所有平台和使用情境的詳細說明

系統需求

  • Python 3.10 或更高版本
  • pip 套件管理器或 uv
  • Docker(可選,用於容器化部署)

快速開始

  1. 複製專案

    git clone https://github.com/twjackysu/TWSEMCPServer.git
    cd TWSEMCPServer
    
  2. 安裝相依套件

    使用 pip:

    pip install -r requirements.txt
    

    使用 uv(推薦):

    uv venv
    .venv\Scripts\activate  # Windows
    # 或
    source .venv/bin/activate  # macOS/Linux
    uv add mcp[cli] httpx fastmcp requests
    
  3. 設定 MCP 客戶端

    在您的 MCP 客戶端設定檔中新增(例如:.vscode/mcp.json):

    {
      "servers": {
        "twse_stock_server": {
          "type": "stdio",
          "command": "python",
          "args": ["${workspaceFolder}/server.py"]
        }
      }
    }
    
  4. 啟動伺服器

    開發模式(熱重載):

    uv run fastmcp dev server.py
    

    正式環境模式:

    uv run fastmcp run server.py
    # 或
    python server.py
    
  5. Docker 部署(可選)

    # 建置 Docker 映像
    docker build -t twstock-mcp-server .
    
    # 執行容器
    docker run -p 8000:8000 twstock-mcp-server
    
    # 測試建置(Windows)
    test-docker.bat
    
    # 測試建置(Linux/macOS)
    chmod +x test-docker.sh && ./test-docker.sh
    

🔧 設定

環境變數

在專案根目錄建立 .env 檔案:

workspaceRoot=your/project/path

相依套件

主要相依套件包括:

  • fastmcp:MCP 伺服器框架
  • requests:HTTP 客戶端進行 API 呼叫
  • logging:Python 內建日誌系統

📚 可用工具

公司資訊

  • get_company_profile(code) - 公司基本資訊
  • get_company_dividend(code) - 股利分配數據
  • get_company_monthly_revenue(code) - 月營收報告

交易數據

  • get_stock_daily_trading(code) - 每日交易統計
  • get_stock_monthly_average(code) - 月平均價格
  • get_stock_valuation_ratios(code) - 估值指標
  • get_stock_monthly_trading(code) - 月交易數據
  • get_stock_yearly_trading(code) - 年度交易統計

財務報表

  • get_company_income_statement(code) - 綜合損益表
  • get_company_balance_sheet(code) - 資產負債表數據

市場數據

  • get_market_index_info() - 市場指數資訊
  • get_margin_trading_info() - 融資融券統計

ESG 與治理

  • get_company_governance_info(code) - 公司治理
  • get_company_climate_management(code) - 氣候相關管理
  • get_company_risk_management(code) - 風險管理政策
  • get_company_supply_chain_management(code) - 供應鏈數據
  • get_company_info_security(code) - 資訊安全指標

🤝 參與貢獻

歡迎開發者社群參與貢獻!您可以透過以下方式協助:

貢獻方式

  1. 新增工具:擴展 API 覆蓋範圍,實作新的 TWSE 端點
  2. 改善文件:協助改進範例和說明文件
  3. 修復錯誤:回報和修復問題
  4. 功能建議:提出新功能想法
  5. 測試:新增測試案例和提升可靠性

開發環境設定

  1. Fork 專案
  2. 建立功能分支
    git checkout -b feature/your-new-tool
    
  3. server.py 中新增您的工具
    @mcp.tool
    def your_new_tool(code: str) -> str:
        """您的工具說明。"""
        # 實作內容
    
  4. 更新說明文件
  5. 提交 Pull Request

API 參考

參考 staticFiles/apis_summary_simple.json 查看可實作為新工具的可用 TWSE API 端點。

程式碼風格

  • 遵循 Python PEP 8 指南
  • 新增完整的 docstrings
  • 包含錯誤處理
  • 記錄重要操作

📋 API 涵蓋範圍

目前支援 15+ TWSE API 端點,包括:

  • 公司檔案和基本資訊
  • 股票交易數據(每日、每月、每年)
  • 財務報表和報告
  • ESG 和永續指標
  • 市場指數和統計
  • 股利和治理資訊

🔒 資料來源

所有資料來源自台灣證券交易所 (TWSE) 官方開放 API:

  • 基礎 URL:https://openapi.twse.com.tw/v1
  • 即時和歷史資料
  • 無需 API 金鑰
  • 適用速率限制

⚠️ 免責聲明

本軟體僅供參考之用,不構成投資建議。使用者應進行自己的研究,並在做出投資決定前諮詢財務專業人士。

📄 授權條款

本專案採用 MIT 授權條款 - 詳見 LICENSE 檔案。

🙏 致謝

  • 台灣證券交易所提供開放資料 API
  • MCP 社群提供協議規範
  • 本專案的貢獻者和使用者

📞 支援


以 ❤️ 為台灣股票分析社群打造

🌏 語言版本

免責聲明:由於我不熟悉 Python,該專案完全由 AI 生成,然後根據需要手動調整。

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured