search_pokemon
Find Pokémon by entering a partial name to retrieve detailed information. Access stats, abilities, and more, enabling precise queries for Pokémon data.
Instructions
Search for Pokémon by partial name match
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Partial name to search for |
Implementation Reference
- src/tools.ts:68-87 (registration)Registers the search_pokemon tool with MCP server, including description, input schema, and inline handler function.server.tool( "search_pokemon", "Search for Pokémon by partial name match", { query: z.string().min(1).describe("Partial name to search for") }, async ({ query }) => { try { // Get a larger list to search through const pokemonList = await pokeAPI.getPokemonList(1500); const matches = pokemonList.results .filter((p) => p.name.toLowerCase().includes(query.toLowerCase().trim()), ) .slice(0, 20); // Limit to 20 results return formatPokemonSearchResults(query, matches); } catch (error) { return formatCaughtError(error, "searching Pokémon"); } }, );
- src/tools.ts:72-86 (handler)The handler executes the tool logic: fetches up to 1500 pokemon, filters names containing the query (case-insensitive), limits to 20 matches, formats and returns results or error.async ({ query }) => { try { // Get a larger list to search through const pokemonList = await pokeAPI.getPokemonList(1500); const matches = pokemonList.results .filter((p) => p.name.toLowerCase().includes(query.toLowerCase().trim()), ) .slice(0, 20); // Limit to 20 results return formatPokemonSearchResults(query, matches); } catch (error) { return formatCaughtError(error, "searching Pokémon"); } },
- src/tools.ts:71-71 (schema)Input schema validates 'query' as a non-empty string.{ query: z.string().min(1).describe("Partial name to search for") },
- src/formatters.ts:159-189 (helper)Helper function formats the search matches into a formatted MCP text response, handling no results case.export function formatPokemonSearchResults( query: string, matches: Array<{ name: string; url: string }> ): MCPResponse { if (matches.length === 0) { return { content: [ { type: "text", text: `No Pokémon found matching "${query}". Try a different search term.`, }, ], }; } const resultText = matches .map((p, index) => { const id = p.url.split("/").filter(Boolean).pop(); return `${index + 1}. ${p.name} (ID: ${id})`; }) .join("\n"); return { content: [ { type: "text", text: `**Search results for "${query}":**\n\n${resultText}\n\n*Use fetch_pokemon with any of these names to get detailed information.*`, }, ], }; }
- src/formatters.ts:208-211 (helper)Helper function formats caught errors into MCP response format.export function formatCaughtError(error: unknown, context: string): MCPResponse { const message = error instanceof Error ? error.message : String(error); return formatError(`Error ${context}: ${message}`); }