Skip to main content

Structural analysis engine for AI coding agents

Project description

archai-mcp

PyPI Version Python Versions License Coverage

Structural analysis engine for AI coding agents. archai analyzes your repository's architecture and exposes it as MCP tools + CLI — no LLM needed, no API keys, zero configuration.

pip install archai-mcp
cd my-project
archai init
opencode .

The agent automatically uses archai's tools to understand your codebase before making changes.


Quick Start

# 1. Install
pip install archai-mcp

# 2. Configure in your project
cd /path/to/your/project
archai init
# → Creates .opencode/opencode.json with MCP config

# 3. Open in OpenCode
opencode .
# → The agent has archai tools available automatically

That's it. No API keys, no ARCHAI_LLM_MODEL, no .env file.


CLI Commands

archai offers 12 commands — one for every MCP tool plus utility commands:

Command Description
archai init Configure the project for OpenCode MCP integration
archai serve Start MCP server (stdio, for AI agents)
archai analyze Show full architecture: clusters, dependencies, functions
archai context <query> Get architecture context relevant to a query
archai file <path> Detailed analysis of a single file
archai state [--var] Shared global state map: writers + readers per variable
archai trace <feature> Trace a feature's call flow through the codebase
archai blast <path> Analyze the impact of changing a file
archai validate <patch> Structural analysis of proposed code changes
archai check Architecture design rule checks (cyclic deps, forbidden imports)
archai ci Run archai checks for CI/CD pipelines (with exit code)
archai mcp Alias for archai serve (deprecated)

All analysis commands support --json for machine-readable output.


MCP Tools

archai exposes 7 structural analysis tools for AI agents:

Tool CLI Description
get_architecture_context archai context Focus cluster, cluster edges, file dependencies, test files for a query
get_file_detail archai file Per-file analysis: functions, classes, imports, dependents
get_shared_state archai state Global variable map showing which functions write/read each variable
trace_feature_flow archai trace Entry point → call chain → shared state → risks
get_blast_radius archai blast Impact analysis: dependents, transitive dependencies, affected subsystems
validate_code_change archai validate Structural context about proposed changes (no "valid/invalid" judgment)
propose_change Given a change description, suggests affected files

How agents use it

User: "Add a login endpoint in the auth module"

Agent:
  1. get_architecture_context("auth", repo_path)
     ← focus cluster, all clusters, dependency edges, file deps
     → Agent's LLM infers: "auth depends on db, API depends on auth"

  2. get_file_detail("src/auth/handler.py")
     ← functions, classes, signatures in the auth module
     → Agent knows what already exists

  3. Writes code respecting inferred architecture

  4. get_blast_radius("src/auth/login.py", repo_path, depth=2)
     ← affected files and subsystems
     → Agent's LLM assesses: "safe change, expected impact"

  5. validate_code_change(repo_path, changes=[...])
     ← structural context about the patch
     → Agent can self-validate before submitting

archai returns raw structural data — the agent's own LLM interprets it. This means:

  • No duplicated LLM calls
  • Context-aware inference (the agent knows WHAT you're building)
  • Zero LLM configuration for archai

Configuration for OpenCode

Generated by archai init:

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "archai": {
      "type": "local",
      "command": ["archai", "serve"],
      "enabled": true
    }
  }
}

No environment passthrough. No API keys. archai needs nothing but your files.


How It Works

                    ┌─────────────────────┐
                    │   archai serve       │
                    │  (MCP Server, no LLM)│
                    └──────────┬──────────┘
                               │
         ┌─────────────────────┼─────────────────────┐
         ▼                     ▼                     ▼
   Bootstrap              Analysis              Resolution
   ┌─────────────┐    ┌──────────────┐    ┌────────────────┐
   │ File        │    │ Clustering   │    │ Focus matching │
   │ discovery   │    │ • directory  │    │ Subsystem rank │
   │ AST parsing │    │ • dependency │    │ Test file      │
   │ Dependency  │    │ • call graph │    │ detection      │
   │ graph       │    │              │    │                │
   │ Var access  │    │ Shared state │    │ Trace flow     │
   │ extraction  │    │ analysis     │    │ Blast radius   │
   └─────────────┘    └──────────────┘    └────────────────┘

archai is a pure structural analysis engine. It discovers files, parses them with tree-sitter, builds a dependency graph, clusters them into logical subsystems, and exposes everything as structured data. No LLM involved.

Key features

  • Multi-language — Python, C, C++ via tree-sitter
  • Intra-file clustering — function-level dependency resolution for C/C++
  • Variable access tracking — shows which functions read/write each global variable
  • Feature tracing — entry point → call chain → shared state → risk assessment
  • Blast radius — transitive dependency impact analysis with configurable depth
  • No LLM — pure static analysis, runs offline, instant results

Why archai?

Problem Solution
Agents don't understand your codebase structure archai provides clusters, dependencies, and focus resolution
Agents make changes without knowing the impact get_blast_radius shows affected files and subsystems
LLM context windows fill with irrelevant files archai finds the relevant subsystem (focus resolution)
Agents violate architecture constraints Structural data enables the agent to self-validate
Configuring LLMs for tools is friction archai needs no LLM config — the agent uses its own

Development

# Run tests
uv run pytest

# Run with coverage
uv run pytest --cov=src --cov-report=html

# Format code
uv run black src/
uv run ruff check src/

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

archai_mcp-0.4.5.tar.gz (49.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

archai_mcp-0.4.5-py3-none-any.whl (53.9 kB view details)

Uploaded Python 3

File details

Details for the file archai_mcp-0.4.5.tar.gz.

File metadata

  • Download URL: archai_mcp-0.4.5.tar.gz
  • Upload date:
  • Size: 49.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for archai_mcp-0.4.5.tar.gz
Algorithm Hash digest
SHA256 ab177924dc334574e55d5ecb30f3824e2bb15983868c7c9c9cdd1b58c4a6abdd
MD5 143458fa44fbbaf63a2c64aba87df008
BLAKE2b-256 5881a399a700bead959def4f28a995dc9f8ec6fed41be45d72aaf5941fbe876e

See more details on using hashes here.

File details

Details for the file archai_mcp-0.4.5-py3-none-any.whl.

File metadata

  • Download URL: archai_mcp-0.4.5-py3-none-any.whl
  • Upload date:
  • Size: 53.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for archai_mcp-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 5aea6726b479ddc071ffa117ca666449b719cd4d7b8a4ebbfd8db9d299246869
MD5 ccd318fea6e95159a63322956c2173bc
BLAKE2b-256 05198f73d507a7b06d1e32b46d9c241bb47b7c87626a66a17597e6bed9a77d7a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page