JSON-MCP服务器
一种模型上下文协议服务器实现,使大型语言模型能够使用扩展的JSONPath语法查询和操作JSON数据,支持过滤、排序、转换和聚合数据的操作。
可用工具 (2 个)
该服务在 MCP 协议中暴露的工具,AI 可按需调用
query 2 个参数 需填 2 项
Query JSON data using JSONPath syntax
必填参数:url、jsonPath
filter 3 个参数 需填 3 项
Filter JSON data using conditions
必填参数:url、jsonPath、condition
服务介绍
JSON MCP 服务器 (@gongrzhe/server-json-mcp@1.0.3)
一个用于查询和操作 JSON 数据的 JSON 模型上下文协议 (MCP) 服务器实现。该服务器通过一组标准化工具使 LLMs 能够与 JSON 数据进行交互。
安装与使用
# Using npx with specific version (recommended)
npx @gongrzhe/server-json-mcp@1.0.3
# Install specific version globally
npm install -g @gongrzhe/server-json-mcp@1.0.3
# Run after global installation
server-json-mcp
组件
工具
-
query
- 使用带有扩展操作的 JSONPath 语法查询 JSON 数据
- 输入:
url(字符串): JSON 数据源的 URLjsonPath(字符串): 带有可选操作的 JSONPath 表达式
-
filter
- 使用条件过滤 JSON 数据
- 输入:
url(字符串): JSON 数据源的 URLjsonPath(字符串): 基础 JSONPath 表达式condition(字符串): 过滤条件
支持的操作
数组操作
- 切片:
$[0:5],$[-3:],$[1:4] - 排序:
$.sort(price),$.sort(-price) - 去重:
$.distinct() - 转换:
- 映射:
$.map(fieldName) - 展平:
$.flatten() - 并集:
$.union([1,2,3]) - 交集:
$.intersection([1,2,3])
- 映射:
字符串操作
- 大小写:
$.toLowerCase(),$.toUpperCase() - 测试:
$.startsWith('test'),$.endsWith('test') - 搜索:
$.contains('test'),$.matches('pattern')
数值操作
- 数学运算:
$.math(+10),$.pow2() - 取整:
$.round(),$.floor(),$.ceil() - 函数:
$.abs(),$.sqrt()
日期操作
- 格式化:
$.format('YYYY-MM-DD') - 检查:
$.isToday() - 修改:
$.add(1, 'days')
聚合操作
- 分组:
$.groupBy(category) - 统计:
$.sum(price),$.avg(price),$.min(price),$.max(price)
配置
与 Claude Desktop 一起使用
要在 Claude Desktop 应用程序中使用此服务器,请将以下配置添加到您的 claude_desktop_config.json 中:
{
"json": {
"command": "npx",
"args": [
"@gongrzhe/server-json-mcp@1.0.3"
]
}
}
或者,如果您已安装该包,可以直接使用 node 命令:
{
"json": {
"command": "node",
"args": [
"path/to/build/index.js"
]
}
}
开发
从源代码构建
- 克隆仓库
- 安装依赖项:
npm install - 构建项目:
npm run build
注意事项
- 所有 JSONPath 表达式都以
$开头,表示根对象 - 数组索引从零开始
- 操作中的字符串值应使用引号包裹
- 日期操作支持 'days', 'months' 和 'years' 单位
- 数值操作支持基本算术运算符 (+, -, *, /)
许可证
MIT