Content
# Grok2 Image MCP Server
A Grok-2 image generation service based on the Model Context Protocol (MCP). This service allows chat assistants to generate images using the Grok-2 model via the MCP protocol.
## Installation
### Using npx (Recommended)
```bash
npx -y grok2-image-mcp-server
```
```json
{
"mcpServers": {
"grok2_image": {
"command": "npx",
"args": [
"grok2-image-mcp-server"
],
"env": {
"XAIAPI_KEY": "xAI Key"
}
}
}
}
```
#### Environment Variables
`XAIAPI_KEY` -> xAI Key
`XAIAPI_BASE_URL` (Optional) -> Request interface proxy. If not provided, it defaults to `https://api.x.ai/v1`. In case of access issues, a third-party proxy can be used, ending with `v1`.
Example:
```bash
XAIAPI_BASE_URL=https://api-proxy.me/xai/v1 // A public proxy, availability not guaranteed
```
`IMAGE_PROXY_DOMAIN` (Optional) -> Image proxy domain name. If not provided, it returns the default image interface domain `imgen.x.ai`. In case of access issues, a third-party proxy can be used.
Example:
```bash
IMAGE_PROXY_DOMAIN=https://image.proxy.workers.dev
```
`HTTP_PROXY` (Optional) -> Network proxy server address, supporting HTTP and HTTPS protocols, which can be used to resolve network access issues.
Example:
```bash
HTTP_PROXY=http://127.0.0.1:7890
HTTP_PROXY=https://user:pass@proxy.example.com:8080
```
### Using Cloudflare Workers to Proxy Image URLs
In case of image access issues, consider using Cloudflare Workers to proxy image URLs. Copy the following code into Cloudflare Workers, deploy it, then bind a custom domain, and configure the `IMAGE_PROXY_DOMAIN` environment variable to the custom domain, for example, `https://image.proxy.workers.dev`.
```js
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
})
}
```
## License
MIT
Connection Info
You Might Also Like
semantic-kernel
Integrate cutting-edge LLM technology quickly and easily into your apps
repomix
📦 Repomix is a powerful tool that packs your entire repository into a...
Serena
A powerful coding agent toolkit providing semantic retrieval and editing...
Blender
BlenderMCP integrates Blender with Claude AI for enhanced 3D modeling.
pydantic-ai
GenAI Agent Framework, the Pydantic way
cua
Open-source infrastructure for Computer-Use Agents. Sandboxes, SDKs, and...