get_image
Retrieve details of a specific ad image by ID. Access fields like URL, dimensions, and status for Facebook and Instagram ad campaigns.
Instructions
Get details of a specific ad image by ID.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| image_id | Yes | Image ID | |
| fields | No | Comma-separated fields to return |
Implementation Reference
- src/tools/images.ts:54-63 (handler)The handler function for the 'get_image' tool. It takes image_id and optional fields parameters, makes a GET request to the ads API using the client to fetch image details, and returns the result as JSON text content.
async ({ image_id, fields }) => { try { const params: Record<string, unknown> = {}; if (fields) params.fields = fields; const { data, rateLimit } = await client.get(`/${image_id}`, params); return { content: [{ type: "text" as const, text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] }; } catch (error) { return { content: [{ type: "text" as const, text: `Failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } - src/tools/images.ts:49-53 (schema)The schema/input definition for the 'get_image' tool. Defines two parameters: image_id (required string) and fields (optional string).
"Get details of a specific ad image by ID.", { image_id: z.string().describe("Image ID"), fields: z.string().optional().describe("Comma-separated fields to return"), }, - src/tools/images.ts:46-64 (registration)Registration of the 'get_image' tool via server.tool() call, which registers it with the MCP server with name 'get_image' and description 'Get details of a specific ad image by ID.'
// ─── get_image ───────────────────────────────────────────── server.tool( "get_image", "Get details of a specific ad image by ID.", { image_id: z.string().describe("Image ID"), fields: z.string().optional().describe("Comma-separated fields to return"), }, async ({ image_id, fields }) => { try { const params: Record<string, unknown> = {}; if (fields) params.fields = fields; const { data, rateLimit } = await client.get(`/${image_id}`, params); return { content: [{ type: "text" as const, text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] }; } catch (error) { return { content: [{ type: "text" as const, text: `Failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } ); - src/tools/images.ts:1-3 (helper)Imports used by the get_image handler: zod for schema validation, McpServer for tool registration, and AdsClient for HTTP requests to the ads API.
import { z } from "zod"; import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { AdsClient } from "../services/ads-client.js";