agentleFS
tosin2013tosin2013/mcp-adr-analysis-server/.github/copilot-instructions.md

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

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
  1. Very specific:

    Use import.meta.url (never __dirname).

    line 14
  2. Very specific:

    Strict mode enabled: All strict type checks are enforced (see tsconfig.json)

    line 20
  3. Very specific:

    Run tests with: npm test or make test

    line 28
  4. Very specific:

    All tools in src/tools/ follow this structure:

    line 73
  5. Very specific:

    Import extensions: Always use .js in imports, even for .ts source files

    line 200
  6. Very specific:

    Cache directory: Never commit .mcp-adr-cache or files in OS temp directories

    line 201
  7. Very specific:

    Tree-sitter in Vitest: Use mocks from tests/__mocks__/, never import native modules directly

    line 203
  8. Very specific:

    ESLint compliance: Run npm run lint before committing (includes type checking)

    line 204
  9. Very specific:

    Pattern detection: When adding infrastructure patterns, update detectionHints for automatic recognition

    line 205

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
copilot-instructions.md

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 .js extensions even for TypeScript files
  • Use import.meta.url (never __dirname). Helper: getCurrentDirCompat() from src/utils/directory-compat.ts
  • Example: import { foo } from './bar.js' (note .js extension)
  • package.json declares "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 test or make 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, build

Testing 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 Inspector

Code Quality

  • Linting: npm run lint runs ESLint + TypeScript type checking (tsc --noEmit)
  • Formatting: Prettier is integrated; use npm run format or npm run lint:fix
  • Pre-commit hooks enforce quality via Husky

AI Execution Architecture

Two-Mode Operation

  1. Full Mode (with OPENROUTER_API_KEY): Returns actual AI-generated analysis results
  2. Prompt Mode (fallback): Returns prompts for manual execution

Key Files:

  • src/utils/ai-executor.ts: OpenRouter.ai integration with caching and retry logic
  • src/config/ai-config.ts: AI configuration management
  • Environment: Set EXECUTION_MODE=full and OPENROUTER_API_KEY for 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 orchestration
  • firebase.yaml - Production Firebase deployment
  • firebase-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 query
  • deploymentPhases: Ordered steps with commands
  • validationChecks: Critical checks with remediation steps
  • detectionHints: 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 detection
  • adr-suggestion-tool.ts: Generate ADR recommendations
  • deployment-readiness-tool.ts: Zero-tolerance validation with hard blocking on failures

Memory & Planning

  • conversation-memory-tool.ts: Session management and context persistence
  • memory-loading-tool.ts: Load historical conversation context
  • mcp-planning-tool.ts: Strategic planning and task breakdown

Research & Integration

  • research-question-tool.ts: Query session state and external sources
  • llm-web-search-tool.ts: Firecrawl integration for web research
  • research-integration-tool.ts: Synthesize research into actionable insights

Deployment & Validation

  • bootstrap-validation-loop-tool.ts: Automated deployment with pattern detection
  • deployment-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)

  1. Test Generation Phase: Define tests, stubs, and validation criteria
  2. 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.ts for 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 tests

Common Pitfalls to Avoid

  1. Never use CommonJS: No require(), module.exports, or __dirname
  2. Import extensions: Always use .js in imports, even for .ts source files
  3. Cache directory: Never commit .mcp-adr-cache or files in OS temp directories
  4. Test coverage: Maintain 85%+ threshold; pre-commit hooks will block otherwise
  5. Tree-sitter in Vitest: Use mocks from tests/__mocks__/, never import native modules directly
  6. ESLint compliance: Run npm run lint before committing (includes type checking)
  7. Pattern detection: When adding infrastructure patterns, update detectionHints for automatic recognition

Integration Points

External Dependencies

  • OpenRouter.ai: AI execution via openai SDK (configured in src/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/sdk v1.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 prompts
  • PROJECT_PATH: Target project directory for analysis
  • AI_MODEL: Optional (default: anthropic/claude-3-sonnet)

Optional:

  • FIRECRAWL_API_KEY: Enable web research tools
  • LOG_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

WorkflowFileTriggerPurpose
CI Doctorci-doctor.mdworkflow_run (on failure)Deep CI failure diagnosis with MCP-specific pattern recognition
Docs Noob Testerdocs-noob-tester.mdMonthly + manualSimulates new developer navigating docs and API docs site, finds gaps
Dependabot Bundlerdependabot-bundler.mdWeekly + manualGroups Dependabot PRs into logical bundles with merge strategies
AI Release Notesai-release-notes-agent.mdTag push (v*) + manualGenerates categorized release notes from commits and PRs
MCP Tool Checkermcp-tool-checker.mdWeekly (Wed) + manualAudits all 73 tools for consistency, ESM compliance, registration
Docs Site Validatordocs-site-validator.mdPost-deploy + weekly + manualValidates 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:

WorkflowFileValidates
MCP Server Validationmcp-server-validation.mdServer init, tool registration, protocol compliance
AI Executor Integrationai-executor-integration.mdPrompt mode, full mode, AI configuration
Knowledge Graph Validationknowledge-graph-validation.mdKG manager, state reinforcement, conversation memory
Deployment Pattern Validationdeployment-pattern-validation.mdPattern schemas, detection, bootstrap tool
ESM Module Validationesm-module-validation.md.js extensions, no CommonJS, compiled output
Tool Chain Orchestratortool-chain-orchestrator-validation.mdTool 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

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.