MCP恢复服务器
用于人工智能简历匹配和生成的生产就绪模型上下文协议(MCP)服务器。
特性
- 🔍 向量相似性搜索:为职位描述找到最匹配的候选人
- 🤖 人工智能简历生成:使用LLM生成优化的简历
- 📊 工作分析:从职位描述中提取关键要求和技能
- 🚀 MCP协议支持:全面实施MCP 2024-11-05规范
- 🌐 HTTP/SSE传输:支持流媒体的RESTful API
- 🎯 模块化架构:干净、可维护和可测试的代码结构
1. 依赖注入
服务是通过工厂创建的,并在需要时注入:
# Services are singletons accessed via getters
llm_service = get_llm_service()
vector_service = get_vector_service()2. 抽象基类
易于交换的实现:
class BaseLLMService(ABC):
# Can use Anthropic, OpenAI, or custom LLM
class BaseVectorService(ABC):
# Can use ChromaDB, Pinecone, Weaviate, etc.3. 类型安全
使用Pydantic模型在整个代码库中提供完整的类型提示。
安装
先决条件
- Python 3.11+
- 点
- 紫外线
设置
- 克隆存储库
git clone
cd jcus.link.mcp- 创建虚拟环境
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- 安装依赖项
uv sync- 配置环境
cp .env.example .env
# Edit .env with your configuration- 设置API密钥
# In .env file
LLM_API_KEY=your_anthropic_api_key_here
# or
OPENAI_API_KEY=your_openai_api_key_here运行服务器
发展模式
# From project root
python -m src.main
# Or with auto-reload
uvicorn src.main:app --reload --host 0.0.0.0 --port 8000生产模式
uvicorn src.main:app --host 0.0.0.0 --port 8000 --workers 4码头工人
在本地构建Docker镜像
docker build -t jcus-link-mcp .在本地运行Docker Contianer
docker run -p 8000:8000 --env-file .env jcus-link-mcp API使用
1.健康检查
curl http://localhost:8000/health2.MCP协议-列表工具
curl -X POST http://localhost:8000/mcp/message \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list"
}'3.上传职位描述
curl -X POST http://localhost:8000/upload-job-description \
-F "file=@job_description.txt"4.搜索匹配的简历
curl -X POST http://localhost:8000/search-matches \
-H "Content-Type: application/json" \
-d '{
"job_description": "Senior Python Developer with 5+ years experience...",
"top_k": 5
}'5.分析职位描述
curl -X POST http://localhost:8000/analyze-job \
-H "Content-Type: application/json" \
-d '{
"job_description": "We are looking for a Senior Software Engineer..."
}'6.生成简历(非流媒体)
curl -X POST http://localhost:8000/generate-resume \
-H "Content-Type: application/json" \
-d '{
"job_description": "Senior Developer position...",
"matched_resumes": [...],
"stream": false
}'7.生成简历(流媒体)
curl -N -X POST http://localhost:8000/generate-resume-stream \
-H "Content-Type: application/json" \
-d '{
"job_description": "Senior Developer position...",
"matched_resumes": [...]
}'配置
所有配置均通过环境变量进行管理 .env:
核心设置
APP_NAME:应用程序名称DEBUG:启用调试模式HOST:服务器主机(默认值:0.0.0.0)PORT:服务器端口(默认值:8000)
LLM配置
LLM_PROVIDER:人型或开放式LLM_MODEL:要使用的模型LLM_API_KEY:LLM提供程序的API密钥
向量数据库
VECTOR_DB_TYPE:chromadb、松果体或weaviateEMBEDDING_MODEL:句子转换模型MIN_SIMILARITY_THRESHOLD:最小相似性得分(0.0-1.0)
添加新功能
添加新工具
- 在中创建工具类
src/tools/:
# src/tools/my_new_tool.py
from .base import BaseTool
from ..core import Tool, ToolResponse, ToolInputSchema
class MyNewTool(BaseTool):
def get_definition(self) -> Tool:
return Tool(
name="my_new_tool",
description="What this tool does",
inputSchema=ToolInputSchema(
type="object",
properties={
"param1": {"type": "string", "description": "..."}
},
required=["param1"]
)
)
async def execute(self, arguments: Dict[str, Any]) -> ToolResponse:
# Implementation
return self.create_text_response("Result")- 注册
src/tools/__init__.py:
from .my_new_tool import MyNewTool
class ToolRegistry:
def _register_default_tools(self):
# ... existing tools ...
self.register(MyNewTool())添加新的LLM提供程序
- 在中创建服务
src/services/llm_service.py:
class CustomLLMService(BaseLLMService):
async def generate_resume(self, ...) -> AsyncIterator[str]:
# Implementation
pass- 更新工厂:
class LLMServiceFactory:
@staticmethod
def create() -> BaseLLMService:
if provider == "custom":
return CustomLLMService()添加新的矢量数据库
与LLM提供商类似的模式-扩展 BaseVectorService 并更新工厂。
测试
# Run tests
pytest tests/
# With coverage
pytest --cov=src tests/部署
码头工人
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY src/ ./src/
COPY .env .
EXPOSE 8000
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"]构建并运行:
docker build -t mcp-resume-server .
docker run -p 8000:8000 --env-file .env mcp-resume-server云部署
铁路/渲染:
- 连接您的GitHub存储库
- 设置环境变量
- 自动部署
AWS/GCP: 使用Docker容器或部署到无服务器平台。
架构优势
✅ 可维护性
- 明确模块边界
- 易于定位和修复错误
- 自文档化代码结构
✅ 可测试性
- 每个组件都可以独立测试
- 易于模拟的服务和依赖关系
- 模块间接口清晰
✅ 可扩展性
- 服务可以提取到微服务中
- 在不破坏现有代码的情况下轻松添加新功能
- 支持多个LLM和矢量数据库提供商
✅ 类型安全
- Pydantic模型在运行时捕获错误
- 类型提示有助于IDE自动补全
- 减少错误并提高代码质量
许可证
麻省理工学院
贡献
- 克隆该仓库
- 创建要素分支
- 进行更改
- 添加测试
- 提交拉取请求
