jono-oliver/mcp-server
If you are the rightful owner of mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
A learning project to create an MCP server that provides Pokemon information using the PokéAPI.
Pokemon MCP Server
A learning project to understand the creation of an MCP (Model Context Protocol) server. This server provides Pokemon information through a simple tool that fetches data from the PokéAPI.
What is MCP?
MCP (Model Context Protocol) is a protocol that allows AI assistants to connect to external data sources and tools. This project demonstrates how to create a custom MCP server that provides Pokemon information as a tool that can be used by AI assistants.
Features
-
Pokemon Lookup Tool: Get detailed information about any Pokemon including:
- Pokemon ID and name
- Type(s)
- Height and weight
- Formatted display
-
Error Handling: Proper error handling for invalid Pokemon names and API failures
-
Type Safety: Uses Zod for schema validation and TypeScript for type safety
Project Structure
├── src/
│ └── server.ts # Main MCP server implementation
├── dist/ # Compiled JavaScript output
├── package.json # Project dependencies and scripts
├── tsconfig.json # TypeScript configuration
└── README.md # This file
Installation
- Clone the repository:
git clone <your-repo-url>
cd mcp-server
- Install dependencies:
npm install
- Build the project:
npm run build
Usage
Running the Server
You can run the server in several ways:
Development mode (with TypeScript):
npm run dev
Production mode:
npm start
Build and watch for changes:
npm run build:watch
Testing with MCP Inspector
To test the server interactively, use the MCP Inspector:
npm run inspect
This will start the MCP Inspector which allows you to test the Pokemon lookup tool.
Available Tools
The server provides one tool:
get_pokemon_pokedex_info: Get information about a Pokemon- Parameter:
name(string) - The name of the Pokemon to look up - Returns: Formatted Pokemon information including ID, types, height, and weight
- Parameter:
Example Usage
When connected to an MCP client, you can use the tool like this:
Tool: get_pokemon_pokedex_info
Parameters: { "name": "pikachu" }
Response:
Pikachu (#25) - Electric type, 0.4m tall, 6kg
Technical Details
Dependencies
@modelcontextprotocol/sdk: Core MCP SDK for building serverszod: Schema validation and type inferencetypescript: Type safety and modern JavaScript features
Key Components
- Pokemon Schema: Uses Zod to validate Pokemon data from the PokéAPI
- Tool Registration: Registers the Pokemon lookup tool with the MCP server
- Error Handling: Comprehensive error handling for API failures and invalid inputs
- Data Formatting: Formats Pokemon data into a readable string format
API Integration
The server integrates with the PokéAPI to fetch Pokemon information. It handles:
- Pokemon name normalization (converts to lowercase, replaces spaces with hyphens)
- HTTP error handling
- Data validation using Zod schemas
Learning Objectives
This project demonstrates:
- MCP Server Creation: How to create a custom MCP server from scratch
- Tool Registration: How to register tools that AI assistants can use
- External API Integration: How to fetch and process data from external APIs
- Type Safety: Using TypeScript and Zod for robust data handling
- Error Handling: Proper error handling patterns for production code
- Schema Validation: Using Zod for runtime type checking
Development
Scripts
npm run build: Compile TypeScript to JavaScriptnpm run build:watch: Watch for changes and rebuild automaticallynpm run dev: Run the server in development mode with TypeScriptnpm run inspect: Start the MCP Inspector for testingnpm start: Run the compiled server
Requirements
- Node.js >= 22.0.0
- npm or yarn
License
ISC
Contributing
This is a learning project, but feel free to fork and experiment with it!