Overview

Use the Image MCP server from your ATXP-powered agent to create images based on a prompt.

Example prompts

  • “Create an image of a cat riding a horse. Use a realistic style.”
  • “Create a coloring page of a child and a puppy.”

Tools

Usage

1

Define the Image service

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 Image tools in a consistent manner.
const imageService = {
    mcpServer: 'https://image.mcp.atxp.ai/',
    createImageToolName: 'image_create_image',
    createImageAsyncToolName: 'image_create_image_async',
    getImageAsyncToolName: 'image_get_image_async',
    description: 'ATXP Image MCP server',
    getArguments: (prompt: string) => ({ prompt }),
    getResult: (result: any) => {
      const jsonResult = result.content[0].text;
      const parsed = JSON.parse(jsonResult);
      return { status: parsed.status, url: parsed.url };
    },
    getAsyncCreateResult: (result: any) => {
      const jsonResult = result.content[0].text;
      const parsed = JSON.parse(jsonResult);
      return { taskId: parsed.taskId };
    },
    getAsyncStatusResult: (result: any) => {
      const jsonResult = result.content[0].text;
      const parsed = JSON.parse(jsonResult);
      return { status: parsed.status, url: parsed.url };
    }
  };
2

Create an ATXP client

Create a client using an ATXP account by importing the ATXP client SDK and other dependencies.
// Import the ATXP client SDK
import { atxpClient, ATXPAccount } from '@atxp/client';

// Read the ATXP account details from environment variables
const atxpConnectionString = process.env.ATXP_CONNECTION;

// Create a client using the `atxpClient` function
const client = await atxpClient({
  mcpServer: imageService.mcpServer,
  account: new ATXPAccount(atxpConnectionString),
});
3

Use the Image service in your agent

Call the Image tool by passing your natural-language instruction as the argument the getArguments method.Read the response using the getResult method.
const prompt = "Create an image of a cat riding a horse. Use a realistic style.";

try {
  const result = await client.callTool({
      name: imageService.createImageToolName,
      arguments: imageService.getArguments(prompt),
  });
  const { status, url } = imageService.getResult(result);
  console.log('Status:', status);
  console.log('URL:', url);
} catch (error) {
  console.error(`Error with ${imageService.description}:`, error);
  process.exit(1);
}
You should see the result of the image creation printed in your console.