Skip to main content
Glama
README.md
<div align="center">

# ๐ŸŽต MusicMCP.AI MCP Server

**AI-Powered Music Generation with Model Context Protocol**

Official MusicMCP.AI Model Context Protocol (MCP) server that enables seamless interaction with our advanced AI music generation platform. This server allows MCP clients like [Claude Desktop](https://www.anthropic.com/claude), [OpenAI Agents](https://github.com/openai/openai-agents-python) and others to generate AI music through natural language commands.

</div>

## โœจ Features

- **๐ŸŽผ AI Music Generation**: Generate songs based on text prompts using MusicMCP.AI's state-of-the-art AI models
- **๐ŸŽต Dual Generation Modes**: Support for both inspiration mode and custom mode
- **๐Ÿ”— Direct Download Links**: Get direct download URLs for generated music
- **๐ŸŽน Instrumental Options**: Generate instrumental-only music or full songs with vocals
- **โœ… Credit Balance Check**: Check your API key validity and remaining credits
- **๐Ÿฅ Health Monitoring**: Check API service health status

## ๐Ÿš€ Quickstart with Claude Desktop

1. **Get Your API Key**: Obtain your API key from [MusicMCP.AI Platform](https://www.musicmcp.ai)
2. **Install uv**: Install the Python package manager with `curl -LsSf https://astral.sh/uv/install.sh | sh`
3. **Configure Claude**: Go to Claude > Settings > Developer > Edit Config > claude_desktop_config.json and add:

```json
{
    "mcpServers": {
        "MusicMCP.AI": {
            "command": "uvx",
            "args": [
                "aimusic-mcp"
            ],
            "env": {
                "MUSICMCP_API_KEY": "<insert-your-api-key-here>",
                "MUSICMCP_API_URL": "https://www.musicmcp.ai/api",
                "TIME_OUT_SECONDS": "600"
            }
        }
    }
}
```

4. **Restart Claude**: Restart the Claude app and you'll see **4 MCP tools** available, indicating successful loading

## โš™๏ธ Environment Variables

| Variable | Description | Default | Required |
|----------|-------------|---------|----------|
| `MUSICMCP_API_KEY` | Your MusicMCP.AI API key | - | โœ… Yes |
| `MUSICMCP_API_URL` | MusicMCP.AI API base URL | `https://www.musicmcp.ai/api` | โŒ No |
| `TIME_OUT_SECONDS` | Timeout for music generation in seconds | `600` (10 min) | โŒ No |

## ๐Ÿ› ๏ธ Available Tools

### 1. ๐ŸŽผ Generate Prompt Song (Inspiration Mode)
Generate AI music based on simple text descriptions. AI automatically creates title, lyrics, and style.

**Cost**: 5 credits per generation (creates 2 songs)

**Parameters:**
- `prompt` (str): Simple description of the music theme (1-1200 characters)
- `instrumental` (bool): Whether to generate instrumental music only
- `style` (str, optional): Music style (e.g., "ambient", "pop", "rock")

**Example Prompts:**
```
"Help me generate a song about a peaceful morning"
"Want a song that expresses longing"
"Create music about friendship"
```

**Output Example:**
```
โœ… Song 1 generated successfully!

๐Ÿ“Œ Title: Peaceful Morning
๐Ÿ†” ID: c7630638-b8ba-4984-876b-6dd7e6eeb796
๐Ÿ”— Download URL: https://cdn.musicmcp.ai/songs/abc123.mp3
๐Ÿ–ผ๏ธ  Cover Image: https://cdn.musicmcp.ai/images/abc123.jpg
โฑ๏ธ  Duration: 180s
๐ŸŽต Style Tags: ambient, meditation, peaceful
๐ŸŽน Instrumental: No
๐Ÿ“… Created: 2025-01-15T10:30:45.123Z
๐Ÿ“ Lyrics:
[Verse]
Gentle sunlight fills the room
Morning dew and sweet perfume
Birds are singing their refrain
Another peaceful day again

You can download or play the audio from the URL above.

โœ… Song 2 generated successfully!

๐Ÿ“Œ Title: Morning Peace
๐Ÿ†” ID: d8741749-c9cb-5095-987c-7ee8f7ffb907
๐Ÿ”— Download URL: https://cdn.musicmcp.ai/songs/def456.mp3
๐Ÿ–ผ๏ธ  Cover Image: https://cdn.musicmcp.ai/images/def456.jpg
โฑ๏ธ  Duration: 213s
๐ŸŽต Style Tags: ambient, meditation, peaceful
๐ŸŽน Instrumental: No
๐Ÿ“… Created: 2025-01-15T10:30:45.126Z
๐Ÿ“ Lyrics:
[Verse]
Calm and quiet, soft and still
Peaceful thoughts upon the hill
Nature's beauty all around
Gentle whispers, soothing sound

You can download or play the audio from the URL above.
```

### 2. ๐ŸŽต Generate Custom Song (Custom Mode)
Generate AI music with specific lyrics, title, and style parameters that you provide.

**Cost**: 5 credits per generation (creates 2 songs)

**Parameters:**
- `title` (str): Song title (required)
- `instrumental` (bool): Whether to generate instrumental music only (required)
- `lyric` (str, optional): Complete lyrics content (not required when instrumental is true)
- `tags` (str, optional): Music style tags (e.g., 'pop', 'rock', 'folk')

**Example Usage:**
```
Please help me generate a song:
Title: Summer Dreams
Lyrics: [complete lyrics content]
Style: folk

Or for instrumental:
Title: Summer Breeze
Instrumental: yes
Style: ambient
```

**Output Example:**
```
โœ… Custom song 'Summer Dreams' (version 1) generated successfully!

๐Ÿ“Œ Title: Summer Dreams
๐Ÿ†” ID: d1ed75a7-3e0b-42c6-b2be-7631204074fe
๐Ÿ”— Download URL: https://cdn.musicmcp.ai/songs/xyz789.mp3
๐Ÿ–ผ๏ธ Cover Image: https://cdn.musicmcp.ai/images/xyz789.jpg
โฑ๏ธ Duration: 195s
๐ŸŽต Style Tags: folk, acoustic, summer
๐ŸŽน Instrumental: No
๐Ÿ“… Created: 2025-01-15T11:45:30.456Z
๐Ÿ“ Lyrics:
[Verse]
Walking through the summer fields
Golden wheat and nature's yields
Sunshine dancing on my face
Summer's warm and sweet embrace

You can download or play the audio from the URL above.

โœ… Custom song 'Summer Dreams' (version 2) generated successfully!

๐Ÿ“Œ Title: Summer Dreams
๐Ÿ†” ID: e2fe86b8-4f1c-53d7-c3cf-8742305185gf
๐Ÿ”— Download URL: https://cdn.musicmcp.ai/songs/uvw012.mp3
๐Ÿ–ผ๏ธ Cover Image: https://cdn.musicmcp.ai/images/uvw012.jpg
โฑ๏ธ Duration: 203s
๐ŸŽต Style Tags: folk, acoustic, summer
๐ŸŽน Instrumental: No
๐Ÿ“… Created: 2025-01-15T11:45:30.459Z
๐Ÿ“ Lyrics:
[Verse]
Walking through the summer fields
Golden wheat and nature's yields
Sunshine dancing on my face
Summer's warm and sweet embrace

You can download or play the audio from the URL above.
```

### 3. โœ… Check Credit Balance
Check if your API key is valid and see your remaining credits.

**Cost**: Free

**Example Usage:**
```
"Check my credit balance"
"How many credits do I have left?"
```

### 4. ๐Ÿฅ Check API Health
Monitor the health status of the MusicMCP.AI API service.

**Cost**: Free

**Example Usage:**
```
"Check API service status"
```

## ๐Ÿ’ฐ Credits & Pricing

| Operation | Credits Cost | Output |
|-----------|-------------|--------|
| Generate Inspiration Music | 5 credits | 2 songs |
| Generate Custom Music | 5 credits | 2 songs |
| Query Music Status | 0 credits (Free) | - |
| Check Credit Balance | 0 credits (Free) | - |
| API Health Check | 0 credits (Free) | - |

## ๐Ÿ’ก Example Usage

โš ๏ธ **Note**: MusicMCP.AI credits are required to use the music generation tools.

### Try asking Claude:

#### **Inspiration Mode:**
- "Please help me generate a song about a peaceful morning"
- "Want a song that expresses longing"
- "Create music about friendship"
- "Generate an ambient music track"

#### **Custom Mode:**
- "Please help me generate a song, Title: Summer Dreams, Lyrics: [complete lyrics], Style: folk"
- "Create a song, Title: Spring Promise, Lyrics: [complete lyrics], Pop style"
- "Generate an instrumental song, Title: Ocean Breeze, Style: ambient"

#### **Management Functions:**
- "Check my credit balance"
- "How many credits do I have left?"
- "Check API service status"

## ๐Ÿ“ฆ Installation

### Using uv (Recommended)
```bash
uvx aimusic-mcp
```

### Using pip
```bash
pip install aimusic-mcp
```

## ๐Ÿ”Œ API Integration

This MCP server integrates with MusicMCP.AI's RESTful API:

- **`POST /music/generate/inspiration`**: Create music generation task (inspiration mode)
- **`POST /music/generate/custom`**: Create custom music generation task
- **`POST /music/generate/query`**: Query music status (batch query supported)
- **`GET /credit`**: Check credit balance
- **`GET /health`**: Check API service health

### ๐Ÿ”„ Async API Workflow

Music generation is **asynchronous**. The MCP server handles this automatically:

**Step 1: Submit Generation Request**
```bash
POST /music/generate/inspiration or /music/generate/custom
โ†’ Returns: {"code": 200, "data": {"ids": ["id1", "id2"]}}
```

**Step 2: Automatic Polling (handled internally by MCP)**
```bash
POST /music/generate/query with {"ids": ["id1", "id2"]}
โ†’ Polls every 2 seconds until status = 1 (completed)
โ†’ Song status: 0 = Failed, 1 = Completed, 2 = In Progress
```

**Step 3: Return Complete Song Information**
```
Once all songs are completed, returns full details:
- songName, songUrl, imgUrl, duration, tags, etc.
```

**Behind the Scenes:**
1. User calls `generate_prompt_song()` or `generate_custom_song()`
2. MCP sends generation request โ†’ receives 2 song IDs
3. MCP automatically polls `/music/generate/query` every 2 seconds
4. When all songs complete (status=1), returns download URLs
5. Default timeout: 10 minutes (configurable via `TIME_OUT_SECONDS`)

**Important Notes:**
- โฑ๏ธ Generation typically takes 2-5 minutes per song
- ๐Ÿ” The MCP server handles all polling automatically
- ๐ŸŽต Each generation always creates 2 song variations
- ๐Ÿ’ฐ Credits (5) are deducted when generation request succeeds
- โš ๏ธ If generation fails, credits are NOT consumed

## ๐Ÿ› Troubleshooting

### Common Issues

1. **API Key Error**: Ensure `MUSICMCP_API_KEY` is set correctly
   - Use the `check_credit_balance` tool to check your key

2. **Insufficient Credits (402 Error)**: You don't have enough credits
   - Check your balance at https://www.musicmcp.ai
   - Recharge your account

3. **Timeout Errors**: Increase `TIME_OUT_SECONDS` if music generation takes longer

### Logs

When running with Claude Desktop, logs can be found at:

- **Windows**: `%APPDATA%\Claude\logs\mcp-server-MusicMCP.AI.log`
- **macOS**: `~/Library/Logs/Claude/mcp-server-MusicMCP.AI.log`

## ๐Ÿงช Development

### Running Tests
```bash
pytest tests/
```

### Local Development
```bash
python -m musicmcp_ai_mcp.api
```

### Code Structure
```
musicmcp_ai_mcp/
โ”œโ”€โ”€ __init__.py          # Package initialization
โ”œโ”€โ”€ __main__.py          # CLI entry point
โ””โ”€โ”€ api.py               # Core MCP server implementation (430 lines)
```

## ๐Ÿ”— Links

- **Platform**: https://www.musicmcp.ai
- **Documentation**: https://www.musicmcp.ai/docs
- **Support**: support@musicmcp.ai

## ๐Ÿ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

---

<div align="center">

**Made with โค๏ธ by the MusicMCP.AI Team**

*Transform your ideas into music with AI*

</div>

TDQS

A3.8/5.0

Scored across 4 tools

Disambiguation5/5

The four tools have clearly distinct purposes: check_api_health monitors service status, check_credit_balance queries account credits, generate_custom_song creates songs from detailed specifications, and generate_prompt_song generates songs from simple themes. There is no overlap or ambiguity between these functions, making tool selection straightforward for an agent.

Naming Consistency5/5

All tool names follow a consistent verb_noun pattern (check_api_health, check_credit_balance, generate_custom_song, generate_prompt_song). The naming is uniform and predictable, using snake_case throughout with clear action-object pairs that enhance readability and usability.

Tool Count4/5

With 4 tools, the count is reasonable for a music generation service, covering essential operations like health checks, balance inquiries, and two song generation modes. However, it feels slightly thin as it lacks tools for managing generated songs (e.g., list, delete) or handling credits beyond checking balance, which could limit functionality in extended workflows.

Completeness3/5

The toolset covers core song generation and basic service operations, but has notable gaps. There are no tools for managing generated songs (e.g., retrieval, deletion), handling credits (e.g., purchase, usage history), or configuring settings. This incompleteness may require workarounds for agents, especially in scenarios involving song lifecycle management or credit transactions.

Maintenance

ActivityInactive
ResponsivenessNo issues