上下文MCP服务器是一个具备检索增强生成(RAG)功能的Model Context Protocol(MCP)服务器,它借助Contextual AI,可与多种MCP客户端集成。本说明文档将重点展示其与Cursor IDE和Claude Desktop的集成应用。
此MCP服务器在AI接口(如Cursor IDE或Claude Desktop)与专门的Contextual AI代理之间搭建了一座桥梁,实现了以下核心功能:
Cursor/Claude Desktop → MCP Server → Contextual AI RAG Agent
↑ ↓ ↓
└──────────────────┴─────────────┴───────────────带引用的响应
git clone https://github.com/ContextualAI/contextual-mcp-server.git
cd contextual-mcp-server
python -m venv .venv
source .venv/bin/activate # Windows上使用`.venv\Scripts\activate`
pip install -r requirements.txt
要修改服务器设置,可按以下步骤操作:
在config.py中添加或修改以下内容:
# 示例配置
API_KEY = "your_api_key"
AGENT_ID = "your_agent_id"
使用.env文件存储API密钥和AGENT_ID:
export API_KEY=your_api_key
export AGENT_ID=your_agent_id
要为Cursor IDE或Claude Desktop配置服务器,可按以下步骤操作:
uv路径:which uv # 或者 locate uv
config.json文件,添加以下内容:{
"server": {
"host": "localhost",
"port": 8000
},
"tools": {
"tool1": {
"command": "python tool.py"
}
}
}
使用uv进行依赖管理:
uv init --python
uv run myapp
在Cursor中提问示例:
# 示例问题
server.get_current_time()
要添加新功能,可按以下步骤操作:
@mcp.tool()装饰器:@mcp.tool()
def new_tool(param: str) -> str:
"""描述工具的功能"""
# 实现代码
return 结果
文档中未提及许可证相关信息。
有关Contextual AI的所有功能,请参考官方文档。