使用说明
Grokipedia MCP服务器-完整文档
目录
快速开始
这是开发阶段的探索,请确保遵守https://x.ai/legal/terms-of-service
先决条件
- Python 3.10+
- xAI API密钥(从https://console.x.ai)
- Git
- Docker(可选)
5分钟设置
# 1. Clone repository
git clone https://github.com/yourusername/grokipedia-mcp.git
cd grokipedia-mcp
# 2. Create virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# 3. Install dependencies
pip install -r requirements.txt
pip install -e .
# 4. Configure API key
cp .env.example .env
# Edit .env and add your XAI_API_KEY
# 5. Validate configuration
python -m grokipedia_mcp --validate-config
# 6. Start server
python -m grokipedia_mcp --transport stdio
安装
选项1:开发设置(建议用于Cursor)
步骤1:克隆和设置
git clone https://github.com/yourusername/grokipedia-mcp.git
cd grokipedia-mcp
# Create and activate virtual environment
python3 -m venv venv
# On Linux/macOS:
source venv/bin/activate
# On Windows PowerShell:
.\venv\Scripts\Activate.ps1
# On Windows CMD:
venv\Scripts\activate.bat
步骤2:安装软件包
# Install in development mode (allows code changes without reinstall)
pip install -e .
# Or with development tools
pip install -e ".[dev]"
步骤3:创建配置
cp .env.example .env
# Edit .env with your favorite editor
nano .env # Linux/macOS
# OR
code .env # VS Code
# OR
notepad .env # Windows
步骤4:验证安装
python -m grokipedia_mcp --validate-config
预期产量:
✓ Configuration validation successful
选项2:Docker设置
# Build image
docker build -t grokipedia-mcp:0.1.0-beta .
# Run container
docker run --rm \\
-e XAI_API_KEY=your_key \\
-e GROKIPEDIA_BASE_URL=https://grokipedia.com \\
grokipedia-mcp:0.1.0-beta
选项3:Docker编写
# Create .env file with your credentials
cp .env.example .env
# Edit .env with your API key
# Start services
docker-compose up -d
# View logs
docker-compose logs -f grokipedia-mcp
# Stop services
docker-compose down
配置
环境变量
必修的:
XAI_API_KEY-您的xAI API密钥(从https://console.x.ai)
可选(具有合理的默认值):
GROKIPEDIA_BASE_URL=https://grokipedia.com
GROK_MODEL=grok-2-latest
REQUEST_TIMEOUT=30
MAX_RETRIES=3
CACHE_ENABLED=true
CACHE_TTL=3600
ENABLE_GROK_ENHANCEMENT=true
LOG_LEVEL=INFO
获取xAI API密钥
-
访问控制台:
- 首选https://console.x.ai
- 使用您的xAI帐户登录(或创建一个)
-
创建API密钥:
- 导航到“API密钥”部分
- 点击“创建新密钥”
- 立即复制密钥(仅显示一次)
-
添加到.env:
XAI_API_KEY=xai_xxxxxxxxxxxxxxxxxxxxx -
测试配置:
python -m grokipedia_mcp --validate-config
配置验证
系统在启动时验证所有设置:
# Run validation without starting server
python -m grokipedia_mcp --validate-config
验证检查:
- ✓ XAI_API_KEY已设置并已正确格式化
- ✓ API密钥长度有效(20多个字符)
- ✓ GROKIPEDIA_BASE_URL以http://或https:开头//
- ✓ REQUEST_TIMEOUT介于1-300秒之间
- ✓ MAX_RETRIES介于0-10之间
- ✓ CACHE_TTL为非负
使用指南
与Cursor IDE一起使用
设置MCP集成
- 创建配置文件:
- 创建
.cursor/mcp.json在项目根目录中(在Windows上,使用正斜杠):
- 创建
{
"mcpServers": {
"grokipedia": {
"command": "C:\\absolute\\path\\to\\grokipedia-mcp\\venv\\Scripts\\python.exe",
"args": ["-m", "grokipedia_mcp"],
"env": {
"XAI_API_KEY": "your_xai_api_key_here",
"GROKIPEDIA_BASE_URL": "https://grokipedia.com",
"LOG_LEVEL": "INFO"
}
}
}
}
重要提示: 将Python路径替换为实际路径:
- 窗户:
C:\\Users\\YourName\\grokipedia-mcp\\venv\\Scripts\\python.exe - 雨衣:
/Users/YourName/grokipedia-mcp/venv/bin/python - Linux:
/home/username/grokipedia-mcp/venv/bin/python
-
重新启动游标 加载MCP配置
-
验证MCP是否处于活动状态:
- 设置→ 特性→ MCP
- 应该在列表中看到“grokipedia”
在光标聊天中使用
在Cursor聊天中,您现在可以使用Grokipedia:
User: Search Grokipedia for "Artificial Intelligence"
Cursor will use the search tool automatically
可用命令:
- “在Grokipedia中搜索[主题]”
- “获取Grokipedia关于[主题]的文章”
- “总结Grokipedia关于[主题]的文章”
- “检查缓存统计信息”
- “清除Grokipedia缓存”
用作独立MCP服务器
标准运输(当地)
python -m grokipedia_mcp --transport stdio
从任何支持stdio的MCP客户端连接。
SSE传输(远程)
python -m grokipedia_mcp --transport sse --host 0.0.0.0 --port 8080
从远程客户端连接 http://your-ip:8080
程序化使用
import asyncio
from grokipedia_mcp.grokipedia_client import GrokipediaClient
from grokipedia_mcp.config import Config
async def main():
# Initialize client
config = Config()
client = GrokipediaClient(config)
# Search
results = await client.search("artificial intelligence", limit=5)
print(results)
# Get article
article = await client.get_article("Machine Learning", use_grok=True)
print(article["content"])
# Get summary
summary = await client.get_summary("Neural Networks")
print(summary["summary"])
# Cleanup
await client.close()
asyncio.run(main())
api参考
可用工具
1.搜索_韩国
搜索Grokipedia上的文章。
参数:
query(字符串,必填):搜索查询(最多500个字符)limit(整数,可选):要返回的最大结果(1-50,默认值:10)
退货:
{
"query": "artificial intelligence",
"limit": 10,
"results": [
{
"title": "Artificial Intelligence",
"snippet": "Artificial intelligence (AI) is...",
"url": "https://grokipedia.com/wiki/Artificial_Intelligence"
}
],
"count": 1,
"status": "success"
}
例子:
User: "Search Grokipedia for machine learning with limit 5"
2.获取石墨烯_文章
从Grokipedia检索完整文章内容。
参数:
title(字符串,必填):文章标题(最多200个字符)use_grok_enhancement(布尔值,可选):使用Grok AI增强(默认值:true)
退货:
{
"title": "Machine Learning",
"content": "# Machine Learning\n\nMachine Learning (ML)...",
"url": "https://grokipedia.com/wiki/Machine_Learning",
"source": "grokipedia",
"grok_enhanced": true,
"status": "success"
}
例子:
User: "Get the full Grokipedia article about quantum computing"
3.get_grokipedia_summary
获取一篇文章的简明摘要。
参数:
title(字符串,必填):文章标题
退货:
{
"title": "Deep Learning",
"summary": "Deep Learning is a subset of machine learning...",
"url": "https://grokipedia.com/wiki/Deep_Learning",
"status": "success"
}
4.get_cache_stats
获取当前缓存统计信息。
退货:
{
"memory_cache_items": 5,
"file_cache_items": 12,
"cache_dir": "/app/.cache",
"ttl_seconds": 3600
}
5.clear_cache
清除所有缓存数据。
退货:
"✓ Cache cleared successfully"
6.验证配置
验证服务器配置。
退货:
✓ Configuration valid
- grokipedia_base_url: https://grokipedia.com
- grok_model: grok-2-latest
- request_timeout: 30
- max_retries: 3
- cache_enabled: true
- cache_ttl: 3600
- enable_grok_enhancement: true
- xai_api_key_configured: true
安全
API密钥安全
最佳实践:
- ✓ 永不承诺
.env到Git - ✓ Use
.env.example作为模板 - ✓ 定期旋转API键
- ✓ 使用单独的密钥进行开发/生产
- ✓ 监控xAI控制台中的API密钥使用情况
安全配置:
# Set permissions on .env file (Unix/Linux/macOS)
chmod 600 .env
# Verify .gitignore includes .env
grep "^.env$" .gitignore
SSL/TLS安全
客户端始终验证SSL证书:
# In grokipedia_client.py
self.session = httpx.AsyncClient(verify=True) # Always enabled
输入验证
所有用户输入都经过验证:
# Query validation
if len(query) > 500:
raise ValueError("Query too long (max 500 characters)")
# Limit validation
if not (1 <= limit <= 50):
raise ValueError("Limit must be between 1 and 50")
错误处理
错误处理得当,不会暴露敏感信息:
# ✓ Safe error message
return {"error": "Failed to fetch article", "status": "failed"}
# ✗ Unsafe - exposes system details
return {"error": str(e), "traceback": traceback.format_exc()}
速率限制
实施限速以防止滥用:
# Environment variable
MAX_RETRIES=3 # Retry failed requests max 3 times
REQUEST_TIMEOUT=30 # Timeout after 30 seconds
数据隐私
- ✓ 没有数据被永久存储
- ✓ 缓存文件使用MD5哈希(不可逆)
- ✓ 日志不包括敏感的API密钥
- ✓ 所有API调用的HTTPS加密
故障排除
问题:“XAI_API_KEY未设置”
解决方案:
# 1. Verify .env file exists
ls -la .env
# 2. Check contents
cat .env | grep XAI_API_KEY
# 3. Re-validate configuration
python -m grokipedia_mcp --validate-config
问题:“找不到命令:grokipedia mcp”
解决方案:
# 1. Ensure package is installed in editable mode
pip install -e .
# 2. Try full path
python -m grokipedia_mcp --validate-config
# 3. Verify venv is activated
which python # Should show venv path
问题:“连接被拒绝”或“网络错误”
解决方案:
# 1. Check Grokipedia is accessible
curl https://grokipedia.com
# 2. Verify API key works
curl -H "Authorization: Bearer YOUR_KEY" https://api.x.ai/v1/models
# 3. Check firewall/proxy settings
问题:“找不到模块”错误
解决方案:
# Reinstall dependencies
pip install -r requirements.txt
# Or full reinstall
pip uninstall grokipedia-mcp
pip install -e .
问题:光标MCP未连接
解决方案:
- 验证
.cursor/mcp.json存在正确的Python路径 - 完全重新启动游标
- 检查光标日志:设置→ MCP → 查看日志
- 直接测试服务器:
python -m grokipedia_mcp --validate-config
问题:缓存不工作
解决方案:
# Check cache status
python -c "from grokipedia_mcp.server import get_client; import asyncio; print(asyncio.run(get_client().cache.get_stats()))"
# Clear cache
python -m grokipedia_mcp --cache-clear
法律与合规
服务条款协议
通过使用此Grokipedia MCP服务器,您同意:
1.xAI API条款:
- 您有责任遵守xAI的服务条款
- 您必须使用自己的xAI API密钥
- 无法绕过API身份验证
- 您不能转售API访问权限
2.Grokipedia条款:
- 尊重Grokipedia的许可条款(见LEGAL.md)
- 提供适当的归因
- 遵循他们的使用政策
3.数据使用:
- 访问的数据受Grokipedia数据政策的约束
- 您负责数据隐私合规
- 内容按“原样”提供
许可证
此项目根据MIT许可证获得许可-请参阅许可证文件。
第三方许可证
完整列表请参见第三方许可证文件。
支持
对于问题:
- GitHub问题:https://github.com/yourusername/grokipedia-mcp/issues
- xAI支持:support@x.ai
- Grokipedia:https://github.com/AppleLamps/Grokipedia
版本: 0.1.0-贝塔
最后更新时间: 2025年11月
状态: Beta版本-使用风险自负
