
Ohm Mcp
io.github.Murugarajr由 GitHub 帳號 Murugarajr 發布v1.0.1更新於 Oct 24, 2026
AST-based Python refactoring MCP server with safe automated refactorings and rollback
概覽
以 AST 為基礎的 Python 重構助理,讓 AI 用戶端分析程式碼品質、規劃重構,並在備份與回復保護下套用變更。
- 可以做什麼
- 分析程式碼庫並規劃重構,包含函式層級的重構方案、說明與統一 diff 修補檔
- 偵測架構與設計問題,例如上帝物件、SOLID 違規、高耦合與設計模式建議
- 找出程式碼品質問題:無用程式碼、重複程式碼、萬用字元匯入,並擷取方法或在專案中重新命名符號
- 評估型別覆蓋率、產生型別存根與特徵測試,並標示巢狀迴圈等效能熱點
- 在試跑預覽、備份、測試驗證與回復機制下套用重構,並檢視操作紀錄
- 產生 HTML、Markdown 或 JSON 格式的品質報告與儀表板
- 適用情境
- 適合在既有的 Python 程式碼庫上工作時,讓助理找出無用程式碼、重複、型別缺口或效能問題,並安全地執行重構。也適合需要追蹤技術債或為 CI 加入品質檢查的團隊。
- 執行需求
- 以 stdio 在本機執行。可使用 Node.js 透過 npx 執行 npm 套件,或安裝 PyPI 套件並在 MCP 用戶端設定 Python 解譯器路徑。未宣告需要帳號、API 金鑰或環境變數。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Ohm Mcp,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
OHM-MCP
AI-Powered Python Refactoring & Code Quality Assistant
Works with GitHub Copilot, Cursor IDE, Cline, and any MCP-compatible AI assistant.
✨ Core Capabilities
🚀 Quick Start
Installation
📦 Recommended: NPM Method (Auto-installs dependencies)
No installation required! Use NPX to run the latest version automatically:
This is the easiest way to get started. Just add the configuration to your AI assistant (see IDE Configuration below).
MCP Registry: mcp-name: io.github.Murugarajr/ohm-mcp
🐍 Alternative: PyPI Method (For local development)
Use this method when you need to:
- Develop locally with the Python package
- Use a specific Python virtual environment
- Install from source for customization
Install from PyPI:
Install from source (for development):
IDE Configuration
📦 Option 1: NPX (Recommended - Auto-installs dependencies)
🔵 GitHub Copilot (VS Code) with NPX
After publishing to npm:
For local development:
Usage:
- Open Copilot Chat
- Type
#and selectohm-mcptools - Ask: "Analyze this file and suggest refactorings"
🟣 Cursor IDE with NPX
Global (After publishing to npm):
For local development:
Usage:
- Open Cursor Chat (Cmd+L / Ctrl+L)
- Tools are automatically available
- Ask: "Use ohm-mcp to detect dead code"
🟢 Cline (VS Code Extension) with NPX
Global (After publishing to npm):
For local development:
Usage:
- Open Cline panel
- Tools are available in agent context
- Ask: "Analyze type coverage and suggest improvements"
🟠 Antigravity with NPX
Global (After publishing to npm):
Usage:
- Tools are automatically available in Antigravity
- Ask: "Use ohm-mcp to analyze architecture"
🔴 Roo Code with NPX
Global (After publishing to npm):
Usage:
- Open Roo Code panel
- Tools are available in agent context
- Ask: "Use ohm-mcp to detect duplicates"
⚫ Codex VS Code with NPX
Configuration (config.toml):
Usage:
- Open Codex panel
- Tools are automatically available
- Ask: "Use ohm-mcp to suggest design patterns"
🟡 Kilo Code with NPX (Local/Global)
Local (For local development with virtual environment):
Global (After publishing to npm):
Usage:
- Open Kilo Code panel
- Tools are available in agent context
- Ask: "Use ohm-mcp for refactoring"
🐍 Option 2: Direct Python (Manual setup)
🔵 GitHub Copilot (VS Code) with Python
First install: pip install ohm-mcp
Then add to .vscode/mcp.json:
Usage:
- Open Copilot Chat
- Type
#and selectohm-mcptools - Ask: "Analyze this file and suggest refactorings"
🟣 Cursor IDE with Python
First install: pip install ohm-mcp
Then add to Cursor's MCP settings file (.cursorrules or MCP config):
Example with virtual environment:
Usage:
- Open Cursor Chat (Cmd+L / Ctrl+L)
- Tools are automatically available
- Ask: "Use ohm-mcp to detect dead code"
🟢 Cline (VS Code Extension) with Python
First install: pip install ohm-mcp
Then add to Cline's MCP settings:
Example with virtual environment:
Note: Cline requires absolute paths for both command and cwd.
Usage:
- Open Cline panel
- Tools are available in agent context
- Ask: "Analyze type coverage and suggest improvements"
🔧 Other MCP-Compatible Clients
Any MCP-compatible client can use this server. General configuration:
Finding your Python path:
💡 Quick Usage Examples
Once configured, simply reference tools in your AI assistant chat using the format: use #ohm-mcp.tool_name on the current file or @file_name.py
🗑️ Find Dead Code
This will detect:
- ✅ Unused imports (import statements never referenced)
- ✅ Unused variables (assigned but never read)
- ✅ Unreachable code (after return/raise/break/continue)
- ✅ Unused functions (defined but never called)
- ✅ Shadowed variables (inner scope hides outer scope variable)
📋 Code Duplication Detection
Finds:
- ✅ Exact duplicates (100% identical code blocks)
- ✅ Near duplicates (90%+ similarity)
- ✅ Duplicate functions (same structure, different names)
- ✅ Provides refactoring suggestions to eliminate duplication
🏗️ Architecture Analysis
Detects:
- ✅ God Objects (classes doing too much)
- ✅ SOLID principle violations
- ✅ Circular dependencies
- ✅ High coupling issues
✂️ Extract Method Refactoring
Automatically:
- ✅ Detects required parameters
- ✅ Identifies return values
- ✅ Generates refactored code
- ✅ Creates unified diff patch
🔄 Safe Symbol Renaming
Features:
- ✅ AST-based (100% accurate)
- ✅ Detects naming conflicts
- ✅ Shows all occurrences before applying
- ✅ Updates docstrings and comments
📊 Type Coverage Analysis
Provides:
- ✅ Coverage percentage and grade
- ✅ Functions missing type hints
- ✅ Suggested type annotations
- ✅ Migration plan with priorities
⚡ Performance Optimization
Detects:
- ✅ Nested loops (O(n²) complexity)
- ✅ Quadratic list operations
- ✅ Repeated function calls (missing caching)
- ✅ Mutable default arguments
- ✅ Inefficient string concatenation
🧪 Auto-Generate Tests
Creates:
- ✅ Happy path test cases
- ✅ Edge cases (None, zero, negative, empty)
- ✅ Ready-to-run pytest code
- ✅ Preserves current behavior before refactoring
🎨 Design Pattern Suggestions
Recommends:
- ✅ Strategy pattern for long if/elif chains
- ✅ Factory pattern for repetitive object creation
- ✅ Observer pattern for callback hell
- ✅ Decorator pattern for cross-cutting concerns
🔧 Import Refactoring
Handles:
- ✅ Direct imports (
import old.module) - ✅ From imports (
from old.module import X) - ✅ Submodule imports
- ✅ Import aliases
🎯 Key Tools (30 Total)
📋 General Analysis & Planning (4 tools)
🏗️ Architecture & Design (4 tools)
🔧 Code Quality & Refactoring (10 tools)
Example - Extract Method:
📊 Type Safety & Testing (5 tools)
⚡ Performance & Prioritization (2 tools)
🤖 Automated Execution & History (4 tools)
Features:
- ✅ Automatic backup before changes
- ✅ Test execution validation
- ✅ Auto-rollback on failure
- ✅ Full audit trail with history
- ✅ Automatic backup cleanup
📈 Metrics & Reporting (1 tool)
generate_quality_report - Comprehensive dashboard in HTML/Markdown/JSON
Output Preview:
Visual Dashboard:
- 🎨 Circular health gauge
- 📊 Color-coded metrics (🟢🟡🔴)
- 📈 Trend tracking ready
- 🔗 CI/CD integration (JSON export)
💡 Common Workflows
1️⃣ Safe Refactoring
2️⃣ Eliminate Duplication
3️⃣ Type Migration
4️⃣ Performance Optimization
5️⃣ Module Refactoring
6️⃣ Symbol Renaming
7️⃣ Quality Tracking
🎨 Visual Examples
Quality Dashboard Preview
Symbol Rename Preview
🧠 Design Principles
🔌 IDE Compatibility
📊 Comparison
🎯 Use Cases
📈 Metrics
🛠️ Troubleshooting
MCP Connection Issues
-
Verify Python path:
-
Test MCP server directly:
-
Check logs:
- VS Code: Check Output panel
- Cursor: Check Cursor logs
- Cline: Check Cline settings panel
-
Common issues:
- ❌ Relative paths in
command→ Use absolute paths - ❌ Missing virtual environment → Activate venv first
- ❌ Wrong
cwdfor Cline → Must be absolute path
- ❌ Relative paths in
🤝 Contributing
Run before submitting:
🙏 Credits
Built with Model Context Protocol • Python AST • Compatible with GitHub Copilot, Cursor IDE, Cline
Made with ❤️ for better code quality
⭐ Star this repo if it helps you write cleaner code!
來源:README.md,提交 755d161
工具
0版本歷史
1- v1.0.1最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分