Skip to main content
Glama

Code AST MCP Server (code-ast-mcp)

Model Context Protocol Python 3.10+ Glama MCP License: MIT

code-ast-mcp は、Python のネイティブな Abstract Syntax Tree (ast) パーサーを使用して構築された、アーキテクチャ指向の Model Context Protocol (MCP) サーバーです。これにより、AI モデル(Claude Desktop、Cursor、Antigravity、またはカスタム MCP クライアント内)は、Python コードベースの構造を分析し、シンボル定義を検索し、依存関係グラフを構築し、docstring のカバレッジを監査し、コードをリファクタリングできます。その際、生のソースファイル全体を LLM コンテキストウィンドウに読み込む必要はありません。

🔗 ライブリポジトリ: https://github.com/m-sameerkhan/code-ast-mcp
🔗 Glama レジストリ: https://glama.ai/mcp/servers/m-sameerkhan/code-ast-mcp


⚡ 機能と能力

🛠️ ツール

  1. analyze_file_ast(file_path: str)

    • .py ファイルを解析して、クリーンな AST アウトラインに変換します。

    • モジュールの docstring、行数、インポート、トップレベルの関数、クラス、メソッド、変数を抽出します。

  2. find_class_methods(file_path: str, class_name: str)

    • 特定のクラスを特定し、メソッドシグネチャ、型注釈、行範囲、docstring を返します。

  3. find_symbol(target_dir: str, symbol_name: str)

    • ディレクトリを再帰的に検索し、symbol_name に一致するクラス、関数、メソッド、または変数代入を探します。

  4. get_imports_graph(target_dir: str)

    • Python ファイルをスキャンして依存関係のインポートマップを構築し、Mermaid ダイアグラム文字列を出力します。

  5. find_missing_docstrings(target_dir: str, include_private: bool = False)

    • コードベースの docstring を監査し、全体的な docstring カバレッジ率を計算します。

📝 プロンプト

  • refactor_code_summary(file_path: str)

    • ファイルの AST アウトラインをレビューし、リファクタリング、デザインパターンの改善、ドキュメント修正を提案するよう LLM に指示する構造化プロンプトを生成します。

📊 リソース

  • codeast://stats

    • ワークスペースの統計情報(スキャンされたファイル総数、docstring カバレッジ %、欠落アイテム数)を提供するライブ JSON リソース。


Related MCP server: codeweave-mcp

🚀 デプロイと使用モード

モード 1: Glama MCP レジストリ経由でデプロイ

code-ast-mcp を Glama MCP レジストリ にデプロイします。Glama は GitHub リポジトリを自動的にクローンし、同梱の Dockerfile を使用してビルドし、組み込みの OAuth 2.1、モニタリング、アクセス制御を備えてホストします。

手順:

  1. glama.ai/mcp/servers に移動します。

  2. 「サーバーを追加」 をクリックします。

  3. GitHub OAuth で認証します(リポジトリへの書き込みアクセスが必要です)。

  4. リポジトリ URL を送信します:

    https://github.com/m-sameerkhan/code-ast-mcp
  5. Glama は Dockerfile を使用して 自動ビルド し、MCP 準拠を検証します。

  6. ビルドが成功すると、サーバーは Glama レジストリ上で公開されます。

レジストリ URL:

https://glama.ai/mcp/servers/m-sameerkhan/code-ast-mcp

注: 手動ホスティングは不要です。Glama がビルド、デプロイ、検証を自動的に処理します。


モード 2: ローカル Stdio MCP サーバー(ローカルコードベース向け推奨)

Claude Desktop、Cursor、または Antigravity で、ローカルマシン上の Python プロジェクトを直接検査するのに最適です。

インストール:

git clone https://github.com/m-sameerkhan/code-ast-mcp.git
cd code-ast-mcp

# Virtual environment setup
python -m venv .venv
# Windows:
.venv\Scripts\activate
# Linux/macOS:
source .venv/bin/activate

pip install -r requirements.txt
pip install -e .

クライアント設定(claude_desktop_config.json / mcp_config.json):

{
  "mcpServers": {
    "code-ast-mcp": {
      "command": "python",
      "args": [
        "-m",
        "code_ast_mcp.server"
      ],
      "cwd": "/path/to/code-ast-mcp"
    }
  }
}

🧪 ローカルでのテスト

ユニットテストを実行

pytest

MCP Inspector でテスト

npx @modelcontextprotocol/inspector python -m code_ast_mcp.server

📦 プロジェクト構造

code-ast-mcp/
├── code_ast_mcp/          # Core MCP package
│   ├── __init__.py        # Package exports
│   ├── analyzer.py        # Python AST parsing & static analysis engine
│   └── server.py          # FastMCP server definition & tool handlers
├── tests/                 # Test suite
│   └── test_analyzer.py   # Unit tests with pytest
├── Dockerfile             # Container image definition (used by Glama)
├── pyproject.toml         # Packaging & metadata
└── requirements.txt       # Dependencies

📄 ライセンス

MIT ライセンス。作成者: m-sameerkhan。

Available Tools

5 tools
analyze_file_astB

Parse a Python file using Python's AST parser and return a detailed outline of its docstrings, imports, top-level classes, functions, variables, and line counts.

:param file_path: Path to the Python (.py) file to analyze.

Inputs: file_path (required). Returns: result

find_class_methodsA

Locate a specific class within a Python file and retrieve all its methods, argument signatures, type annotations, line numbers, and docstrings.

:param file_path: Path to the Python file containing the class. :param class_name: Name of the target class to inspect.

Inputs: file_path (required), class_name (required). Returns: result

find_missing_docstringsB

Audit Python files in a directory to identify modules, classes, and functions that lack docstrings, calculating overall docstring coverage percentage.

:param target_dir: Directory path to audit. :param include_private: Whether to include private functions/methods (starting with '_').

Inputs: target_dir (required), include_private. Returns: result

find_symbolA

Recursively search a directory or file for classes, functions, methods, or variables matching the target symbol name.

:param target_dir: Directory path or file path to search. :param symbol_name: Name or partial name of the symbol to search for.

Inputs: target_dir (required), symbol_name (required). Returns: result

get_imports_graphA

Scan all Python files in a directory to build an import dependency graph and output both a structured map and a Mermaid diagram definition.

:param target_dir: Path to the directory containing Python files.

Inputs: target_dir (required). Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.7/5.0

    Scored across 5 tools

    Disambiguation4/5

    Each tool has a distinct role: file outline, class methods, symbol search, import graph, and docstring audit. There is minor overlap because analyze_file_ast, find_class_methods, and find_symbol all inspect Python definitions, but their scopes differ enough to guide selection.

    Naming Consistency4/5

    All tool names use snake_case and mostly follow a verb_target pattern. Three use find_, while analyze_file_ast and get_imports_graph deviate slightly, but the naming remains predictable and readable.

    Tool Count5/5

    Five tools is a well-scoped size for an AST inspection server. Each tool serves a distinct static analysis workflow without redundancy or bloat.

    Completeness4/5

    The set covers file outlines, class methods, symbol lookup, import graphs, and docstring coverage, which handles most Python code-inspection needs. Minor gaps exist, such as a dedicated detail view for standalone functions or arbitrary AST node inspection, but they are not critical.

    Maintenance

    ActivityInactive
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      B
      quality
      D
      maintenance
      An MCP server that enables LLMs to understand and analyze code structure through function call graphs, allowing AI assistants to explore relationships between functions and analyze dependencies in Python repositories.
      6
      18
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      An MCP server that gives AI agents structured code understanding and precise code intelligence via local indexing of AST, call graphs, and semantic search.
      110 npm
      4
      Apache 2.0
    • -
      license
      Not graded
      quality
      Not graded
      maintenance
      An advanced MCP server that provides deep code understanding and analysis using GraphRAG, AST parsing, and semantic memory, enabling AI agents to query and interact with complex codebases.
      -
    • A
      license
      A
      quality
      D
      maintenance
      Universal MCP server that analyzes any codebase and provides structured context to AI assistants. Dynamic, accurate, and token-efficient.
      18
      MIT