使用说明
🤖 集成Cerebras云的MCP PDF问答服务器
一个强大的模型上下文协议(MCP)服务器,利用Cerebras Cloud AI提供智能的PDF文档分析和问答功能。该服务器专为辅导父亲设计,包含两种不同的提示类型,以适应不同的治疗方式。
✨ 特点
- 📚 书籍 PDF文档处理从PDF文件中提取并分析文本
- 🔍 看起来像是放大镜或搜索的符号,可以翻译为“🔍(放大镜/搜索)”或者根据上下文具体含义翻译。 智能搜索基于人工智能的文档选择和问题回答
- 🧠 这个表情符号通常代表“大脑”或“思考”,在中文中可以翻译为“大脑”或“思考中”。不过,由于表情符号的翻译可能因语境和文化差异而有所变化,所以“🧠”也可以简单地理解为“大脑”或“思考”的意象。 Cerebras云集成使用Cerebras Cloud API进行高级AI处理
- 👨👧👦 翻译成中文是“一家三口”或“父母与子女”。这个表情符号由一个父亲、一个母亲和一个孩子组成,通常用来表示一个家庭的温馨场景。 父亲角色咨询的重点促进父亲角色发展的专业提示
- 📝 双提示类型:
journal_review_prompt(3行)- 全面反思ai_assisted_journal_prompt(一行)- 集中探究
- 🚀火箭或快速前进的符号 Vercel 部署就绪包含无服务器部署配置
- ⚡(闪电符号,无具体文字含义,常用于表示速度、活力或警示等) 缓存系统文档预处理与智能缓存
- 🎯(目标/瞄准) MCP协议标准模型上下文协议实现
🏗️ 建筑学
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Client Apps │ │ MCP Server │ │ Cerebras Cloud │
│ │ │ (server_v3.js) │ │ API │
│ • client_v3.js │◄──►│ │◄──►│ │
│ • Web UI │ │ • PDF Processing │ │ • AI Analysis │
│ • CLI Tools │ │ • Document Cache │ │ • Text Gen │
└─────────────────┘ │ • MCP Tools │ └─────────────────┘
└──────────────────┘
│
▼
┌──────────────────┐
│ PDF Storage │
│ │
│ • Local Files │
│ • Cloud Storage │
└──────────────────┘
🚀 快速入门
先决条件
- Node.js 18及以上版本
- Cerebras Cloud API密钥
- 用于分析的PDF文档
安装
- 克隆仓库
git clone <your-repo-url>
cd mcp-demo
- 安装依赖项
npm install
- 设置环境变量
# Copy the example file
cp .env.example .env
# Edit .env with your Cerebras API key
CEREBRAS_API_KEY=your_actual_cerebras_cloud_api_key_here
CEREBRAS_BASE_URL=https://api.cerebras.ai/v1
- 启动服务器
node server_v3.js
服务器将在 http://localhost:3000/mcp
📖 使用方法
可用的MCP工具
| 工具 | 描述 | 参数 |
|---|---|---|
list_pdfs |
可用的PDF文档列表 | 无 |
read_pdf 从特定PDF中提取文本 filename |
||
search_pdfs |
利用AI技术在PDF中进行搜索 | question, maxDocuments, promptType |
analyze_pdf |
PDF的详细分析 | filename, analysisType |
preprocess_documents |
缓存文档以加快搜索速度 | 无 |
cache_management |
管理文档缓存 | action |
命令行客户端
使用随附的 client_v3.js 便于测试:
# List available PDFs
node client_v3.js list
# Read a specific PDF
node client_v3.js read "Levels of Fathering Identity Development in Christians.pdf"
# Search with journal_review prompt (3 lines)
node client_v3.js search "I'm struggling with being a good father" journal_review
# Search with ai_assisted_journal prompt (1 line)
node client_v3.js search "I'm struggling with being a good father" ai_assisted_journal
# Auto-detect prompt type
node client_v3.js search "I need to review my fathering approach"
# Interactive mode
node client_v3.js interactive
API 端点
所有工具均可通过HTTP POST访问 http://localhost:3000/mcp:
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "search_pdfs",
"arguments": {
"question": "I'm struggling with being a good father",
"promptType": "journal_review",
"maxDocuments": 3
}
}
}
🎯 提示类型
1. 期刊评审提示(3行格式)
- 用例全面反思与深入探索
- 格式3个简洁的要点
- **Tone 翻译成中文是“音调”或“语调”**富有同情心,不带评判
- 焦点自我反思问题
- 触发器包含“review”或“journal”的问题
示例回复:
• What are some common reactions you have as a father, and how do they impact your relationships with your children?
• How do you currently make decisions as a parent, and what drives those choices?
• What are some areas where you feel like you're just "winging it" as a father, and how might you take a more thoughtful approach?
2. 人工智能辅助日记提示(一行格式)
- 用例快速、有针对性的调查
- 格式1个简洁的问题
- 音调富有同情心,不评判他人
- 焦点自我反省问题
- 触发器所有其他问题
示例回复:
What are some ways you find yourself reacting impulsively as a father, and how do you think that might be impacting your relationships with your children?
3. 自动检测
- 根据问题内容自动选择适当的提示类型
- 像“评论”或“期刊”这样的关键词 →
journal_review_prompt - 所有其他问题 →
ai_assisted_journal_prompt
🔧 配置
环境变量
| 变量 | 描述 | 默认值 |
|---|---|---|
CEREBRAS_API_KEY 您的Cerebras Cloud API密钥 |
必填 | |
CEREBRAS_BASE_URL Cerebras API 基础 URL https://api.cerebras.ai/v1 |
||
PORT |
服务器端口 | 3000 |
Cerebras云配置
- 获取API密钥在(以下网址)注册 Cerebras Cloud(赛瑞斯云)
- 添加到环境设置
CEREBRAS_API_KEY在你的.env文件 - 测试连接跑
node test_cerebras.js验证
🚀 部署
本地开发
node server_v3.js
Vercel 部署(无服务器)
- 为Vercel做准备:
cd vercel
-
将PDF文件上传到云存储 (AWS S3、Cloudinary 等)
-
设置环境变量 在Vercel仪表板中:
CEREBRAS_API_KEYPDF_STORAGE_URL
-
部署:
vercel --prod
您的API将在以下地址可用: https://your-project.vercel.app/api/mcp
🧪 测试
测试脚本
# Test Cerebras API connection
node test/test_cerebras.js
# Test both prompt types
node test/test_prompt_types_client.js
# Test server tools
node test/test_server_tools.js
# Test client integration
node client_v3.js search "test question" journal_review
预期的响应格式
期刊评审提示(3行):
- ✅ 正好3个要点
- ✅ 具有同理心,不带评判性的语气
- ✅ 自我反思问题
- ✅ 基于父亲角色的五个层次模型
AI辅助日记提示(1行):
- ✅ 单一问题
- ✅ 具有同理心,不带评判性的语气
- ✅ 自我反省的重点
- ✅ 基于父亲角色的五个层次模型
📁 项目结构
mcp-demo/
├── server_v3.js # Main MCP server
├── client_v3.js # Command-line client
├── client.js # Basic client
├── vercel/ # Vercel deployment files
│ ├── api/mcp.js # Serverless function
│ ├── package.json # Vercel dependencies
│ ├── vercel.json # Vercel configuration
│ └── VERCEL_DEPLOYMENT.md # Deployment guide
├── pdf/ # PDF documents
│ ├── Christian Financial Stewardship - A Developmental Model.pdf
│ ├── Levels of Fathering Identity Development in Christians.pdf
│ └── ...
├── test/ # Test scripts
│ ├── test_cerebras.js
│ ├── test_client_prompts.js
│ ├── test_prompt_types.js
│ └── ...
├── package.json # Dependencies
├── .env.example # Environment template
└── README.md # This file
🔍 故障排除
常见问题
-
“CEREBRAS_API_KEY 未找到”
- 检查你的
.env文件已存在 - 验证API密钥是否正确
- 跑
node test_cerebras.js进行测试
- 检查你的
-
“无法连接到MCP服务器”
- 确保
server_v3.js正在运行 - 检查端口3000是否可用
- 验证服务器已成功启动
- 确保
-
“基于关键词的回退机制”
- Cerebras API 可能已宕机
- 请检查您的API密钥和配额
- 验证网络连接
-
未找到PDF文件
- 检查文件名拼写
- 确保PDF文件已放入(指定位置/文件夹中)
pdf/文件夹 - 使用
list_pdfs查看可用文件
调试模式
通过设置启用调试日志记录:
DEBUG=mcp:* node server_v3.js
🤝 贡献(或“参与贡献”)
- 为仓库创建分支
- 创建一个特性分支
- 进行你的更改
- 添加测试
- 提交一个拉取请求
📄 许可证
此项目采用MIT许可证授权——详见LICENSE文件。
🙏 致谢
- Cerebras Cloud(赛瑞斯布拉斯云) 用于人工智能处理能力
- 模型上下文协议 用于标准化接口
- 父亲角色的五个层次 治疗框架模型
📞 支持
对于问题和疑问:
- 查阅故障排除部分
- 审查示例测试脚本
- 在GitHub上提交一个问题
为追求成长与发展的父亲们,满怀爱意地打造
