get_pokemon_info
Retrieve complete Pokémon information including stats, images, and basic data by name or ID number. Use this tool to access comprehensive Pokémon details from the PokeAPI database.
Instructions
ポケモンの完全な情報(ステータス、画像、基本情報)を取得
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pokemon | Yes | ポケモン名またはID番号 |
Implementation Reference
- src/index.ts:430-489 (handler)The core handler function for the 'get_pokemon_info' tool. Fetches Pokemon data from PokeAPI, processes base stats, extracts types, height, weight, experience, and various sprite images, then returns a JSON-formatted response.private async getPokemonInfo(pokemon: string) { try { const data = await this.fetchPokemonData(pokemon); // ステータス情報を初期化 const stats: PokemonStats = { hp: 0, attack: 0, defense: 0, "special-attack": 0, "special-defense": 0, speed: 0 }; // APIから取得したステータスデータを整形 data.stats.forEach(stat => { const statName = stat.stat.name as keyof PokemonStats; if (statName in stats) { stats[statName] = stat.base_stat; } }); // 全ての情報をまとめたオブジェクトを作成 const pokemonInfo = { id: data.id, // ポケモンID name: data.name, // ポケモン名 height: data.height, // 身長 weight: data.weight, // 体重 base_experience: data.base_experience, // 基礎経験値 types: data.types.map(t => t.type.name), // タイプ配列 stats: stats, // ステータス情報 images: { // 画像情報 front_default: data.sprites.front_default, // 通常の前面画像 front_shiny: data.sprites.front_shiny, // 色違いの前面画像 back_default: data.sprites.back_default, // 通常の後面画像 back_shiny: data.sprites.back_shiny, // 色違いの後面画像 official_artwork: data.sprites.other["official-artwork"].front_default // 公式アートワーク } }; return { content: [ { type: "text", text: JSON.stringify(pokemonInfo, null, 2) } ] }; } catch (error) { return { content: [ { type: "text", text: `エラー: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } }
- src/index.ts:114-123 (schema)Input schema defining the required 'pokemon' parameter as a string for the tool.inputSchema: { type: "object", properties: { pokemon: { type: "string", description: "ポケモン名またはID番号", }, }, required: ["pokemon"], },
- src/index.ts:111-124 (registration)Tool registration object in the array passed to server.setTools(), specifying name, description, and input schema.{ name: "get_pokemon_info", description: "ポケモンの完全な情報(ステータス、画像、基本情報)を取得", inputSchema: { type: "object", properties: { pokemon: { type: "string", description: "ポケモン名またはID番号", }, }, required: ["pokemon"], }, },
- src/index.ts:182-192 (helper)Shared helper function to fetch raw Pokemon data from PokeAPI endpoint, with specific handling for 404 not found errors.private async fetchPokemonData(pokemon: string): Promise<PokemonData> { try { const response = await axios.get(`https://pokeapi.co/api/v2/pokemon/${pokemon.toLowerCase()}`); return response.data; } catch (error) { if (axios.isAxiosError(error) && error.response?.status === 404) { throw new Error(`ポケモン "${pokemon}" が見つかりません`); } throw new Error(`ポケモンデータの取得に失敗しました: ${error instanceof Error ? error.message : String(error)}`); } }