Fire in da houseTop Tip:Most people pay up to $340 per month for Perplexity, MidJourney, Runway, ChatGPT, and more - but you can get them all your AI tools for $15 with Galaxy. It's free to test!Fire in da houseCheck it out

grok2-image-mcp-server

MCP.Pizza Chef: fl0w1nd

The grok2-image-mcp-server is an MCP server that integrates the Grok-2 image generation model with the Model Context Protocol. It allows chat assistants and other MCP clients to generate images by communicating with the Grok-2 model through standardized MCP interactions. The server supports environment variable configuration for API keys, proxy settings, and image URL proxying, enabling flexible deployment and network access control. This server facilitates seamless image generation workflows within MCP-enabled applications.

Use This MCP server To

Generate images from text prompts via MCP-enabled chat assistants Integrate Grok-2 image generation into AI workflows Proxy image requests through configurable domains Configure network proxies for API access Deploy image generation services with environment variable control

README

Grok2 Image MCP Server

一个基于 Model Context Protocol (MCP) 的 Grok-2 图像生成服务。此服务允许聊天助手通过 MCP 协议使用 Grok-2 模型生成图像。

安装

使用 npx(推荐)

npx -y grok2-image-mcp-server
{
    "mcpServers": {
        "grok2_image": {
            "command": "npx",
            "args": [
                "grok2-image-mcp-server"
            ],
            "env": {
                "XAIAPI_KEY": "xAI Key"
            }
        }
    }
}

环境变量

XAIAPI_KEY -> xAI Key

XAIAPI_BASE_URL(可选) -> 请求接口代理,若不填则默认使用 https://api.x.ai/v1,遇到无法访问的情况可使用第三方代理,末尾以v1结束

示例:

XAIAPI_BASE_URL=https://api-proxy.me/xai/v1  //某个公开代理,不保证可用性

IMAGE_PROXY_DOMAIN(可选) -> 图片代理域名,若不填则返回默认的图片接口域名 imgen.x.ai,遇到无法访问的情况可使用第三方代理

示例:

IMAGE_PROXY_DOMAIN=https://image.proxy.workers.dev

HTTP_PROXY(可选) -> 网络代理服务器地址,支持 HTTP、HTTPS 协议,可用于解决网络访问问题

示例:

HTTP_PROXY=http://127.0.0.1:7890

HTTP_PROXY=https://user:pass@proxy.example.com:8080

使用 cloudflare workers 代理图片 URL

遇到图片无法访问的情况,可以考虑使用 cloudflare workers 代理图片 URL,复制以下代码到 cloudflare workers 中,并部署,随后绑定自定义域名,并在环境变量中配置 IMAGE_PROXY_DOMAIN 为自定义域名,例如 https://image.proxy.workers.dev

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

const TARGET_DOMAIN = 'imgen.x.ai'

async function handleRequest(request) {

  const url = new URL(request.url)
  const targetUrl = `https://${TARGET_DOMAIN}${url.pathname}${url.search}`


  const init = {
    method: request.method,
    headers: request.headers,
    body: request.method === 'GET' || request.method === 'HEAD' ? undefined : request.body,
    redirect: 'follow'
  }


  const response = await fetch(targetUrl, init)


  const newHeaders = new Headers(response.headers)
  newHeaders.set('Access-Control-Allow-Origin', '*')

  return new Response(response.body, {
    status: response.status,
    statusText: response.statusText,
    headers: newHeaders
  })
}

许可证

MIT

grok2-image-mcp-server FAQ

How do I install the grok2-image-mcp-server?
You can install it easily using npx with the command `npx -y grok2-image-mcp-server`.
What environment variables are required to run this server?
You need to set `XAIAPI_KEY` for the xAI API key. Optional variables include `XAIAPI_BASE_URL`, `IMAGE_PROXY_DOMAIN`, and `HTTP_PROXY` for proxy configurations.
Can I use a proxy for image URLs?
Yes, you can configure `IMAGE_PROXY_DOMAIN` to use a third-party image proxy if the default domain is inaccessible.
How does the server handle network proxy settings?
You can set the `HTTP_PROXY` environment variable to specify an HTTP or HTTPS proxy server for network requests.
Is this server compatible with multiple LLM providers?
While primarily designed for Grok-2 image generation, it can be integrated with MCP clients that use models like OpenAI, Claude, and Gemini for broader AI workflows.
Can I customize the API base URL?
Yes, by setting `XAIAPI_BASE_URL` you can specify a different API endpoint, useful for proxying or regional access.
What is the default image proxy domain?
The default image proxy domain is `imgen.x.ai`, but it can be overridden with `IMAGE_PROXY_DOMAIN`.