fetch_pokemon
Retrieve detailed Pokémon data including stats, abilities, sprites, and battle mechanics by providing a name or ID. This tool accesses comprehensive information from the Pokédex MCP Server for AI agents.
Instructions
Fetch detailed information about a Pokémon by name or ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | The name or ID of the Pokémon |
Implementation Reference
- src/tools.ts:21-28 (handler)The async handler function for the 'fetch_pokemon' tool. It takes the 'name' parameter, fetches the Pokémon data using pokeAPI.getPokemon, formats it with formatPokemon, and handles errors with formatCaughtError.async ({ name }) => { try { const pokemon = await pokeAPI.getPokemon(name.toLowerCase().trim()); return formatPokemon(pokemon); } catch (error) { return formatCaughtError(error, "fetching Pokémon"); } },
- src/tools.ts:18-20 (schema)The Zod input schema defining the 'name' parameter for the 'fetch_pokemon' tool.{ name: z.string().min(1).describe("The name or ID of the Pokémon"), },
- src/tools.ts:15-29 (registration)The MCP server.tool registration for 'fetch_pokemon', including name, description, schema, and inline handler.server.tool( "fetch_pokemon", "Fetch detailed information about a Pokémon by name or ID", { name: z.string().min(1).describe("The name or ID of the Pokémon"), }, async ({ name }) => { try { const pokemon = await pokeAPI.getPokemon(name.toLowerCase().trim()); return formatPokemon(pokemon); } catch (error) { return formatCaughtError(error, "fetching Pokémon"); } }, );
- src/formatters.ts:25-61 (helper)Helper function to format the fetched Pokémon data into a formatted MCP text response.export function formatPokemon(pokemon: Pokemon): MCPResponse { const stats = pokemon.stats .map((s) => `${s.stat.name}: ${s.base_stat}`) .join(", "); const types = pokemon.types.map((t) => t.type.name).join(", "); const abilities = pokemon.abilities .map((a) => a.is_hidden ? `${a.ability.name} (hidden)` : a.ability.name, ) .join(", "); const artworkUrl = pokemon.sprites.other?.["official-artwork"]?.front_default; return { content: [ { type: "text", text: `**${pokemon.name}** (ID: ${pokemon.id}) Height: ${pokemon.height} decimetres (${(pokemon.height / 10).toFixed(1)}m) Weight: ${pokemon.weight} hectograms (${(pokemon.weight / 10).toFixed(1)}kg) Base Experience: ${pokemon.base_experience || "N/A"} Order: ${pokemon.order || "N/A"} **Types:** ${types} **Abilities:** ${abilities} **Base Stats:** ${stats} **Sprites:** - Default: ${pokemon.sprites.front_default || "N/A"} - Shiny: ${pokemon.sprites.front_shiny || "N/A"} ${artworkUrl ? `- Artwork: ${artworkUrl}` : ""}`, }, ], }; }
- src/client.ts:191-193 (helper)The PokeAPIClient.getPokemon method called by the handler to fetch raw Pokémon data from the PokeAPI.async getPokemon(idOrName: string | number): Promise<Pokemon> { return this.fetchAPI<Pokemon>(`/pokemon/${idOrName}`); }