-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
44 lines (35 loc) · 1.36 KB
/
server.py
File metadata and controls
44 lines (35 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import httpx
from mcp.server.fastmcp import FastMCP
import json
# Initialize FastMCP server
mcp = FastMCP("Pokemon")
@mcp.tool()
async def get_pokemon_details(pokemon_name: str) -> str:
"""
Retrieve detailed information about a Pokémon.
Args:
pokemon_name (str): The name of the Pokémon to retrieve information for.
"""
async with httpx.AsyncClient() as client:
try:
response = await client.get(f"https://pokeapi.co/api/v2/pokemon/{pokemon_name}", timeout=30.0)
response.raise_for_status()
pokemon = response.json()
pokemon_details = {
"name": pokemon_name,
"abilities": [a["ability"]["name"] for a in pokemon["abilities"]],
"weight": pokemon["weight"],
"height": pokemon["height"],
"moves": [move["move"]["name"] for move in pokemon["moves"]],
"pokemon_type": [t["type"]["name"] for t in pokemon["types"]],
"species": pokemon["species"]["name"],
"stats": {s["stat"]["name"]: s["base_stat"] for s in pokemon["stats"]}
}
return json.dumps(pokemon_details)
except Exception:
return "Invalid Pokémon Name"
def main():
print("Running pokemon-mcp-server!")
mcp.run(transport='stdio')
if __name__ == "__main__":
main()