Skip to main content

OpenAI图像生成MCP服务 (v0.1.3)

这是一个基于MCP协议的OpenAI图像生成服务器,允许大语言模型通过MCP协议调用OpenAI的图像生成API,生成图像后自动上传到图床并返回图片链接。

安装

pip install mcp-image-gen

功能

工具 (Tools)

  • generate_image: 根据文本提示生成图像,自动上传到图床,返回图片URL。

    • 参数:
      • prompt: 描述想要生成的图像的文本提示
      • size: 图像尺寸,可选 1024x1024(默认), 1024x1536, 1536x1024
      • quality: 图像质量,可选 low, medium(默认), high, auto
      • model: 使用的模型,默认为 gpt-image-1
      • save_locally: 是否同时保存图像到本地文件,默认为False
      • api_key: 可选,自定义API密钥,不提供则使用默认值
      • base_url: 可选,自定义API基础URL,不提供则使用默认值
      • image_hosting_token: 可选,自定义图床API令牌,不提供则使用默认值
      • image_hosting_url: 可选,自定义图床API URL,不提供则使用默认值
  • save_image_base64: 将Base64编码的图像数据保存为文件。

    • 参数:
      • base64_data: Base64编码的图像数据
      • filename: 要保存的文件名,默认为 generated_image.png
  • upload_to_image_hosting: 将Base64编码的图像数据上传到图床。

    • 参数:
      • base64_data: Base64编码的图像数据
      • filename: 上传的文件名,默认为 generated_image.png
      • permission: 图片权限,1=公开,0=私有,默认为1
      • image_hosting_token: 可选,自定义图床API令牌,不提供则使用默认值
      • image_hosting_url: 可选,自定义图床API URL,不提供则使用默认值

资源 (Resources)

  • openai://api/status: 检查OpenAI API的可用性状态。

在阿里云百炼中使用

在阿里云百炼平台的MCP服务配置中,使用以下JSON:

{
  "mcpServers": {
    "openai-image-gen": {  // 服务名称,可自定义
      "command": "uvx",
      "args": ["mcp-image-gen"]
    }
  }
}

本地运行

安装后,您可以在本地通过以下方式运行:

# 使用uvx
uvx mcp-image-gen

# 使用包提供的命令
mcp-image-gen

# 使用Python -m
python -m mcp_image_gen

按 Ctrl+C 停止服务器。

配置

默认情况下,服务器使用内置的API密钥、代理URL和图床配置,但您可以在调用工具时通过参数覆盖它们。这使得大语言模型可以灵活地传入自定义凭证和配置。

错误处理

服务器会将所有错误信息返回给调用方,格式为 "Error: 具体错误信息",方便大语言模型理解错误原因并做出相应处理。

图床功能

本服务使用 tu.my 图床服务来托管生成的图像,确保图像生成后能够立即获得可访问的URL。

许可证

MIT License

Metadata

Release files for mcp-image-gen 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-image-gen 0.1.3
File Size Uploaded Provenance
mcp_image_gen-0.1.3.tar.gz 7.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mcp-image-gen 0.1.3
File Interpreter ABI Platform
mcp_image_gen-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 16.0 kB

Release files / mcp_image_gen-0.1.3.tar.gz

Download URL mcp_image_gen-0.1.3.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1334dcb10531dc1279ebc065228537c4c89694f57994f92cff649da77cdc3524
BLAKE2b-256 checksum
How to use checksums
b32ceab69a419b306bfe00813d46e1c339f9a59bab738cf3963bafecc11bbc7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.2

Release files / mcp_image_gen-0.1.3-py3-none-any.whl

Download URL mcp_image_gen-0.1.3-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
209966870b92e14aa6d5145460109099462e28d1bdf24434d0f7c847568de1ff
BLAKE2b-256 checksum
How to use checksums
7f658a4ce935b44e57e1c1a541bac67dab1f013498a6bf4bf0d515604c2eb558
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.2

Security for mcp-image-gen 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page