Skip to content

Commit 43fbd17

Browse files
czlonkowskiclaude
andauthored
docs: rewrite CLAUDE.md and add AGENTS.md contributor guide (#928)
* docs: rewrite CLAUDE.md to match current codebase Architecture section replaced with a directory-level map covering all current subsystems (telemetry, community, triggers, n8n wrapper, tool-docs, skills). Commands verified against package.json: removed broken test:templates and stale migrate:fts5, added build:all, test:e2e, fetch:community, generate:docs:incremental with pointers to the MEMORY_N8N_UPDATE.md and MEMORY_TEMPLATE_UPDATE.md runbooks. Replaced retired get_node_essentials/get_node_info guidance with get_node detail levels. Removed the duplicated instruction block and version annotations, fixed the attribution spelling. 208 lines down to 100. Conceived by Romuald Członkowski - www.aiadvisors.pl/en Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * docs: add repository contributor guide Conceived by Romuald Członkowski - www.aiadvisors.pl/en * docs: address Copilot review feedback Mark the src/ map as non-exhaustive and add the scripts/ subsystem, scope the attribution rule to exclude file contents unambiguously, and mention src/scripts/ in the AGENTS.md project structure. Conceived by Romuald Członkowski - www.aiadvisors.pl/en Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 951a121 commit 43fbd17

2 files changed

Lines changed: 100 additions & 177 deletions

File tree

AGENTS.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Repository Guidelines
2+
3+
## Project Structure & Module Organization
4+
5+
Core TypeScript lives in `src/`: MCP tools in `src/mcp/`, business logic in `src/services/`, persistence in `src/database/`, and shared code in `src/types/` and `src/utils/`. Tests mirror these areas in `tests/unit/` and `tests/integration/`; supporting fixtures and mocks stay under `tests/`. React/Vite apps live in `ui-apps/src/`, repo utilities in `scripts/`, TypeScript maintenance scripts in `src/scripts/` (compiled to `dist/scripts/` at build time), documentation in `docs/`, and generated skills/databases in `data/`. Treat `dist/`, coverage output, and `ui-apps/dist/` as generated.
6+
7+
## Build, Test, and Development Commands
8+
9+
- `npm install` installs root dependencies; repeat in `ui-apps/` for UI work.
10+
- `npm run build` compiles production TypeScript to `dist/`.
11+
- `npm run build:all` synchronizes skills, builds UI apps, and compiles the server.
12+
- `npm run typecheck` (also `npm run lint`) performs strict checks without emitting.
13+
- `npm run dev:http` rebuilds and restarts the HTTP server as sources change.
14+
- `npm run rebuild` regenerates the node database; expect this to take several minutes.
15+
- `npm run validate` checks generated node data after a build/rebuild.
16+
17+
## Coding Style & Naming Conventions
18+
19+
Use strict TypeScript, two-space indentation, single quotes, and semicolons. Prefer `camelCase` for variables/functions, `PascalCase` for classes/types, and kebab-case filenames such as `workflow-auto-fixer.ts`. Use configured `@/` and `@tests/` aliases where helpful. Keep modules focused, validate external input, and do not edit generated outputs. No separate formatter is configured; `npm run typecheck` is the required static check.
20+
21+
## Testing Guidelines
22+
23+
Vitest is the primary framework; MSW handles API mocking. Name tests `*.test.ts` and place them in the matching test subtree. Run `npm run test:unit` for fast checks, `npm run test:integration` for system behavior, and `npm run test:coverage` before substantial PRs. Thresholds are 75% for lines, functions, and statements and 70% for branches. Live n8n tests need configuration and clean database state; do not mask flakes with retries.
24+
25+
## Commit & Pull Request Guidelines
26+
27+
Recent history follows Conventional Commit prefixes such as `feat:`, `fix:`, `docs:`, `chore:`, and scoped forms like `ci(deps):`. Use a feature branch; never commit directly to `main`. PRs should explain intent and verification, link relevant issues, and include screenshots for UI changes. Enable “Allow edits by maintainers.” Follow the commit/PR attribution requirement in `CLAUDE.md`, but never add that attribution to product file contents.
28+
29+
## Security & Configuration
30+
31+
This is a public repository: never commit credentials, API keys, private URLs, or customer data. Start from `.env.example`, keep local secrets untracked, and validate workflows before deploying them to n8n.

CLAUDE.md

Lines changed: 69 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -6,204 +6,96 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
66
77
## Project Overview
88

9-
n8n-mcp is a comprehensive documentation and knowledge server that provides AI assistants with complete access to n8n node information through the Model Context Protocol (MCP). It serves as a bridge between n8n's workflow automation platform and AI models, enabling them to understand and work with n8n nodes effectively.
10-
11-
### Current Architecture:
12-
```
13-
src/
14-
├── loaders/
15-
│ └── node-loader.ts # NPM package loader for both packages
16-
├── parsers/
17-
│ ├── node-parser.ts # Enhanced parser with version support
18-
│ └── property-extractor.ts # Dedicated property/operation extraction
19-
├── mappers/
20-
│ └── docs-mapper.ts # Documentation mapping with fixes
21-
├── database/
22-
│ ├── schema.sql # SQLite schema
23-
│ ├── node-repository.ts # Data access layer
24-
│ └── database-adapter.ts # Universal database adapter (NEW in v2.3)
25-
├── services/
26-
│ ├── property-filter.ts # Filters properties to essentials (NEW in v2.4)
27-
│ ├── example-generator.ts # Generates working examples (NEW in v2.4)
28-
│ ├── task-templates.ts # Pre-configured node settings (NEW in v2.4)
29-
│ ├── config-validator.ts # Configuration validation (NEW in v2.4)
30-
│ ├── enhanced-config-validator.ts # Operation-aware validation (NEW in v2.4.2)
31-
│ ├── node-specific-validators.ts # Node-specific validation logic (NEW in v2.4.2)
32-
│ ├── property-dependencies.ts # Dependency analysis (NEW in v2.4)
33-
│ ├── type-structure-service.ts # Type structure validation (NEW in v2.22.21)
34-
│ ├── expression-validator.ts # n8n expression syntax validation (NEW in v2.5.0)
35-
│ └── workflow-validator.ts # Complete workflow validation (NEW in v2.5.0)
36-
├── types/
37-
│ ├── type-structures.ts # Type structure definitions (NEW in v2.22.21)
38-
│ ├── instance-context.ts # Multi-tenant instance configuration
39-
│ └── session-state.ts # Session persistence types (NEW in v2.24.1)
40-
├── constants/
41-
│ └── type-structures.ts # 22 complete type structures (NEW in v2.22.21)
42-
├── templates/
43-
│ ├── template-fetcher.ts # Fetches templates from n8n.io API (NEW in v2.4.1)
44-
│ ├── template-repository.ts # Template database operations (NEW in v2.4.1)
45-
│ └── template-service.ts # Template business logic (NEW in v2.4.1)
46-
├── scripts/
47-
│ ├── rebuild.ts # Database rebuild with validation
48-
│ ├── validate.ts # Node validation (includes critical-node checks)
49-
│ ├── test-essentials.ts # Test new essentials tools (NEW in v2.4)
50-
│ ├── test-enhanced-validation.ts # Test enhanced validation (NEW in v2.4.2)
51-
│ ├── test-structure-validation.ts # Test type structure validation (NEW in v2.22.21)
52-
│ ├── test-workflow-validation.ts # Test workflow validation (NEW in v2.5.0)
53-
│ ├── test-ai-workflow-validation.ts # Test AI workflow validation (NEW in v2.5.1)
54-
│ ├── test-mcp-tools.ts # Test MCP tool enhancements (NEW in v2.5.1)
55-
│ ├── test-n8n-validate-workflow.ts # Test n8n_validate_workflow tool (NEW in v2.6.3)
56-
│ ├── test-typeversion-validation.ts # Test typeVersion validation (NEW in v2.6.1)
57-
│ ├── test-workflow-diff.ts # Test workflow diff engine (NEW in v2.7.0)
58-
│ ├── test-tools-documentation.ts # Test tools documentation (NEW in v2.7.3)
59-
│ ├── fetch-templates.ts # Fetch workflow templates from n8n.io (NEW in v2.4.1)
60-
│ └── test-templates.ts # Test template functionality (NEW in v2.4.1)
61-
├── mcp/
62-
│ ├── server.ts # MCP server with enhanced tools
63-
│ ├── tools.ts # Tool definitions including new essentials
64-
│ ├── tools-documentation.ts # Tool documentation system (NEW in v2.7.3)
65-
│ └── index.ts # Main entry point with mode selection
66-
├── utils/
67-
│ ├── console-manager.ts # Console output isolation (NEW in v2.3.1)
68-
│ └── logger.ts # Logging utility with HTTP awareness
69-
├── http-server-single-session.ts # Single-session HTTP server (NEW in v2.3.1)
70-
│ # Session persistence API (NEW in v2.24.1)
71-
├── mcp-engine.ts # Clean API for service integration (NEW in v2.3.1)
72-
│ # Session persistence wrappers (NEW in v2.24.1)
73-
└── index.ts # Library exports
74-
```
9+
n8n-mcp is an MCP (Model Context Protocol) server that gives AI assistants access to n8n node documentation, workflow validation, and workflow management. Documentation and validation tools work offline against a bundled SQLite database of node information; management tools (`n8n_*`) operate on a live n8n instance when API credentials are configured.
7510

7611
## Common Development Commands
7712

7813
```bash
79-
# Build and Setup
80-
npm run build # Build TypeScript (always run after changes)
14+
# Build
15+
npm run build # Compile TypeScript (always run after changes)
16+
npm run build:all # Sync skills pack + build UI apps + compile
8117
npm run rebuild # Rebuild node database from n8n packages
82-
npm run validate # Validate all node data in database
18+
npm run validate # Validate node data in database
19+
npm run dev # build + rebuild + validate
8320

8421
# Testing
85-
npm test # Run all tests
86-
npm run test:unit # Run unit tests only
87-
npm run test:integration # Run integration tests
88-
npm run test:coverage # Run tests with coverage report
89-
npm run test:watch # Run tests in watch mode
90-
npm run test:structure-validation # Test type structure validation (Phase 3)
91-
92-
# Run a single test file
93-
npm test -- tests/unit/services/property-filter.test.ts
94-
95-
# Linting and Type Checking
96-
npm run lint # Check TypeScript types (alias for typecheck)
97-
npm run typecheck # Check TypeScript types
98-
99-
# Running the Server
100-
npm start # Start MCP server in stdio mode
101-
npm run start:http # Start MCP server in HTTP mode
102-
npm run dev # Build, rebuild database, and validate
103-
npm run dev:http # Run HTTP server with auto-reload
104-
105-
# Update n8n Dependencies
106-
npm run update:n8n:check # Check for n8n updates (dry run)
107-
npm run update:n8n # Update n8n packages to latest
108-
109-
# Database Management
110-
npm run db:rebuild # Rebuild database from scratch
111-
npm run migrate:fts5 # Migrate to FTS5 search (if needed)
112-
113-
# Template Management
114-
npm run fetch:templates # Fetch latest workflow templates from n8n.io
115-
npm run test:templates # Test template functionality
22+
npm test # Run all tests (vitest)
23+
npm run test:unit # Unit tests only
24+
npm run test:integration # Integration tests
25+
npm run test:e2e # End-to-end tests
26+
npm run test:coverage # Coverage report
27+
npm test -- tests/unit/services/property-filter.test.ts # Single file
28+
29+
# Type checking
30+
npm run typecheck # tsc --noEmit (npm run lint is an alias)
31+
32+
# Running the server
33+
npm start # MCP server in stdio mode
34+
npm run start:http # MCP server in HTTP mode
35+
npm run dev:http # HTTP server with auto-reload
36+
37+
# n8n dependency updates — follow MEMORY_N8N_UPDATE.md
38+
npm run update:n8n:check # Dry run
39+
npm run update:n8n # Update n8n packages
40+
41+
# Templates and community nodes
42+
npm run fetch:templates # Fetch workflow templates from n8n.io — see MEMORY_TEMPLATE_UPDATE.md
43+
npm run fetch:community # Fetch/refresh community nodes (upserts; preserves existing docs)
44+
npm run generate:docs:incremental # Generate AI docs for community nodes missing them
11645
```
11746

118-
## High-Level Architecture
47+
## Architecture
11948

120-
### Core Components
49+
Key subsystems of `src/` (non-exhaustive — smaller directories are omitted). This file intentionally stays at subsystem level; for file-level detail, explore the directories.
12150

122-
1. **MCP Server** (`mcp/server.ts`)
123-
- Implements Model Context Protocol for AI assistants
124-
- Provides tools for searching, validating, and managing n8n nodes
125-
- Supports both stdio (Claude Desktop) and HTTP modes
51+
- `mcp/` — MCP server, tool definitions (`tools.ts`, `tools-n8n-manager.ts`), request handlers, per-tool documentation (`tool-docs/`), bundled skills (`skills/`)
52+
- `database/` — SQLite storage: universal adapter over better-sqlite3/sql.js, `node-repository.ts` data access, FTS5 full-text search, `migrations/`
53+
- `loaders/`, `parsers/`, `mappers/` — node processing pipeline: load nodes from n8n packages → parse metadata and properties → map external documentation
54+
- `services/` — business logic: config/workflow/expression validators, validation profiles, workflow diff engine, auto-fixer, node similarity and version services, n8n API client, security/audit scanners
55+
- `templates/` — fetching and storing workflow templates from n8n.io
56+
- `community/` — community node fetching and documentation generation
57+
- `telemetry/` — opt-in anonymous usage telemetry
58+
- `triggers/` — trigger detection and registry
59+
- `n8n/` — n8n community node wrapper (N8N_MODE)
60+
- `scripts/` — maintenance CLI scripts (rebuild, validate, template/community fetching), compiled to `dist/scripts/`
61+
- `types/`, `constants/`, `utils/` — shared types, type structures, helpers
62+
- `http-server.ts`, `http-server-single-session.ts` — HTTP mode with session persistence
63+
- `mcp-engine.ts`, `mcp-tools-engine.ts` — clean API for embedding the server in other services
12664

127-
2. **Database Layer** (`database/`)
128-
- SQLite database storing all n8n node information
129-
- Universal adapter pattern supporting both better-sqlite3 and sql.js
130-
- Full-text search capabilities with FTS5
65+
### Key design patterns
13166

132-
3. **Node Processing Pipeline**
133-
- **Loader** (`loaders/node-loader.ts`): Loads nodes from n8n packages
134-
- **Parser** (`parsers/node-parser.ts`): Extracts node metadata and structure
135-
- **Property Extractor** (`parsers/property-extractor.ts`): Deep property analysis
136-
- **Docs Mapper** (`mappers/docs-mapper.ts`): Maps external documentation
67+
1. **Repository pattern**: all database operations go through repository classes
68+
2. **Service layer**: business logic separated from data access
69+
3. **Validation profiles**: strictness levels `minimal`, `runtime`, `ai-friendly`, `strict`
70+
4. **Diff-based updates**: `n8n_update_partial_workflow` applies operation diffs, saving 80–90% of tokens vs full updates
13771

138-
4. **Service Layer** (`services/`)
139-
- **Property Filter**: Reduces node properties to AI-friendly essentials
140-
- **Config Validator**: Multi-profile validation system
141-
- **Type Structure Service**: Validates complex type structures (filter, resourceMapper, etc.)
142-
- **Expression Validator**: Validates n8n expression syntax
143-
- **Workflow Validator**: Complete workflow structure validation
72+
### MCP tools
14473

145-
5. **Template System** (`templates/`)
146-
- Fetches and stores workflow templates from n8n.io
147-
- Provides pre-built workflow examples
148-
- Supports template search and validation
74+
Two groups:
14975

150-
### Key Design Patterns
76+
- **Documentation and validation** (offline, always available): `search_nodes`, `get_node`, `validate_node`, `validate_workflow`, `search_templates`, `get_template`, `tools_documentation`
77+
- **Management** (`n8n_*`, require n8n API configuration): workflow CRUD and partial updates, executions, workflow testing, versions, autofix, template deployment, credentials, datatables, instance audit
15178

152-
1. **Repository Pattern**: All database operations go through repository classes
153-
2. **Service Layer**: Business logic separated from data access
154-
3. **Validation Profiles**: Different validation strictness levels (minimal, runtime, ai-friendly, strict)
155-
4. **Diff-Based Updates**: Efficient workflow updates using operation diffs
79+
`get_node` supports detail levels (`minimal`/`standard`/`full`) — request the smallest level that answers the question.
15680

157-
### MCP Tools Architecture
81+
## Development Workflow
15882

159-
The MCP server exposes tools in several categories:
83+
- After changing MCP server code: build, then ask the user to reload the MCP server before testing
84+
- Run `npm run typecheck` after every code change
85+
- Never commit directly to main — use feature branches and PRs
86+
- Add to every commit message and PR description: `Conceived by Romuald Członkowski - www.aiadvisors.pl/en`. The attribution belongs in commit messages and PR descriptions only — never in source, test, or documentation file contents
87+
- When reviewing issues, use the GH CLI (`gh`) to fetch the issue and all its comments
88+
- Do not use hyperbolic or dramatic language in comments and documentation
16089

161-
1. **Discovery Tools**: Finding and exploring nodes
162-
2. **Configuration Tools**: Getting node details and examples
163-
3. **Validation Tools**: Validating configurations before deployment
164-
4. **Workflow Tools**: Complete workflow validation
165-
5. **Management Tools**: Creating and updating workflows (requires API config)
90+
### Sub-agents
16691

167-
## Memories and Notes for Development
92+
- When a task divides into independent subtasks, spawn sub-agents to handle them in parallel; pick the best agent type per its description
93+
- Sub-agents must not spawn further sub-agents
94+
- Sub-agents must not commit or push — do that yourself
16895

169-
### Development Workflow Reminders
170-
- When you make changes to MCP server, you need to ask the user to reload it before you test
171-
- When the user asks to review issues, you should use GH CLI to get the issue and all the comments
172-
- When the task can be divided into separated subtasks, you should spawn separate sub-agents to handle them in parallel
173-
- Use the best sub-agent for the task as per their descriptions
96+
### Pitfalls
17497

175-
### Testing Best Practices
176-
- Always run `npm run build` before testing changes
177-
- Use `npm run dev` to rebuild database after package updates
178-
- Check coverage with `npm run test:coverage`
98+
- Database rebuilds take 2–3 minutes due to n8n package size
17999
- Integration tests require a clean database state
180-
181-
### Common Pitfalls
182-
- The MCP server needs to be reloaded in Claude Desktop after changes
183-
- HTTP mode requires proper CORS and auth token configuration
184-
- Database rebuilds can take 2-3 minutes due to n8n package size
185-
- Always validate workflows before deployment to n8n
186-
187-
### Performance Considerations
188-
- Use `get_node_essentials()` instead of `get_node_info()` for faster responses
189-
- Batch validation operations when possible
190-
- The diff-based update system saves 80-90% tokens on workflow updates
191-
192-
### Agent Interaction Guidelines
193-
- Sub-agents are not allowed to spawn further sub-agents
194-
- When you use sub-agents, do not allow them to commit and push. That should be done by you
195-
196-
### Development Best Practices
197-
- Run typecheck and lint after every code change
198-
199-
# important-instruction-reminders
200-
Do what has been asked; nothing more, nothing less.
201-
NEVER create files unless they're absolutely necessary for achieving your goal.
202-
ALWAYS prefer editing an existing file to creating a new one.
203-
NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested by the User.
204-
- When you make changes to MCP server, you need to ask the user to reload it before you test
205-
- When the user asks to review issues, you should use GH CLI to get the issue and all the comments
206-
- When the task can be divided into separated subtasks, you should spawn separate sub-agents to handle them in paralel
207-
- Use the best sub-agent for the task as per their descriptions
208-
- Do not use hyperbolic or dramatic language in comments and documentation
209-
- Add to every commit and PR: Concieved by Romuald Członkowski - and then link to www.aiadvisors.pl/en. Don't add it in conversations
100+
- HTTP mode requires proper auth token configuration
101+
- Always validate workflows before deploying them to n8n

0 commit comments

Comments
 (0)