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 分