search-museum-objects
Find specific objects in the Metropolitan Museum of Art's collection by querying titles, images, or department IDs. Retrieve object IDs for targeted searches or broader 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 |
|---|---|---|---|
| __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. | |
| departmentId | No | Returns objects that are in the specified department. The departmentId should come from the 'list-departments' tool. | |
| hasImages | No | Only returns objects that have images | |
| q | Yes | The search query, Returns a listing of all Object IDs for objects that contain the search query within the object's data | |
| title | No | This should be set to true if you want to search for objects by title |
Implementation Reference
- The async execute method implements the core logic of the 'search-museum-objects' tool: builds the Met Museum search API URL with query parameters, fetches data using a rate limiter, validates response with SearchResponseSchema, formats the total count and object IDs into text output, or handles errors.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, }; } }
- Zod input schema defining parameters for the search-museum-objects tool: query string, optional hasImages, title, and departmentId flags.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/types/types.ts:22-29 (schema)Zod schema for validating the response from Met Museum search API, used in the tool's execute method to parse total and objectIDs.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:68-72 (registration)Registers the 'search-museum-objects' tool directly with the MCP server using its name, description, input schema shape, and bound execute method in the setupTools function.this.search.name, this.search.description, this.search.inputSchema.shape, this.search.execute.bind(this.search), );
- src/index.ts:42-42 (registration)Instantiates the SearchMuseumObjectsTool instance used for registration and execution.this.search = new SearchMuseumObjectsTool();