-
Notifications
You must be signed in to change notification settings - Fork 909
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into link-new-server
- Loading branch information
Showing
10 changed files
with
667 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# EverArt MCP Server | ||
|
||
Image generation server for Claude Desktop using EverArt's API. | ||
|
||
## Install | ||
```bash | ||
npm install | ||
export EVERART_API_KEY=your_key_here | ||
``` | ||
|
||
## Config | ||
Add to Claude Desktop config: | ||
```json | ||
{ | ||
"mcpServers": { | ||
"everart": { | ||
"command": "npx", | ||
"args": ["-y", "@modelcontextprotocol/server-everart"], | ||
"env": { | ||
"EVERART_API_KEY": "your_key_here" | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Tools | ||
|
||
### generate_image | ||
Generates images with multiple model options. Opens result in browser and returns URL. | ||
|
||
Parameters: | ||
```typescript | ||
{ | ||
prompt: string, // Image description | ||
model?: string, // Model ID (default: "207910310772879360") | ||
image_count?: number // Number of images (default: 1) | ||
} | ||
``` | ||
|
||
Models: | ||
- 5000: FLUX1.1 (standard) | ||
- 9000: FLUX1.1-ultra | ||
- 6000: SD3.5 | ||
- 7000: Recraft-Real | ||
- 8000: Recraft-Vector | ||
|
||
All images generated at 1024x1024. | ||
|
||
Sample usage: | ||
```javascript | ||
const result = await client.callTool({ | ||
name: "generate_image", | ||
arguments: { | ||
prompt: "A cat sitting elegantly", | ||
model: "7000", | ||
image_count: 1 | ||
} | ||
}); | ||
``` | ||
|
||
Response format: | ||
``` | ||
Image generated successfully! | ||
The image has been opened in your default browser. | ||
Generation details: | ||
- Model: 7000 | ||
- Prompt: "A cat sitting elegantly" | ||
- Image URL: https://storage.googleapis.com/... | ||
You can also click the URL above to view the image again. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
#!/usr/bin/env node | ||
import EverArt from "everart"; | ||
import { Server } from "@modelcontextprotocol/sdk/server/index.js"; | ||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; | ||
import { | ||
CallToolRequestSchema, | ||
ListToolsRequestSchema, | ||
ListResourcesRequestSchema, | ||
ReadResourceRequestSchema, | ||
} from "@modelcontextprotocol/sdk/types.js"; | ||
import fetch from "node-fetch"; | ||
import open from "open"; | ||
|
||
const server = new Server( | ||
{ | ||
name: "example-servers/everart", | ||
version: "0.2.0", | ||
}, | ||
{ | ||
capabilities: { | ||
tools: {}, | ||
resources: {}, // Required for image resources | ||
}, | ||
}, | ||
); | ||
|
||
if (!process.env.EVERART_API_KEY) { | ||
console.error("EVERART_API_KEY environment variable is not set"); | ||
process.exit(1); | ||
} | ||
|
||
const client = new EverArt.default(process.env.EVERART_API_KEY); | ||
|
||
server.setRequestHandler(ListToolsRequestSchema, async () => ({ | ||
tools: [ | ||
{ | ||
name: "generate_image", | ||
description: | ||
"Generate images using EverArt Models and returns a clickable link to view the generated image. " + | ||
"The tool will return a URL that can be clicked to view the image in a browser. " + | ||
"Available models:\n" + | ||
"- 5000:FLUX1.1: Standard quality\n" + | ||
"- 9000:FLUX1.1-ultra: Ultra high quality\n" + | ||
"- 6000:SD3.5: Stable Diffusion 3.5\n" + | ||
"- 7000:Recraft-Real: Photorealistic style\n" + | ||
"- 8000:Recraft-Vector: Vector art style\n" + | ||
"\nThe response will contain a direct link to view the generated image.", | ||
inputSchema: { | ||
type: "object", | ||
properties: { | ||
prompt: { | ||
type: "string", | ||
description: "Text description of desired image", | ||
}, | ||
model: { | ||
type: "string", | ||
description: | ||
"Model ID (5000:FLUX1.1, 9000:FLUX1.1-ultra, 6000:SD3.5, 7000:Recraft-Real, 8000:Recraft-Vector)", | ||
default: "5000", | ||
}, | ||
image_count: { | ||
type: "number", | ||
description: "Number of images to generate", | ||
default: 1, | ||
}, | ||
}, | ||
required: ["prompt"], | ||
}, | ||
}, | ||
], | ||
})); | ||
|
||
server.setRequestHandler(ListResourcesRequestSchema, async () => { | ||
return { | ||
resources: [ | ||
{ | ||
uri: "everart://images", | ||
mimeType: "image/png", | ||
name: "Generated Images", | ||
}, | ||
], | ||
}; | ||
}); | ||
|
||
server.setRequestHandler(ReadResourceRequestSchema, async (request) => { | ||
if (request.params.uri === "everart://images") { | ||
return { | ||
contents: [ | ||
{ | ||
uri: "everart://images", | ||
mimeType: "image/png", | ||
blob: "", // Empty since this is just for listing | ||
}, | ||
], | ||
}; | ||
} | ||
throw new Error("Resource not found"); | ||
}); | ||
|
||
server.setRequestHandler(CallToolRequestSchema, async (request) => { | ||
if (request.params.name === "generate_image") { | ||
try { | ||
const { | ||
prompt, | ||
model = "207910310772879360", | ||
image_count = 1, | ||
} = request.params.arguments as any; | ||
|
||
// Use correct EverArt API method | ||
const generation = await client.v1.generations.create( | ||
model, | ||
prompt, | ||
"txt2img", | ||
{ | ||
imageCount: image_count, | ||
height: 1024, | ||
width: 1024, | ||
}, | ||
); | ||
|
||
// Wait for generation to complete | ||
const completedGen = await client.v1.generations.fetchWithPolling( | ||
generation[0].id, | ||
); | ||
|
||
const imgUrl = completedGen.image_url; | ||
if (!imgUrl) throw new Error("No image URL"); | ||
|
||
// Automatically open the image URL in the default browser | ||
await open(imgUrl); | ||
|
||
// Return a formatted message with the clickable link | ||
return { | ||
content: [ | ||
{ | ||
type: "text", | ||
text: `Image generated successfully!\nThe image has been opened in your default browser.\n\nGeneration details:\n- Model: ${model}\n- Prompt: "${prompt}"\n- Image URL: ${imgUrl}\n\nYou can also click the URL above to view the image again.`, | ||
}, | ||
], | ||
}; | ||
} catch (error: unknown) { | ||
console.error("Detailed error:", error); | ||
const errorMessage = | ||
error instanceof Error ? error.message : "Unknown error"; | ||
return { | ||
content: [{ type: "text", text: `Error: ${errorMessage}` }], | ||
isError: true, | ||
}; | ||
} | ||
} | ||
throw new Error(`Unknown tool: ${request.params.name}`); | ||
}); | ||
|
||
async function runServer() { | ||
const transport = new StdioServerTransport(); | ||
await server.connect(transport); | ||
console.error("EverArt MCP Server running on stdio"); | ||
} | ||
|
||
runServer().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "@modelcontextprotocol/server-everart", | ||
"version": "0.1.0", | ||
"description": "MCP server for EverArt API integration", | ||
"license": "MIT", | ||
"author": "Anthropic, PBC (https://anthropic.com)", | ||
"homepage": "https://modelcontextprotocol.io", | ||
"bugs": "https://github.com/modelcontextprotocol/servers/issues", | ||
"type": "module", | ||
"bin": { | ||
"mcp-server-everart": "dist/index.js" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "tsc && shx chmod +x dist/*.js", | ||
"prepare": "npm run build", | ||
"watch": "tsc --watch" | ||
}, | ||
"dependencies": { | ||
"@modelcontextprotocol/sdk": "0.5.0", | ||
"everart": "^1.0.0", | ||
"node-fetch": "^3.3.2", | ||
"open": "^9.1.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.11.0", | ||
"shx": "^0.3.4", | ||
"typescript": "^5.3.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./dist", | ||
"rootDir": "." | ||
}, | ||
"include": [ | ||
"./**/*.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.