Skip to main content
Glama

Code AST MCP 서버 (code-ast-mcp)

Model Context Protocol Python 3.10+ Glama MCP License: MIT

**code-ast-mcp**는 Python의 네이티브 추상 구문 트리(ast) 파서로 구축된 아키텍처 기반 Model Context Protocol (MCP) 서버입니다. AI 모델(Claude Desktop, Cursor, Antigravity 또는 사용자 지정 MCP 클라이언트)이 전체 원시 소스 파일을 LLM 컨텍스트 창에 로드하지 않고도 Python 코드베이스 구조를 분석하고, 심볼 정의를 검색하고, 의존성 그래프를 구축하고, docstring 적용 범위를 감사하고, 코드를 리팩터링할 수 있게 해줍니다.

🔗 라이브 저장소: 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)

    • LLM이 파일의 AST 개요를 검토하고 리팩터링, 디자인 패턴 개선 및 문서 수정을 제안하도록 지시하는 구조화된 프롬프트를 생성합니다.

📊 리소스

  • 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. "Add Server" 를 클릭합니다.

  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