图像生成与网页抓取服务器

MCP服务器提供基于Flux Pro模型的图像生成和通过ScrapeGraph实现的网页抓取功能,适用于内容创作和数据收集场景。

  • by bananabit-dev
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 bananabit-dev/mcp

使用说明

用于Windsurf/Roocode的MCP服务器

这是一个模型上下文协议(MCP)服务器,为Windsurf提供图像生成和网络抓取功能。

特性

  • 图像生成:使用Flux Pro模型生成图像
  • Web剪贴:使用ScrapeGraph从网页中提取内容

入门指南

  1. 克隆并设置项目:

    git clone https://github.com/bananabit-dev/mcp.git
    cd mcp
    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    pip install -r requirements.txt
    
  2. 设置环境变量:

    cp .env.example .env
    

    然后编辑 .env 添加API密钥:

    AIMLAPI_KEY=your_flux_pro_api_key
    SGAI_API_KEY=your_scrapegraph_api_key
    

MCP服务器配置

  1. 将此配置添加到 ~/.codeium/windsurf/mcp_config.json:
{
  "mcpServers": {
    "bananabit-mcp": {
      "command": "/absolute/path/to/your/.venv/bin/python",
      "args": ["-m", "app.mcp_server"],
      "cwd": "/absolute/path/to/mcp",
      "env": {
        "PYTHONPATH": "/absolute/path/to/mcp",
        "AIMLAPI_KEY": "${env:AIMLAPI_KEY}",
        "SGAI_API_KEY": "${env:SGAI_API_KEY}"
      }
    }
  }
}
  1. 在Windsurf中,单击锤子图标并“刷新”以加载MCP服务器。

示例用法

图像生成

让我们创造一个舒适的川崎客厅!以下是与Windsurf的对话示例:

User: Generate a image of a cozy warm living room in kawaii and anime style.

Assistant: I'll help you generate a cozy warm living room image in kawaii and anime style!

[Generated image saved as cozy_kawaii_living_room.png]
User: Try again with an even more cozy and kawaii living room.

Assistant: I'll enhance the kawaii and cozy elements even more in this new version!

[Generated image saved as super_cozy_kawaii_living_room.png]

MCP服务器每次都会生成唯一的图像,但它们将遵循提示中指定的样式和元素。尝试创建自己的舒适空间或其他创意图像!

Web剪贴

MCP服务器通过ScrapeGraph API提供强大的web抓取功能。以下是主要特征:

  1. 内容提取

    # Extract main content from a webpage
    result = await extract_webpage_content(
        url="https://example.com"
    )
    
  2. Markdown转换

    # Convert webpage to clean markdown
    result = await markdownify_webpage(
        url="https://example.com",
        clean_level="medium"  # Options: light, medium, aggressive
    )
    
  3. 智能刮擦

    # Extract specific information using AI
    result = await scrape_webpage(
        url="https://example.com"
    )
    

特性

  • 人工智能驱动的提取:智能识别和提取主要内容
  • 清洁输出:删除广告、导航和其他杂乱内容
  • 格式选项:获取原始HTML、markdown或结构化数据中的内容
  • 错误处理:提取失败后的巧妙回退
  • 定制:控制清洁级别和输出格式

示例用例

  1. 文档生成

    # Create local documentation from online sources
    content = await markdownify_webpage(
        url="https://docs.example.com/guide",
        clean_level="medium"
    )
    with open(".docs/guide.md", "w") as f:
        f.write(content)
    
  2. 内容分析

    # Extract and analyze webpage sentiment
    content = await extract_webpage_content(
        url="https://example.com/article"
    )
    sentiment = await analyze_text_sentiment(
        text=content["text"]
    )
    
  3. 数据收集

    # Extract structured data
    data = await scrape_webpage(
        url="https://example.com/products"
    )
    # Process extracted data
    for item in data["structured_data"]:
        process_item(item)
    

最佳实践

  1. 速率限制

    • 遵守网站费率限制
    • 增加请求之间的延迟
    • 尽可能使用缓存
  2. 错误处理

    try:
        content = await extract_webpage_content(url)
    except Exception as e:
        # Fall back to simpler extraction
        content = await markdownify_webpage(url)
    
  3. 内容物清理

    • 从“中等”清洁级别开始
    • 对于非常嘈杂的页面使用“攻击性”
    • 在保留格式很重要时使用“轻”
  4. 输出处理

    • 验证提取的内容
    • 处理空结果或部分结果
    • 适当处理结构化数据

许可证

麻省理工学院