Yggdrasil
MCP ServersMCP 伺服器 SKILLs技能 PlugIns解決方案 Asgard AI SolutionAsgard AI 方案 Submit Listing申請上架 GitHub
U

Universal EC E-Invoice 汎宇電商電子發票

Released已發布
payment taiwan

MCP Server for Taiwan e-invoice (Universal EC / 汎宇電商) — 27 AI-callable tools covering all POS Web Service function codes (MIG 4.1).

汎宇電商台灣電子發票 MCP Server — 27 個 AI 可呼叫工具,涵蓋所有 POS Web Service 功能碼(開立、作廢、折讓、查詢)。

Status狀態
released
Tools工具數
27
Category分類
payment
Region地區
taiwan
Maintainer維護者
GitHub

Features功能特色

  • 27 MCP tools — Full coverage of all Universal EC e-invoice API function codes
  • stdio JSON-RPC 2.0 — Standard MCP transport protocol
  • 3 wrapper formats — INDEX, Invoice, Allowance (auto-selected per function)
  • Credential injection — SELLERID/POSID/POSSN auto-injected by connector
  • TDD tested — 53 unit tests + 5 live regression tests
  • 27 個 MCP 工具 — 完整涵蓋汎宇電商電子發票 API 所有功能代碼
  • stdio JSON-RPC 2.0 — 標準 MCP 傳輸協定
  • 3 種封裝格式 — INDEX、Invoice、Allowance(依功能自動選擇)
  • 憑證自動注入 — SELLERID/POSID/POSSN 由 connector 自動注入
  • TDD 測試 — 53 個單元測試 + 5 個即時回歸測試

Quick Start快速開始

# Setup
uv venv && source .venv/bin/activate
uv pip install -e ".[dev]"

# Configure credentials
cp .env.example .env
# Edit .env with your Universal EC credentials

# Run server
python mcp_server.py
# 安裝
uv venv && source .venv/bin/activate
uv pip install -e ".[dev]"

# 設定憑證
cp .env.example .env
# 編輯 .env 填入你的汎宇電商憑證

# 啟動伺服器
python mcp_server.py

Available Tools可用工具

System

Tool Code Description
get_system_time Y01 Connection test / get server time

Invoice Number Management

Tool Code Description
get_invoice_numbers A01 Get invoice number allocation (current period)
get_next_period_numbers C01 Get invoice number allocation (next period)
get_invoice_numbers_expanded Z21 Get numbers expanded per-invoice with AESKEY
get_next_period_numbers_expanded Z22 Get next period numbers expanded with AESKEY

B2C Invoices

Tool Code Description
create_b2c_invoice C0401 Create B2C invoice (positional field format)
create_b2c_invoice_named C0401N Create B2C invoice (named field format)
void_b2c_invoice C0501 Void a B2C invoice

B2B Invoices

Tool Code Description
create_b2b_invoice A0401 Create B2B invoice (platform certified)
void_b2b_invoice A0501 Void a B2B invoice
create_b2b_exchange_invoice A0101 Create B2B exchange invoice
void_b2b_exchange_invoice A0201 Void a B2B exchange invoice

Allowances (折讓)

Tool Code Description
create_b2c_allowance D0401 Create B2C allowance
create_b2c_allowance_named D0401N Create B2C allowance (named format)
void_b2c_allowance D0501 Void a B2C allowance
create_b2b_allowance B0401 Create B2B allowance
void_b2b_allowance B0501 Void a B2B allowance
create_b2b_exchange_allowance B0101 Create B2B exchange allowance

Cancellation (註銷)

Tool Code Description
cancel_invoice C0701 Cancel an invoice
batch_cancel_invoice B0701 Batch cancel with full invoice data

Queries

Tool Code Description
get_cancel_status Z11 Get invoice cancel process status
get_downloaded_track_ranges Z31 Query downloaded track ranges
get_assignment_info Z33 Query tax ID number assignment
get_winning_list Z34 Download winning invoice list

Administration

Tool Code Description
upload_next_period_tracks Z32 Upload next period track numbers
assign_branch_tracks E0401 Branch office track assignment
report_unused_tracks E0402 Report unused track ranges

系統

工具 代碼 說明
get_system_time Y01 連線測試 / 取得伺服器時間

發票號碼管理

工具 代碼 說明
get_invoice_numbers A01 取得發票號碼配號(本期)
get_next_period_numbers C01 取得發票號碼配號(下期)
get_invoice_numbers_expanded Z21 展開取號含 AESKEY(本期)
get_next_period_numbers_expanded Z22 展開取號含 AESKEY(下期)

B2C 發票

工具 代碼 說明
create_b2c_invoice C0401 開立 B2C 發票(位置欄位格式)
create_b2c_invoice_named C0401N 開立 B2C 發票(命名欄位格式)
void_b2c_invoice C0501 作廢 B2C 發票

B2B 發票

工具 代碼 說明
create_b2b_invoice A0401 開立 B2B 發票(平台存證)
void_b2b_invoice A0501 作廢 B2B 發票
create_b2b_exchange_invoice A0101 開立 B2B 交換發票
void_b2b_exchange_invoice A0201 作廢 B2B 交換發票

折讓

工具 代碼 說明
create_b2c_allowance D0401 開立 B2C 折讓證明單
create_b2c_allowance_named D0401N 開立 B2C 折讓(命名格式)
void_b2c_allowance D0501 作廢 B2C 折讓證明單
create_b2b_allowance B0401 開立 B2B 折讓證明單
void_b2b_allowance B0501 作廢 B2B 折讓證明單
create_b2b_exchange_allowance B0101 開立 B2B 交換折讓證明單

註銷

工具 代碼 說明
cancel_invoice C0701 註銷發票
batch_cancel_invoice B0701 批次註銷(含完整發票資料)

查詢

工具 代碼 說明
get_cancel_status Z11 查詢發票註銷流程狀態
get_downloaded_track_ranges Z31 查詢已下載字軌區間
get_assignment_info Z33 查詢統編配號(自動/手動)
get_winning_list Z34 下載中獎清冊

管理

工具 代碼 說明
upload_next_period_tracks Z32 上傳下期字軌配號
assign_branch_tracks E0401 分支機構配號
report_unused_tracks E0402 空白未使用字軌回報

License授權

MIT License — see LICENSE for details.

MIT License — 詳見 LICENSE

ConfigurationConfiguration

Create a .env file with your Universal EC POS credentials:

EINVOICE_BASE_URL=https://epostw.einvoice.com.tw/GetInvoice.ashx
EINVOICE_SELLER_ID=your_seller_id
EINVOICE_POS_ID=your_pos_id
EINVOICE_POS_SN=your_pos_sn
Environment URL
Test (測試機) https://epostw.einvoice.com.tw/GetInvoice.ashx
Production (正式機) https://eposw.einvoice.com.tw/GetInvoice.ashx

建立 .env 檔案,填入汎宇電商 POS 機憑證:

EINVOICE_BASE_URL=https://epostw.einvoice.com.tw/GetInvoice.ashx
EINVOICE_SELLER_ID=your_seller_id
EINVOICE_POS_ID=your_pos_id
EINVOICE_POS_SN=your_pos_sn
環境 URL
測試機 https://epostw.einvoice.com.tw/GetInvoice.ashx
正式機 https://eposw.einvoice.com.tw/GetInvoice.ashx

Project StructureProject Structure

mcp-universalec-e-invoice/
├── app.py                          # FastMCP singleton
├── mcp_server.py                   # Entry point (stdio transport)
├── config/
│   └── settings.py                 # URL + credentials from .env
├── connectors/
│   └── einvoice_client.py          # Single POST connector (3 wrappers)
├── tools/
│   ├── system_tools.py             # Y01
│   ├── invoice_number_tools.py     # A01, C01, Z21, Z22
│   ├── b2c_invoice_tools.py        # C0401, C0401N, C0501
│   ├── b2b_invoice_tools.py        # A0401, A0501, A0101, A0201
│   ├── allowance_tools.py          # D0401, D0401N, D0501, B0401, B0501, B0101
│   ├── cancel_tools.py             # C0701, B0701
│   ├── query_tools.py              # Z11, Z31, Z33, Z34
│   └── admin_tools.py              # Z32, E0401, E0402
└── tests/
    ├── conftest.py                 # Shared fixtures
    ├── test_einvoice_client.py     # Connector unit tests
    ├── test_system_tools.py        # Y01 tests
    ├── test_invoice_number_tools.py
    ├── test_b2c_invoice_tools.py
    ├── test_b2b_invoice_tools.py
    ├── test_allowance_tools.py
    ├── test_cancel_tools.py
    ├── test_query_tools.py
    ├── test_admin_tools.py
    └── test_regression.py          # Live API tests
mcp-universalec-e-invoice/
├── app.py                          # FastMCP 單例
├── mcp_server.py                   # 進入點 (stdio 傳輸)
├── config/
│   └── settings.py                 # URL + 憑證 (從 .env 讀取)
├── connectors/
│   └── einvoice_client.py          # 單一 POST 連接器 (3 種封裝格式)
├── tools/
│   ├── system_tools.py             # Y01
│   ├── invoice_number_tools.py     # A01, C01, Z21, Z22
│   ├── b2c_invoice_tools.py        # C0401, C0401N, C0501
│   ├── b2b_invoice_tools.py        # A0401, A0501, A0101, A0201
│   ├── allowance_tools.py          # D0401, D0401N, D0501, B0401, B0501, B0101
│   ├── cancel_tools.py             # C0701, B0701
│   ├── query_tools.py              # Z11, Z31, Z33, Z34
│   └── admin_tools.py              # Z32, E0401, E0402
└── tests/
    ├── conftest.py                 # 共用 fixtures
    ├── test_einvoice_client.py     # 連接器單元測試
    ├── test_system_tools.py        # Y01 測試
    ├── test_invoice_number_tools.py
    ├── test_b2c_invoice_tools.py
    ├── test_b2b_invoice_tools.py
    ├── test_allowance_tools.py
    ├── test_cancel_tools.py
    ├── test_query_tools.py
    ├── test_admin_tools.py
    └── test_regression.py          # 即時 API 測試

Usage ExamplesUsage Examples

Once the MCP server is running, an AI assistant (e.g. Claude) can call these tools on your behalf. Here are real-world scenarios showing what you say and how the AI responds.


"Help me check if the e-invoice system is connected"

You: 幫我測試一下電子發票系統有沒有連線成功

AI calls: get_system_time()

Result: The system returns REPLY: "1" with MESSAGE: "連線成功" and the server time 2026/04/01 22:29:03. Your connection is working.


"What invoice numbers do I have available right now?"

You: 我目前有哪些可用的發票號碼?

AI calls: get_invoice_numbers()

Result: Current period is 115 年 03-04 月, track GS, numbers 82775400 ~ 82775449 (50 invoices available). The AI can also explain the QRCode AES key returned for barcode generation.


"I need to get the detailed invoice numbers with AES keys for printing"

You: 我需要取得每張發票的 AESKEY 跟隨機碼,準備列印用

AI calls: get_invoice_numbers_expanded()

Result: Returns 50 individual invoices, each with its own number, AESKEY, and random number:

GS82775450 → AESKEY: Xymp9aqy..., RandomNumber: 7833
GS82775451 → AESKEY: XausdWBO..., RandomNumber: 4581
...

"Issue an invoice for a customer who bought 2 lattes and 1 cake"

You: 幫我開一張發票,客人買了 2 杯拿鐵 65 元、1 個巧克力蛋糕 85 元,總共 215 元含稅,紙本發票已列印

AI calls: get_invoice_numbers_expanded() to get an available number, then:

create_b2c_invoice(
  invoice_number = "GS82775402",     ← from the allocation
  invoice_date   = "2026-04-01",
  invoice_time   = "14:30:00",
  buyer_id       = "0000000000",     ← consumer, no tax ID
  buyer_name     = "0000",
  invoice_type   = "07",
  donate_mark    = "0",
  print_mark     = "Y",
  random_number  = "6136",           ← from the allocation
  tax_type = "1", tax_rate = "0.05", tax_amount = "10",
  sales_amount = "205", free_tax = "0", zero_tax = "0", total = "215",
  items = [
    {B1:"1", B2:"拿鐵咖啡", B3:"2", B5:"65", B6:"130", B7:"1", B13:"1"},
    {B1:"2", B2:"巧克力蛋糕", B3:"1", B5:"85", B6:"85", B7:"2", B13:"1"},
  ]
)

Result: REPLY: "1", MESSAGE: "成功", invoice GS82775402 created.


"Please void invoice GS82775401"

You: 請幫我作廢發票 GS82775401,原因是客戶取消訂單

AI calls:

void_b2c_invoice(
  invoice_number = "GS82775401",
  invoice_date   = "2026-04-01",
  buyer_id       = "0000000000",
  seller_id      = "23997652",
  cancel_date    = "2026-04-01",
  cancel_time    = "15:00:00",
  cancel_reason  = "客戶取消訂單",
)

Result: REPLY: "1", MESSAGE: "成功" — invoice voided successfully.


"Check the cancellation status of invoice GS82775400"

You: 幫我查一下 GS82775400 這張發票的註銷狀態

AI calls: get_cancel_status(invoice_number="GS82775400", invoice_date="2026-04-01")

Result: STATUSCODE: "1" = completed, "2" = pending, "3" = failed. The AI interprets and tells you the current status in plain language.


"Cancel invoice GS82775400 — it was issued by mistake"

You: 發票 GS82775400 開錯了,幫我註銷

AI calls:

cancel_invoice(
  invoice_number = "GS82775400",
  invoice_date   = "2026-04-01",
  buyer_id       = "0000000000",
  seller_id      = "23997652",
  cancel_date    = "2026-04-01",
  cancel_time    = "16:00:00",
  cancel_reason  = "誤開發票",
)

Result: If the invoice has been uploaded to the tax authority, REPLY: "1" confirms cancellation. If it hasn't been uploaded yet, the system returns REPLY: "-1" with a message explaining the invoice is still being processed — the AI will tell you to try again later.

Note: "作廢" (C0501 void) and "註銷" (C0701 cancel) are different. Void happens before upload to tax authority; cancel happens after. The AI picks the right tool based on context.


"I need to check what invoice number ranges have been downloaded"

You: 查一下統編 23997652 在 11504 期的 GS 字軌已下載的配號區間

AI calls:

get_downloaded_track_ranges(
  head_ban      = "23997652",
  branch_ban    = "23997652",
  invoice_type  = "07",
  year_month    = "11504",
  invoice_track = "GS",
)

Result: Returns the track ranges that have been successfully downloaded for this period.

MCP 伺服器啟動後,AI 助手(如 Claude)可以代你呼叫這些工具。以下是實際使用情境,展示你怎麼說、AI 怎麼做。


「幫我測試電子發票系統有沒有連線成功」

AI 呼叫: get_system_time()

結果: 系統回傳 REPLY: "1"MESSAGE: "連線成功",伺服器時間 2026/04/01 22:29:03。連線正常。


「我目前有哪些可用的發票號碼?」

AI 呼叫: get_invoice_numbers()

結果: 本期 115 年 03-04 月,字軌 GS,號碼 82775400 ~ 82775449(共 50 張可用)。AI 同時會說明回傳的 QRCode AES 金鑰用途。


「我需要取得每張發票的 AESKEY 跟隨機碼,準備列印用」

AI 呼叫: get_invoice_numbers_expanded()

結果: 回傳 50 張發票的個別資訊:

GS82775450 → AESKEY: Xymp9aqy..., 隨機碼: 7833
GS82775451 → AESKEY: XausdWBO..., 隨機碼: 4581
...

「幫我開一張發票,客人買了 2 杯拿鐵 65 元、1 個蛋糕 85 元」

AI 先呼叫 get_invoice_numbers_expanded() 取得可用號碼,再呼叫:

create_b2c_invoice(
  invoice_number = "GS82775402",     ← 從配號取得
  invoice_date   = "2026-04-01",
  invoice_time   = "14:30:00",
  buyer_id       = "0000000000",     ← 消費者,無統編
  buyer_name     = "0000",
  invoice_type   = "07",
  donate_mark    = "0",
  print_mark     = "Y",
  random_number  = "6136",           ← 從配號取得
  tax_type = "1", tax_rate = "0.05", tax_amount = "10",
  sales_amount = "205", free_tax = "0", zero_tax = "0", total = "215",
  items = [
    {B1:"1", B2:"拿鐵咖啡", B3:"2", B5:"65", B6:"130", B7:"1", B13:"1"},
    {B1:"2", B2:"巧克力蛋糕", B3:"1", B5:"85", B6:"85", B7:"2", B13:"1"},
  ]
)

結果: REPLY: "1"MESSAGE: "成功",發票 GS82775402 開立完成。


「請幫我作廢發票 GS82775401,客戶取消訂單」

AI 呼叫:

void_b2c_invoice(
  invoice_number = "GS82775401",
  invoice_date   = "2026-04-01",
  buyer_id       = "0000000000",
  seller_id      = "23997652",
  cancel_date    = "2026-04-01",
  cancel_time    = "15:00:00",
  cancel_reason  = "客戶取消訂單",
)

結果: REPLY: "1"MESSAGE: "成功" — 發票作廢成功。


「幫我查一下 GS82775400 的註銷狀態」

AI 呼叫: get_cancel_status(invoice_number="GS82775400", invoice_date="2026-04-01")

結果: STATUSCODE: "1" = 已完成、"2" = 尚未完成、"3" = 失敗。AI 會用白話告訴你目前狀態。


「發票 GS82775400 開錯了,幫我註銷」

AI 呼叫:

cancel_invoice(
  invoice_number = "GS82775400",
  invoice_date   = "2026-04-01",
  buyer_id       = "0000000000",
  seller_id      = "23997652",
  cancel_date    = "2026-04-01",
  cancel_time    = "16:00:00",
  cancel_reason  = "誤開發票",
)

結果: 若發票已上傳財政部,REPLY: "1" 表示註銷成功。若尚未上傳,系統回傳 REPLY: "-1" 說明發票仍在處理中 — AI 會告訴你稍後再試。

備註:「作廢」(C0501) 和「註銷」(C0701) 不同。作廢是發票尚未上傳財政部前的操作;註銷是上傳後的操作。AI 會根據情境自動選擇正確的工具。


「查一下這期 GS 字軌已下載的配號區間」

AI 呼叫:

get_downloaded_track_ranges(
  head_ban      = "23997652",
  branch_ban    = "23997652",
  invoice_type  = "07",
  year_month    = "11504",
  invoice_track = "GS",
)

結果: 回傳該期別已成功下載的字軌區間明細。

TestingTesting

# Unit tests (mocked HTTP, no credentials needed)
pytest tests/ --ignore=tests/test_regression.py -v

# Regression tests (requires .env with valid credentials)
pytest tests/test_regression.py -v -s
# 單元測試(模擬 HTTP,不需要憑證)
pytest tests/ --ignore=tests/test_regression.py -v

# 回歸測試(需要 .env 中的有效憑證)
pytest tests/test_regression.py -v -s

ArchitectureArchitecture

All 27 functions communicate through a single POST endpoint (GetInvoice.ashx), differentiated by function code in the JSON body. The connector auto-injects credentials (SELLERID, POSID, POSSN) and system time.

Three JSON wrapper formats:

  • INDEX — System/number functions (Y01, A01, C01, Z21, Z22, Z11)
  • Invoice — Invoice/allowance/admin CRUD (C0401, A0401, D0401, C0701, E0401, Z31, etc.)
  • Allowance — B0501 only (void B2B allowance)

所有 27 個功能透過單一 POST 端點 (GetInvoice.ashx) 通訊,以 JSON body 中的功能代碼區分。連接器自動注入憑證 (SELLERID, POSID, POSSN) 與系統時間。

三種 JSON 封裝格式:

  • INDEX — 系統/號碼功能 (Y01, A01, C01, Z21, Z22, Z11)
  • Invoice — 發票/折讓/管理 CRUD (C0401, A0401, D0401, C0701, E0401, Z31 等)
  • Allowance — 僅 B0501(作廢 B2B 折讓)

Part Of The Asgard EcosystemPart Of The Asgard Ecosystem

See the full Asgard AI Platform for more MCP servers.

See the full Asgard AI Platform for more MCP servers.

Tags標籤

invoicee-invoicepostaiwan

Need more powerful payment capabilities? 需要更強大的payment能力?

Upgrade to Asgard for enterprise-grade features, SLAs, and dedicated support.

升級至 Asgard 取得企業級功能、SLA 與專屬支援。

View Asgard Products →查看 Asgard 產品 →

Related MCP Servers相關 MCP 伺服器