MCP HubMCP Hub
apinetwork

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.

36created 26/12/2024
Visit
TypeScript
API

πŸ“Œ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

Installation

  1. Clone the repository:
git clone https://github.com/apinetwork/piapi-mcp-server
cd piapi-mcp-server
  1. Install dependencies:
npm install
  1. 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.

  1. (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:

  1. Open: File > Preferences > Cursor Settings, or press Ctrl+Shift+J.
  2. Select the "MCP" tab.
  3. Click "Add new global MCP server".
  4. 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"
      }
    }
  }
}
  1. After saving, you will see a "piapi" entry in the MCP Servers page.
  2. Click Refresh on the entry or restart Cursor to connect.

To test image generation:

  1. Open Cursor Chat and select "Agent mode" (shortcut: Ctrl+I).
  2. Enter a prompt like "generate image of a dog".
  3. The image will be generated via the piapi server.

To disable the piapi server:

  1. Go to MCP Servers page in Cursor Settings.
  2. Find the "piapi" server entry.
  3. 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