mcp-adr-analysis-server
Copilot instructions35 starsChanged 2 months agoMITView on GitHub
This is a Model Context Protocol (MCP) server that provides AI-powered architectural analysis and ADR (Architectural Decision Record) management. The server integrates with AI assistants (Claude, Cline, Cursor) via the MCP protocol and uses OpenRouter.ai for generating actual analysis results instead of prompts. Core Architecture: MCP server (src/index.ts) exposes 73 tools through @modelcontextprotocol/sdk that call into utilities for AI execution, caching, session/tool-usage tracking, and memory management. All tools in src/tools/ follow this structure:
- Reads credentials
In this repository2 other files it gives its agents.
The file
We split this copilot-instructions.md into the rules it gives an agent
9 rules. About 0 are common, 0 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 14
Use import.meta.url (never __dirname).
- Very specific: line 20
Strict mode enabled: All strict type checks are enforced (see tsconfig.json)
- Very specific: line 28
Run tests with: npm test or make test
- Very specific: line 73
All tools in src/tools/ follow this structure:
- Very specific: line 200
Import extensions: Always use .js in imports, even for .ts source files
- Very specific: line 201
Cache directory: Never commit .mcp-adr-cache or files in OS temp directories
- Very specific: line 203
Tree-sitter in Vitest: Use mocks from tests/__mocks__/, never import native modules directly
- Very specific: line 204
ESLint compliance: Run npm run lint before committing (includes type checking)
- Very specific: line 205
Pattern detection: When adding infrastructure patterns, update detectionHints for automatic recognition
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
MCP ADR Analysis Server - AI Coding Agent Instructions
Project Overview
This is a Model Context Protocol (MCP) server that provides AI-powered architectural analysis and ADR (Architectural Decision Record) management. The server integrates with AI assistants (Claude, Cline, Cursor) via the MCP protocol and uses OpenRouter.ai for generating actual analysis results instead of prompts.
Core Architecture: MCP server (src/index.ts) exposes 73 tools through @modelcontextprotocol/sdk that call into utilities for AI execution, caching, session/tool-usage tracking, and memory management.
Critical Technical Conventions
ESM-Only Module System
- Pure ESM (no CommonJS): All imports must use
.jsextensions even for TypeScript files - Use
import.meta.url(never__dirname). Helper:getCurrentDirCompat()fromsrc/utils/directory-compat.ts - Example:
import { foo } from './bar.js'(note.jsextension) package.jsondeclares"type": "module"and targets ES2022
TypeScript Configuration
- Strict mode enabled: All strict type checks are enforced (see
tsconfig.json) - Output directory:
dist/src/with source maps and declarations - Tree-sitter native modules are mocked in Vitest (
tests/__mocks__/)
Testing Requirements
- Coverage threshold: 85% (branches, functions, lines, statements)
- Vitest with native ESM and TypeScript support
- Run tests with:
npm testormake test - Tree-sitter modules must be mocked for Vitest environment
Development Workflows
Build & Run
npm run build # Clean + TypeScript compile to dist/
npm start # Run production server from dist/
npm run dev # Development server with tsx hot-reload
make ci # Full pipeline: security, lint, test, buildTesting Strategy
npm test # All tests with Vitest
npm run test:coverage # Generate coverage report
npm run test:unit # Unit tests via scripts/test-infrastructure.sh
npm run test:integration # Integration tests
npm run test:mcp-interactive # Test with MCP InspectorCode Quality
- Linting:
npm run lintruns ESLint + TypeScript type checking (tsc --noEmit) - Formatting: Prettier is integrated; use
npm run formatornpm run lint:fix - Pre-commit hooks enforce quality via Husky
AI Execution Architecture
Two-Mode Operation
- Full Mode (with
OPENROUTER_API_KEY): Returns actual AI-generated analysis results - Prompt Mode (fallback): Returns prompts for manual execution
Key Files:
src/utils/ai-executor.ts: OpenRouter.ai integration with caching and retry logicsrc/config/ai-config.ts: AI configuration management- Environment: Set
EXECUTION_MODE=fullandOPENROUTER_API_KEYfor AI results
Tool Response Pattern
All tools in src/tools/ follow this structure:
return {
content: [{ type: "text", text: "result" }],
isError?: boolean
};Memory & State Management
Session & Tool-Usage Tracker (src/utils/knowledge-graph-manager.ts)
- Persistent storage in project-local JSON snapshots:
$TMPDIR/{projectName}/cache/knowledge-graph-snapshots.json - Tracks intents, tool executions, ADR decisions, and relationships
- Provides
queryKnowledgeGraph()for keyword-scored retrieval over stored snapshots - Memory operations are recorded for analytics (limited to last 1000 entries)
State Reinforcement (src/utils/state-reinforcement-manager.ts)
- Context decay mitigation: Re-injects core context every 5 turns or when responses exceed 3000 tokens
- Integrates recent session tracker intents into context reminders
- Configuration:
turnInterval,tokenThreshold,includeKnowledgeGraphContext
Conversation Memory (src/utils/conversation-memory-manager.ts)
- Phase 3 context decay mitigation: Structured external memory for long conversations
- Stores conversation sessions, expandable content, and resumption context
- Auto-cleanup of sessions older than 24 hours
Deployment Pattern Framework
Validated Patterns (patterns/infrastructure/*.yaml)
Authoritative templates for infrastructure deployment that LLMs query for platform-specific guidance:
Available Patterns:
kubernetes.yaml- Container orchestrationfirebase.yaml- Production Firebase deploymentfirebase-emulators.yaml- Local Firebase testing (emulator-first workflow)aws.yaml,openshift.yaml- Cloud platforms
Pattern Structure:
authoritativeSources: URLs with priority (1-10) for LLMs to querydeploymentPhases: Ordered steps with commandsvalidationChecks: Critical checks with remediation stepsdetectionHints: Files/patterns for automatic pattern detection (e.g.,firebase.json→ Firebase)
Tool Integration: bootstrap-validation-loop-tool.ts auto-detects patterns based on project files with confidence scoring.
Key Tool Categories
Architectural Analysis
analyze_project_ecosystem: Comprehensive project analysis with technology detectionadr-suggestion-tool.ts: Generate ADR recommendationsdeployment-readiness-tool.ts: Zero-tolerance validation with hard blocking on failures
Memory & Planning
conversation-memory-tool.ts: Session management and context persistencememory-loading-tool.ts: Load historical conversation contextmcp-planning-tool.ts: Strategic planning and task breakdown
Research & Integration
research-question-tool.ts: Query session state and external sourcesllm-web-search-tool.ts: Firecrawl integration for web researchresearch-integration-tool.ts: Synthesize research into actionable insights
Deployment & Validation
bootstrap-validation-loop-tool.ts: Automated deployment with pattern detectiondeployment-readiness-tool.ts: Pre-deployment validation (see ADR 002)adr-bootstrap-validation-tool.ts: ADR-based deployment guidance
Orchestration
tool-chain-orchestrator.ts: AI-powered dynamic tool sequencing that generates execution plans for the calling LLM
Project-Specific Patterns
Two-Phase Test-Driven Development (ADR 003)
- Test Generation Phase: Define tests, stubs, and validation criteria
- Implementation Phase: Implement and validate against generated tests
- Zero-tolerance for test failures (deployment readiness check)
Content Security Masking
src/utils/output-masking.ts: Automatic detection and masking of sensitive content- Patterns defined in
src/types/masking-schemas.ts - Used in
content-masking-tool.tsfor security analysis
Cache Management
- Multi-level caching in OS temp directories (never commit
.mcp-adr-cache) - Knowledge graph snapshots:
$TMPDIR/{projectName}/cache/knowledge-graph-snapshots.json - Conversation memory:
$TMPDIR/{projectName}/conversation-memory/
File Structure Essentials
src/
├── index.ts # MCP server entry point (8466 lines - tool/resource/prompt handlers)
├── tools/ # 73 specialized MCP tools
├── utils/ # Core utilities (AI, caching, session tracking, logging)
├── types/ # TypeScript type definitions and schemas
├── config/ # Configuration management
├── prompts/ # Prompt templates for AI execution
└── resources/ # MCP resource handlers
patterns/ # Deployment pattern templates
├── infrastructure/ # Platform-specific YAML patterns
└── schema.json # Pattern validation schema
tests/ # 85%+ coverage requirement
├── __mocks__/ # Tree-sitter and native module mocks
└── *.test.ts # Unit and integration testsCommon Pitfalls to Avoid
- Never use CommonJS: No
require(),module.exports, or__dirname - Import extensions: Always use
.jsin imports, even for.tssource files - Cache directory: Never commit
.mcp-adr-cacheor files in OS temp directories - Test coverage: Maintain 85%+ threshold; pre-commit hooks will block otherwise
- Tree-sitter in Vitest: Use mocks from
tests/__mocks__/, never import native modules directly - ESLint compliance: Run
npm run lintbefore committing (includes type checking) - Pattern detection: When adding infrastructure patterns, update
detectionHintsfor automatic recognition
Integration Points
External Dependencies
- OpenRouter.ai: AI execution via
openaiSDK (configured insrc/config/ai-config.ts) - Firecrawl: Web scraping for research tools (
@mendable/firecrawl-js) - Tree-sitter: Code parsing (multiple language grammars - mocked in tests)
MCP Protocol
- SDK:
@modelcontextprotocol/sdkv1.19.1+ - Transport: StdioServerTransport for JSON-RPC communication
- Schemas:
CallToolRequestSchema,ListToolsRequestSchema,ListResourcesRequestSchema, etc.
Environment Configuration
Required for full functionality:
OPENROUTER_API_KEY: Enable AI execution (get from openrouter.ai/keys)EXECUTION_MODE=full: Return AI results instead of promptsPROJECT_PATH: Target project directory for analysisAI_MODEL: Optional (default:anthropic/claude-3-sonnet)
Optional:
FIRECRAWL_API_KEY: Enable web research toolsLOG_LEVEL: Adjust logging verbosity
Agentic Workflows (gh-aw)
This project uses GitHub Agentic Workflows (Markdown-based workflows with AI coding agents powered by Copilot) for intelligent CI/CD automation alongside traditional YAML workflows.
Foundation
copilot-setup-steps.yml— Required setup (checkout, Node 20, npm ci, build) that runs before any agentic workflow
New Agentic Workflows
| Workflow | File | Trigger | Purpose |
| CI Doctor | ci-doctor.md | workflow_run (on failure) | Deep CI failure diagnosis with MCP-specific pattern recognition |
| Docs Noob Tester | docs-noob-tester.md | Monthly + manual | Simulates new developer navigating docs and API docs site, finds gaps |
| Dependabot Bundler | dependabot-bundler.md | Weekly + manual | Groups Dependabot PRs into logical bundles with merge strategies |
| AI Release Notes | ai-release-notes-agent.md | Tag push (v*) + manual | Generates categorized release notes from commits and PRs |
| MCP Tool Checker | mcp-tool-checker.md | Weekly (Wed) + manual | Audits all 73 tools for consistency, ESM compliance, registration |
| Docs Site Validator | docs-site-validator.md | Post-deploy + weekly + manual | Validates live GitHub Pages site: links, assets, search, sitemap, mobile, a11y |
Migrated Validation Agents
These replaced the former .github/agents/ YAML files with AI-enhanced gh-aw equivalents:
| Workflow | File | Validates |
| MCP Server Validation | mcp-server-validation.md | Server init, tool registration, protocol compliance |
| AI Executor Integration | ai-executor-integration.md | Prompt mode, full mode, AI configuration |
| Knowledge Graph Validation | knowledge-graph-validation.md | KG manager, state reinforcement, conversation memory |
| Deployment Pattern Validation | deployment-pattern-validation.md | Pattern schemas, detection, bootstrap tool |
| ESM Module Validation | esm-module-validation.md | .js extensions, no CommonJS, compiled output |
| Tool Chain Orchestrator | tool-chain-orchestrator-validation.md | Tool registry, workflow analysis, dependency resolution |
Traditional YAML Workflows (Unchanged)
These remain as standard GitHub Actions: lint.yml, test.yml, build.yml, publish.yml, deploy-docusaurus.yml, codeql-analysis.yml, security-scanning.yml, validate-patterns.yml, dependencies.yml, release-drafter.yml, auto-release-on-merge.yml
auto-release-on-merge.yml is the sole owner of releases for every merge to main, Dependabot included. (dependabot-auto-release.yml was retired — it never fired, and it tagged the pre-bump commit.)
Documentation References
- Main README:
README.md- Installation, quick start, use cases - CLAUDE.md: Detailed architecture, tools, patterns framework
- LLM_CONTEXT.md: Auto-generated context reference (45 DocuMCP tools)
- docs/diataxis-index.md: Full documentation structure
- Makefile: Build system targets and CI pipeline
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

