JSON搜索服务器

一个通用的MCP-RAG服务器,可将任何JSON文件转换为AI助手可搜索的知识库。

  • by akapug
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 akapug/mcp-rag-generic

使用说明

通用MCP-RAG服务器

一种通用的模型上下文协议(MCP)服务器,可以为 任何JSON文件 作为Windsurf和Cursor等人工智能助手的可搜索资源。在几秒钟内将您的数据转换为AI可访问的知识库。

🚀 快速开始

# Clone the repository
git clone https://github.com/akapug/mcp-rag-generic.git
cd mcp-rag-generic

# Serve any JSON file
node mcp-rag-server.js your-data.json

# Or with custom configuration
node mcp-rag-server.js --file docs.json --name "Documentation" --port 8127

✨ 特性

  • 通用JSON支持:适用于任何有效的JSON文件结构
  • 零依赖:仅使用Node.js内置模块
  • 命令行接口:通过CLI参数灵活配置
  • 增强型搜索:通过嵌套JSON结构进行深度搜索
  • 符合MCP协议:完全支持模型上下文协议
  • 实时就绪:服务器发送事件(SSE)支持
  • 自动配置:基于文件名的智能默认值

📋 需求

  • Node.js 14.x或更高版本
  • 您想搜索的任何JSON文件

🛠 安装

选项1:克隆并运行

git clone https://github.com/akapug/mcp-rag-generic.git
cd mcp-rag-generic
node mcp-rag-server.js --help

选项2:直接下载

下载 mcp-rag-server.js 并直接运行它:

node mcp-rag-server.js your-data.json

📖 用法

基本用法

# Serve a JSON file with automatic configuration
node mcp-rag-server.js data.json

高级配置

node mcp-rag-server.js \
  --file my-docs.json \
  --name "My Documentation" \
  --uri "docs:knowledge" \
  --port 8127 \
  --server-name "Custom RAG Server"

命令行选项

选项 简短 描述 默认
--file -f 要提供的JSON文件的路径 必需的
--port -p 运行服务器的端口 8126
--name -n 人可读资源名称 自动生成
--uri -u 资源的URI标识符 自动生成
--server-name -s MCP服务器的名称 “通用MCP RAG服务器”
--help -h 显示帮助消息 -

自动生成的默认值

如果您没有指定 --name 或 --uri,服务器将根据您的文件名生成它们:

  • 文件: api-documentation.json
  • 姓名: "Api Documentation"
  • URI: "rag:api_documentation"

🔌 风帆/光标集成

1.启动服务器

node mcp-rag-server.js your-data.json
# Server running on http://localhost:8126

2.配置MCP客户端

添加到您的 mcp_config.json:

{
  "mcpServers": {
    "MyDataRAG": {
      "serverUrl": "http://localhost:8126/sse"
    }
  }
}

3.重新启动您的AI助手

重新启动Windsurf或Cursor以加载新的MCP服务器。

4.开始搜索!

您的AI助手现在可以搜索您的JSON数据:

  • 使用 search_data 查询内容的工具
  • 作为MCP资源访问完整的JSON结构
  • 使用数据路径获取上下文搜索结果

🔍 搜索功能

服务器提供强大的搜索功能:

搜索类型

  • 密钥匹配:查找包含搜索词的JSON键
  • 价值搜索:搜索所有字符串值
  • 深度穿越:搜索嵌套对象和数组
  • 路径跟踪:显示每个结果的确切位置

搜索结果格式

{
  "path": "projects.frontend.dependencies[2]",
  "type": "string",
  "value": "react-router-dom",
  "context": "react-router-dom"
}

📊 示例用例

API文档

node mcp-rag-server.js api-docs.json --name "API Reference"

配置数据

node mcp-rag-server.js config.json --name "App Config" --port 8127

知识库

node mcp-rag-server.js knowledge.json --name "Company Knowledge"

产品目录

node mcp-rag-server.js products.json --name "Product Catalog"

🏗 JSON结构支持

服务器可以使用任何JSON结构:

// Simple object
{"name": "value"}

// Nested objects
{
  "section": {
    "subsection": {
      "data": "searchable content"
    }
  }
}

// Arrays
{
  "items": [
    {"name": "item1"},
    {"name": "item2"}
  ]
}

// Mixed structures
{
  "metadata": {"version": "1.0"},
  "data": [
    {"id": 1, "info": {"details": "searchable"}}
  ]
}

🔧 服务器信息端点

访问 http://localhost:8126 (或您配置的端口)查看服务器信息:

{
  "name": "Generic MCP RAG Server",
  "version": "1.0.0",
  "endpoint": "/sse",
  "resource": {
    "uri": "rag:your_data",
    "name": "Your Data",
    "file": "/path/to/your-data.json"
  }
}

由以下材料制成❤️ 面向人工智能开发社区