MCP-RAG Server
MCP-RAG:带有 RAG 的模型上下文协议🚀
使用 GroundX 和 OpenAI 实现的强大而高效的 RAG(检索增强生成),采用现代上下文处理 (MCP) 构建。
🌟 功能
高级 RAG 实现:利用 GroundX 进行高精度文档检索
模型上下文协议:与 MCP 无缝集成,增强上下文处理
类型安全:使用 Pydantic 构建,可进行强大的类型检查和验证
灵活的配置:通过环境变量轻松定制设置
文档提取:支持 PDF 文档提取和处理
智能搜索:具有评分的语义搜索功能
Related MCP server: PDF Knowledgebase MCP Server
🛠️ 先决条件
Python 3.12 或更高版本
OpenAI API 密钥
GroundX API 密钥
MCP CLI 工具
📦安装
克隆存储库:
git clone <repository-url>
cd mcp-rag创建并激活虚拟环境:
uv sync
source .venv/bin/activate # On Windows, use `.venv\Scripts\activate`⚙️ 配置
复制示例环境文件:
cp .env.example .env在
.env中配置环境变量:
GROUNDX_API_KEY="your-groundx-api-key"
OPENAI_API_KEY="your-openai-api-key"
BUCKET_ID="your-bucket-id"🚀 使用方法
启动服务器
使用以下命令运行检查服务器:
mcp dev server.py文档摄取
要获取新文档:
from server import ingest_documents
result = ingest_documents("path/to/your/document.pdf")
print(result)执行搜索
基本搜索查询:
from server import process_search_query
response = process_search_query("your search query here")
print(f"Query: {response.query}")
print(f"Score: {response.score}")
print(f"Result: {response.result}")使用自定义配置:
from server import process_search_query, SearchConfig
config = SearchConfig(
completion_model="gpt-4",
bucket_id="custom-bucket-id"
)
response = process_search_query("your query", config)📚 依赖项
groundx(≥2.3.0):核心 RAG 功能openai(≥1.75.0):OpenAI API 集成mcp[cli](≥1.6.0):现代上下文处理工具ipykernel(≥6.29.5):Jupyter 笔记本支持
🔒 安全
切勿提交包含 API 密钥的
.env文件对所有敏感信息使用环境变量
定期轮换您的 API 密钥
监控 API 使用情况,防止任何未经授权的访问
🤝 贡献
分叉存储库
创建你的功能分支(
git checkout -b feature/amazing-feature)提交您的更改(
git commit -m 'Add some amazing feature')推送到分支(
git push origin feature/amazing-feature)打开拉取请求
Available Tools
3 toolsingest_documentsB
Ingest documents from a local file into the knowledge base.
Args:
local_file_path: The path to the local file containing the documents to ingest.
Returns:
str: A message indicating the documents have been ingested.
| Name | Required | Description | Default |
|---|---|---|---|
| local_file_path | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action ('ingest') and return value, but lacks details on permissions, side effects (e.g., overwriting), rate limits, or error handling. This is inadequate for a mutation tool with zero annotation coverage.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is well-structured and concise, with a clear purpose statement followed by Args and Returns sections. Each sentence adds value, though the return description could be more specific (e.g., success/failure indicators).
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the tool's complexity (a mutation with no annotations or output schema), the description is minimally adequate. It covers purpose and parameters but lacks behavioral details and output specifics. The absence of annotations increases the burden, leaving gaps in understanding the tool's full behavior.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The description adds meaningful context for the single parameter 'local_file_path' by explaining it's 'the path to the local file containing the documents to ingest.' With schema description coverage at 0%, this compensates well, though it doesn't specify format constraints (e.g., absolute vs. relative paths).
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool's purpose: 'Ingest documents from a local file into the knowledge base.' It specifies the verb ('ingest'), resource ('documents'), and source ('local file'), but doesn't explicitly differentiate from sibling tools like 'process_search_query' or 'search_doc_for_rag_context', which appear to be for querying rather than ingestion.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., file format requirements), exclusions, or compare it to sibling tools. The agent must infer usage from the purpose alone.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
process_search_queryB
Process a search query using GroundX and OpenAI.
Args:
query: The search query string
config: Optional SearchConfig object for customization
Returns:
SearchResponse object containing the query, score, and result
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| config | No |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the technologies (GroundX and OpenAI) but doesn't explain what 'process' entails—whether it's a read-only search, requires API keys, has rate limits, or affects data. The description lacks critical behavioral context for a tool that likely involves external API calls.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is well-structured and concise, with zero wasted words. It starts with the core purpose, then lists parameters and returns in a clear, bullet-like format. Every sentence adds value, making it easy for an agent to parse quickly.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the complexity (2 parameters, no output schema, no annotations), the description is partially complete. It covers the purpose and parameters but lacks behavioral details, usage context, and output explanation. It's adequate as a baseline but has clear gaps, especially for a tool that likely involves external processing.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The description adds meaningful semantics beyond the input schema. It explains that 'query' is a 'search query string' and 'config' is an 'Optional SearchConfig object for customization,' which clarifies their roles. Since schema description coverage is 0%, this compensates well, though it doesn't detail the SearchConfig properties like 'openai_api_key' or 'bucket_id'.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool's purpose: 'Process a search query using GroundX and OpenAI.' It specifies the verb ('process') and resource ('search query'), and mentions the technologies involved. However, it doesn't explicitly differentiate from sibling tools like 'search_doc_for_rag_context' or 'ingest_documents', which prevents a perfect score.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives. There's no mention of sibling tools, specific use cases, or prerequisites. The agent must infer usage from the tool name and description alone, which is insufficient for optimal tool selection.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
search_doc_for_rag_contextC
Searches and retrieves relevant context from a knowledge base,
based on the user's query.
Args:
query: The search query supplied by the user.
Returns:
str: Relevant text content that can be used by the LLM to answer the query.
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool 'searches and retrieves' but doesn't cover critical aspects like whether this is a read-only operation, potential rate limits, authentication requirements, or how results are formatted (e.g., pagination, ranking). For a search tool with zero annotation coverage, this is a significant gap in transparency.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is appropriately sized with three sentences: purpose, parameter explanation, and return value. It's front-loaded with the core functionality and avoids unnecessary fluff. However, the structure could be slightly improved by integrating the 'Args' and 'Returns' sections more seamlessly into the flow.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the tool's complexity (search/retrieval operation), lack of annotations, and no output schema, the description is incomplete. It doesn't explain behavioral traits, usage context, or return format details (beyond stating it returns a string). For a tool that likely involves data retrieval and potential constraints, more comprehensive information is needed.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The description includes an 'Args' section that documents the single parameter 'query' as 'The search query supplied by the user.' With 0% schema description coverage, this adds essential meaning beyond the bare schema. However, it doesn't provide details on query syntax, length limits, or special characters, leaving some semantic gaps. The baseline is 3 since the description compensates partially but not fully.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool's purpose: 'Searches and retrieves relevant context from a knowledge base, based on the user's query.' It specifies the verb ('searches and retrieves'), resource ('relevant context from a knowledge base'), and scope ('based on the user's query'). However, it doesn't explicitly differentiate from sibling tools like 'process_search_query' or 'ingest_documents', which prevents a perfect score.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'process_search_query' or 'ingest_documents', nor does it specify prerequisites, constraints, or appropriate contexts for usage. This leaves the agent without direction on tool selection.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
3 tool updates
v0.1.0- First observed
ingest_documents - First observed
process_search_query - First observed
search_doc_for_rag_context
TDQS
Scored across 3 tools
The tools have significant overlap and unclear boundaries. Both 'process_search_query' and 'search_doc_for_rag_context' appear to handle search queries with similar inputs (query strings) and similar purposes (retrieving relevant information). While 'process_search_query' mentions GroundX and OpenAI integration and returns a structured SearchResponse, while 'search_doc_for_rag_context' returns plain text for RAG context, their core functionality is too similar, likely causing agent confusion about which to use for search tasks.
The naming is mostly consistent with a verb_noun pattern ('ingest_documents', 'process_search_query', 'search_doc_for_rag_context'), though 'search_doc_for_rag_context' is slightly verbose and includes an abbreviation (RAG). All use snake_case, and the verbs ('ingest', 'process', 'search') are appropriate for their actions, with only minor deviations from perfect consistency.
With only 3 tools, the count feels thin for a RAG server's scope, which typically involves more operations like document management (e.g., delete, list), query customization, or knowledge base maintenance. While the tools cover basic ingestion and search, the limited number may restrict agent workflows and indicate an incomplete surface, though it's not extreme.
There are significant gaps in the tool surface for a RAG server. Core operations are missing: no tools to list, update, or delete documents from the knowledge base, and no way to manage the knowledge base itself (e.g., clear or reset). The search functionality is duplicated rather than expanded, and there's no support for advanced RAG features like chunking or metadata handling, which will likely cause agent failures in complex tasks.
Maintenance
Related MCP Connectors
The Needle MCP server enables semantic search on documents stored in files like PDFs, DOCX, and XLSX by connecting AI applications to external data sources. It provides capabilities to create and manage document collections, perform natural language searches on stored content, and retrieve relevant information without requiring exact keyword matches.
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
The CustomGPT.ai MCP server is a fully managed, RAG-powered endpoint that connects large language models with private knowledge bases and external data sources. It provides tools for retrieval-augmented generation queries (send_message), data ingestion (upload_file), and source listing, enabling AI agents to query private documents like PDFs with high accuracy and real-time citations.
MCP server unifying ERPs, CRMs, APIs and knowledge base for Claude, ChatGPT and Gemini.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceImplements Retrieval-Augmented Generation (RAG) using GroundX and OpenAI, allowing users to ingest documents and perform semantic searches with advanced context handling through Modern Context Processing (MCP).5-
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that enables intelligent document search and retrieval from PDF collections, providing semantic search capabilities powered by OpenAI embeddings and ChromaDB vector storage.13MIT
- AlicenseNot gradedqualityNot gradedmaintenanceA Python server that enables retrieval-augmented generation through semantic, question/answer, and style search modalities using PostgreSQL and pgvector for embedding storage and retrieval.2Apache 2.0
- AlicenseNot gradedqualityDmaintenanceA local RAG server that enables document indexing and sentence window retrieval across multiple file formats like PDF, MD, and DOCX. It supports both local Hugging Face models and OpenAI embeddings for efficient context-aware querying through the Model Context Protocol.GPL 3.0