search-for-artist
Find specific artists in the Art Institute of Chicago collection by name, with options to paginate and limit search results for precise queries.
Instructions
Search for artists in the Art Institute of Chicago collection
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | The number of resources to return per page. | |
| name | Yes | The name of the artist to search for. | |
| page | No | The page of results to return. Used for pagination. |
Implementation Reference
- src/tools/ArtistSearchTool.ts:20-67 (handler)The executeCore method implements the core logic of the 'search-for-artist' tool: constructs an Elasticsearch query for artist search, performs POST API request to /agents/search, parses response using artistSearchResponseSchema, and formats results with pagination info.public async executeCore(input: z.infer<typeof this.inputSchema>) { const { name, limit, page } = input; const query = { query: { bool: { should: [ { match_phrase: { title: `"${name}"` } }, ], minimum_should_match: 1, }, }, }; const url = new URL(`${this.apiBaseUrl}/agents/search`); url.searchParams.set('page', `${page}`); url.searchParams.set('limit', `${limit}`); const parsedData = await this.safeApiRequest( url, { method: 'POST', body: JSON.stringify(query), }, artistSearchResponseSchema, ); if (parsedData.data.length === 0) { return { content: [{ type: 'text' as const, text: `No results found for "${name}".`, }], }; } const text = parsedData.data.map((artist) => { return `Title: ${artist.title}\n` + `Artist ID: ${artist.id}\n` + `Score: ${artist._score}\n`; }).join('\n-----\n'); const paginationText = `\nPagination Info\n` + `Total: ${parsedData.pagination.total}\n` + `Total Pages: ${parsedData.pagination.total_pages}\n` + `Current Page: ${parsedData.pagination.current_page}\n`; return { content: [{ type: 'text' as const, text: text + paginationText }], }; }
- src/tools/ArtistSearchTool.ts:5-9 (schema)Input schema defining the parameters for the 'search-for-artist' tool: artist name (required), optional limit and page for pagination.const artistSearchSchema = z.object({ name: z.string().describe('The name of the artist to search for.'), limit: z.number().optional().default(10).describe('The number of resources to return per page.'), page: z.number().optional().default(1).describe('The page of results to return. Used for pagination.'), });
- src/schemas/schemas.ts:96-110 (schema)Zod schema for validating the response from the Art Institute API artist search endpoint (/agents/search), used in safeApiRequest.export const artistSearchResponseSchema = z.object({ preference: z.string().nullable(), pagination: paginationSchema, data: z.array(z.object({ _score: z.number(), id: z.number(), api_model: z.string(), api_link: z.string(), title: z.string(), timestamp: z.string(), })), info: apiInfoSchema, config: apiConfigSchema, });
- src/index.ts:75-80 (registration)Registers the 'search-for-artist' tool with the MCP server by calling server.tool with name, description, input schema, and execute function.this.server.tool( this.artistSearchTool.name, this.artistSearchTool.description, this.artistSearchTool.inputSchema.shape, this.artistSearchTool.execute.bind(this.artistSearchTool), );