一个强大的模型上下文协议(MCP)服务器,提供本地文件和远程HTTP/HTTPS端点的JSON模式生成和过滤工具。使用quicktype构建,以生成健壮的TypeScript类型。
<a href="https://glama.ai/mcp/servers/@kehvinbehvin/json-mcp"> <img width="380" height="200" src="https://gips1.baidu.com/it/u=701535186,2826575631&fm=3081&app=3081&f=PNG?w=760&h=400" alt="JSON Server MCP 服务器" />适用于:过滤大型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 <repository-url>
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生成类型以保证安全