list-departments
Retrieve all department names from the Metropolitan Museum of Art to explore their collection by category and identify specific areas for further research.
Instructions
List all departments in the Metropolitan Museum of Art (Met Museum)
Input Schema
TableJSON 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. |
Implementation Reference
- src/tools/ListDepartmentsTool.ts:12-38 (handler)The `execute` method fetches the departments list from the Met Museum API, validates the response using `DepartmentsSchema`, formats the departments into a text string, and returns it. Handles errors gracefully.public async execute() { try { const response = await metMuseumRateLimiter.fetch(this.apiUrl); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const jsonData = await response.json(); const parseResult = DepartmentsSchema.safeParse(jsonData); if (!parseResult.success) { throw new Error(`Invalid response shape: ${JSON.stringify(parseResult.error.issues, null, 2)}`); } const text = parseResult.data.departments.map((department) => { return `Department ID: ${department.departmentId}, Display Name: ${department.displayName}`; }).join('\n'); return { content: [{ type: 'text' as const, text }], isError: false, }; } catch (error) { console.error('Error listing departments:', error); return { content: [{ type: 'text' as const, text: `Error listing departments: ${error}` }], isError: true, }; } }
- src/index.ts:61-66 (registration)Registers the 'list-departments' tool with the MCP server by providing its name, description, input schema shape, and bound execute method.this.server.tool( this.listDepartments.name, this.listDepartments.description, this.listDepartments.inputSchema.shape, this.listDepartments.execute.bind(this.listDepartments), );
- src/tools/ListDepartmentsTool.ts:8-8 (schema)Zod input schema for the tool, which requires no parameters.public readonly inputSchema = z.object({}).describe('No input required');
- src/types/types.ts:14-20 (schema)Zod schema used to validate the API response containing the list of departments. References `DepartmentSchema` defined earlier.export const DepartmentsSchema = z.object({ departments: z.array(DepartmentSchema).describe( 'An array containing the JSON objects that contain each department\'s ' + 'departmentId and display name. The departmentId is to be used as a ' + 'query parameter on the `/objects` endpoint', ), });
- src/tools/ListDepartmentsTool.ts:3-3 (helper)Import of the rate limiter utility used in the execute method to fetch the API without exceeding rate limits.import { metMuseumRateLimiter } from '../utils/RateLimiter.js';