ArchVanguard-MCP
Framework-agnostic architecture-rule enforcement for AI agents: analyzes Python codebases import graphs against declarative rulesets to report layer, forbidden-import, and cycle violations with file and line numbers. Supports MCP, OpenAI, Anthropic, LangChain, LlamaIndex, and CLI integrations.
README
<!-- GitHub topics: ai-agent llm-tools mcp langchain openai-function-calling pydantic architecture static-analysis import-linter dependency-graph code-quality -->
ArchVanguard-MCP
Framework-agnostic architecture-rule enforcement for AI agents: analyze a Python codebase's import graph against a declarative ruleset and report layer, forbidden-import, and cycle violations with file and line.
Abstract
Autonomous coding agents refactor, generate, and merge code faster than humans can review architecture. ArchVanguard-MCP gives an agent (or a CI job) one deterministic question: does this codebase obey its declared architecture? It parses a Python package's imports with the standard-library ast module — never executing the target code — builds the module dependency graph, and evaluates a declarative ruleset for layer-dependency violations, forbidden imports, and import cycles, returning each finding with a precise file and line. The core is a pure, framework-free Python library wrapped by thin optional adapters for OpenAI, Anthropic, LangChain, LlamaIndex, an MCP stdio server, and a CLI, so the same engine binds to any agent stack without conditionals.
Feature matrix
| Framework | Status | Extra | Entry point |
|---|---|---|---|
| Core library (sync + async) | ✅ | (none) | archvanguard_mcp.core.execute |
| OpenAI function-calling | ✅ | openai |
adapters.openai_tool.tool_spec / run_tool_call |
| Anthropic tool-use | ✅ | anthropic |
adapters.anthropic_tool.tool_spec / handle_tool_use |
| LangChain | ✅ | langchain |
adapters.langchain_tool.build_tool |
| LlamaIndex | ✅ | llamaindex |
adapters.llamaindex_tool.build_tool |
| MCP (stdio, JSON-RPC 2.0) | ✅ | (none; stdlib) | python -m archvanguard_mcp.adapters.mcp_server |
| CLI | ✅ | (none) | archvanguard |
Architecture
flowchart TD
A[AI Agent / CI / Human] -->|tool call| S[Generated Tool Schema]
S --> AD[Adapter layer<br/>openai · anthropic · langchain · llamaindex · mcp · cli]
AD -->|typed args| V[Validation & sanitization<br/>paths · limits · rules]
V -->|invalid| E[Structured error envelope<br/>stable code + details]
V -->|valid| C[Core engine<br/>ast parse → graph → rule eval]
C --> R[Response envelope<br/>violations + summary]
C -->|failure| E
E --> AD
R --> AD
AD --> A
The core (archvanguard_mcp.core) imports no AI framework. Framework code lives only in adapters, behind optional extras that fail with a clear, actionable error if not installed.
Quickstart
# 1. Install
pip install archvanguard-mcp
# 2. Write a ruleset (rules.json)
cat > rules.json <<'JSON'
{
"layers": [
{"name": "core", "patterns": ["myapp.core", "myapp.core.*"]},
{"name": "adapters", "patterns": ["myapp.adapters", "myapp.adapters.*"]}
],
"allowed_dependencies": [{"from_layer": "adapters", "to_layer": "core"}],
"forbidden_imports": [{"importer": "myapp.core.*", "forbidden": "langchain*"}],
"allow_cycles": false
}
JSON
# 3. Enforce (exit code 1 if any violation — use it as a merge gate)
archvanguard --root ./src/myapp --rules rules.json
Framework integration
OpenAI (native function-calling)
from openai import OpenAI
from archvanguard_mcp.adapters import openai_tool
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Check ./src/myapp against rules.json"}],
tools=[openai_tool.tool_spec()],
)
for call in response.choices[0].message.tool_calls or []:
tool_message = openai_tool.run_tool_call(call) # dispatches to the engine
# append tool_message to your messages and continue the loop
Anthropic (native tool-use)
import anthropic
from archvanguard_mcp.adapters import anthropic_tool
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-sonnet-4-5",
max_tokens=1024,
tools=[anthropic_tool.tool_spec()],
messages=[{"role": "user", "content": "Verify the layering of ./src/myapp"}],
)
for block in message.content:
if block.type == "tool_use":
tool_result = anthropic_tool.handle_tool_use(block) # -> tool_result block
LangChain
from archvanguard_mcp.adapters import langchain_tool
tool = langchain_tool.build_tool() # a StructuredTool with args_schema
# agent = create_react_agent(llm, [tool]) ; agent.invoke(...)
LlamaIndex
from archvanguard_mcp.adapters import llamaindex_tool
tool = llamaindex_tool.build_tool() # a FunctionTool
# agent = ReActAgent.from_tools([tool], llm=llm) ; agent.chat(...)
MCP server
Run python -m archvanguard_mcp.adapters.mcp_server, and register it in your MCP
client (claude_desktop_config.json or mcp.json):
{
"mcpServers": {
"archvanguard": {
"command": "python",
"args": ["-m", "archvanguard_mcp.adapters.mcp_server"]
}
}
}
API reference
Tool name: enforce_architecture. Full field tables are in
docs/SCHEMA.md; the machine schemas are generated into
schemas/.
| Input field | Type | Required | Notes |
|---|---|---|---|
root_path |
string | yes | Existing directory to scan. |
language |
"python" |
no | Only Python is supported. |
rules |
object | no | layers, allowed_dependencies, forbidden_imports, allow_cycles. |
include / exclude |
string[] | no | Module-name globs. |
strict_parse |
bool | no | Abort on first unparseable file. |
config |
object | no | Hard-bounded max_files, max_file_bytes, wall_clock_ms, max_dir_depth, parallel. |
The response contains status, correlation_id, violations[] (rule_type,
file, line, from_module, to_module, message), a summary, and an
error envelope when status == "error".
Error codes
| Code | Meaning | Retryable | Remediation |
|---|---|---|---|
VALIDATION_ERROR |
Arguments failed schema/semantic validation | no | Fix the request per details. |
PATH_NOT_FOUND |
root_path does not exist |
no | Provide an existing directory. |
PATH_NOT_ALLOWED |
Not a directory, or symlink/traversal escape | no | Point at a real directory inside the tree. |
LIMIT_EXCEEDED |
A hard cap (files, size, patterns, concurrency) was hit | no | Narrow scope or lower the workload. |
PARSE_ERROR |
A file failed to parse (only fatal with strict_parse) |
no | Fix the file or disable strict_parse. |
TIMEOUT |
Wall-clock budget exceeded | yes | Raise wall_clock_ms (≤30000) or narrow scope. |
DEPENDENCY_MISSING |
An adapter extra is not installed | no | pip install "archvanguard-mcp[<extra>]". |
INTERNAL_ERROR |
Unexpected fault (details redacted) | yes | Retry; report if persistent. |
Performance
Measured on 16 cores, Linux, Python 3.13 (see docs/BENCHMARKS.md;
reproduce with python scripts/benchmark.py):
| Modules | p50 | p95 |
|---|---|---|
| 250 | 18.5 ms | 19.6 ms |
| 1000 | 125 ms | 132 ms |
| 3000 | 374 ms | 390 ms |
| 4500 | 547 ms | 565 ms |
p95 stays under the 2000 ms budget across the full supported range (up to the 5000-file hard cap).
Security
The analyzer never executes target code, rejects path traversal and symlink
escape, enforces hard resource caps, and accepts only fnmatch globs (no raw
regex, so no ReDoS surface). See docs/THREAT_MODEL.md.
Report vulnerabilities privately per SECURITY.md — acknowledgement
within 3 business days.
Contributing
See CONTRIBUTING.md. Dev setup:
pip install -e ".[all,dev]" && pre-commit install
make all # lint + type + coverage(≥90%) + schema + security + build
Commits follow Conventional Commits. The core must stay framework-free (INV-1); schemas are generated, never hand-edited.
Roadmap
- [ ] Additional target languages (JavaScript/TypeScript, Go) behind the
languageenum. - [ ] Allowlist for statically resolvable dynamic imports.
- [ ] Optional per-rule severity and baseline/ratchet mode for legacy repos.
- [ ] SARIF output for code-scanning integration.
Citation
@software{fatih_archvanguard_mcp_2026,
author = {Farhang Fatih},
title = {ArchVanguard-MCP: Framework-agnostic architecture-rule enforcement for AI agents},
year = {2026},
version = {0.1.0},
license = {MIT},
url = {https://github.com/MrGuevara4/ArchVanguard-MCP}
}
License
MIT © Farhang Fatih. See LICENSE.
Author & Principal Architect: Farhang Fatih
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。