ASCII Table MCP Server

ASCII Table MCP Server

MCP server for generating properly aligned ASCII, Unicode box-drawing, and Markdown tables, with correct width measurement for Thai, Pali, and CJK characters using wcwidth.

Category
访问服务器

README

ASCII Table MCP Server

+------------+------------------+------+---------------+
| คำบาลี      | Roman            | หมวด | ความหมาย      |
+------------+------------------+------+---------------+
| ปฏิจจสมุปฺปาท | paṭiccasamuppāda | ธรรม | เหตุปัจจัยต่อเนื่อง |
| กามจฺฉนฺท    | kāmacchanda      | นิวรณ์ | ความพอใจในกาม |
| อวิชฺชา      | avijjā           | กิเลส | ความไม่รู้       |
+------------+------------------+------+---------------+

ตารางภาษาไทย + Roman + ตัวเลข → alignment ตรงทุกบรรทัด

MCP server สำหรับสร้างตาราง (ASCII grid / Unicode box-drawing) ที่รองรับภาษาไทย บาลี โรมัน และ CJK อย่างถูกต้อง — ใช้ wcwidth ในการวัดความกว้างตัวอักษร ไม่ใช้ len() ที่นับผิด


Features

  • 4 table styles: grid (ASCII +---+), box (Unicode ┌─┬─┐), pipe (Markdown | | |), safe (char-count padding)
  • 10 grid sub-styles: mysql, separated, compact, gfm, reddit, rounded, rst, box, unicode, dots
  • Auto-format: รองรับตัวเลข (right-align) และหัวตาราง (center) — ได้แรงบันดาลใจจาก ozh/ascii-tables
  • Thai/Pali/CJK: zero-width combining marks (พินทุ, สระบน/ล่าง) alignment ไม่เพี้ยน
  • Safe width mode: extra padding ชดเชย platform ที่ zero-width ≠ 0 (Discord, browser code blocks)
  • 7 MCP tools: make_table, make_table_from_csv, make_table_from_json, make_table_preview, debug_table, analyze_table, validate_table_text
  • Zero external dependencies (beyond mcp + wcwidth)

Quick Start

uvx (no install)

uvx --from git+https://github.com/dhammawatthumpra-coder/ascii-table-mcp ascii-table-mcp

pip install

git clone https://github.com/dhammawatthumpra-coder/ascii-table-mcp.git
cd ascii-table-mcp
pip install -e .
python -m ascii_table_mcp

Register with Claude Desktop

{
  "mcpServers": {
    "ascii-table": {
      "command": "python",
      "args": ["-m", "ascii_table_mcp"]
    }
  }
}

Register with Hermes

# หลังจาก pip install -e . แล้ว
hermes mcp add ascii-table --command "python -m ascii_table_mcp"

MCP Tools

make_table

สร้างตารางจาก headers + rows รองรับ style, auto-format, safe width

Parameter Type Default Description
headers list[str] — หัวตาราง
rows / data list[list[str]] — แถวข้อมูล
fmt str "grid" "grid", "box", "pipe", "safe"
style str "mysql" ดูตาราง Styles ด้านล่าง
auto_format bool true right-align ตัวเลข, center หัวตาราง
safe_width bool false extra padding สำหรับ Discord/browser

ตัวอย่าง: style="separated" พร้อม auto-format

{
  "headers": ["สินค้า", "ราคา", "จำนวน"],
  "rows": [
    ["ก๋วยเตี๋ยว", "45", "3"],
    ["ข้าวผัด", "55", "2"],
    ["รวม", "100", "5"]
  ],
  "fmt": "grid",
  "style": "separated"
}

ผลลัพธ์:

+============+======+=======+
|   สินค้า    | ราคา | จำนวน |
+============+======+=======+
+------------+------+-------+
| ก๋วยเตี๋ยว |   45 |     3 |
+------------+------+-------+
| ข้าวผัด    |   55 |     2 |
+------------+------+-------+
| รวม        |  100 |     5 |
+------------+------+-------+

สังเกต: auto_format=true ทำให้คอลัมน์ "ราคา" กับ "จำนวน" ถูกจัดชิดขวา (ตัวเลข) หัวตารางถูกจัดกลาง

Safe width สำหรับ Discord:

{
  "rows": [["ชื่อ", "ราคา"], ["ก๋วยเตี๋ยว", "45"]],
  "fmt": "grid",
  "safe_width": true
}

ผลลัพธ์มี padding เพิ่มตามจำนวน zero-width marks เพื่อชดเชย Discord/browser ที่ render marks ด้วย width > 0

Style compact (ไม่มีกรอบ):

{ "headers": ["A", "B"], "rows": [["x", "1"]], "fmt": "grid", "style": "compact" }
   A    B  
 ----- --- 
  x     1  

Style rounded:

{ "headers": ["A"], "rows": [["x"]], "fmt": "grid", "style": "rounded" }
.---.
| A |
:---:
| x |
'---'

make_table_from_csv

{
  "csv_text": "คำบาลี,Roman,หมวด,ความหมาย\\nกมฺม,kamma,นาม,กรรม",
  "fmt": "grid"
}

make_table_from_json

{
  "json_data": "[ [\"คำ\",\"แปล\"], [\"กมฺม\",\"kamma\"], [\"อวิชฺชา\",\"avijjā\"] ]",
  "fmt": "grid"
}

debug_table

แสดงตำแหน่ง char@pos และ drift analysis สำหรับ debugging alignment:

┌───────┬───────┐
│ คำบาลี │ Roman │ ← │@char9 vs ┬@char8 ❌ drift=1
├───────┼───────┤
│ กมฺม   │ kamma │ ← ✅ align
└───────┴───────┘

analyze_table

วิเคราะห์ column positions ของ +--+ table และ validate | alignment

validate_table_text

ตรวจสอบโครงสร้างตาราง: column count, border alternation, format detection


Thai Character Width Compensation

Discord, browser code blocks, และ terminal บางประเภท ไม่รองรับ zero-width combining marks ( ิ ี ึ ื ั ุ ู ฺ) — แต่ละ mark จะกิน width 1 แทนที่จะเป็น 0 ทำให้ตารางภาษาไทย/บาลี drift

ปัญหา

+------------+------+-------+
|    ชื่อ     | ราคา | จำนวน |   ← ชื่อ + ื + ่ = width 3 ใน Discord
| ก๋วยเตี๋ยว |   45 |     3 |   ← ก๋วยเตี๋ยว + ๋ + ี + ๋ = width 11
+------------+------+-------+
         ↑ width 12 ใน wcwidth แต่ Discord render 13 → │ ขยับ!

ก๋วยเตี๋ยว len=10, wcwidth=7 → gap=3 (3 zero-width marks)

Solution: safe_width=True

เมื่อเปิด safe_width โปรแกรมจะคำนวณ:

  1. คำนวณ column width ด้วย len() แทน wcwidth (นับทุกตัวอักษรเป็น width 1)
  2. เพิ่ม gap = len_cell - wcwidth_cell ให้ padded_lens (ชดเชย mark ที่ Platform render)
  3. เพิ่ม buffer +1 สำหรับ font overhang
+----------------+------+-------+
|      ชื่อ      | ราคา | จำนวน |   ← extra 4 spaces
| ก๋วยเตี๋ยว     |   45 |     3 |   ← gap(3) + buffer(1) = 4 extra
+----------------+------+-------+

วิธีเรียกใช้

{
  "headers": ["ชื่อ", "ราคา"],
  "rows": [["ก๋วยเตี๋ยว", "45"]],
  "fmt": "grid",
  "safe_width": true
}

หรือผ่าน Python API:

from ascii_table_mcp.generate_table import render_ascii_grid
table = render_ascii_grid(rows, safe_width=True)

อนาคต: Character Width Database

การคำนวณ width แบบ wcwidth หรือ len() ยัง approximation — อนาคตอาจสร้าง ตาราง lookup ความกว้างจริงของอักขระไทยแต่ละตัว สำหรับ platform/font หลักๆ (Discord, Terminal Windows, Terminal Linux) เพื่อให้ alignment แน่นอน 100%

ภาษาไทยและบาลีมีอักขระ zero-width combining marks เช่น:

  • พินทุ ( ฺ ) — 0-width ในพจนานุกรม
  • สระบน ( ิ ี ึ ื ั ) — 0-width ติดพยัญชนะ
  • สระล่าง ( ุ ู ) — 0-width
  • ไม้หันอากาศ ( ั ) — 0-width

len() ใน Python นับผิด:

len("กมฺม")  → 4   ❌ (นับพินทุเป็นตัวอักษร)
wcswidth("กมฺม") → 3  ✅ (พินทุ width 0)

ถ้าใช้ len() ในการจัดตาราง:

+----------+-----------+   ← border ยาว 8
| คำบาลี    | Roman     |   ← "กมฺม" = 4 char → padding 4 → len=9 ❌ drift!
+----------+-----------+

ของเราใช้ wcwidth.wcswidth() แทน len() → alignment ตรงทุก platform


Grid Styles

10 styles จาก ozh/ascii-tables:

Style Top Header sep Data sep Bottom Notes
mysql +--+ +--+ +--+ +--+ default
separated +==+ +==+ +--+ +--+ หัวตารางหนา
compact none --- none none ไม่มีกรอบ
gfm none |--| none none GitHub style
reddit none --|-- none none Reddit style
rounded .--. :+: none '--' มุมมน
rst +==+ +--+ +==+ +==+ reStructuredText
box ┌┬┐ ├┼┤ ├┼┤ └┴┘ Unicode box
unicode ╔╦╗ ╠╬╣ ╠╬╣ ╚╩╝ double-line
dots ┌┬┐ ├┼┤ none └┴┘ no row separators

Format Comparison

Format Example เหมาะกับ
grid +----+----+ Default — terminal, code review, GitHub
box / safe ┌────┬────┐ presentation, formal doc
pipe | | | Markdown
grid + safe_width=True +------+----+ Discord, browser ที่ zero-width ≠ 0

CLI Usage

# CSV args → grid
python -m ascii_table_mcp.generate_table --grid 'ชื่อ,อายุ' 'สมชาย,30' 'สมหญิง,25'

# TSV pipe → grid
printf 'ชื่อ\tอายุ\nสมชาย\t30\n' | python -m ascii_table_mcp.generate_table --tsv --grid

# JSON
python -m ascii_table_mcp.generate_table --json '{"headers":["A","B"],"rows":[["1","2"]]}' --grid

# ASCII/Pipe Table → auto-convert
cat table.txt | python -m ascii_table_mcp.generate_table --ascii
+-------+-----+
| ชื่อ    | อายุ |
+-------+-----+
| สมชาย | 30  |
| สมหญิง | 25  |
+-------+-----+

Architecture

ascii-table-mcp/
├── ascii_table_mcp/
│   ├── __init__.py      # MCP server (FastMCP)
│   └── generate_table.py # Core rendering engine
├── server.py            # Thin wrapper for `python server.py`
├── requirements.txt     # mcp + wcwidth
├── pyproject.toml        # uv / pip install
├── ascii-table-mcp.bat  # Windows wrapper
├── LICENSE              # MIT
└── README.md            # เอกสารนี้

Core rendering (render_table, render_ascii_grid, render_pipe_table, render_table_safe) อยู่ใน generate_table.py — server.py import มาใช้ ไม่มี code ซ้ำ


Related

  • ozh/ascii-tables — ต้นแบบ table styles (mysql, separated, compact, gfm, reddit, rounded, rst, box, unicode, dots)
  • dmarsters/ascii-art-mcp — decorative ASCII art (shaded boxes, styled tables)
  • schachmat/wego — Go terminal weather app, uses go-runewidth (equivalent to our wcwidth)
  • akiomik/seaw — Scala port of wcwidth
  • wcwidth — Python port of wcwidth(3)

License

MIT — แจกฟรี ใช้ได้ทั้งส่วนตัวและพาณิชย์

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选