get_pokemon
Retrieve detailed Pokémon information including types, base stats, and abilities from PokeAPI by specifying the Pokémon name.
Instructions
Ficha con tipos, base stats y habilidades (PokeAPI).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes |
Implementation Reference
- src/pokeapi.ts:116-124 (handler)Main handler logic for the get_pokemon tool: retrieves raw pokemon data and formats it into name, sorted types, abbreviated base_stats, and abilities list.async pokemonCore(name: string) { const p = await this.getPokemon(name); return { name: p.name, types: (p.types as AnyObj[]).sort((a,b)=>a.slot-b.slot).map(t => t.type.name), base_stats: Object.fromEntries((p.stats as AnyObj[]).map(s => [s.stat.name.replace('special-attack','spa').replace('special-defense','spd').replace('speed','spe').replace('attack','atk').replace('defense','def').replace('hp','hp'), s.base_stat])), abilities: (p.abilities as AnyObj[]).map(a => a.ability.name) }; }
- src/index.ts:58-58 (schema)Input schema definition for the get_pokemon tool, requiring a 'name' string parameter.type:'object', properties:{ name:{type:'string'} }, required:['name']
- src/index.ts:57-63 (registration)Registration of the get_pokemon tool in the MCP server registry.registerTool('get_pokemon', 'Ficha con tipos, base stats y habilidades (PokeAPI).', { type:'object', properties:{ name:{type:'string'} }, required:['name'] }, async (args:any) => { const name = String(args.name); const core = await pokeapi.pokemonCore(name); return jsonContent(core); });
- src/pokeapi.ts:35-39 (helper)Cached API fetcher for raw pokemon data, used by pokemonCore.async getPokemon(name: string): Promise<AnyObj> { const n = normName(name); if (!this.pokemonCache.has(n)) this.pokemonCache.set(n, this.getJSON(`${API}/pokemon/${n}`)); return this.pokemonCache.get(n)!; }
- src/utils.ts:5-14 (helper)Utility for normalizing pokemon names to PokeAPI kebab-case format (e.g., handles spaces, gender symbols). Used in getPokemon.export function normName(s: string): string { return s .toLowerCase() .replace(/[\s_.]/g, '-') .replace(/♀/g, '-f') .replace(/♂/g, '-m') .replace(/'/g, '') .replace(/[^a-z0-9-]/g, '') .replace(/-+/g, '-') .trim();