V2.ai Insights刮刀MCP
一个模型上下文协议(MCP)服务器,它从V2.ai Insights中抓取博客文章,提取内容,并使用OpenAI的GPT-4提供ai驱动的摘要。 目前支持Contentful CMS与搜索功能的集成。
📋 战略愿景:该项目正在发展成为一个全面的人工智能平台。看 STRATEGIC_VISION.md 从内容API到战略智能平台的完整路线图。
特性
- 🔍 多源内容:从Contentful CMS和V2.ai网页抓取中获取
- 📝 内容提取:使用智能回退提取标题、日期、作者和内容
- 🔎 全文检索:使用Contentful的搜索API搜索所有博客内容
- 🤖 AI总结:使用OpenAI GPT-4生成摘要
- 🔧 MCP集成:公开用于Claude Desktop集成的工具
可用工具
get_latest_posts()-使用元数据检索博客文章(Contentful+V2.ai回退)get_contentful_posts(limit)-直接从Contentful CMS获取帖子search_blogs(query, limit)- 新 -搜索所有博客内容summarize_post(index)-返回AI生成的特定帖子摘要get_post_content(index)-返回特定帖子的完整内容
设置
先决条件
- Python 3.12+
- 紫外线 包管理器
- OpenAI API密钥
- 内容丰富的CMS凭据(可选,用于增强功能)
安装
- 克隆并导航到项目:
cd v2-ai-mcp- 安装依赖项:
uv add fastmcp beautifulsoup4 requests openai- 设置环境变量:
创建一个 .env 文件基于 .env.example:
cp .env.example .env编辑 .env 使用您的凭据:
# Required
OPENAI_API_KEY=your-openai-api-key-here
# Optional (for Contentful integration)
CONTENTFUL_SPACE_ID=your-contentful-space-id
CONTENTFUL_ACCESS_TOKEN=your-contentful-access-token
CONTENTFUL_CONTENT_TYPE=pageBlogPost运行服务器
uv run python -m src.v2_ai_mcp.main服务器将启动并可用于MCP连接。
测试刮板
测试单个组件:
# Test scraper
uv run python -c "from src.v2_ai_mcp.scraper import fetch_blog_posts; print(fetch_blog_posts()[0]['title'])"
# Test with summarizer (requires OpenAI API key)
uv run python -c "from src.v2_ai_mcp.scraper import fetch_blog_posts; from src.v2_ai_mcp.summarizer import summarize; post = fetch_blog_posts()[0]; print(summarize(post['content'][:1000]))"
# Run unit tests
uv run pytest tests/ -v --cov=srcClaude桌面集成
配置
- 安装克劳德桌面 (如果尚未安装)
- 在Claude Desktop中配置MCP:
添加到您的Claude Desktop MCP配置中:
{
"mcpServers": {
"v2-insights-scraper": {
"command": "/path/to/uv",
"args": ["run", "--directory", "/path/to/your/v2-ai-mcp", "python", "-m", "src.v2_ai_mcp.main"],
"env": {
"OPENAI_API_KEY": "your-api-key-here",
"CONTENTFUL_SPACE_ID": "your-contentful-space-id",
"CONTENTFUL_ACCESS_TOKEN": "your-contentful-access-token",
"CONTENTFUL_CONTENT_TYPE": "pageBlogPost"
}
}
}
}- 重新启动克劳德桌面 加载MCP服务器
使用工具
配置后,您可以在Claude Desktop中使用这些工具:
- 获取最新帖子:
get_latest_posts()(智能内容+V2.ai回退) - 获取有内容的帖子:
get_contentful_posts(10)(直接访问CMS) - 搜索博客:
search_blogs("AI automation", 5)(新 -全文搜索) - 总结帖子:
summarize_post(0)(第一篇帖子索引为0) - 获取完整内容:
get_post_content(0)
示例用法
🔍 Search for AI-related content:
search_blogs("artificial intelligence", 3)
📚 Get latest posts with automatic source selection:
get_latest_posts()
🤖 Get AI summary of specific post:
summarize_post(0)项目结构
v2-ai-mcp/
├── src/
│ └── v2_ai_mcp/
│ ├── __init__.py # Package initialization
│ ├── main.py # FastMCP server with tool definitions
│ ├── scraper.py # Web scraping logic
│ └── summarizer.py # OpenAI GPT-4 integration
├── tests/
│ ├── __init__.py # Test package initialization
│ ├── test_scraper.py # Unit tests for scraper
│ └── test_summarizer.py # Unit tests for summarizer
├── .github/
│ └── workflows/
│ └── ci.yml # GitHub Actions CI/CD pipeline
├── pyproject.toml # Project dependencies and config
├── .env.example # Environment variables template
├── .gitignore # Git ignore patterns
└── README.md # This file当前实施情况
scraper目前针对的是这篇特定的博客文章:
- 网址:
https://www.v2.ai/insights/adopting-AI-assistants-while-balancing-risks
提取的数据
- 标题:“在平衡风险的同时采用人工智能助手”
- 作者:“阿什利·罗丹”
- 日期:“2025年7月3日”
- 内容:主要内容约12785个字符
发展
添加更多博客文章
要抓取多个帖子或不同的网址,请修改 fetch_blog_posts() 功能在 scraper.py:
def fetch_blog_posts() -> list:
urls = [
"https://www.v2.ai/insights/post1",
"https://www.v2.ai/insights/post2",
# Add more URLs
]
return [fetch_blog_post(url) for url in urls]改进内容提取
scraper使用多种回退策略来提取内容。您可以通过以下方式增强它:
- 检查V2.ai的HTML结构
- 添加更具体的CSS选择器
- 改进日期/作者提取模式
故障排除
常见问题
- OpenAI API密钥错误:确保在环境变量中设置了API密钥
- 导入错误:运行
uv sync确保所有依赖项都已安装 - 报废问题:检查目标URL是否可访问,HTML结构是否未更改
测试组件
# Test scraper only
uv run python -c "from src.v2_ai_mcp.scraper import fetch_blog_posts; posts = fetch_blog_posts(); print(f'Found {len(posts)} posts')"
# Run full test suite
uv run pytest tests/ -v --cov=src
# Test MCP server startup
uv run python -m src.v2_ai_mcp.main发展
运行测试
# Run all tests
uv run pytest
# Run with coverage
uv run pytest --cov=src --cov-report=html
# Run specific test file
uv run pytest tests/test_scraper.py -v代码质量
# Format code
uv run ruff format src tests
# Lint code
uv run ruff check src tests
# Fix auto-fixable issues
uv run ruff check --fix src tests许可证
该项目旨在教育和发展。
