piapi-mcp-server
by: apinetwork
A TypeScript implementation of a Model Context Protocol (MCP) server that integrates with PiAPI's API. PiAPI makes user able to generate media content with Midjourney/Flux/Kling/LumaLabs/Udio/Chrip/Trellis directly from Claude or any other MCP-compatible apps.
πOverview
Purpose: The piapi-mcp-server is designed to facilitate the integration of Model Context Protocol (MCP) support with PiAPI's API for generating media content.
Overview: This TypeScript-based implementation acts as a server allowing users to generate various forms of media content using different platforms directly from compatible applications like Claude. It streamlines the creative process by connecting multiple media generation tools seamlessly.
Key Features:
-
Base Media Toolkits: Offers fundamental toolkits for image and video generation, making it a versatile solution for content creators.
-
Multi-Platform Media Generation: Supports generation from multiple sources, including text and image prompts for various media types such as images, videos, and music.
piapi-mcp-server
A TypeScript implementation of a Model Context Protocol (MCP) server that integrates with PiAPI's API. PiAPI enables users to generate media content with Midjourney, Flux, Kling, LumaLabs, Udio, Chrip, Trellis directly from Claude or any other MCP-compatible apps.
Features (more coming soon)
Note: Time-consuming tools like video generation may not complete due to Claude's timeout limitations
- Base Image toolkit
- Base Video toolkit
- Flux Image generation from text/image prompt
- Hunyuan Video generation from text/image prompt
- Skyreels Video generation from image prompt
- Wan Video generation from text/image prompt
- MMAudio Music generation from video
- TTS Zero-Shot voice generation
- Midjourney Image generation
- imagine (implemented)
- Kling Video and Effects generation
- Luma Dream Machine video generation
- Suno Music generation
- Trellis 3D model generation from image
- Workflow planning inside LLMs (upcoming)
Prerequisites
- Node.js 16.x or higher
- npm or yarn
- A PiAPI API key (get one at https://piapi.ai/workspace/key)
Installation
- Clone the repository:
git clone https://github.com/apinetwork/piapi-mcp-server
cd piapi-mcp-server
- Install dependencies:
npm install
- Build the project:
npm run build
After building, a dist/index.js
file will be generated. You can then configure this file with Claude Desktop and other applications.
- (Optional) Test server with MCP Inspector:
Create a .env
file in the project root directory with your API key:
PIAPI_API_KEY=your_api_key_here
Run the following command to start the MCP Inspector:
npm run inspect
MCP Inspector will be available at http://localhost:5173. The default timeout for inspector operations is 10000ms (10 seconds). To test image generation or other time-consuming operations, increase the timeout by adding a timeout parameter to the URL, e.g., http://localhost:5173?timeout=60000 (60 seconds).
MCP Inspector features:
- Interactive Testing
- Real-time Feedback
- Request/Response Inspection
- Function Documentation
- Custom Parameters (e.g., timeout)
- History Tracking
For detailed information about MCP Inspector, visit the official MCP documentation.
Usage
Connecting to Claude Desktop
Add this to your Claude Desktop configuration file (~/Library/Application Support/Claude/claude_desktop_config.json
on macOS or %APPDATA%\Claude\claude_desktop_config.json
on Windows):
{
"mcpServers": {
"piapi": {
"command": "node",
"args": ["/absolute/path/to/piapi-mcp-server/dist/index.js"],
"env": {
"PIAPI_API_KEY": "your_api_key_here"
}
}
}
}
After updating your configuration, restart Claude Desktop. A hammer icon should appear in the bottom right corner of the input box.
For more details, see the official MCP documentation: https://modelcontextprotocol.io/quickstart/user
Connecting to Cursor
Note: This guide is based on Cursor 0.47.5; features may vary in other versions.
To configure the MCP server:
- Open: File > Preferences > Cursor Settings, or press
Ctrl+Shift+J
. - Select the "MCP" tab.
- Click "Add new global MCP server".
- Add your configuration in the opened
mcp.json
file:
{
"mcpServers": {
"piapi": {
"command": "node",
"args": ["/absolute/path/to/piapi-mcp-server/dist/index.js"],
"env": {
"PIAPI_API_KEY": "your_api_key_here"
}
}
}
}
- After saving, you will see a "piapi" entry in the MCP Servers page.
- Click Refresh on the entry or restart Cursor to connect.
To test image generation:
- Open Cursor Chat and select "Agent mode" (shortcut:
Ctrl+I
). - Enter a prompt like "generate image of a dog".
- The image will be generated via the piapi server.
To disable the piapi server:
- Go to MCP Servers page in Cursor Settings.
- Find the "piapi" server entry.
- Toggle the Enabled button to disable.
Development
Project Structure
piapi-mcp-server/
βββ assets/
βββ src/
β βββ index.ts # Main server entry point
βββ package.json
βββ tsconfig.json
βββ .env.example
License
MIT