Skip to main content
Glama

iRAG MCP Server

by kuai0901

百度iRAG MCP服务器

一个基于百度iRAG图片生成API的MCP(Model Context Protocol)服务器,允许MCP客户端(如Claude Desktop)通过标准化接口调用百度的图片生成服务。

🚨 重要提醒

在使用前,请务必进行真实API测试!

基础测试只验证服务器启动,要确保完全可用,需要:

  1. 获取真实的百度API Key
  2. 运行 npm run test:api 进行真实API测试
  3. 验证图片生成和Base64转换功能

详细设置指南请查看:FINAL_SETUP.md

功能特性

  • 🎨 支持百度iRAG图片生成API
  • 🔧 完整的MCP协议实现
  • 📝 支持多种模型(irag-1.0, flux.1-schnell)
  • 🖼️ 灵活的图片尺寸配置
  • 🔄 自动重试机制
  • 📊 完善的日志记录
  • ✅ 全面的参数验证
  • 🧪 完整的测试覆盖

支持的模型

  • irag-1.0: 百度自研的图片生成模型
  • flux.1-schnell: 支持更多高级参数的快速生成模型

安装

前置要求

  • Node.js >= 18.0.0
  • npm 或 yarn

克隆项目

git clone <repository-url> cd irag-mcp-server

安装依赖

npm install

构建项目

npm run build

配置

1. 获取百度API Key

  1. 访问百度智能云控制台
  2. 创建API Key并选择千帆ModelBuilder
  3. 配置对应的应用资源
  4. 复制API Key(格式:bce-v3/ALTAK-****/****

2. 环境变量配置

复制环境变量模板:

cp .env.example .env

编辑 .env 文件:

# 必需配置 BAIDU_API_KEY=bce-v3/ALTAK-your-access-key/your-secret-key # 图片资源配置 RESOURCE_MODE=local # local: 保存到本地文件 | url: 仅返回URL和base64 BASE_PATH= # 自定义保存路径(可选,默认为桌面/irag-images) MODEL=irag-1.0 # 默认模型: irag-1.0 | flux.1-schnell # 可选配置 SERVER_NAME=irag-mcp-server SERVER_VERSION=1.0.0 LOG_LEVEL=info LOG_FILE=logs/server.log API_TIMEOUT=30000 MAX_RETRIES=3
图片保存配置说明
  • RESOURCE_MODE=local: 图片将保存到本地文件系统,同时返回base64数据和文件路径
  • RESOURCE_MODE=url: 仅返回图片URL和base64数据,不保存本地文件
  • BASE_PATH: 自定义图片保存路径,留空则使用默认路径(用户桌面/irag-images文件夹)
  • MODEL: 设置默认使用的图片生成模型
    • irag-1.0: 百度自研模型,通用性好,速度快
    • flux.1-schnell: 支持更多高级参数,质量更高

使用方法

启动服务器

# 开发模式 npm run dev # 生产模式 npm start

MCP客户端配置

Claude Desktop配置

在Claude Desktop的配置文件中添加:

Windows: %APPDATA%\Claude\claude_desktop_config.json macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

{ "mcpServers": { "irag-image-generator": { "command": "node", "args": ["/path/to/irag-mcp-server/dist/index.js"], "env": { "BAIDU_API_KEY": "bce-v3/ALTAK-your-access-key/your-secret-key" } } } }

API参考

generate_image 工具

生成图片的MCP工具。

参数
参数名类型必需默认值描述
promptstring-图片生成提示词
refer_imagestring-参考图片URL
ninteger1生成图片数量(1-4)
sizestring1024x1024图片尺寸
stepsinteger-采样步数(1-50,仅flux.1-schnell)
seedinteger-随机种子(仅flux.1-schnell)
guidancenumber3.5指导密度值(0-30,仅flux.1-schnell)

注意: 模型通过配置文件的MODEL参数设置,不在请求中指定。

支持的图片尺寸
  • 512x512, 768x768, 1024x768, 1024x1024
使用示例
{ "name": "generate_image", "arguments": { "prompt": "一只可爱的橘猫坐在窗台上,阳光透过窗户洒在它身上", "size": "1024x1024", "n": 2 } }

开发

项目结构

src/ ├── client/ # API客户端 ├── config/ # 配置管理 ├── server/ # MCP服务器 ├── types/ # 类型定义 ├── utils/ # 工具函数 ├── __tests__/ # 测试文件 └── index.ts # 主入口

开发命令

# 开发模式运行 npm run dev # 构建项目 npm run build # 运行测试 npm test # 监听测试 npm run test:watch # 代码检查 npm run lint # 修复代码风格 npm run lint:fix # 清理构建文件 npm run clean

测试

运行所有测试:

npm test

查看测试覆盖率:

npm test -- --coverage

故障排除

常见问题

  1. API Key无效
    • 确保API Key格式正确:bce-v3/ALTAK-****/****
    • 检查API Key是否已配置千帆ModelBuilder资源
  2. 连接超时
    • 检查网络连接
    • 增加 API_TIMEOUT 配置值
  3. 图片生成失败
    • 检查提示词是否符合要求
    • 确认模型参数配置正确
  4. Base64验证错误
    • 服务器会自动下载图片并转换为base64格式
    • 如果下载失败,会返回错误信息和原始URL
    • 检查网络连接和图片URL的可访问性
  5. MCP客户端连接问题
    • 确保Claude Desktop配置文件路径正确
    • 检查Node.js版本(需要>=18.0.0)
    • 验证项目已正确构建(运行npm run build

日志调试

设置日志级别为debug:

LOG_LEVEL=debug

查看详细的API调用日志和图片下载过程。

许可证

MIT License

贡献

欢迎提交Issue和Pull Request!

更新日志

v1.0.0

  • 初始版本发布
  • 支持百度iRAG图片生成API
  • 完整的MCP协议实现
  • 支持多种模型和参数配置
Install Server
A
security – no known vulnerabilities
F
license - not found
A
quality - confirmed to work

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

A Model Context Protocol server that enables Claude Desktop to generate images using Baidu's iRAG image generation API through a standardized interface.

  1. 🚨 重要提醒
    1. 功能特性
      1. 支持的模型
        1. 安装
          1. 前置要求
          2. 克隆项目
          3. 安装依赖
          4. 构建项目
        2. 配置
          1. 获取百度API Key
          2. 环境变量配置
        3. 使用方法
          1. 启动服务器
          2. MCP客户端配置
        4. API参考
          1. generate_image 工具
        5. 开发
          1. 项目结构
          2. 开发命令
          3. 测试
        6. 故障排除
          1. 常见问题
          2. 日志调试
        7. 许可证
          1. 贡献
            1. 更新日志
              1. v1.0.0

            Related MCP Servers

            • -
              security
              A
              license
              -
              quality
              Model Context Protocol server that enables Claude Desktop (or any MCP client) to fetch web content and process images appropriately.
              Last updated -
              11
              MIT License
              • Apple
            • A
              security
              F
              license
              A
              quality
              A Model Context Protocol server that enables Claude to generate and upscale images through the Letz AI API, allowing users to create images directly within Claude conversations.
              Last updated -
              2
              1
              JavaScript
              • Linux
              • Apple
            • A
              security
              A
              license
              A
              quality
              A server that enables Claude Desktop to generate images using Google's Gemini AI models through the Model Context Protocol (MCP).
              Last updated -
              7
              6
              JavaScript
              MIT License
            • A
              security
              A
              license
              A
              quality
              A Model Context Protocol server that enables Claude Desktop to browse the web, likely allowing the AI to access and interact with web content.
              Last updated -
              2
              93
              5
              JavaScript
              MIT License
              • Apple

            View all related MCP servers

            MCP directory API

            We provide all the information about MCP servers via our MCP API.

            curl -X GET 'https://glama.ai/api/mcp/v1/servers/kuai0901/irag-mcp-server'

            If you have feedback or need assistance with the MCP directory API, please join our Discord server