search-museum-objects
Search the Metropolitan Museum of Art collection by query, department, or title to find objects with or without images. Returns object IDs and total count for further exploration.
Instructions
Search for objects in the Metropolitan Museum of Art (Met Museum). Will return Total objects found, followed by a list of Object Ids.The parameter title should be set to true if you want to search for objects by title.The parameter hasImages is false by default, but can be set to true to return objects without images.If the parameter hasImages is true, the parameter title should be false.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| q | Yes | The search query, Returns a listing of all Object IDs for objects that contain the search query within the object's data | |
| hasImages | No | Only returns objects that have images | |
| title | No | This should be set to true if you want to search for objects by title | |
| departmentId | No | Returns objects that are in the specified department. The departmentId should come from the 'list-departments' tool. | |
| __intent | Yes | In ≤ 30 words, describe why you are calling this tool and how its result advances your overall task. Don't use first-person pronouns like "I" or "my". Make sure to give a gist of the whole task and how this tool fits into it. |
Implementation Reference
- The `execute` method containing the core tool implementation: builds the search URL, performs rate-limited API fetch to Met Museum, parses response using SearchResponseSchema, handles no results or errors, and returns formatted text with total count and object IDs.public async execute({ q, hasImages, title, departmentId }: z.infer<typeof this.inputSchema>) { try { const url = new URL(this.apiBaseUrl); url.searchParams.set('q', q); if (hasImages) { url.searchParams.set('hasImages', 'true'); } if (title && !hasImages) { url.searchParams.set('title', 'true'); } if (departmentId) { url.searchParams.set('departmentId', departmentId.toString()); } const response = await metMuseumRateLimiter.fetch(url.toString()); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const jsonData = await response.json(); const parseResult = SearchResponseSchema.safeParse(jsonData); if (!parseResult.success) { throw new Error(`Invalid response shape: ${JSON.stringify(parseResult.error.issues, null, 2)}`); } if (parseResult.data.total === 0 || !parseResult.data.objectIDs) { return { content: [{ type: 'text' as const, text: 'No objects found' }], isError: false, }; } const text = `Total objects found: ${parseResult.data.total}\nObject IDs: ${parseResult.data.objectIDs.join(', ')}`; return { content: [{ type: 'text' as const, text }], isError: false, }; } catch (error) { console.error('Error searching museum objects:', error); return { content: [{ type: 'text' as const, text: `Error searching museum objects: ${error}` }], isError: true, }; } }
- Input schema using Zod defining the tool parameters: q (search query), hasImages (filter), title (search mode), departmentId (filter).public readonly inputSchema = z.object({ q: z.string().describe(`The search query, Returns a listing of all Object IDs for objects that contain the search query within the object's data`), hasImages: z.boolean().optional().default(false).describe(`Only returns objects that have images`), title: z.boolean().optional().default(false).describe(`This should be set to true if you want to search for objects by title`), departmentId: z.number().optional().describe(`Returns objects that are in the specified department. The departmentId should come from the 'list-departments' tool.`), });
- src/index.ts:67-72 (registration)Registers the 'search-museum-objects' tool with the MCP server by calling server.tool with name, description, input schema shape, and bound execute method.this.server.tool( this.search.name, this.search.description, this.search.inputSchema.shape, this.search.execute.bind(this.search), );
- src/types/types.ts:22-29 (schema)Output response schema for parsing the Met Museum search API response, used in the handler for validation.export const SearchResponseSchema = z.object({ total: z.number().describe( 'The total number of publicly-available objects', ), objectIDs: z.array(z.number()).nullable().describe( 'An array containing the object ID of publicly-available object', ), });
- src/index.ts:42-42 (registration)Instantiates the SearchMuseumObjectsTool class instance used for registration.this.search = new SearchMuseumObjectsTool();