Content
# Grok2 Image MCP Server
A Grok-2 image generation service based on 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 filled, the default `https://api.x.ai/v1` will be used. If you encounter access problems, you can use a third-party proxy, ending with `v1`.
Example:
```bash
XAIAPI_BASE_URL=https://api-proxy.me/xai/v1 //some public proxy, availability not guaranteed
```
`IMAGE_PROXY_DOMAIN` (Optional) -> Image proxy domain. If not filled, the default image interface domain `imgen.x.ai` will be returned. If you encounter access problems, you can use a third-party proxy.
Example:
```bash
IMAGE_PROXY_DOMAIN=https://image.proxy.workers.dev
```
`HTTP_PROXY` (Optional) -> Network proxy server address, supports HTTP and HTTPS protocols, can be used to solve network access problems
Example:
```bash
HTTP_PROXY=http://127.0.0.1:7890
HTTP_PROXY=https://user:pass@proxy.example.com:8080
```
### Use cloudflare workers to proxy image URL
If you encounter problems accessing images, you can consider using cloudflare workers to proxy the image URL. Copy the following code into cloudflare workers, deploy it, and then bind a custom domain, and configure `IMAGE_PROXY_DOMAIN` to the custom domain in the environment variables, 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
markitdown
Python tool for converting files and office documents to Markdown.
oh-my-opencode
Background agents · Curated agents like oracle, librarians, frontend...
chatbox
User-friendly Desktop Client App for AI Models/LLMs (GPT, Claude, Gemini, Ollama...)
indonesia-gov-apis
🇮🇩 50 Indonesian Government APIs & Data Sources — BPS, OJK, BPJPH, BPOM,...
exstruct
Conversion from Excel to structured JSON (tables, shapes, charts) for...
laravel-toon
Laravel TOON is a token-optimized encoder/decoder for efficient data handling.