mcp-hotspots-handler
This MCP server provides a tool to analyze git repository hotspots, returning a sorted list of files with risk scores based on change frequency and author count.
README
In this task, you'll turn a real repo analysis task into a production-ready MCP tool.
You'll implement analyze_hotspots as a thin handler and make it fail cleanly with structured errors.
Workflow at a glance
👩💻
- Set up your environment
- Implement
analyze_hotspotsas a thin MCP handler - Add structured error handling
- Run tests and fix failures
- Check your work
- Submit
1. Set up your environment
Once you log in to your GitHub account, the repository for this task will be added automatically.
- Confirm that
mcp-hotspots-handlerappears in your account. - Clone the repo locally and open it in your editor (Cursor, VS Code, etc.)
2. Implement analyze_hotspots as a thin handler
Implement the MCP tool handler analyze_hotspots.
Requirements:
- Implement it in
tools.py - Register it with
@server.tool() - It must be
async - Parameters:
repo_path: strdays: int = 30limit: int = 10
Inside the handler:
- Instantiate the adapter:
repo = GitRepository(repo_path) - Delegate analysis:
results = analyzer.analyze_hotspots(repo, days=days, limit=limit) - Return structured JSON as MCP
TextContent.
3. Add structured error handling
Your handler must fail cleanly with MCP structured errors:
Input validation errors → InvalidParams
Validate business rules (not types):
- If
repo_pathdoesn't exist →InvalidParams - If
repo_pathexists but isn't a Git repo (no.git) →InvalidParams
Runtime errors → InternalError
Wrap the analysis call:
- If analysis raises a Git operation error →
InternalError - Any other exception →
InternalErrorwith a message like "Analysis failed"
4. Make the tool discoverable
Make the tool discoverable and callable via MCP Inspector.
-
🤔 What's MCP Inspector?
MCP Inspector is an interactive tool for testing and debugging MCP servers. It lets you connect to your server, see which tools are exposed, inspect their schemas, and try calling them manually.
You can use it to check whether:
analyze_hotspotsis discoverable as a tool- Its parameters show up correctly
- The server returns the expected result or a structured error
It's not required for passing the task, but it's a useful way to confirm that your tool works from an MCP client's point of view.
Requirements
<aside> ⌨️
Node.js: ^22.7.5
</aside>
Quick Start (UI mode)
To get up and running right away with the UI, just execute the following:
<aside> ⌨️
npx @modelcontextprotocol/inspector</aside>
🚀 Speed up with a prompt (optional)
You can use AI to generate a first implementation of the handler. Do this only after reading the task requirements and understanding what the handler is supposed to do.
You still need to review the code, run the tests locally, and make sure the final implementation satisfies the full specification and submission checklist.
Prompt
You are working in a repository called `mcp-hotspots-handler`.
Implement the MCP tool handler `analyze_hotspots` in `tools.py` and make it satisfy these exact requirements.
Tool requirements:
- Register it with `@server.tool()`
- The function must be `async`
- It must accept:
- `repo_path: str`
- `days: int = 30`
- `limit: int = 10`
Implementation requirements:
- `tools.py` must import the server with exactly:
- `from app import server`
- Keep the handler thin
- Do not implement hotspot analysis logic inside `tools.py`
- Use `GitRepository` from `git_utils.py`
- Inside the handler:
1. instantiate the adapter with `repo = GitRepository(repo_path)`
2. call `analysis.analyze_hotspots(repo, days=days, limit=limit)`
3. return the result as JSON using MCP `TextContent`
- Use `json.dumps(...)`
Error handling requirements:
- Import:
- `McpError` from `mcp.shared.exceptions`
- `INVALID_PARAMS`
- `INTERNAL_ERROR`
- If `repo_path` does not exist, raise `McpError(code=INVALID_PARAMS, ...)`
- If `repo_path` exists but is not a git repo, raise `McpError(code=INVALID_PARAMS, ...)`
- Check that the repo is a git repo by verifying that the `.git` directory exists
- Wrap the analysis call in `try/except`
- Catch `GitCommandError` explicitly
- If a git operation fails, raise `McpError(code=INTERNAL_ERROR, ...)`
- If any other exception occurs, raise `McpError(code=INTERNAL_ERROR, ...)` with a message containing:
- `"Analysis failed"`
Analysis requirements:
- `analysis.analyze_hotspots(...)` must return a non-empty list
- Each item must contain:
- `file`
- `authors`
- `changes`
- `risk_score`
- Results must be sorted by `risk_score` in descending order
- The `limit` parameter must be respected
Make `pytest` pass.
Build the simplest implementation that satisfies these requirements.
5. Check your work
Before submitting, test your functionality locally and review the submission checklist.
✅ Submission checklist
Handler behavior
- [ ]
analyze_hotspotsexists intools.py, isasync, and is registered with@server.tool() - [ ] Accepts
repo_path,days=30, andlimit=10 - [ ] Is thin: only orchestrates and doesn't contain hotspot-analysis logic
- [ ] Creates a repository adapter with
GitRepository(repo_path) - [ ] Delegates to
analysis.analyze_hotspots(...) - [ ] Returns MCP
TextContent - [ ] Returns a valid JSON string
- [ ] Uses
json.dumps(...) - [ ] Checks for a
.gitdirectory - [ ] Catches
GitCommandErrorexplicitly
Error handling
- [ ] If
repo_pathdoesn't exist or isn't a Git repo, the handler raises anMcpErrorwith codeINVALID_PARAMS - [ ] If a Git operation or any other runtime error happens during analysis, the handler raises
McpErrorwith codeINTERNAL_ERROR - [ ] Generic internal errors include the message
"Analysis failed"
6. Submit your task
- Commit your changes.
- Push to GitHub.
- Return to the lesson and click "Submit."
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.