这是一个提供围绕 jq 命令行工具的封装的模型上下文协议(MCP)服务器,用于查询和操作 JSON 数据。
jq 命令行工具macOS:
brew install jq
Ubuntu/Debian:
sudo apt-get install jq
Windows: 从 https://jqlang.github.io/jq/download/ 下载
# 全局安装
npm install -g @247arjun/mcp-jq
# 或者在项目中本地安装
npm install @247arjun/mcp-jq
# 克隆仓库
git clone https://github.com/247arjun/mcp-jq.git
cd mcp-jq
# 安装依赖
npm install
# 构建项目
npm run build
# 可选:全局链接
npm link
# 直接从 GitHub 安装
npm install -g git+https://github.com/247arjun/mcp-jq.git
添加到您的 Claude Desktop 配置文件:
位置:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%/Claude/claude_desktop_config.json配置:
{
"mcpServers": {
"mcp-jq": {
"command": "mcp-jq",
"args": []
}
}
}
替代方案:使用 npx(无需全局安装)
{
"mcpServers": {
"mcp-jq": {
"command": "npx",
"args": ["@247arjun/mcp-jq"]
}
}
}
本地开发设置
{
"mcpServers": {
"mcp-jq": {
"command": "node",
"args": ["/绝对路径/to/mcp-jq/build/index.js"]
}
}
}
添加配置后,请重启 Claude Desktop 以加载 MCP 服务器。
jq_query使用 jq 语法查询 JSON 数据。
参数:
json_data (字符串):要查询的 JSON 数据filter (字符串):jq 过滤表达式raw_output (布尔值,可选):返回原始输出而不是 JSON (默认: false)示例:
{
"json_data": "{\"users\": [{\"name\": \"John\", \"age\": 30}]}",
"filter": ".users[0].name"
}
jq_query_file使用 jq 语法查询 JSON 文件。
参数:
file_path (字符串):JSON 文件路径filter (字符串):jq 过滤表达式raw_output (布尔值,可选):返回原始输出而不是 JSON (默认: false)示例:
{
"file_path": "./data/users.json",
"filter": ".users | length"
}
jq_format格式化和美化 JSON 数据。
参数:
json_data (字符串):要格式化的 JSON 数据示例:
{
"json_data": "{\"name\":\"John\",\"age\":30}"
}
jq_validate验证字符串是否为有效的 JSON。
参数:
json_data (字符串):要验证的 JSON 数据示例:
{
"json_data": "{\"name\": \"John\", \"age\": 30}"
}
jq_keys从 JSON 对象或对象数组中获取所有键。
参数:
json_data (字符串):要提取键的 JSON 数据recursive (布尔值,可选):递归获取键 (默认: false)示例:
{
"json_data": "{\"user\": {\"name\": \"John\", \"details\": {\"age\": 30}}}",
"recursive": true
}
{
"tool": "jq_query",
"json_data": "{\"users\": [{\"name\": \"John\"}, {\"name\": \"Jane\"}]}",
"filter": ".users[].name"
}
{
"tool": "jq_format",
"json_data": "{\"name\":\"John\",\"age\":30,\"city\":\"NYC\"}"
}
{
"tool": "jq_query_file",
"file_path": "./data/config.json",
"filter": ".database.host"
}
# 开发模式自动重建
npm run dev
# 生产构建
npm run build
# 启动服务器
npm start
# 运行测试
npm test
mcp-jq/
├── src/
│ └── index.ts # 主服务器实现
├── build/ # 编译后的 JavaScript (构建后)
├── examples/ # 测试用的样本 JSON 文件
│ ├── users.json
│ └── company.json
├── package.json # 项目依赖和脚本
├── tsconfig.json # TypeScript 配置
├── install.sh # 安装脚本
├── test.js # 测试脚本
└── README.md # 本文档
测试服务器是否正常工作:
# 测试已构建的服务器
node build/index.js
# 应显示: "JQ MCP Server running on stdio"
# 按 Ctrl+C 退出
"命令未找到" 错误
npm install -g @247arjun/mcp-jq"command": "npx", "args": ["@247arjun/mcp-jq"]"权限被拒绝" 错误
chmod +x build/index.jsnpm run buildMCP 服务器未出现在 Claude 中
"jq 命令未找到"
jq --version通过设置环境变量启用详细日志记录:
# 开发模式
DEBUG=1 node build/index.js
# 使用示例输入测试
echo '{"jsonrpc": "2.0", "method": "initialize", "params": {}}' | node build/index.js