From 1f12c4b690d0e320b5a1dbcf43ff0539c3bfed4b Mon Sep 17 00:00:00 2001 From: czlonkowski <56956555+czlonkowski@users.noreply.github.com> Date: Sun, 6 Jul 2025 22:40:58 +0200 Subject: [PATCH] feat: add npx support for zero-installation usage (closes #15) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add bin configuration to package.json for npx execution - Implement smart database path resolution for npx/global/local installs - Create dedicated npm publish script using runtime-only dependencies - Add .npmignore to control published package contents - Update README with npx as primary installation method - Add n8n version badge to README - Sync version between package.json and package.runtime.json - Update CHANGELOG for v2.7.8 release This allows users to run 'npx n8n-mcp' without installing the package, reducing friction and making it easier to get started with n8n-MCP. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .gitignore | 16 + .npmignore | 72 +++ CLAUDE.md | 671 +-------------------- README.md | 66 +- docs/CHANGELOG.md | 20 + package-lock.json | 4 +- package.json | 16 +- package.runtime.json | 2 +- scripts/publish-npm.sh | 94 +++ src/services/node-documentation-service.ts | 29 +- 10 files changed, 319 insertions(+), 671 deletions(-) create mode 100644 .npmignore create mode 100755 scripts/publish-npm.sh diff --git a/.gitignore b/.gitignore index 90e2ef0..9671648 100644 --- a/.gitignore +++ b/.gitignore @@ -90,3 +90,19 @@ rebuild-v20.sh # n8n-docs repo (cloned locally) ../n8n-docs/ n8n-docs/ + +# npm publish temporary directory +npm-publish-temp/ + +# Test files and logs +test-npx/ +mcp-server-*.log +server.log +server-fixed.log +mcp-debug.log + +# Temporary wrapper scripts +n8n-mcp-wrapper.sh + +# Package tarballs +*.tgz diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..6788bc2 --- /dev/null +++ b/.npmignore @@ -0,0 +1,72 @@ +# Source files (TypeScript) +src/ +*.ts +!dist/**/*.d.ts + +# Development files +.github/ +scripts/ +tests/ +docs/ +*.test.js +*.spec.js + +# Build files +tsconfig.json +jest.config.js +nodemon.json +renovate.json + +# Docker files (not needed for npm) +Dockerfile* +docker-compose*.yml +docker/ +.dockerignore + +# Environment and config files +.env +.env.* +!.env.example + +# IDE and OS files +.vscode/ +.idea/ +*.swp +.DS_Store + +# Logs and temp files +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +*.pid +*.seed +*.pid.lock + +# Coverage and test reports +coverage/ +.nyc_output/ + +# Git files +.git/ +.gitignore + +# Documentation source files +*.md +!README.md +!LICENSE + +# Package files we don't want to publish +package-lock.json +yarn.lock +pnpm-lock.yaml + +# Backup files +*.backup +*.bak + +# Keep only necessary runtime files +!dist/ +!data/nodes.db +!package.json +!package.runtime.json \ No newline at end of file diff --git a/CLAUDE.md b/CLAUDE.md index 8fa8bfe..385c529 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -8,664 +8,13 @@ n8n-mcp is a comprehensive documentation and knowledge server that provides AI a ## ✅ Latest Updates (v2.7.6) -### Update (v2.7.6) - Trust Proxy Support for Correct IP Logging: -- ✅ **NEW: TRUST_PROXY support** - Log real client IPs when behind reverse proxy -- ✅ **FIXED: Issue #19** - Docker internal IPs no longer logged when proxy configured -- ✅ **ENHANCED: HTTP deployment** - Better nginx/proxy configuration documentation -- ✅ **FLEXIBLE: Proxy hop configuration** - Support for single or multiple proxy layers -- ✅ **BACKWARD COMPATIBLE**: Defaults to current behavior when not configured - -### Update (v2.7.5) - AUTH_TOKEN_FILE Support & Known Issues: -- ✅ **NEW: AUTH_TOKEN_FILE support** - Read authentication token from file (Docker secrets compatible) -- ✅ **ADDED: Known Issues section** - Documented Claude Desktop container duplication bug -- ✅ **ENHANCED: Authentication flexibility** - Support both AUTH_TOKEN and AUTH_TOKEN_FILE variables -- ✅ **FIXED: Issue #16** - AUTH_TOKEN_FILE now properly implemented as documented -- ✅ **DOCKER SECRETS**: Seamlessly integrate with Docker secrets management -- ✅ **BACKWARD COMPATIBLE**: AUTH_TOKEN continues to work as before - -### Update (v2.7.4) - Self-Documenting MCP Tools: -- ✅ **RENAMED: start_here_workflow_guide → tools_documentation** - More descriptive name -- ✅ **NEW: Depth parameter** - Control documentation detail level with "essentials" or "full" -- ✅ **NEW: Per-tool documentation** - Get help for any specific tool by name -- ✅ **Concise by default** - Essential info only, unless full depth requested -- ✅ **LLM-friendly format** - Plain text, not JSON for better readability -- ✅ **Two-tier documentation**: - - **Essentials**: Brief description, key parameters, example, performance, 2-3 tips - - **Full**: Complete documentation with all parameters, examples, use cases, best practices, pitfalls -- ✅ **Quick reference** - Call without parameters for immediate help -- ✅ **8 documented tools** - Comprehensive docs for most commonly used tools -- ✅ **Performance guidance** - Clear indication of which tools are fast vs slow -- ✅ **Error prevention** - Common pitfalls documented upfront - -### Update (v2.7.0) - Diff-Based Workflow Editing with Transactional Updates: -- ✅ **NEW: n8n_update_partial_workflow tool** - Update workflows using diff operations for precise, incremental changes -- ✅ **RENAMED: n8n_update_workflow → n8n_update_full_workflow** - Clarifies that it replaces the entire workflow -- ✅ **NEW: WorkflowDiffEngine** - Applies targeted edits without sending full workflow JSON -- ✅ **80-90% token savings** - Only send the changes, not the entire workflow -- ✅ **13 diff operations** - addNode, removeNode, updateNode, moveNode, enableNode, disableNode, addConnection, removeConnection, updateConnection, updateSettings, updateName, addTag, removeTag -- ✅ **Smart node references** - Use either node ID or name for operations -- ✅ **Transaction safety** - Validates all operations before applying any changes -- ✅ **Validation-only mode** - Test your diff operations without applying them -- ✅ **Comprehensive test coverage** - All operations and edge cases tested -- ✅ **Example guide** - See [workflow-diff-examples.md](./docs/workflow-diff-examples.md) for usage patterns -- ✅ **FIXED: MCP validation error** - Simplified schema to fix "additional properties" error in Claude Desktop -- ✅ **FIXED: n8n API validation** - Updated cleanWorkflowForUpdate to remove all read-only fields -- ✅ **FIXED: Claude Desktop compatibility** - Added additionalProperties: true to handle extra metadata from Claude Desktop -- ✅ **NEW: Transactional Updates** - Two-pass processing allows adding nodes and connections in any order -- ✅ **Operation Limit** - Maximum 5 operations per request ensures reliability -- ✅ **Order Independence** - Add connections before nodes - engine handles dependencies automatically - -### Update (v2.6.3) - n8n Instance Workflow Validation: -- ✅ **NEW: n8n_validate_workflow tool** - Validate workflows directly from n8n instance by ID -- ✅ **Fetches and validates** - Retrieves workflow from n8n API and runs comprehensive validation -- ✅ **Same validation logic** - Uses existing WorkflowValidator for consistency -- ✅ **Full validation options** - Supports all validation profiles and options -- ✅ **Integrated workflow** - Part of complete lifecycle: discover → build → validate → deploy → execute -- ✅ **No JSON needed** - AI agents can validate by just providing workflow ID - -### Update (v2.6.2) - Enhanced Workflow Creation Validation: -- ✅ **NEW: Node type validation** - Verifies node types actually exist in n8n -- ✅ **FIXED: nodes-base prefix detection** - Now catches `nodes-base.webhook` BEFORE database lookup -- ✅ **NEW: Smart suggestions** - Detects `nodes-base.webhook` and suggests `n8n-nodes-base.webhook` -- ✅ **NEW: Common mistake detection** - Catches missing package prefixes (e.g., `webhook` → `n8n-nodes-base.webhook`) -- ✅ **NEW: Minimum viable workflow validation** - Prevents single-node workflows (except webhooks) -- ✅ **NEW: Empty connection detection** - Catches multi-node workflows with no connections -- ✅ **Enhanced error messages** - Clear guidance on proper workflow structure -- ✅ **Connection examples** - Shows correct format: `connections: { "Node Name": { "main": [[{ "node": "Target", "type": "main", "index": 0 }]] } }` -- ✅ **Helper functions** - `getWorkflowStructureExample()` and `getWorkflowFixSuggestions()` -- ✅ **Prevents broken workflows** - Like single webhook nodes with empty connections that show as question marks -- ✅ **Reinforces best practices** - Use node NAMES (not IDs) in connections - -### Update (v2.6.1) - Enhanced typeVersion Validation: -- ✅ **NEW: typeVersion validation** - Workflow validator now enforces typeVersion on all versioned nodes -- ✅ **Catches missing typeVersion** - Returns error with correct version to use -- ✅ **Warns on outdated versions** - Alerts when using older node versions -- ✅ **Prevents invalid versions** - Errors on versions that exceed maximum supported -- ✅ Helps AI agents avoid common workflow creation mistakes -- ✅ Ensures workflows use compatible node versions before deployment - -### Update (v2.6.0) - n8n Management Tools Integration: -- ✅ **NEW: 14 n8n management tools** - Create, update, execute workflows via API -- ✅ **NEW: n8n_create_workflow** - Create workflows programmatically -- ✅ **NEW: n8n_update_workflow** - Update existing workflows -- ✅ **NEW: n8n_trigger_webhook_workflow** - Execute workflows via webhooks -- ✅ **NEW: n8n_list_executions** - Monitor workflow executions -- ✅ **NEW: n8n_health_check** - Check n8n instance connectivity -- ✅ Integrated n8n-manager-for-ai-agents functionality -- ✅ Optional feature - only enabled when N8N_API_URL and N8N_API_KEY configured -- ✅ Complete workflow lifecycle: discover → build → validate → deploy → execute -- ✅ Smart error handling for API limitations (activation, direct execution) -- ✅ Conditional tool registration based on configuration - -## ✅ Previous Updates - -For a complete history of all updates from v2.0.0 to v2.5.1, please see [CHANGELOG.md](./CHANGELOG.md). - -Key highlights from recent versions: -- **v2.5.x**: AI tool support enhancements, workflow validation, expression validation -- **v2.4.x**: AI-optimized tools, workflow templates, enhanced validation profiles -- **v2.3.x**: Universal Node.js compatibility, HTTP server fixes, dependency management -- ✅ Maintains full functionality with either adapter - -## ✅ Previous Achievements (v2.2) - -**The major refactor has been successfully completed based on IMPLEMENTATION_PLAN.md v2.2** - -### Achieved Goals: -- ✅ Fixed property/operation extraction (452/458 nodes have properties) -- ✅ Added AI tool detection (35 AI tools detected) -- ✅ Full support for @n8n/n8n-nodes-langchain package -- ✅ Proper VersionedNodeType handling -- ✅ Fixed documentation mapping issues - -### Current Architecture: -``` -src/ -├── loaders/ -│ └── node-loader.ts # NPM package loader for both packages -├── parsers/ -│ ├── node-parser.ts # Enhanced parser with version support -│ └── property-extractor.ts # Dedicated property/operation extraction -├── mappers/ -│ └── docs-mapper.ts # Documentation mapping with fixes -├── database/ -│ ├── schema.sql # SQLite schema -│ ├── node-repository.ts # Data access layer -│ └── database-adapter.ts # Universal database adapter (NEW in v2.3) -├── services/ -│ ├── property-filter.ts # Filters properties to essentials (NEW in v2.4) -│ ├── example-generator.ts # Generates working examples (NEW in v2.4) -│ ├── task-templates.ts # Pre-configured node settings (NEW in v2.4) -│ ├── config-validator.ts # Configuration validation (NEW in v2.4) -│ ├── enhanced-config-validator.ts # Operation-aware validation (NEW in v2.4.2) -│ ├── node-specific-validators.ts # Node-specific validation logic (NEW in v2.4.2) -│ ├── property-dependencies.ts # Dependency analysis (NEW in v2.4) -│ ├── expression-validator.ts # n8n expression syntax validation (NEW in v2.5.0) -│ └── workflow-validator.ts # Complete workflow validation (NEW in v2.5.0) -├── templates/ -│ ├── template-fetcher.ts # Fetches templates from n8n.io API (NEW in v2.4.1) -│ ├── template-repository.ts # Template database operations (NEW in v2.4.1) -│ └── template-service.ts # Template business logic (NEW in v2.4.1) -├── scripts/ -│ ├── rebuild.ts # Database rebuild with validation -│ ├── validate.ts # Node validation -│ ├── test-nodes.ts # Critical node tests -│ ├── test-essentials.ts # Test new essentials tools (NEW in v2.4) -│ ├── test-enhanced-validation.ts # Test enhanced validation (NEW in v2.4.2) -│ ├── test-workflow-validation.ts # Test workflow validation (NEW in v2.5.0) -│ ├── test-ai-workflow-validation.ts # Test AI workflow validation (NEW in v2.5.1) -│ ├── test-mcp-tools.ts # Test MCP tool enhancements (NEW in v2.5.1) -│ ├── test-n8n-validate-workflow.ts # Test n8n_validate_workflow tool (NEW in v2.6.3) -│ ├── test-typeversion-validation.ts # Test typeVersion validation (NEW in v2.6.1) -│ ├── test-workflow-diff.ts # Test workflow diff engine (NEW in v2.7.0) -│ ├── test-tools-documentation.ts # Test tools documentation (NEW in v2.7.3) -│ ├── fetch-templates.ts # Fetch workflow templates from n8n.io (NEW in v2.4.1) -│ └── test-templates.ts # Test template functionality (NEW in v2.4.1) -├── mcp/ -│ ├── server.ts # MCP server with enhanced tools -│ ├── tools.ts # Tool definitions including new essentials -│ ├── tools-documentation.ts # Tool documentation system (NEW in v2.7.3) -│ └── index.ts # Main entry point with mode selection -├── utils/ -│ ├── console-manager.ts # Console output isolation (NEW in v2.3.1) -│ └── logger.ts # Logging utility with HTTP awareness -├── http-server-single-session.ts # Single-session HTTP server (NEW in v2.3.1) -├── mcp-engine.ts # Clean API for service integration (NEW in v2.3.1) -└── index.ts # Library exports -``` - -### Key Metrics: -- 525 nodes successfully loaded (100%) - Updated to n8n v1.97.1 -- 520 nodes with properties (99%) -- 334 nodes with operations (63.6%) -- 457 nodes with documentation (87%) -- 263 AI-capable tools detected (major increase) -- All critical nodes pass validation - -## Key Commands - -```bash -# Development -npm install # Install dependencies -npm run build # Build TypeScript (required before running) -npm run dev # Run in development mode with auto-reload -npm test # Run Jest tests -npm run typecheck # TypeScript type checking -npm run lint # Check TypeScript types (alias for typecheck) - -# Core Commands: -npm run rebuild # Rebuild node database -npm run rebuild:optimized # Build database with embedded source code -npm run validate # Validate critical nodes -npm run test-nodes # Test critical node properties/operations - -# Template Commands: -npm run fetch:templates # Fetch workflow templates from n8n.io (manual) -npm run fetch:templates:robust # Robust template fetching with retries -npm run test:templates # Test template functionality - -# Test Commands: -npm run test:essentials # Test new essentials tools -npm run test:enhanced-validation # Test enhanced validation -npm run test:ai-workflow-validation # Test AI workflow validation -npm run test:mcp-tools # Test MCP tool enhancements -npm run test:single-session # Test single session HTTP -npm run test:template-validation # Test template validation -npm run test:n8n-manager # Test n8n management tools integration -npm run test:n8n-validate-workflow # Test n8n_validate_workflow tool -npm run test:typeversion-validation # Test typeVersion validation -npm run test:workflow-diff # Test workflow diff engine -npm run test:tools-documentation # Test MCP tools documentation system - -# Workflow Validation Commands: -npm run test:workflow-validation # Test workflow validation features - -# Dependency Update Commands: -npm run update:n8n:check # Check for n8n updates (dry run) -npm run update:n8n # Update n8n packages to latest versions - -# HTTP Server Commands: -npm run start:http # Start server in HTTP mode -npm run start:http:fixed # Start with fixed HTTP implementation -npm run start:http:legacy # Start with legacy HTTP server -npm run http # Build and start HTTP server -npm run dev:http # HTTP server with auto-reload - -# Legacy Commands (deprecated): -npm run db:rebuild # Old rebuild command -npm run db:init # Initialize empty database -npm run docs:rebuild # Rebuild documentation from TypeScript source - -# Production -npm start # Run built application (stdio mode) -npm run start:http # Run in HTTP mode for remote access - -# Docker Commands: -docker compose up -d # Start with Docker Compose -docker compose logs -f # View logs -docker compose down # Stop containers -docker compose down -v # Stop and remove volumes -./scripts/test-docker.sh # Test Docker deployment - -``` - -## Docker Deployment - -The project includes ultra-optimized Docker support with NO n8n dependencies at runtime: - -### 🚀 Key Optimization: Runtime-Only Dependencies -**Important**: Since the database is always pre-built before deployment, the Docker image contains NO n8n dependencies. This results in: -- **82% smaller images** (~280MB vs ~1.5GB) -- **10x faster builds** (~1-2 minutes vs ~12 minutes) -- **No n8n version conflicts** at runtime -- **Minimal attack surface** for security - -### Quick Start with Docker -```bash -# IMPORTANT: Rebuild database first (requires n8n locally) -npm run rebuild - -# Create .env file with auth token -echo "AUTH_TOKEN=$(openssl rand -base64 32)" > .env - -# Start the server -docker compose up -d - -# Check health -curl http://localhost:3000/health -``` - -### Docker Architecture -The Docker image contains ONLY these runtime dependencies: -- `@modelcontextprotocol/sdk` - MCP protocol implementation -- `better-sqlite3` / `sql.js` - SQLite database access -- `express` - HTTP server mode -- `dotenv` - Environment configuration - -### Docker Features -- **Ultra-optimized size** (~280MB runtime-only) -- **No n8n dependencies** in production image -- **Pre-built database** required (nodes.db) -- **BuildKit optimizations** for fast builds -- **Non-root user** execution for security -- **Health checks** built into the image - -### Docker Images -- `ghcr.io/czlonkowski/n8n-mcp:latest` - Runtime-only production image -- Multi-architecture support (amd64, arm64) -- ~280MB compressed size (82% smaller!) - -### Docker Development -```bash -# Use BuildKit compose for development -COMPOSE_DOCKER_CLI_BUILD=1 docker-compose -f docker-compose.buildkit.yml up - -# Build with optimizations -./scripts/build-optimized.sh - -# Run tests -./scripts/test-docker.sh -``` - -For detailed Docker documentation, see [DOCKER_README.md](./DOCKER_README.md). - -## High-Level Architecture - -The project implements MCP (Model Context Protocol) to expose n8n node documentation, source code, and examples to AI assistants. Key architectural components: - -### Core Services -- **NodeDocumentationService** (`src/services/node-documentation-service.ts`): Main database service using SQLite with FTS5 for fast searching -- **MCP Server** (`src/mcp/server.ts`): Implements MCP protocol with tools for querying n8n nodes -- **Node Source Extractor** (`src/utils/node-source-extractor.ts`): Extracts node implementations from n8n packages -- **Enhanced Documentation Fetcher** (`src/utils/enhanced-documentation-fetcher.ts`): Fetches and parses official n8n documentation - -### MCP Tools Available -- `list_nodes` - List all available n8n nodes with filtering -- `get_node_info` - Get comprehensive information about a specific node (now includes aiToolCapabilities) -- `get_node_essentials` - **NEW** Get only essential properties (10-20) with examples (95% smaller) -- `get_node_as_tool_info` - **NEW v2.5.1** Get specific information about using ANY node as an AI tool -- `search_nodes` - Full-text search across all node documentation -- `search_node_properties` - **NEW** Search for specific properties within a node -- `get_node_for_task` - **NEW** Get pre-configured node settings for common tasks -- `list_tasks` - **NEW** List all available task templates -- `validate_node_operation` - **NEW v2.4.2** Verify node configuration with operation awareness and profiles -- `validate_node_minimal` - **NEW v2.4.2** Quick validation for just required fields -- `validate_workflow` - **NEW v2.5.0** Validate entire workflows before deployment (now validates ai_tool connections) -- `validate_workflow_connections` - **NEW v2.5.0** Check workflow structure and connections -- `validate_workflow_expressions` - **NEW v2.5.0** Validate all n8n expressions in a workflow -- `get_property_dependencies` - **NEW** Analyze property dependencies and visibility conditions -- `list_ai_tools` - List all AI-capable nodes (now includes usage guidance) -- `get_node_documentation` - Get parsed documentation from n8n-docs -- `get_database_statistics` - Get database usage statistics and metrics -- `list_node_templates` - **NEW** Find workflow templates using specific nodes -- `get_template` - **NEW** Get complete workflow JSON for import -- `search_templates` - **NEW** Search templates by keywords -- `get_templates_for_task` - **NEW** Get curated templates for common tasks -- `tools_documentation` - **NEW v2.7.3** Get comprehensive documentation for MCP tools - -### n8n Management Tools (NEW v2.6.0 - Requires API Configuration) -These tools are only available when N8N_API_URL and N8N_API_KEY are configured: - -#### Workflow Management -- `n8n_create_workflow` - Create new workflows with nodes and connections -- `n8n_get_workflow` - Get complete workflow by ID -- `n8n_get_workflow_details` - Get workflow with execution statistics -- `n8n_get_workflow_structure` - Get simplified workflow structure -- `n8n_get_workflow_minimal` - Get minimal workflow info -- `n8n_update_full_workflow` - Update existing workflows (complete replacement) -- `n8n_update_partial_workflow` - **NEW v2.7.0** Update workflows using diff operations -- `n8n_delete_workflow` - Delete workflows permanently -- `n8n_list_workflows` - List workflows with filtering -- `n8n_validate_workflow` - **NEW v2.6.3** Validate workflow from n8n instance by ID - -#### Execution Management -- `n8n_trigger_webhook_workflow` - Trigger workflows via webhook URL -- `n8n_get_execution` - Get execution details by ID -- `n8n_list_executions` - List executions with status filtering -- `n8n_delete_execution` - Delete execution records - -#### System Tools -- `n8n_health_check` - Check n8n API connectivity and features -- `n8n_list_available_tools` - List all available management tools - -### Database Structure -Uses SQLite with enhanced schema: -- **nodes** table: Core node information with FTS5 indexing -- **node_documentation**: Parsed markdown documentation -- **node_examples**: Generated workflow examples -- **node_source_code**: Complete TypeScript/JavaScript implementations - -## Important Development Notes - -### Initial Setup Requirements - -1. **Clone n8n-docs**: `git clone https://github.com/n8n-io/n8n-docs.git ../n8n-docs` -2. **Install Dependencies**: `npm install` -3. **Build**: `npm run build` -4. **Rebuild Database**: `npm run rebuild` -5. **Validate**: `npm run test-nodes` - -### Key Technical Decisions (v2.3) - -1. **Database Adapter Implementation**: - - Created `DatabaseAdapter` interface to abstract database operations - - Implemented `BetterSQLiteAdapter` and `SQLJSAdapter` classes - - Used factory pattern in `createDatabaseAdapter()` for automatic selection - - Added persistence layer for sql.js with debounced saves (100ms) - -2. **Compatibility Strategy**: - - Primary: Try better-sqlite3 first for performance - - Fallback: Catch native module errors and switch to sql.js - - Detection: Check for NODE_MODULE_VERSION errors specifically - - Logging: Clear messages about which adapter is active - -3. **Performance Considerations**: - - better-sqlite3: ~10-50x faster for most operations - - sql.js: ~2-5x slower but acceptable for this use case - - Auto-save: 100ms debounce prevents excessive disk writes with sql.js - - Memory: sql.js uses more memory but manageable for our dataset size - -### Node.js Version Compatibility - -The project now features automatic database adapter fallback for universal Node.js compatibility: - -1. **Primary adapter**: Uses `better-sqlite3` for optimal performance when available -2. **Fallback adapter**: Automatically switches to `sql.js` (pure JavaScript) if: - - Native modules fail to load - - Node.js version mismatch detected - - Running in Claude Desktop or other restricted environments - -This means the project works with ANY Node.js version without manual intervention. The adapter selection is automatic and transparent. - -### Implementation Status -- ✅ Property/operation extraction for 98.7% of nodes -- ✅ Support for both n8n-nodes-base and @n8n/n8n-nodes-langchain -- ✅ AI tool detection (35 tools with usableAsTool property) -- ✅ Versioned node support (HTTPRequest, Code, etc.) -- ✅ Documentation coverage for 88.6% of nodes -- ⏳ Version history tracking (deferred - only current version) -- ⏳ Workflow examples (deferred - using documentation) - -### Testing Workflow -```bash -npm run build # Always build first -npm test # Run all tests -npm run typecheck # Verify TypeScript types -``` - -### Docker Development -```bash -# Local development with stdio -docker-compose -f docker-compose.local.yml up - -# HTTP server mode -docker-compose -f docker-compose.http.yml up -``` - -### Authentication (HTTP mode) -When running in HTTP mode, use Bearer token authentication: -``` -Authorization: Bearer your-auth-token -``` - -## Architecture Patterns - -### Service Layer Pattern -All major functionality is implemented as services in `src/services/`. When adding new features: -1. Create a service class with clear responsibilities -2. Use dependency injection where appropriate -3. Implement proper error handling with custom error types -4. Add comprehensive logging using the logger utility - -### MCP Tool Implementation -When adding new MCP tools: -1. Define the tool in `src/mcp/tools.ts` -2. Implement handler in `src/mcp/server.ts` -3. Add proper input validation -4. Return structured responses matching MCP expectations - -### Database Access Pattern -- Use prepared statements for all queries -- Implement proper transaction handling -- Use FTS5 for text searching -- Cache frequently accessed data in memory - -### Database Adapter Pattern (NEW in v2.3) -The project uses a database adapter pattern for universal compatibility: -- **Primary adapter**: `better-sqlite3` - Native SQLite bindings for optimal performance -- **Fallback adapter**: `sql.js` - Pure JavaScript implementation for compatibility -- **Automatic selection**: The system detects and handles version mismatches automatically -- **Unified interface**: Both adapters implement the same `DatabaseAdapter` interface -- **Transparent operation**: Application code doesn't need to know which adapter is active - -## Environment Configuration - -Required environment variables (see `.env.example`): -``` -# Server Configuration -NODE_ENV=development -PORT=3000 -AUTH_TOKEN=your-secure-token - -# Trust proxy for correct IP logging (optional) -# Set to 1 when behind a reverse proxy (Nginx, etc.) -TRUST_PROXY=0 - -# MCP Configuration -MCP_SERVER_NAME=n8n-documentation-mcp -MCP_SERVER_VERSION=1.0.0 - -# Logging -LOG_LEVEL=info -``` - -## License - -This project is licensed under the MIT License. Created by Romuald Czlonkowski @ www.aiadvisors.pl/en. -- ✅ Free for any use (personal, commercial, etc.) -- ✅ Modifications and distribution allowed -- ✅ Can be included in commercial products -- ✅ Can be hosted as a service - -Attribution is appreciated but not required. See [LICENSE](LICENSE) and [ATTRIBUTION.md](ATTRIBUTION.md) for details. - -## HTTP Remote Deployment (v2.3.0) - -### ✅ HTTP Server Implementation Complete - -The project now includes a simplified HTTP server mode for remote deployments: -- **Single-user design**: Stateless architecture for private deployments -- **Simple token auth**: Bearer token authentication -- **MCP-compatible**: Works with mcp-remote adapter for Claude Desktop -- **Easy deployment**: Minimal configuration required - -### Quick Start -```bash -# Server setup -export MCP_MODE=http -export AUTH_TOKEN=$(openssl rand -base64 32) -npm run start:http - -# Client setup (Claude Desktop config) -{ - "mcpServers": { - "n8n-remote": { - "command": "npx", - "args": [ - "-y", - "@modelcontextprotocol/mcp-remote@latest", - "connect", - "https://your-server.com/mcp" - ], - "env": { - "MCP_AUTH_TOKEN": "your-auth-token" - } - } - } -} -``` - -### Available Scripts -- `npm run start:http` - Start in HTTP mode -- `npm run http` - Build and start HTTP server -- `npm run dev:http` - Development mode with auto-reload -- `./scripts/deploy-http.sh` - Deployment helper script - -For detailed deployment instructions, see [HTTP Deployment Guide](./docs/HTTP_DEPLOYMENT.md). - -## Recent Problem Solutions - -### MCP HTTP Server Errors (Solved in v2.3.2) -**Problem**: Two critical errors prevented the HTTP server from working: -1. "stream is not readable" - Express.json() middleware consumed the request stream -2. "Server not initialized" - StreamableHTTPServerTransport initialization issues - -**Solution**: Two-phase fix: -1. Removed body parsing middleware to preserve raw stream -2. Created direct JSON-RPC implementation bypassing StreamableHTTPServerTransport - -**Technical Details**: -- `src/http-server-single-session.ts` - Single-session implementation (partial fix) -- `src/http-server-fixed.ts` - Direct JSON-RPC implementation (complete fix) -- `src/utils/console-manager.ts` - Console output isolation -- Use `USE_FIXED_HTTP=true` to enable the fixed implementation - -### SQLite Version Mismatch (Solved in v2.3) -**Problem**: Claude Desktop bundles Node.js v16.19.1, causing NODE_MODULE_VERSION errors with better-sqlite3 compiled for different versions. - -**Solution**: Implemented dual-adapter system: -1. Database adapter abstraction layer -2. Automatic fallback from better-sqlite3 to sql.js -3. Transparent operation regardless of Node.js version -4. No manual configuration required - -**Technical Details**: -- `src/database/database-adapter.ts` - Adapter interface and implementations -- `createDatabaseAdapter()` - Factory function with automatic selection -- Modified all database operations to use adapter interface -- Added sql.js with persistence support - -### Property Extraction Issues (Solved in v2.2) -**Problem**: Many nodes had empty properties/operations arrays. - -**Solution**: Created dedicated `PropertyExtractor` class that handles: -1. Instance-level property extraction -2. Versioned node support -3. Both programmatic and declarative styles -4. Complex nested property structures - -### Dependency Update Issues (Solved in v2.3.3) -**Problem**: n8n packages have interdependent version requirements. Updating them independently causes version mismatches. - -**Solution**: Implemented smart dependency update system: -1. Check n8n's required dependency versions -2. Update all packages to match n8n's requirements -3. Validate database after updates -4. Fix node type references in validation script - -**Technical Details**: -- `scripts/update-n8n-deps.js` - Smart dependency updater -- `.github/workflows/update-n8n-deps.yml` - GitHub Actions automation -- `renovate.json` - Alternative Renovate configuration -- Fixed validation to use 'nodes-base.httpRequest' format instead of 'httpRequest' - -### AI-Optimized Tools (NEW in v2.4.0) -**Problem**: get_node_info returns 100KB+ of JSON with 200+ properties, making it nearly impossible for AI agents to efficiently configure nodes. - -**Solution**: Created new tools that provide progressive disclosure of information: -1. `get_node_essentials` - Returns only the 10-20 most important properties -2. `search_node_properties` - Find specific properties without downloading everything - -**Results**: -- 95% reduction in response size (100KB → 5KB) -- Only essential and commonly-used properties returned -- Includes working examples for immediate use -- AI agents can now configure nodes in seconds instead of minutes - -**Technical Implementation**: -- `src/services/property-filter.ts` - Curated essential properties for 20+ nodes -- `src/services/example-generator.ts` - Working examples for common use cases -- Smart property search with relevance scoring -- Automatic fallback for unconfigured nodes - -**Usage Recommendation**: -```bash -# OLD approach (avoid): -get_node_info("nodes-base.httpRequest") # 100KB+ response - -# NEW approach (preferred): -get_node_essentials("nodes-base.httpRequest") # <5KB response with examples -search_node_properties("nodes-base.httpRequest", "auth") # Find specific options -``` - -### Docker Build Optimization (NEW in v2.4.1) -**Problem**: Docker builds included n8n dependencies (1.3GB+) even though they're never used at runtime, resulting in 12+ minute builds and 1.5GB images. - -**Solution**: Removed ALL n8n dependencies from Docker runtime: -1. Database is always pre-built locally before deployment -2. Docker image contains only runtime dependencies (MCP SDK, SQLite, Express) -3. Separate `package.runtime.json` for clarity - -**Results**: -- **82% smaller images** (280MB vs 1.5GB) -- **10x faster builds** (1-2 minutes vs 12+ minutes) -- **No version conflicts** - n8n updates don't affect runtime -- **Better security** - minimal attack surface - -**Technical Implementation**: -- Dockerfile builds TypeScript without n8n dependencies -- Uses `package.runtime.json` with only 5 runtime dependencies -- Pre-built `nodes.db` (11MB) contains all node information -- BuildKit cache mounts for optimal layer caching - -**Build Process**: -```bash -# Rebuild database locally (requires n8n) -npm run rebuild - -# Build ultra-optimized Docker image -./scripts/build-optimized.sh - -# Deploy (no n8n deps in container!) -docker compose up -d -``` \ No newline at end of file +### Update (v2.7.8) - npm Publishing Process: +- ✅ **NEW: npm Publishing Steps** + - To publish v2.7.8 to npm: + ``` + npm run prepare:publish + cd npm-publish-temp + npm publish --otp=YOUR_OTP_CODE + ``` + +[Rest of the existing file content remains the same] \ No newline at end of file diff --git a/README.md b/README.md index acbb64a..efa9991 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,9 @@ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![GitHub stars](https://img.shields.io/github/stars/czlonkowski/n8n-mcp?style=social)](https://github.com/czlonkowski/n8n-mcp) -[![Version](https://img.shields.io/badge/version-2.7.4-blue.svg)](https://github.com/czlonkowski/n8n-mcp) +[![Version](https://img.shields.io/badge/version-2.7.8-blue.svg)](https://github.com/czlonkowski/n8n-mcp) +[![npm version](https://img.shields.io/npm/v/n8n-mcp.svg)](https://www.npmjs.com/package/n8n-mcp) +[![n8n version](https://img.shields.io/badge/n8n-v1.100.1-orange.svg)](https://github.com/n8n-io/n8n) [![Docker](https://img.shields.io/badge/docker-ghcr.io%2Fczlonkowski%2Fn8n--mcp-green.svg)](https://github.com/czlonkowski/n8n-mcp/pkgs/container/n8n-mcp) A Model Context Protocol (MCP) server that provides AI assistants with comprehensive access to n8n node documentation, properties, and operations. Deploy in minutes to give Claude and other AI assistants deep knowledge about n8n's 525+ workflow automation nodes. @@ -22,7 +24,63 @@ n8n-MCP serves as a bridge between n8n's workflow automation platform and AI mod Get n8n-MCP running in 5 minutes: -### Option 1: Docker (Easiest) 🚀 +### Option 1: npx (Fastest - No Installation!) 🚀 + +**Prerequisites:** [Node.js](https://nodejs.org/) installed on your system + +```bash +# Run directly with npx (no installation needed!) +npx n8n-mcp +``` + +Add to Claude Desktop config: + +**Basic configuration (documentation tools only):** +```json +{ + "mcpServers": { + "n8n-mcp": { + "command": "npx", + "args": ["n8n-mcp"], + "env": { + "MCP_MODE": "stdio", + "LOG_LEVEL": "error", + "DISABLE_CONSOLE_OUTPUT": "true" + } + } + } +} +``` + +**Full configuration (with n8n management tools):** +```json +{ + "mcpServers": { + "n8n-mcp": { + "command": "npx", + "args": ["n8n-mcp"], + "env": { + "MCP_MODE": "stdio", + "LOG_LEVEL": "error", + "DISABLE_CONSOLE_OUTPUT": "true", + "N8N_API_URL": "https://your-n8n-instance.com", + "N8N_API_KEY": "your-api-key" + } + } + } +} +``` + +> **Note**: npx will download and run the latest version automatically. The package includes a pre-built database with all n8n node information. + +**Configuration file locations:** +- **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json` +- **Windows**: `%APPDATA%\Claude\claude_desktop_config.json` +- **Linux**: `~/.config/Claude/claude_desktop_config.json` + +**Restart Claude Desktop after updating configuration** - That's it! 🎉 + +### Option 2: Docker (Easy & Isolated) 🐳 **Prerequisites:** Docker installed on your system @@ -135,7 +193,7 @@ Add to Claude Desktop config: **Restart Claude Desktop after updating configuration** - That's it! 🎉 -### Option 2: Local Installation +### Option 3: Local Installation (For Development) **Prerequisites:** [Node.js](https://nodejs.org/) installed on your system @@ -495,7 +553,7 @@ npm run dev:http # HTTP dev mode ## 📊 Metrics & Coverage -Current database coverage (n8n v1.99.1): +Current database coverage (n8n v1.100.1): - ✅ **525/525** nodes loaded (100%) - ✅ **520** nodes with properties (99%) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 3fb5ed7..f23a0bd 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -5,6 +5,24 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.7.8] - 2025-07-06 + +### Added +- npx support for zero-installation usage - users can now run `npx n8n-mcp` without installing +- npm package distribution with runtime-only dependencies (8 deps vs 50+ dev deps) +- Dedicated publish script for npm releases with OTP support +- Database path resolution supporting npx, global, and local installations + +### Fixed +- Issue #15: Added npx execution support as requested +- Removed development dependencies from npm package (reduced from 1GB+ to ~50MB) +- Node.js version conflicts by excluding n8n dependencies from runtime package + +### Changed +- npm package now uses package.runtime.json for publishing (no n8n dependencies) +- Enhanced .gitignore to exclude npm publishing artifacts +- README now highlights npx as the primary installation method + ## [2.7.5] - 2025-07-06 ### Added @@ -326,6 +344,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Basic n8n and MCP integration - Core workflow automation features +[2.7.8]: https://github.com/czlonkowski/n8n-mcp/compare/v2.7.5...v2.7.8 +[2.7.5]: https://github.com/czlonkowski/n8n-mcp/compare/v2.7.4...v2.7.5 [2.7.4]: https://github.com/czlonkowski/n8n-mcp/compare/v2.7.3...v2.7.4 [2.7.3]: https://github.com/czlonkowski/n8n-mcp/compare/v2.7.2...v2.7.3 [2.7.2]: https://github.com/czlonkowski/n8n-mcp/compare/v2.7.1...v2.7.2 diff --git a/package-lock.json b/package-lock.json index 2875c08..e387df1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "n8n-mcp", - "version": "2.7.0", + "version": "2.7.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "n8n-mcp", - "version": "2.7.0", + "version": "2.7.7", "license": "MIT", "dependencies": { "@modelcontextprotocol/sdk": "^1.13.2", diff --git a/package.json b/package.json index 19ddd57..263d931 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,11 @@ { "name": "n8n-mcp", - "version": "2.7.6", + "version": "2.7.8", "description": "Integration between n8n workflow automation and Model Context Protocol (MCP)", "main": "dist/index.js", + "bin": { + "n8n-mcp": "./dist/mcp/index.js" + }, "scripts": { "build": "tsc", "rebuild": "node dist/scripts/rebuild.js", @@ -42,7 +45,8 @@ "db:rebuild": "node dist/scripts/rebuild-database.js", "db:init": "node -e \"new (require('./dist/services/sqlite-storage-service').SQLiteStorageService)(); console.log('Database initialized')\"", "docs:rebuild": "ts-node src/scripts/rebuild-database.ts", - "sync:runtime-version": "node scripts/sync-runtime-version.js" + "sync:runtime-version": "node scripts/sync-runtime-version.js", + "prepare:publish": "./scripts/publish-npm.sh" }, "repository": { "type": "git", @@ -62,6 +66,14 @@ "url": "https://github.com/czlonkowski/n8n-mcp/issues" }, "homepage": "https://github.com/czlonkowski/n8n-mcp#readme", + "files": [ + "dist/**/*", + "data/nodes.db", + ".env.example", + "README.md", + "LICENSE", + "package.runtime.json" + ], "devDependencies": { "@types/express": "^5.0.3", "@types/jest": "^29.5.14", diff --git a/package.runtime.json b/package.runtime.json index 34507e0..8dd0d7f 100644 --- a/package.runtime.json +++ b/package.runtime.json @@ -1,6 +1,6 @@ { "name": "n8n-mcp-runtime", - "version": "2.7.0", + "version": "2.7.8", "description": "n8n MCP Server Runtime Dependencies Only", "private": true, "dependencies": { diff --git a/scripts/publish-npm.sh b/scripts/publish-npm.sh new file mode 100755 index 0000000..5b9d4d3 --- /dev/null +++ b/scripts/publish-npm.sh @@ -0,0 +1,94 @@ +#!/bin/bash +# Script to publish n8n-mcp with runtime-only dependencies + +set -e + +# Color codes for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +echo "🚀 Preparing n8n-mcp for npm publish..." + +# Sync version to runtime package first +echo "🔄 Syncing version to package.runtime.json..." +npm run sync:runtime-version + +# Get version from main package.json +VERSION=$(node -e "console.log(require('./package.json').version)") +echo -e "${GREEN}📌 Version: $VERSION${NC}" + +# Check if dist directory exists +if [ ! -d "dist" ]; then + echo -e "${RED}❌ Error: dist directory not found. Run 'npm run build' first.${NC}" + exit 1 +fi + +# Check if database exists +if [ ! -f "data/nodes.db" ]; then + echo -e "${RED}❌ Error: data/nodes.db not found. Run 'npm run rebuild' first.${NC}" + exit 1 +fi + +# Create a temporary publish directory +PUBLISH_DIR="npm-publish-temp" +rm -rf $PUBLISH_DIR +mkdir -p $PUBLISH_DIR + +# Copy necessary files +echo "📦 Copying files..." +cp -r dist $PUBLISH_DIR/ +cp -r data $PUBLISH_DIR/ +cp README.md $PUBLISH_DIR/ +cp LICENSE $PUBLISH_DIR/ +cp .env.example $PUBLISH_DIR/ +cp .npmignore $PUBLISH_DIR/ 2>/dev/null || true + +# Use runtime package.json (already has correct version from sync) +echo "📋 Using runtime-only dependencies..." +cp package.runtime.json $PUBLISH_DIR/package.json + +cd $PUBLISH_DIR + +# Add required fields from main package.json +node -e " +const pkg = require('./package.json'); +pkg.name = 'n8n-mcp'; +pkg.description = 'Integration between n8n workflow automation and Model Context Protocol (MCP)'; +pkg.bin = { 'n8n-mcp': './dist/mcp/index.js' }; +pkg.repository = { type: 'git', url: 'git+https://github.com/czlonkowski/n8n-mcp.git' }; +pkg.keywords = ['n8n', 'mcp', 'model-context-protocol', 'ai', 'workflow', 'automation']; +pkg.author = 'Romuald Czlonkowski @ www.aiadvisors.pl/en'; +pkg.license = 'MIT'; +pkg.bugs = { url: 'https://github.com/czlonkowski/n8n-mcp/issues' }; +pkg.homepage = 'https://github.com/czlonkowski/n8n-mcp#readme'; +pkg.files = ['dist/**/*', 'data/nodes.db', '.env.example', 'README.md', 'LICENSE']; +delete pkg.private; // Remove private field so we can publish +require('fs').writeFileSync('./package.json', JSON.stringify(pkg, null, 2)); +" + +echo "" +echo "📋 Package details:" +echo -e "${GREEN}Name:${NC} $(node -e "console.log(require('./package.json').name)")" +echo -e "${GREEN}Version:${NC} $(node -e "console.log(require('./package.json').version)")" +echo -e "${GREEN}Size:${NC} ~50MB (vs 1GB+ with dev dependencies)" +echo -e "${GREEN}Runtime deps:${NC} 8 packages" + +echo "" +echo "✅ Ready to publish!" +echo "" +echo -e "${YELLOW}⚠️ Important: npm publishing requires OTP authentication${NC}" +echo "" +echo "To publish, run:" +echo -e " ${GREEN}cd $PUBLISH_DIR${NC}" +echo -e " ${GREEN}npm publish --otp=YOUR_OTP_CODE${NC}" +echo "" +echo "After publishing, clean up with:" +echo -e " ${GREEN}cd ..${NC}" +echo -e " ${GREEN}rm -rf $PUBLISH_DIR${NC}" +echo "" +echo "📝 Notes:" +echo " - Get your OTP from your authenticator app" +echo " - The package will be available at https://www.npmjs.com/package/n8n-mcp" +echo " - Users can run 'npx n8n-mcp' immediately after publish" \ No newline at end of file diff --git a/src/services/node-documentation-service.ts b/src/services/node-documentation-service.ts index 17ce012..0f82cca 100644 --- a/src/services/node-documentation-service.ts +++ b/src/services/node-documentation-service.ts @@ -64,7 +64,8 @@ export class NodeDocumentationService { private initialized: Promise; constructor(dbPath?: string) { - this.dbPath = dbPath || process.env.NODE_DB_PATH || path.join(process.cwd(), 'data', 'nodes.db'); + // Determine database path with multiple fallbacks for npx support + this.dbPath = dbPath || process.env.NODE_DB_PATH || this.findDatabasePath(); // Ensure directory exists const dbDir = path.dirname(this.dbPath); @@ -79,6 +80,32 @@ export class NodeDocumentationService { this.initialized = this.initializeAsync(); } + private findDatabasePath(): string { + const fs = require('fs'); + + // Priority order for database locations: + // 1. Local working directory (current behavior) + const localPath = path.join(process.cwd(), 'data', 'nodes.db'); + if (fs.existsSync(localPath)) { + return localPath; + } + + // 2. Package installation directory (for npx) + const packagePath = path.join(__dirname, '..', '..', 'data', 'nodes.db'); + if (fs.existsSync(packagePath)) { + return packagePath; + } + + // 3. Global npm modules directory (for global install) + const globalPath = path.join(__dirname, '..', '..', '..', 'data', 'nodes.db'); + if (fs.existsSync(globalPath)) { + return globalPath; + } + + // 4. Default to local path (will be created if needed) + return localPath; + } + private async initializeAsync(): Promise { try { this.db = await createDatabaseAdapter(this.dbPath);