内容
# JSON MCP 服务器 (@gongrzhe/server-json-mcp@1.0.3)
查询和操作 JSON 数据的 JSON 模型上下文协议(MCP)服务器实现。此服务器使 LLM 能够通过一组标准化的工具与 JSON 数据交互。
<a href="https://glama.ai/mcp/servers/9g137c4b4k">
<img width="380" height="200" src="https://glama.ai/mcp/servers/9g137c4b4k/badge" alt="JSON 服务器 MCP 服务器" />
</a>
## 安装与使用
```bash
# 使用 npx 指定版本(推荐)
npx @gongrzhe/server-json-mcp@1.0.3
# 全局安装指定版本
npm install -g @gongrzhe/server-json-mcp@1.0.3
# 全局安装后运行
server-json-mcp
```
## 组件
### 工具
- **查询**
- 使用带有扩展操作的 JSONPath 语法查询 JSON 数据
- 输入:
- `url`(字符串):JSON 数据源的 URL
- `jsonPath`(字符串):带有可选操作的 JSONPath 表达式
- **过滤**
- 使用条件过滤 JSON 数据
- 输入:
- `url`(字符串):JSON 数据源的 URL
- `jsonPath`(字符串):基础 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
{
"json": {
"command": "npx",
"args": [
"@gongrzhe/server-json-mcp@1.0.3"
]
}
}
```
或者,如果您已安装该软件包,可以直接使用 node 命令:
```json
{
"json": {
"command": "node",
"args": [
"path/to/build/index.js"
]
}
}
```
## 开发
### 从源代码构建
1. 克隆仓库
2. 安装依赖:
```bash
npm install
```
3. 构建项目:
```bash
npm run build
```
## 注意事项
1. 所有 JSONPath 表达式均以 `$` 开头,表示根对象
2. 数组索引从零开始
3. 操作中的字符串值应括在引号中
4. 日期操作支持 'days'、'months' 和 'years' 单位
5. 数值操作支持基本算术运算符(+、-、\*、/)
## License
MIT