一個全面的模型上下文協議 (MCP) 伺服器,專為台灣證券交易所 (TWSE) 數據分析設計。它提供即時股票資訊、財務報表、ESG 數據和趨勢分析功能,助力使用者深入了解台灣股市。
複製專案
git clone https://github.com/yourusername/TWStockMCPServer.git
cd TWStockMCPServer
安裝相依套件
使用 pip:
pip install -r requirements.txt
使用 uv(推薦):
uv sync
啟動伺服器
開發模式(熱重載):
uv run fastmcp dev server.py
正式環境模式:
uv run fastmcp run server.py
複製專案
git clone https://github.com/yourusername/TWStockMCPServer.git
cd TWStockMCPServer
安裝相依套件
使用 pip:
pip install -r requirements.txt
使用 uv(推薦):
uv sync
啟動伺服器
開發模式(熱重載):
uv run fastmcp dev server.py
正式環境模式:
uv run fastmcp run server.py
以下是使用部分工具的示例:
# 获取公司基本信息
from server import mcp
@mcp.tool
def get_company_profile(code: str) -> str:
"""获取公司基本信息。"""
# 实现内容
pass
company_info = get_company_profile('1234')
print(company_info)
在实际项目中,可以组合多个工具进行更复杂的分析:
# 结合多个工具进行综合分析
from server import mcp
@mcp.tool
def get_company_profile(code: str) -> str:
"""获取公司基本信息。"""
# 实现内容
pass
@mcp.tool
def get_stock_daily_trading(code: str) -> str:
"""获取每日交易统计。"""
# 实现内容
pass
company_info = get_company_profile('1234')
trading_info = get_stock_daily_trading('1234')
# 进行综合分析
# ...
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() - 融資融券統計get_real_time_trading_stats() - 即時交易統計(每 5 秒更新)get_market_historical_index() - 發行量加權股價指數歷史資料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) - 資訊安全指標目前提供 19 個 MCP Tools,涵蓋 19+ TWSE API 端點,包括:
所有資料來源自台灣證券交易所 (TWSE) 官方開放 API:
https://openapi.twse.com.tw/v1歡迎開發者社群參與貢獻!您可以透過以下方式協助:
git checkout -b feature/your-new-tool
server.py 中新增您的工具@mcp.tool
def your_new_tool(code: str) -> str:
"""您的工具說明。"""
# 實作內容
參考 staticFiles/apis_summary_simple.json 查看可實作為新工具的可用 TWSE API 端點。
⚠️ 重要提示
本軟體僅供參考之用,不構成投資建議。使用者應進行自己的研究,並在做出投資決定前諮詢財務專業人士。由於我不熟悉 Python,該專案完全由 AI 生成,然後根據需要手動調整。
本專案採用 MIT 授權條款 - 詳見 LICENSE 檔案。
以 ❤️ 為台灣股票分析社群打造