pyscn

io.github.ludo-technologies由 GitHub 帳號 ludo-technologies 發布v1.33.2更新於 Nov 8, 2026

Python code analysis for AI agents: complexity, dead code, clones, coupling, and a health score.

已驗證STDIO僅桌面開發者工具資料與分析

概覽

AI 產生的概覽

把 pyscn 的 Python 程式碼品質分析(複雜度、死程式碼、重複程式碼、耦合與健康評分)以 MCP 工具形式提供給編碼助理。

可以做什麼
  • 對整個程式碼庫執行健康分析,給出 0-100 分與 A-F 等級
  • 偵測死程式碼、重複程式碼(Type 1-4 複製)與複雜度熱點
  • 審查架構:循環匯入、分層規則違規與模組社群
  • 透過耦合與內聚指標檢查類別設計
  • 產生 JSON 或 HTML 報告,並執行 CI 式的通過/失敗檢查
適用情境
適合助理處理 Python 程式碼庫時檢查可維護性、找出重構目標,或依品質門檻把關變更。較適用於 AI 生成程式碼的審查與架構稽核,而非一次性腳本任務。
執行需求
以 stdio 在本機執行,通常用 uvx pyscn-mcp 啟動,需要 Python 工具鏈。選用環境變數 PYSCN_CONFIG 指向 .pyscn.toml 設定檔;否則會從被分析的目錄尋找 .pyscn.toml 或 pyproject.toml。Intel macOS 上需改用 Homebrew 或 Go 安裝,PyPI wheel 無法使用。
安裝前請注意
它會讀取並分析所指目錄中的原始碼,應限定在目標專案範圍內。報告可能寫入輸出目錄。未宣告任何驗證或憑證。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 pyscn,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

English | 日本語 | 简体中文 | Français


[pyscn]

Code quality analysis for Python in the age of AI coding.

Building with Cursor, Claude, or ChatGPT? pyscn keeps AI-generated code maintainable with structural analysis.

[Article] [PyPI] [Downloads] [Go] [License]

[Install Polyscan App for free]

Quick Start

bash
# Run analysis without installationuvx pyscn@latest analyze .# orpipx run pyscn analyze .

Demo

[pyscn analysis report]

Features

One command scores your whole codebase (0-100 with an A-F grade) and generates an HTML report that shows what to fix first.

pyscn looks at your code from five angles:

  • 🧹 Dead code - unreachable code you can safely delete
  • 📋 Duplicate code - copy-pasted and structurally similar code worth merging (Type 1-4 clone detection)
  • 🌀 Complexity - functions and executable class suites that are hard to read and test (cyclomatic and cognitive complexity)
  • 🔥 Module and directory hotspots - per-file quality and per-directory complexity rollups for prioritizing refactors
  • 🏗️ Architecture - circular imports, layer rule violations (clean / layered / hexagonal / MVC presets), and auto-detected module communities that reveal how your code is actually structured
  • 🧩 Class design - classes that do too much or depend on too much (CBO coupling, LCOM4 cohesion)

100,000+ lines/sec • Built with Go + tree-sitter

Other Languages

pyscn is the Python analyzer of polyscan. For JavaScript, TypeScript, Go, Rust and C++, run:

bash
npx polyscan analyze .

Same five angles, same 0-100 score, one HTML report.

Polyscan for GitHub

Polyscan App files a weekly audit report as a GitHub Issue. Free for public repositories.

[Install Polyscan App for free]

AI Agent Integration

pyscn ships Agent Skills that teach AI coding agents when and how to run each analysis: health checks, refactoring, architecture review, and CI-friendly reports.

Agent Skills (Recommended)

bash
uvx add-skills ludo-technologies/pyscn

This installs the Skills into your project. They work with Claude Code, Cursor, Codex, Gemini CLI, and many other agents (add --agent cursor etc. to target one, --global for all projects).

Then just ask your agent:

  1. "Analyze the code quality of the app/ directory"

  2. "Find duplicate code and help me refactor it"

  3. "Show me complex code and help me simplify it"

MCP Server (Optional)

For tighter integration, the bundled pyscn-mcp server exposes the same analyses as MCP tools to Claude Code, Cursor, ChatGPT, and other MCP clients.

Claude Code plugin (sets up the MCP server and the Skills together):

bash
claude plugin marketplace add ludo-technologies/pyscnclaude plugin install pyscn-mcp@pyscn-marketplace

Manual setup for Claude Code:

bash
claude mcp add pyscn-mcp uvx -- pyscn-mcp

Cursor / Claude Desktop: add to your MCP settings (~/.config/claude-desktop/config.json or Cursor settings):

json
{  "mcpServers": {    "pyscn-mcp": {      "command": "uvx",      "args": ["pyscn-mcp"],      "env": {        "PYSCN_CONFIG": "/path/to/.pyscn.toml"      }    }  }}

Dive deeper in mcp/README.md for setup walkthroughs and docs/MCP_INTEGRATION.md for architecture details.

Installation

bash
# Install with pipx (recommended)pipx install pyscn
# Or with uvuv tool install pyscn

macOS Intel (x86_64): PyPI wheels are built for Apple Silicon only (the Intel wheel was dropped in v1.5.1), so uvx, pipx, uv, and pip cannot install pyscn on Intel Macs. Use brew install pyscn or go install github.com/ludo-technologies/pyscn/cmd/pyscn@latest instead.

Alternative installation methods

Build from source

bash
git clone https://github.com/ludo-technologies/pyscn.gitcd pyscnmake build

Go install

bash
go install github.com/ludo-technologies/pyscn/cmd/pyscn@latest

Common Commands

pyscn analyze

Run comprehensive analysis with HTML report

bash
pyscn analyze .                              # All analyses with HTML reportpyscn analyze --json .                       # Generate JSON reportpyscn analyze --json --output - . | jq       # JSON report on stdoutpyscn analyze --json --html --no-open .      # JSON and HTML reports from one runpyscn analyze --select complexity .          # Only complexity analysispyscn analyze --select deps .                # Only dependency analysispyscn analyze --select complexity,deps,deadcode . # Multiple analysespyscn analyze --skip-communities .           # Skip module community detection

pyscn check

Fast CI-friendly quality gate

bash
pyscn check .                         # Quick pass/fail checkpyscn check --max-complexity 15 .     # Custom thresholdspyscn check --max-cycles 0 .          # Only allow 0 cycle dependencypyscn check --select deps .           # Check only for circular dependenciespyscn check --select di .             # Detect DI anti-patterns (opt-in)pyscn check --allow-circular-deps .   # Allow circular dependencies (warning only)

pyscn init

Create configuration file

bash
pyscn init                         # Generate .pyscn.toml

💡 Run pyscn --help or pyscn <command> --help for complete options

Configuration

Create a .pyscn.toml file or add [tool.pyscn] to your pyproject.toml:

toml
# .pyscn.toml[complexity]max_complexity = 15
[dead_code]min_severity = "warning"
[output]directory = "reports"

⚙️ Run pyscn init to generate a full configuration file with all available options


Documentation

📖 pyscn documentation site — installation, rule catalog, CLI reference, configuration, output specification

For contributors: Development Guide • Architecture • Testing

Enterprise Support

For commercial support, custom integrations, or consulting services, contact us at [email protected]

License

MIT License — see LICENSE


Built with ❤️ using Go and tree-sitter

來源:README.md,提交 155305b

工具

8

analyze_code

Comprehensive Python code quality analysis with complexity, dead code, clone detection, and coupling metrics

輸入參數path必填analysesrecursiveoutput_mode

check_cohesion

Analyze class cohesion (LCOM4 - Lack of Cohesion of Methods) metrics

輸入參數path必填max_resultsoutput_mode

check_complexity

Analyze cyclomatic complexity of Python execution scopes

輸入參數path必填max_resultsoutput_modeshow_detailsmax_complexitymin_complexity

check_coupling

Analyze class coupling (CBO - Coupling Between Objects) metrics

輸入參數path必填min_cbomax_resultsoutput_mode

detect_clones

Detect code clones using APTED tree edit distance and LSH acceleration

輸入參數path必填min_linesmax_resultsoutput_modegroup_clonessimilarity_threshold

detect_di_antipatterns

Detect Dependency Injection anti-patterns in Python code (constructor over-injection, hidden dependencies, concrete dependencies, service locator)

輸入參數path必填min_severityconstructor_param_threshold

find_dead_code

Find unreachable code using Control Flow Graph (CFG) analysis

輸入參數path必填max_resultsoutput_modemin_severity

get_health_score

Get overall code health score (0-100) with grade and category scores

輸入參數path必填

版本歷史

7
  1. v1.33.1Oct 29, 2026
  2. v1.33.0Oct 24, 2026
  3. v1.32.5Oct 16, 2026
  4. v1.32.3Oct 3, 2026
  5. v1.32.2Sep 30, 2026
  6. v1.32.1Sep 20, 2026
  7. v1.32.0Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分