JSON 转 Excel MCP(模型上下文协议)提供了一个标准化接口,用于使用模型上下文协议将 JSON 数据转换为 CSV 格式字符串。此 MCP 实现提供了两个特定的数据转换工具:
JSON 转 Excel MCP 是 WTSolutions 的 JSON 转 Excel 工具包的一部分:
可用的 MCP 服务器(SSE 和 Streamable HTTP):
服务器配置 JSON:
{
"mcpServers": {
"json_to_excel": {
"args": [
"mcp-remote",
"https://mcp2.wtsolutions.cn/sse",
"--transport",
"sse-only"
],
"command": "npx"
}
}
}
传输方式:SSE
URL: https://mcp2.wtsolutions.cn/sse
服务器配置 JSON:
{
"mcpServers": {
"json2excelsse": {
"type": "sse",
"url": "https://mcp2.wtsolutions.cn/sse"
}
}
}
传输方式:Streamable HTTP
URL: https://mcp2.wtsolutions.cn/mcp
服务器配置 JSON:
{
"mcpServers": {
"json2excelmcp": {
"type": "streamableHttp",
"url": "https://mcp2.wtsolutions.cn/mcp"
}
}
}
将 JSON 数据字符串转换为 CSV 格式字符串。
参数 | 类型 | 是否必需 | 描述 |
---|---|---|---|
data | string | 是 | 要转换为 CSV 的 JSON 数据字符串。必须是有效的 JSON 数组或对象。 |
注意:
将以下 JSON 数据转换为 CSV 格式:
[
{"Name": "张三", "Age": 25, "IsStudent": false},
{"Name": "李四", "Age": 30, "IsStudent": true}
]
将以下 JSON 对象转换为 CSV 格式:
{
"Name": "张三",
"Age": 25,
"IsStudent": false,
"Courses": ["数学", "科学"]
}
将提供的 URL 中的 JSON 数据转换为 Excel 数据。
参数 | 类型 | 是否必需 | 描述 |
---|---|---|---|
url | string | 是 | 指向 JSON 文件(.json)的 URL |
注意:
将 JSON 文件转换为 Excel,文件 URL: https://mcp.wtsolutions.cn/example.json
(仅当您没有 URL 并使用在线 AI LLM 时适用)
我刚刚上传了一个 .json 文件给您,请提取其 URL 并将其发送到 MCP 工具 ‘json_to_excel_mcp_from_url’,以进行 JSON 到 Excel 的转换。
MCP 工具返回具有以下结构的 JSON 对象:
字段 | 类型 | 描述 |
---|---|---|
isError | boolean | 指示处理请求时是否出错 |
msg | string | ‘success’ 或错误描述 |
data | string | 转换后的 CSV 数据字符串,出错时为空字符串。此 CSV 数据可轻松导入到 Excel。 |
{
"content": [{
"type": "text",
"text": "{\"isError\":false,\"msg\":\"success\",\"data\":\"Name,Age,IsStudent\n张三,25,false\n李四,30,true\"}"
}]
}
以上是 MCP 工具的响应,在大多数情况下,您的 LLM 应该解释响应并向您呈现一个 JSON 对象,例如如下所示。
注意,不同的 LLM 模型可能有不同的解释 JSON 对象的方式,因此请检查您的 LLM 模型是否正确解释了 JSON 对象。
{
"isError": false,
"msg": "success",
"data": "Name,Age,IsStudent\n张三,25,false\n李四,30,true"
}
{
"content": [{
"type": "text",
"text": "{\"isError\": true, \"msg\": \"Invalid JSON format\", \"data\": \"\"}"
}]
}
以上是 MCP 工具的响应,在大多数情况下,您的 LLM 应该解释响应并向您呈现一个 JSON 对象,例如如下所示。
注意,不同的 LLM 模型可能有不同的解释 JSON 对象的方式,因此请检查响应是否被您的 LLM 模型正确解释。
{
"isError": true,
"msg": "Invalid JSON format",
"data": ""
}
或者,您的 LLM 可能会对您说"无效的 JSON 格式,请提供有效的 JSON 字符串"。
API 自动处理 JSON 中的不同数据类型:
MCP 为常见问题返回描述性错误消息:
Invalid JSON format
:当输入数据不是有效的 JSON 字符串时Empty JSON data
:当输入数据是空的 JSON 字符串时Network Error when fetching file
:当从提供的 URL 下载文件时出错时File not found
:当找不到提供的 URL 上的文件时Server Internal Error
:当发生意外错误时目前免费。