JSON MCP过滤器是一款强大的模型上下文协议(MCP)服务器,它为本地文件和远程HTTP/HTTPS端点提供JSON模式生成和过滤工具。该工具借助quicktype实现强大的TypeScript类型生成功能。
适用场景:过滤大型JSON文件和API响应,仅提取大语言模型(LLM)上下文中的相关数据,同时保证类型安全。
json_schema从JSON数据生成TypeScript接口。
参数:
filePath:本地文件路径或HTTP/HTTPS URL示例:
// 输入JSON
{"name": "John", "age": 30, "city": "New York"}
// 生成的TypeScript
export interface GeneratedType {
name: string;
age: number;
city: string;
}
json_filter使用基于形状的过滤提取特定字段,并为大型数据集自动分块。
参数:
filePath:本地文件路径或HTTP/HTTPS URLshape:定义要提取哪些字段的对象chunkIndex(可选):大型数据集的分块索引(从0开始)自动分块:
400KB:自动分块并附带元数据
json_dry_run在过滤之前分析数据大小并提供分块建议。
参数:
filePath:本地文件路径或HTTP/HTTPS URLshape:定义要分析的内容的对象返回:大小明细和分块建议
// 简单字段提取
json_filter({
filePath: "https://api.example.com/users",
shape: {"name": true, "email": true}
})
// 单个字段
{"name": true}
// 嵌套对象
{"user": {"name": true, "email": true}}
// 数组(应用于每个项目)
{"users": {"name": true, "age": true}}
// 复杂嵌套
{
"results": {
"profile": {"name": true, "location": {"city": true}}
}
}
// 1. 首先检查大小
json_dry_run({filePath: "./large.json", shape: {"users": {"id": true}}})
// → "建议分块数: 6"
// 2. 获取分块
json_filter({filePath: "./large.json", shape: {"users": {"id": true}}})
// → 分块0 + 元数据
json_filter({filePath: "./large.json", shape: {"users": {"id": true}}, chunkIndex: 1})
// → 分块1 + 元数据
远程数据获取:此工具会从HTTP/HTTPS URL获取数据。用户需要负责:
✅ 安全实践:
❌ 维护者不负责:
💡 建议:仅使用受信任的公共数据源。
# 无需安装
npx json-mcp-filter@latest
npm install -g json-mcp-filter@latest
json-mcp-server
git clone
cd json-mcp-filter
npm install
npm run build
添加到您的配置文件:
{
"mcpServers": {
"json-mcp-filter": {
"command": "npx",
"args": ["-y", "json-mcp-filter@latest"]
}
}
}
# 通过CLI添加
claude mcp add json-mcp-filter npx -y json-mcp-filter@latest
或者手动添加:
json-mcp-filternpx["-y", "json-mcp-filter@latest"]npm run build # 编译TypeScript
npm run start # 运行编译后的服务器
npm run inspect # 使用MCP检查器进行调试
npx tsc --noEmit # 仅进行类型检查
npm run inspect # 交互式测试界面
src/
├── index.ts # 主服务器 + 工具
├── strategies/ # 数据摄取策略
│ ├── JsonIngestionStrategy.ts # 抽象接口
│ ├── LocalFileStrategy.ts # 本地文件访问
│ └── HttpJsonStrategy.ts # HTTP/HTTPS获取
├── context/
│ └── JsonIngestionContext.ts # 策略管理
└── types/
└── JsonIngestion.ts # 类型定义
所有错误都包含可操作的调试信息。
| 文件大小 | 处理时间 |
|---|---|
| < 100 KB | < 10ms |
| 1 - 10 MB | 100ms - 1s |
| 10 - 50 MB | 1s - 5s |
| > 50 MB | 阻止 |
json_dry_runjson_filter进行过滤http://localhostLLM集成:
json_filter提取相关字段json_schema生成类型以确保安全性