Take in lyrics and prompt and produce a hex encoded MP3 file. An example prompt would be “polka, upbeat, fast”. Example lyrics would be “[intro]Hey there cowboy[verse]That’s a mighty fine horse you got[outro]”. The output will contain a URL to the MP3 file.
The lyrics you would like to include in the music. You can use new lines to separate verses. You can use [intro][verse][chorus][bridge][outro] to specify the structure of the song. Defaults to “[instrumental]” for instrumental music.
The URL that the generated MP3 file is accessible at.
music_create_async
Takes in lyrics and prompt and starts asynchronous music generation. Returns a task ID that can be used to check status and retrieve the result. Use this for longer music generation tasks to avoid timeouts.
The lyrics you would like to include in the music. You can use new lines to separate verses. You can use [intro][verse][chorus][bridge][outro] to specify the structure of the song. Defaults to “[instrumental]” for instrumental music.
Create a reusable service configuration that points to the MCP server and standardizes how you pass arguments and read results. This lets your agent easily interact with the Music tools in a consistent manner.
Create a client using an ATXP account by importing the ATXP client SDK and other dependencies.
// Import the ATXP client SDKimport { atxpClient, ATXPAccount } from '@atxp/client';// Read the ATXP account details from environment variablesconst atxpConnectionString = process.env.ATXP_CONNECTION;// Create a client using the `atxpClient` functionconst client = await atxpClient({ mcpServer: musicService.mcpServer, account: new ATXPAccount(atxpConnectionString),});
Create a client using a Base account by importing the ATXP client SDK and other dependencies.
// Import the ATXP client SDK and Base accountimport { atxpClient } from '@atxp/client';import { BaseAccount } from '@atxp/base';// Read the Base account details from the environment variablesconst baseRpcUrl = process.env.BASE_RPC_URL;const basePrivateKey = process.env.BASE_PRIVATE_KEY;// Create a client using the `atxpClient` functionconst client = await atxpClient({ mcpServer: musicService.mcpServer, account: new BaseAccount(baseRpcUrl, basePrivateKey),});
Create a client using a Solana account by importing the ATXP client SDK and other dependencies.
// Import the ATXP client SDK and Solana accountimport { atxpClient } from '@atxp/client';import { SolanaAccount } from '@atxp/solana';// Read the Solana account details from the environment variablesconst solanaRpcUrl = process.env.SOLANA_RPC_URL;const solanaPrivateKey = process.env.SOLANA_PRIVATE_KEY;// Create a client using the `atxpClient` functionconst client = await atxpClient({ mcpServer: musicService.mcpServer, account: new SolanaAccount(solanaRpcUrl, solanaPrivateKey),});
Create a client using a Worldchain account with MiniKit integration.
// Import the ATXP client SDK and Worldchain account creatorimport { atxpClient } from '@atxp/client';import { createMiniKitWorldchainAccount } from '@atxp/worldchain';import { MiniKit } from '@worldcoin/minikit-js';// Create a Worldchain account using MiniKitconst account = await createMiniKitWorldchainAccount({ walletAddress: '0x1234...', // User's wallet address miniKit: MiniKit});// Create a client using the `atxpClient` functionconst client = await atxpClient({ mcpServer: musicService.mcpServer, account,});
Browser applications:
// Import the ATXP client SDK and Polygon browser accountimport { atxpClient } from '@atxp/client';import { PolygonBrowserAccount } from '@atxp/polygon';// Initialize the Polygon browser account with wallet providerconst account = await PolygonBrowserAccount.initialize({ provider: window.ethereum, // or any EIP-1193 provider walletAddress: '0x1234...', // User's wallet address});// Create a client using the `atxpClient` functionconst client = await atxpClient({ mcpServer: musicService.mcpServer, account,});
Server/CLI applications:
// Import the ATXP client SDK and Polygon server accountimport { atxpClient } from '@atxp/client';import { PolygonServerAccount } from '@atxp/polygon';// Read the Polygon account details from the environment variablesconst polygonRpcUrl = process.env.POLYGON_RPC_URL;const polygonPrivateKey = process.env.POLYGON_PRIVATE_KEY;// Create a Polygon server accountconst account = new PolygonServerAccount( polygonRpcUrl, polygonPrivateKey, 137 // Chain ID: 137 = Polygon mainnet, 80002 = Amoy testnet);// Create a client using the `atxpClient` functionconst client = await atxpClient({ mcpServer: musicService.mcpServer, account,});
3
Use the Music service in your agent
Synchronous Generation
Asynchronous Generation
Call the Music tool by passing your natural-language instruction as the argument the getArguments method.Read the response using the getResult method.
const prompt = "polka, upbeat, fast";const lyrics = "[intro]Hey there cowboy[verse]That's a mighty fine horse you got[outro]";try { const result = await client.callTool({ name: musicService.createMusicToolName, arguments: musicService.getArguments(prompt, lyrics), }); const { status, url } = musicService.getResult(result); console.log('Status:', status); console.log('URL:', url);} catch (error) { console.error(`Error with ${musicService.description}:`, error); process.exit(1);}
You should see the result of the music creation printed in your console.
For longer music generation tasks (which can take 1-3 minutes), use the async tools to avoid blocking your application. Start the generation and poll for completion.
const prompt = "polka, upbeat, fast";const lyrics = "[intro]Hey there cowboy[verse]That's a mighty fine horse you got[outro]";try { // Start async music generation const asyncResult = await client.callTool({ name: musicService.createMusicAsyncToolName, arguments: musicService.getArguments(prompt, lyrics), }); const { taskId } = musicService.getAsyncCreateResult(asyncResult); console.log('Task started with ID:', taskId); // Poll for completion let completed = false; while (!completed) { await new Promise(resolve => setTimeout(resolve, 10000)); // Wait 10 seconds const statusResult = await client.callTool({ name: musicService.getMusicAsyncToolName, arguments: { taskId }, }); const { status, url, errorMessage } = musicService.getAsyncStatusResult(statusResult); console.log('Status:', status); if (status === 'completed') { console.log('URL:', url); completed = true; } else if (status === 'error') { console.error('Music generation failed:', errorMessage); completed = true; } }} catch (error) { console.error(`Error with ${musicService.description}:`, error); process.exit(1);}
You should see the task ID printed first, followed by status updates, and finally the music URL when generation completes.