Skip to main content

CSV2JSON MCP 服务器

一个基于 FastMCP 的 CSV 到 JSON 转换 MCP (Model Context Protocol) 服务器,提供高效的 CSV 数据转换服务。

功能特性

  • ✅ CSV 文件信息获取 - 获取 CSV 文件大小、行列数、列名等基本信息
  • ✅ CSV 文件转 JSON 文件 - 将 CSV 文件转换为 JSON 文件格式
  • ✅ CSV 字符串转 JSON - 将 CSV 格式的字符串转换为 JSON 数据
  • 🚀 高性能转换 - 基于 pandas 的高效数据处理
  • 🔧 灵活配置 - 支持多种分隔符、编码格式和 JSON 输出格式
  • 📚 MCP 协议 - 符合 Model Context Protocol 标准

快速开始

环境要求

  • Python 3.11+

MCP 服务器配置

mcp server 配置

 {
  "mcpServers": {
   "csv2json": {
      "command": "uvx",
      "args": ["csv2json-mcp"],
      "type": "stdio"
    } 
  }
}

可用工具

1. get_csv_info

获取 CSV 文件的基本信息,用于辅助转换操作。

参数:

  • file_path (str): CSV 文件路径

返回值:

{
    "success": true,
    "file_info": {
        "file_size": 132,
        "row_count": 5,
        "column_count": 4,
        "columns": ["name", "age", "city", "score"],
        "sample_data": [/* 示例数据 */],
        "file_encoding": "utf-8",
        "detected_delimiter": ","
    },
    "message": "CSV 文件信息获取成功"
}

2. convert_csv_file

将 CSV 文件转换为 JSON 文件。

参数:

  • file_path (str): CSV 文件路径
  • output_file_path (str, 可选): 输出 JSON 文件路径,默认为 CSV 文件同目录下的 .json 文件
  • delimiter (str, 可选): CSV 分隔符,默认为 ,
  • orient (str, 可选): JSON 输出格式,默认为 "records"
  • encoding (str, 可选): 文件编码,默认为 "utf-8"

返回值:

{
    "success": true,
    "json_file_path": "path/to/output.json",
    "message": "转换成功"
}

3. convert_csv_string

将 CSV 格式的字符串转换为 JSON 数据。

参数:

  • csv_content (str): CSV 格式的字符串内容
  • delimiter (str, 可选): CSV 分隔符,默认为 ,
  • skip_rows (int, 可选): 跳过的行数,默认为 0
  • header (bool, 可选): 是否包含表头,默认为 true
  • orient (str, 可选): JSON 输出格式,默认为 "records"
  • indent (int, 可选): JSON 缩进,默认为 None

返回值:

{
    "success": true,
    "json": [/* JSON 数据 */],
    "message": "CSV 字符串转换成功"
}

JSON 输出格式

支持以下 JSON 输出格式:

  • "records": 每行作为一个字典对象的列表(默认)
  • "values": 仅包含值的二维数组
  • "index": 包含索引的字典
  • "table": 包含 schema 和数据的完整表格格式
  • "split": 分开存储列名和数据的格式

项目结构

csv2json-mcp/
├── csv2json_mcp/          # 核心包
│   ├── __init__.py        # 包初始化
│   ├── converter.py       # 转换器实现
│   └── server.py          # MCP 服务器
├── example/               # 示例文件
│   ├── example.csv        # 示例 CSV 文件
│   ├── example_client.py  # 客户端示例
│   └── example_output.json # 输出示例
├── pyproject.toml         # 项目配置
└── README.md             # 项目文档

许可证

本项目采用 MIT 许可证。

贡献

欢迎提交 Issue 和 Pull Request 来改进项目。

联系方式

如有问题,请通过以下方式联系:

Metadata

Release files for csv2json-mcp 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for csv2json-mcp 0.1.4
File Size Uploaded Provenance
csv2json_mcp-0.1.4.tar.gz 10.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for csv2json-mcp 0.1.4
File Interpreter ABI Platform
csv2json_mcp-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 19.6 kB

Release files / csv2json_mcp-0.1.4.tar.gz

Download URL csv2json_mcp-0.1.4.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
14379fbf00d50da0439daaf93b78d193ac6f74597f69af5cdfc7ac00d84a6e21
BLAKE2b-256 checksum
How to use checksums
e41f360138c595566cf892326796ee76215fa4b1a35aa74aeac7d3324a276ef2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / csv2json_mcp-0.1.4-py3-none-any.whl

Download URL csv2json_mcp-0.1.4-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7206a80a1c6894cdd50ddf4d2fe3137ea93b566d737db548e0a8b75ad0c2d9fb
BLAKE2b-256 checksum
How to use checksums
de819ec24d4e3e8b2c89c06d700e92c9348996316afd2f2827fa49c44e771969
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Security for csv2json-mcp 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page