Implement MCP server with superhero tool#14
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR implements a complete MCP (Model Context Protocol) server for querying superhero data. The implementation transforms an empty placeholder file into a fully functional TypeScript-based MCP server that provides superhero information through a tool interface.
- Adds MCP server setup with tool registration for querying superhero data
- Implements data loading from JSON file with error handling
- Adds case-insensitive search functionality by name or ID
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const hero = superheroes.find(h => { | ||
| const heroNameLc = h.name?.toLowerCase() ?? ""; | ||
| const heroIdStr = h.id?.toString() ?? ""; | ||
| return heroNameLc === nameLc || heroIdStr === idStr; | ||
| }); |
There was a problem hiding this comment.
The search logic allows matching with empty strings. When both name and id are undefined, nameLc and idStr will be empty strings, and the first hero with an empty/undefined name or id will be returned instead of throwing 'Superhero not found'. Add validation to ensure at least one search parameter is provided before searching.
| server.registerTool( | ||
| "get_superhero", | ||
| { | ||
| description: "Get superhero details by name or id", |
There was a problem hiding this comment.
The description indicates 'name or id' but the implementation uses OR logic that matches on either field. Consider clarifying that at least one parameter is required, or add validation to enforce this requirement (as noted in the search logic issue).
This PR implements a complete MCP server that provides a get_superhero tool for retrieving superhero details by name or ID. The implementation includes: