markdown-json-excel-mcp 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- markdown_json_excel_mcp-0.1.0/PKG-INFO +87 -0
- markdown_json_excel_mcp-0.1.0/README.md +77 -0
- markdown_json_excel_mcp-0.1.0/excel_mcp/__init__.py +6 -0
- markdown_json_excel_mcp-0.1.0/excel_mcp/__main__.py +7 -0
- markdown_json_excel_mcp-0.1.0/excel_mcp/server.py +146 -0
- markdown_json_excel_mcp-0.1.0/markdown_json_excel_mcp.egg-info/PKG-INFO +87 -0
- markdown_json_excel_mcp-0.1.0/markdown_json_excel_mcp.egg-info/SOURCES.txt +11 -0
- markdown_json_excel_mcp-0.1.0/markdown_json_excel_mcp.egg-info/dependency_links.txt +1 -0
- markdown_json_excel_mcp-0.1.0/markdown_json_excel_mcp.egg-info/entry_points.txt +2 -0
- markdown_json_excel_mcp-0.1.0/markdown_json_excel_mcp.egg-info/requires.txt +2 -0
- markdown_json_excel_mcp-0.1.0/markdown_json_excel_mcp.egg-info/top_level.txt +1 -0
- markdown_json_excel_mcp-0.1.0/pyproject.toml +21 -0
- markdown_json_excel_mcp-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: markdown-json-excel-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP server: convert markdown tables, JSON and CSV to Excel files
|
|
5
|
+
Author: shsy-cong
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: fastmcp>=2.0
|
|
9
|
+
Requires-Dist: openpyxl>=3.1
|
|
10
|
+
|
|
11
|
+
# markdown-json-excel-mcp
|
|
12
|
+
|
|
13
|
+
MCP Server:把 Markdown 表格 / JSON / CSV 数据转成 Excel 文件。
|
|
14
|
+
|
|
15
|
+
## 项目简介
|
|
16
|
+
|
|
17
|
+
这是一个基于 MCP(Model Context Protocol)的工具服务,可以把各种格式的表格数据转换成 Excel 文件。适用于需要快速生成 Excel 报表的场景,比如数据导出、报表生成、批量表格处理等。
|
|
18
|
+
|
|
19
|
+
## 功能列表
|
|
20
|
+
|
|
21
|
+
| 工具 | 功能 |
|
|
22
|
+
|---|---|
|
|
23
|
+
| `json_to_excel` | JSON 数组 / 对象转 Excel |
|
|
24
|
+
| `markdown_table_to_excel` | Markdown 表格转 Excel |
|
|
25
|
+
| `text_to_excel` | CSV / TSV 文本转 Excel |
|
|
26
|
+
|
|
27
|
+
## 部署指南
|
|
28
|
+
|
|
29
|
+
### 本地测试
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# 安装依赖
|
|
33
|
+
pip install markdown-json-excel-mcp
|
|
34
|
+
|
|
35
|
+
# 运行(stdio 模式)
|
|
36
|
+
markdown-json-excel-mcp
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### MCP 客户端配置
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"mcpServers": {
|
|
44
|
+
"markdown-json-excel": {
|
|
45
|
+
"command": "uvx",
|
|
46
|
+
"args": ["markdown-json-excel-mcp"]
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 使用示例
|
|
53
|
+
|
|
54
|
+
### JSON 转 Excel
|
|
55
|
+
|
|
56
|
+
输入:
|
|
57
|
+
```json
|
|
58
|
+
[
|
|
59
|
+
{"姓名": "张三", "年龄": 25, "城市": "杭州"},
|
|
60
|
+
{"姓名": "李四", "年龄": 30, "城市": "绍兴"}
|
|
61
|
+
]
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
输出:`Excel 已生成:/tmp/excel_output/output_xxx.xlsx,共 2 行 3 列`
|
|
65
|
+
|
|
66
|
+
### Markdown 表格转 Excel
|
|
67
|
+
|
|
68
|
+
输入:
|
|
69
|
+
```
|
|
70
|
+
| 产品 | 销量 | 单价 |
|
|
71
|
+
|------|------|------|
|
|
72
|
+
| 制冷 | 120 | 2500 |
|
|
73
|
+
| 电子 | 80 | 1500 |
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
输出:`Excel 已生成:/tmp/excel_output/output_xxx.xlsx,共 2 行 3 列`
|
|
77
|
+
|
|
78
|
+
### CSV 转 Excel
|
|
79
|
+
|
|
80
|
+
输入:
|
|
81
|
+
```
|
|
82
|
+
日期,销售额,订单数
|
|
83
|
+
2024-01,120000,320
|
|
84
|
+
2024-02,150000,410
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
输出:`Excel 已生成:/tmp/excel_output/output_xxx.xlsx,共 2 行 3 列`
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# markdown-json-excel-mcp
|
|
2
|
+
|
|
3
|
+
MCP Server:把 Markdown 表格 / JSON / CSV 数据转成 Excel 文件。
|
|
4
|
+
|
|
5
|
+
## 项目简介
|
|
6
|
+
|
|
7
|
+
这是一个基于 MCP(Model Context Protocol)的工具服务,可以把各种格式的表格数据转换成 Excel 文件。适用于需要快速生成 Excel 报表的场景,比如数据导出、报表生成、批量表格处理等。
|
|
8
|
+
|
|
9
|
+
## 功能列表
|
|
10
|
+
|
|
11
|
+
| 工具 | 功能 |
|
|
12
|
+
|---|---|
|
|
13
|
+
| `json_to_excel` | JSON 数组 / 对象转 Excel |
|
|
14
|
+
| `markdown_table_to_excel` | Markdown 表格转 Excel |
|
|
15
|
+
| `text_to_excel` | CSV / TSV 文本转 Excel |
|
|
16
|
+
|
|
17
|
+
## 部署指南
|
|
18
|
+
|
|
19
|
+
### 本地测试
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# 安装依赖
|
|
23
|
+
pip install markdown-json-excel-mcp
|
|
24
|
+
|
|
25
|
+
# 运行(stdio 模式)
|
|
26
|
+
markdown-json-excel-mcp
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### MCP 客户端配置
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"mcpServers": {
|
|
34
|
+
"markdown-json-excel": {
|
|
35
|
+
"command": "uvx",
|
|
36
|
+
"args": ["markdown-json-excel-mcp"]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 使用示例
|
|
43
|
+
|
|
44
|
+
### JSON 转 Excel
|
|
45
|
+
|
|
46
|
+
输入:
|
|
47
|
+
```json
|
|
48
|
+
[
|
|
49
|
+
{"姓名": "张三", "年龄": 25, "城市": "杭州"},
|
|
50
|
+
{"姓名": "李四", "年龄": 30, "城市": "绍兴"}
|
|
51
|
+
]
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
输出:`Excel 已生成:/tmp/excel_output/output_xxx.xlsx,共 2 行 3 列`
|
|
55
|
+
|
|
56
|
+
### Markdown 表格转 Excel
|
|
57
|
+
|
|
58
|
+
输入:
|
|
59
|
+
```
|
|
60
|
+
| 产品 | 销量 | 单价 |
|
|
61
|
+
|------|------|------|
|
|
62
|
+
| 制冷 | 120 | 2500 |
|
|
63
|
+
| 电子 | 80 | 1500 |
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
输出:`Excel 已生成:/tmp/excel_output/output_xxx.xlsx,共 2 行 3 列`
|
|
67
|
+
|
|
68
|
+
### CSV 转 Excel
|
|
69
|
+
|
|
70
|
+
输入:
|
|
71
|
+
```
|
|
72
|
+
日期,销售额,订单数
|
|
73
|
+
2024-01,120000,320
|
|
74
|
+
2024-02,150000,410
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
输出:`Excel 已生成:/tmp/excel_output/output_xxx.xlsx,共 2 行 3 列`
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Excel MCP Server(stdio 模式)
|
|
3
|
+
|
|
4
|
+
支持:
|
|
5
|
+
1. JSON 数据转 Excel
|
|
6
|
+
2. Markdown 表格转 Excel
|
|
7
|
+
3. CSV/TSV 文本转 Excel
|
|
8
|
+
"""
|
|
9
|
+
import io
|
|
10
|
+
import json
|
|
11
|
+
from datetime import datetime
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
from fastmcp import FastMCP
|
|
15
|
+
from openpyxl import Workbook
|
|
16
|
+
|
|
17
|
+
mcp = FastMCP("markdown-json-excel")
|
|
18
|
+
|
|
19
|
+
# 输出目录
|
|
20
|
+
OUTPUT_DIR = Path("/tmp/excel_output")
|
|
21
|
+
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _save_excel(headers: list, rows: list, filename: str | None = None) -> str:
|
|
25
|
+
"""把数据存成 Excel,返回文件路径。"""
|
|
26
|
+
wb = Workbook()
|
|
27
|
+
ws = wb.active
|
|
28
|
+
ws.append(headers)
|
|
29
|
+
for row in rows:
|
|
30
|
+
ws.append(row)
|
|
31
|
+
|
|
32
|
+
if not filename:
|
|
33
|
+
ts = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
34
|
+
filename = f"output_{ts}.xlsx"
|
|
35
|
+
path = OUTPUT_DIR / filename
|
|
36
|
+
wb.save(path)
|
|
37
|
+
return str(path)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@mcp.tool()
|
|
41
|
+
def json_to_excel(
|
|
42
|
+
data: str,
|
|
43
|
+
filename: str | None = None,
|
|
44
|
+
) -> str:
|
|
45
|
+
"""
|
|
46
|
+
把 JSON 数据转成 Excel 文件。
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
data: JSON 字符串,支持两种格式:
|
|
50
|
+
1. 数组对象:[{"name":"张三","age":20},{"name":"李四","age":30}]
|
|
51
|
+
2. 带表头的对象:{"columns":["姓名","年龄"],"data":[["张三",20],["李四",30]]}
|
|
52
|
+
filename: 输出文件名(可选)
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
生成的 Excel 文件路径
|
|
56
|
+
"""
|
|
57
|
+
parsed = json.loads(data)
|
|
58
|
+
|
|
59
|
+
if isinstance(parsed, list) and len(parsed) > 0:
|
|
60
|
+
headers = list(parsed[0].keys())
|
|
61
|
+
rows = [[item.get(h, "") for h in headers] for item in parsed]
|
|
62
|
+
elif isinstance(parsed, dict) and "columns" in parsed and "data" in parsed:
|
|
63
|
+
headers = parsed["columns"]
|
|
64
|
+
rows = parsed["data"]
|
|
65
|
+
else:
|
|
66
|
+
raise ValueError("JSON 格式不支持,请传数组对象或 {columns, data} 格式")
|
|
67
|
+
|
|
68
|
+
path = _save_excel(headers, rows, filename)
|
|
69
|
+
return f"Excel 已生成:{path},共 {len(rows)} 行 {len(headers)} 列"
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@mcp.tool()
|
|
73
|
+
def markdown_table_to_excel(
|
|
74
|
+
markdown: str,
|
|
75
|
+
filename: str | None = None,
|
|
76
|
+
) -> str:
|
|
77
|
+
"""
|
|
78
|
+
把 Markdown 表格转成 Excel 文件。
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
markdown: Markdown 表格文本,例如:
|
|
82
|
+
| 姓名 | 年龄 | 城市 |
|
|
83
|
+
|------|------|------|
|
|
84
|
+
| 张三 | 25 | 杭州 |
|
|
85
|
+
| 李四 | 30 | 绍兴 |
|
|
86
|
+
filename: 输出文件名(可选)
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
生成的 Excel 文件路径
|
|
90
|
+
"""
|
|
91
|
+
lines = [l.strip() for l in markdown.strip().splitlines() if l.strip()]
|
|
92
|
+
table_lines = [l for l in lines if l.startswith("|") and l.endswith("|")]
|
|
93
|
+
|
|
94
|
+
if len(table_lines) < 2:
|
|
95
|
+
raise ValueError("未检测到有效的 Markdown 表格")
|
|
96
|
+
|
|
97
|
+
def parse_row(line: str) -> list:
|
|
98
|
+
cells = [c.strip() for c in line.split("|")]
|
|
99
|
+
return [c for c in cells if c != ""]
|
|
100
|
+
|
|
101
|
+
headers = parse_row(table_lines[0])
|
|
102
|
+
# 第二行是分隔线,跳过
|
|
103
|
+
rows = [parse_row(l) for l in table_lines[2:]]
|
|
104
|
+
|
|
105
|
+
path = _save_excel(headers, rows, filename)
|
|
106
|
+
return f"Excel 已生成:{path},共 {len(rows)} 行 {len(headers)} 列"
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@mcp.tool()
|
|
110
|
+
def text_to_excel(
|
|
111
|
+
text: str,
|
|
112
|
+
delimiter: str = ",",
|
|
113
|
+
has_header: bool = True,
|
|
114
|
+
filename: str | None = None,
|
|
115
|
+
) -> str:
|
|
116
|
+
"""
|
|
117
|
+
把分隔符文本(CSV / TSV 等)转成 Excel。
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
text: 文本内容,按行分隔,每行按 delimiter 分割
|
|
121
|
+
delimiter: 分隔符,默认逗号
|
|
122
|
+
has_header: 第一行是否是表头
|
|
123
|
+
filename: 输出文件名(可选)
|
|
124
|
+
|
|
125
|
+
Returns:
|
|
126
|
+
生成的 Excel 文件路径
|
|
127
|
+
"""
|
|
128
|
+
lines = text.strip().splitlines()
|
|
129
|
+
if has_header:
|
|
130
|
+
headers = lines[0].split(delimiter)
|
|
131
|
+
rows = [l.split(delimiter) for l in lines[1:]]
|
|
132
|
+
else:
|
|
133
|
+
headers = [f"列{i+1}" for i in range(len(lines[0].split(delimiter)))]
|
|
134
|
+
rows = [l.split(delimiter) for l in lines]
|
|
135
|
+
|
|
136
|
+
path = _save_excel(headers, rows, filename)
|
|
137
|
+
return f"Excel 已生成:{path},共 {len(rows)} 行 {len(headers)} 列"
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def main():
|
|
141
|
+
"""启动 MCP 服务(stdio 模式)。"""
|
|
142
|
+
mcp.run()
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
if __name__ == "__main__":
|
|
146
|
+
main()
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: markdown-json-excel-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP server: convert markdown tables, JSON and CSV to Excel files
|
|
5
|
+
Author: shsy-cong
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: fastmcp>=2.0
|
|
9
|
+
Requires-Dist: openpyxl>=3.1
|
|
10
|
+
|
|
11
|
+
# markdown-json-excel-mcp
|
|
12
|
+
|
|
13
|
+
MCP Server:把 Markdown 表格 / JSON / CSV 数据转成 Excel 文件。
|
|
14
|
+
|
|
15
|
+
## 项目简介
|
|
16
|
+
|
|
17
|
+
这是一个基于 MCP(Model Context Protocol)的工具服务,可以把各种格式的表格数据转换成 Excel 文件。适用于需要快速生成 Excel 报表的场景,比如数据导出、报表生成、批量表格处理等。
|
|
18
|
+
|
|
19
|
+
## 功能列表
|
|
20
|
+
|
|
21
|
+
| 工具 | 功能 |
|
|
22
|
+
|---|---|
|
|
23
|
+
| `json_to_excel` | JSON 数组 / 对象转 Excel |
|
|
24
|
+
| `markdown_table_to_excel` | Markdown 表格转 Excel |
|
|
25
|
+
| `text_to_excel` | CSV / TSV 文本转 Excel |
|
|
26
|
+
|
|
27
|
+
## 部署指南
|
|
28
|
+
|
|
29
|
+
### 本地测试
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# 安装依赖
|
|
33
|
+
pip install markdown-json-excel-mcp
|
|
34
|
+
|
|
35
|
+
# 运行(stdio 模式)
|
|
36
|
+
markdown-json-excel-mcp
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### MCP 客户端配置
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"mcpServers": {
|
|
44
|
+
"markdown-json-excel": {
|
|
45
|
+
"command": "uvx",
|
|
46
|
+
"args": ["markdown-json-excel-mcp"]
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 使用示例
|
|
53
|
+
|
|
54
|
+
### JSON 转 Excel
|
|
55
|
+
|
|
56
|
+
输入:
|
|
57
|
+
```json
|
|
58
|
+
[
|
|
59
|
+
{"姓名": "张三", "年龄": 25, "城市": "杭州"},
|
|
60
|
+
{"姓名": "李四", "年龄": 30, "城市": "绍兴"}
|
|
61
|
+
]
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
输出:`Excel 已生成:/tmp/excel_output/output_xxx.xlsx,共 2 行 3 列`
|
|
65
|
+
|
|
66
|
+
### Markdown 表格转 Excel
|
|
67
|
+
|
|
68
|
+
输入:
|
|
69
|
+
```
|
|
70
|
+
| 产品 | 销量 | 单价 |
|
|
71
|
+
|------|------|------|
|
|
72
|
+
| 制冷 | 120 | 2500 |
|
|
73
|
+
| 电子 | 80 | 1500 |
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
输出:`Excel 已生成:/tmp/excel_output/output_xxx.xlsx,共 2 行 3 列`
|
|
77
|
+
|
|
78
|
+
### CSV 转 Excel
|
|
79
|
+
|
|
80
|
+
输入:
|
|
81
|
+
```
|
|
82
|
+
日期,销售额,订单数
|
|
83
|
+
2024-01,120000,320
|
|
84
|
+
2024-02,150000,410
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
输出:`Excel 已生成:/tmp/excel_output/output_xxx.xlsx,共 2 行 3 列`
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
excel_mcp/__init__.py
|
|
4
|
+
excel_mcp/__main__.py
|
|
5
|
+
excel_mcp/server.py
|
|
6
|
+
markdown_json_excel_mcp.egg-info/PKG-INFO
|
|
7
|
+
markdown_json_excel_mcp.egg-info/SOURCES.txt
|
|
8
|
+
markdown_json_excel_mcp.egg-info/dependency_links.txt
|
|
9
|
+
markdown_json_excel_mcp.egg-info/entry_points.txt
|
|
10
|
+
markdown_json_excel_mcp.egg-info/requires.txt
|
|
11
|
+
markdown_json_excel_mcp.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
excel_mcp
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "markdown-json-excel-mcp"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
authors = [{ name = "shsy-cong" }]
|
|
9
|
+
description = "MCP server: convert markdown tables, JSON and CSV to Excel files"
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"fastmcp>=2.0",
|
|
14
|
+
"openpyxl>=3.1",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[tool.setuptools.packages.find]
|
|
18
|
+
include = ["excel_mcp*"]
|
|
19
|
+
|
|
20
|
+
[project.scripts]
|
|
21
|
+
markdown-json-excel-mcp = "excel_mcp.server:main"
|