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."
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。