get-similar-images-by-description
Find visually similar images by entering a text description. This tool searches Inspire's image database to return matching results based on your descriptive input.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| description | Yes | image description | |
| limit | No | pagination: limit. set at least 5 | |
| offset | Yes | pagination: offset |
Implementation Reference
- src/tools/getSimilarImages.ts:22-87 (handler)The handler function executes the tool logic: searches for posts by text description, fetches post details, downloads images as base64, interleaves them with size limits, and returns content.handler: async ({ description, limit, offset, }: { description: string; limit: number; offset: number; }) => { const results = (await searchClient.searchPosts({ searchBy: { case: "textQuery", value: description }, offset, limit, })) as SearchImagesResponse; if (!results) { return { content: [ { type: "text" as const, text: "Failed to retrieve similar images" }, ], }; } const posts = (await postsClient.getPosts({ postIds: results.results.map((res) => res.postId), })) as GetPostsResponse; if (!posts) { return { content: [ { type: "text" as const, text: "Failed to retrieve posts for images", }, ], }; } const postsImages = await Promise.all( posts.posts.map(downloadImageAsBase64), ); const interleavedContent: ( | { type: "text"; text: string } | { type: "image"; mimeType: string; data: string } )[] = []; const MAX_RESPONSE_SIZE = 1_048_576; let currentSize = 0; for (const imageData of postsImages) { const estimatedSize = Buffer.byteLength(imageData.base64, "base64"); if (currentSize + estimatedSize > MAX_RESPONSE_SIZE) break; interleavedContent.push({ type: "image" as const, data: imageData.base64, mimeType: imageData.mimeType, }); currentSize += estimatedSize; } return { content: interleavedContent }; },
- src/tools/getSimilarImages.ts:9-18 (schema)Zod schema defining input parameters: description (string), limit (number 1-10 default 10), offset (number).inputSchema: { description: z.string().describe("image description"), limit: z .number() .min(1) .max(10) .default(10) .describe("pagination: limit. set at least 5"), offset: z.number().describe("pagination: offset"), },
- src/tools/registerTools.ts:5-10 (registration)Registers the tool with the MCP server using its name, inputSchema, metadata, and handler.server.tool( getSimilarImagesTool.name, getSimilarImagesTool.inputSchema, getSimilarImagesTool.metadata, getSimilarImagesTool.handler, );