Skip to main content

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

Project description

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 来改进项目。

联系方式

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

csv2json_mcp-0.1.4.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

csv2json_mcp-0.1.4-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file csv2json_mcp-0.1.4.tar.gz.

File metadata

  • Download URL: csv2json_mcp-0.1.4.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for csv2json_mcp-0.1.4.tar.gz
Algorithm Hash digest
SHA256 14379fbf00d50da0439daaf93b78d193ac6f74597f69af5cdfc7ac00d84a6e21
MD5 ac36c470ebd75a289c01d8940fcc31c5
BLAKE2b-256 e41f360138c595566cf892326796ee76215fa4b1a35aa74aeac7d3324a276ef2

See more details on using hashes here.

File details

Details for the file csv2json_mcp-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: csv2json_mcp-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for csv2json_mcp-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7206a80a1c6894cdd50ddf4d2fe3137ea93b566d737db548e0a8b75ad0c2d9fb
MD5 7d5908a229ffab266de330ab5cfa0b81
BLAKE2b-256 de819ec24d4e3e8b2c89c06d700e92c9348996316afd2f2827fa49c44e771969

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page