refactor: major cleanup of legacy and temporary files

- Removed ~965MB of temporary directories (temp/, extracted-nodes/, etc)
- Deleted outdated database files and backups (.bak files)
- Removed legacy shell scripts (mcp-server-v20.sh, rebuild-v20.sh)
- Cleaned up orphan test files and debugging scripts
- Removed duplicate schema file (src/db/schema.sql)
- Deleted old Dockerfile.old and empty database files
- Updated documentation structure in README.md
- Added n8n_diagnostic tool to documentation
- Condensed version history in CLAUDE.md
- Created release notes for v2.7.0

Total impact: Removed 34 files, saving ~965MB+ of disk space

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
czlonkowski
2025-06-29 19:06:31 +02:00
parent 91386b2d02
commit 1907e5ce8e
34 changed files with 112 additions and 2898 deletions

View File

@@ -1,424 +0,0 @@
# Changelog
All notable changes to this project will be documented in this file.
## [2.7.0] - 2025-06-28
### Added
- **Diff-Based Workflow Editing**: Revolutionary token-efficient workflow updates
- **NEW**: `n8n_update_partial_workflow` tool - Update workflows using diff operations for precise, incremental changes
- **NEW**: WorkflowDiffEngine - Applies targeted edits without sending full workflow JSON
- **NEW**: 13 diff operations - addNode, removeNode, updateNode, moveNode, enableNode, disableNode, addConnection, removeConnection, updateConnection, updateSettings, updateName, addTag, removeTag
- **NEW**: Transaction safety - Validates all operations before applying any changes
- **NEW**: Validation-only mode - Test your diff operations without applying them
- **NEW**: Transactional Updates - Two-pass processing allows adding nodes and connections in any order
- Smart node references - Use either node ID or name for operations
- Order independence - Add connections before nodes, engine handles dependencies automatically
- Operation limit - Maximum 5 operations per request ensures reliability
- 80-90% token savings - Only send the changes, not the entire workflow
- Comprehensive test coverage - All operations and edge cases tested
- Example guide - See [workflow-diff-examples.md](./workflow-diff-examples.md) for usage patterns
### Changed
- **RENAMED**: `n8n_update_workflow``n8n_update_full_workflow` - Clarifies that it replaces the entire workflow
### Fixed
- **Docker Runtime Dependencies**: Added missing `uuid` package to runtime dependencies
- Fixed MODULE_NOT_FOUND error in Docker containers
- Updated both package.json and package.runtime.json
- Aligned package versions between main and runtime configurations
## [2.6.2] - 2025-06-26
### Added
- **Enhanced Workflow Creation Validation**: Major improvements to prevent broken workflows
- **NEW**: Node type existence validation - Verifies node types actually exist in n8n
- **NEW**: Smart suggestions for common mistakes - Detects `webhook` and suggests `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
- **NEW**: Helper functions - `getWorkflowStructureExample()` and `getWorkflowFixSuggestions()`
- Enhanced error messages with clear guidance and connection examples
- Prevents broken workflows that show as question marks in n8n UI
### Fixed
- **Critical**: `nodes-base.webhook` validation - Now caught BEFORE database lookup
- Previously, `nodes-base.webhook` would pass validation because it existed in the normalized database
- Now explicitly checks for and rejects `nodes-base.` prefix before any database operations
- This fixes the exact issue causing workflows to appear broken in n8n UI
### Changed
- Workflow validator now checks node types in order: invalid patterns → database lookup → suggestions
- Connection validation messages now include proper format examples
- Error messages are more actionable with specific fix instructions
## [2.6.1] - 2025-06-26
### Added
- **Enhanced typeVersion Validation**: Comprehensive validation for versioned nodes
- **NEW**: typeVersion validation enforced on all versioned nodes
- Catches missing typeVersion and provides correct version to use
- Warns on outdated versions when newer versions are available
- Prevents invalid versions that exceed maximum supported
- Helps AI agents avoid common workflow creation mistakes
- Test coverage for all typeVersion scenarios
### Changed
- WorkflowValidator now includes typeVersion in its validation pipeline
- Enhanced error messages for typeVersion issues with actionable suggestions
## [2.6.0] - 2025-06-26
### Added
- **n8n Management Tools Integration**: Complete workflow lifecycle management via API
- **NEW**: 14 n8n management tools for creating, updating, and executing workflows
- **NEW**: `n8n_create_workflow` - Create workflows programmatically with validation
- **NEW**: `n8n_update_workflow` - Update existing workflows with safety checks
- **NEW**: `n8n_trigger_webhook_workflow` - Execute workflows via webhooks
- **NEW**: `n8n_list_executions` - Monitor workflow executions with filtering
- **NEW**: `n8n_health_check` - Check n8n instance connectivity and features
- **NEW**: Workflow management tools with smart error handling
- **NEW**: Execution management tools for monitoring and debugging
- 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
### Changed
- Updated `start_here_workflow_guide` to include n8n management tools documentation
- Enhanced MCP server to conditionally register management tools
- Added comprehensive integration tests for all management features
## [2.5.1] - 2025-01-25
### Added
- **AI Tool Support Enhancement**: Major improvements to AI tool integration
- **NEW**: `get_node_as_tool_info` tool - Get specific information about using ANY node as an AI tool
- **ENHANCED**: `get_node_info` now includes `aiToolCapabilities` section for all nodes
- **ENHANCED**: `list_ai_tools` - Added usage guidance explaining ANY node can be used as a tool
- **ENHANCED**: `WorkflowValidator` - Now validates `ai_tool` connections in workflows
- AI workflow pattern detection - Warns when AI Agents have no tools connected
- Community node detection - Reminds about N8N_COMMUNITY_PACKAGES_ALLOW_TOOL_USAGE environment variable
- **NEW**: AI Tool TaskTemplates - Added use_google_sheets_as_tool, use_slack_as_tool, multi_tool_ai_agent
- Comprehensive examples showing how to connect regular nodes as AI tools
- Tool usage documentation with $fromAI() expression examples
### Changed
- Clarified that ANY node can be used as an AI tool, not just nodes with usableAsTool property
- Enhanced workflow validation to understand and validate ai_tool connections
- Improved expression validation to support $fromAI() dynamic AI parameters
## [2.5.0] - 2025-01-20
### Added
- **Complete Workflow Validation**: Professional-grade workflow validation system
- **NEW**: `validate_workflow` tool - Validate entire workflows before deployment
- **NEW**: `validate_workflow_connections` tool - Check workflow structure and connections
- **NEW**: `validate_workflow_expressions` tool - Validate all n8n expressions in a workflow
- **NEW**: `ExpressionValidator` - Comprehensive n8n expression syntax validation
- **NEW**: `WorkflowValidator` - Complete workflow structure and logic validation
- Detects cycles (infinite loops) in workflows
- Validates node references in expressions ($node["Node Name"])
- Checks for orphaned nodes and missing connections
- Expression syntax validation with common mistake detection
- Workflow best practices analysis with suggestions
- Supports partial validation (nodes only, connections only, expressions only)
- Test coverage for all validation scenarios
## [2.4.2] - 2025-01-15
### Added
- **Enhanced Node Configuration Validation**: Operation-aware validation with dramatic accuracy improvements
- **NEW**: `validate_node_operation` tool - Operation-aware validation with 80%+ fewer false positives
- **NEW**: `validate_node_minimal` tool - Lightning-fast validation for just required fields
- **NEW**: Validation profiles - Choose between minimal, runtime, ai-friendly, or strict validation
- **NEW**: `EnhancedConfigValidator` - Smart validation that only checks relevant properties
- **NEW**: Node-specific validators - Custom logic for Slack, Google Sheets, OpenAI, MongoDB, Webhook, Postgres, MySQL
- **NEW**: SQL safety features - Detects SQL injection risks, unsafe DELETE/UPDATE queries
- Added operation context filtering (only validates properties for selected operation)
- Integrated working examples in validation responses when errors found
- Added actionable next steps and auto-fix suggestions
- Basic code syntax validation for JavaScript/Python in Code node
- Dramatic improvement for complex multi-operation nodes
- Test results: Slack validation reduced from 45 errors to 1 error!
### Removed
- Deprecated `validate_node_config` tool in favor of new operation-aware validators
## [2.4.1] - 2025-01-10
### Added
- **n8n Workflow Templates**: Integration with n8n.io template library
- **NEW**: `list_node_templates` tool - Find workflow templates using specific nodes
- **NEW**: `get_template` tool - Get complete workflow JSON for import
- **NEW**: `search_templates` tool - Search templates by keywords
- **NEW**: `get_templates_for_task` tool - Get curated templates for common tasks
- Added Templates system with n8n.io API integration
- Templates filtered to last 6 months only (freshness guarantee)
- Manual fetch system - not part of regular rebuild
- Full workflow JSON available for immediate use
- 10 task categories: AI automation, data sync, webhooks, etc.
## [2.4.0] - 2025-01-05
### Added
- **AI-Optimized MCP Tools**: Dramatically improved AI agent experience
- **NEW**: `get_node_essentials` tool - Returns only 10-20 essential properties (95% size reduction)
- **NEW**: `search_node_properties` tool - Search for specific properties within nodes
- **NEW**: `get_node_for_task` tool - Pre-configured settings for 14 common tasks
- **NEW**: `list_tasks` tool - Discover available task templates
- **NEW**: `validate_node_config` tool - Validate configurations before use
- **NEW**: `get_property_dependencies` tool - Analyze property visibility dependencies
- Added PropertyFilter service with curated essential properties for 20+ nodes
- Added ExampleGenerator with working examples for common use cases
- Added TaskTemplates service with 14 pre-configured tasks
- Added ConfigValidator service for comprehensive validation
- Added PropertyDependencies service for dependency analysis
- Enhanced all property descriptions - 100% coverage
- Added version information to essentials response
- Response sizes reduced from 100KB+ to <5KB for common nodes
### Changed
- **License Change**: Changed from Apache 2.0 to MIT License for wider adoption
- Fixed missing AI and LangChain node documentation
- Improved documentation mapping for better coverage
## [2.3.3] - 2025-06-16
### Added
- **Automated Dependency Update System**: Comprehensive solution for keeping n8n packages in sync
- Custom update script (`scripts/update-n8n-deps.js`) that respects n8n's interdependencies
- GitHub Actions workflow for weekly automated updates
- Renovate configuration as an alternative solution
- Dependency update documentation guide
- Support for automatic n8n package version synchronization
- Documentation updates reflecting current metrics
### Fixed
- **Validation Script Node Type References**: Fixed node type format issues
- Changed from short names (e.g., 'httpRequest') to full names (e.g., 'nodes-base.httpRequest')
- Removed versioned check for Code node as it's not consistently detected
- All validation tests now pass after dependency updates
### Changed
- Updated n8n dependencies to latest versions:
- n8n: 1.14.1 1.97.1
- n8n-core: 1.14.1 1.96.0
- n8n-workflow: 1.82.0 1.94.0
- @n8n/n8n-nodes-langchain: 1.97.0 1.96.1
- Significant increase in detected nodes and capabilities:
- Total nodes: 458 525
- AI-capable tools: 35 263 (major increase due to updated detection)
- Nodes with properties: 98.7% 99%
- Nodes with operations: 57.9% 63.6%
### Technical Details
- Dependency update script now checks n8n's required dependency versions
- Validation script uses correct database column names
- All critical nodes (httpRequest, code, slack, agent) validate successfully
## [2.3.2] - 2025-06-14
### Fixed
- **HTTP Server Stream Error**: Complete fix for "stream is not readable" error
- Removed Express body parsing middleware that was consuming request streams
- Fixed "Server not initialized" error with direct JSON-RPC implementation
- Added `USE_FIXED_HTTP=true` environment variable for stable HTTP mode
- Bypassed problematic StreamableHTTPServerTransport implementation
- HTTP server now works reliably with average response time of ~12ms
- Updated all HTTP server implementations to preserve raw streams
### Added
- `http-server-fixed.ts` - Direct JSON-RPC implementation
- `ConsoleManager` utility for stream isolation
- `MCP Engine` interface for service integration
- Comprehensive documentation for HTTP server fixes
### Changed
- Default HTTP mode now uses fixed implementation when `USE_FIXED_HTTP=true`
- Updated Docker configuration to use fixed implementation by default
- Improved error handling and logging in HTTP mode
## [2.3.1] - 2025-06-14
### Added
- **Single-Session Architecture**: Initial attempt to fix HTTP server issues
- Implemented session reuse across requests
- Added console output isolation
- Created engine interface for service integration
### Fixed
- Partial fix for "stream is not readable" error (completed in v2.3.2)
## [2.3.0] - 2024-12-06
### Added
- **HTTP Remote Deployment**: Single-user HTTP server for remote access
- Stateless architecture for simple deployments
- Bearer token authentication
- Compatible with mcp-remote adapter for Claude Desktop
- New HTTP mode scripts and deployment helper
- **Universal Node.js Compatibility**: Automatic database adapter fallback system
- Primary adapter: `better-sqlite3` for optimal performance
- Fallback adapter: `sql.js` (pure JavaScript) for version mismatches
- Automatic detection and switching between adapters
- No manual configuration required
- Database adapter abstraction layer (`src/database/database-adapter.ts`)
- Version detection and logging for troubleshooting
- sql.js dependency for pure JavaScript SQLite implementation
- HTTP server implementation (`src/http-server.ts`)
- Deployment documentation and scripts
### Changed
- Updated all database operations to use the adapter interface
- Removed Node.js v20.17.0 requirement - now works with ANY version
- Simplified Claude Desktop setup - no wrapper scripts needed
- Enhanced error messages for database initialization
- Made all MCP tool handlers async for proper initialization
### Fixed
- NODE_MODULE_VERSION mismatch errors with Claude Desktop
- Native module compilation issues in restricted environments
- Compatibility issues when running with different Node.js versions
- Database initialization race conditions in HTTP mode
### Technical Details
- Better-sqlite3: ~10-50x faster (when compatible)
- sql.js: ~2-5x slower but universally compatible
- Both adapters maintain identical API and functionality
- Automatic persistence for sql.js with 100ms debounced saves
- HTTP server uses StreamableHTTPServerTransport for MCP compatibility
## [2.2.0] - 2024-12-06
### Added
- PropertyExtractor class for dedicated property/operation extraction
- NodeRepository for proper JSON serialization/deserialization
- Support for @n8n/n8n-nodes-langchain package (59 AI nodes)
- AI tool detection (35 tools with usableAsTool property)
- Test suite for critical node validation
- Comprehensive documentation (README, SETUP, CHANGELOG)
- Example configuration files for Claude Desktop
- Node.js v20.17.0 wrapper scripts for compatibility
### Fixed
- Empty properties/operations arrays (now 98.7% nodes have properties)
- Versioned node detection (HTTPRequest, Code properly identified)
- Documentation mapping for nodes with directory-based docs
- Critical node validation (httpRequest, slack, code all pass)
### Changed
- Refactored parser to handle instance-level properties
- Updated MCP server to use NodeRepository
- Improved rebuild script with validation
- Enhanced database schema with proper typing
### Metrics
- 458 total nodes (100% success rate)
- 452 nodes with properties (98.7%)
- 265 nodes with operations (57.9%)
- 406 nodes with documentation (88.6%)
- 35 AI-capable tools detected
- All critical nodes validated
## [2.1.0] - 2025-01-08
### Added
- Remote deployment capabilities via HTTP/JSON-RPC transport
- Domain configuration through environment variables (`MCP_DOMAIN`)
- Bearer token authentication for remote access
- Comprehensive remote deployment documentation
- PM2 and Nginx configuration examples
- HTTP server mode (`npm run start:http`)
### Enhanced
- Support for both local (stdio) and remote (HTTP) deployment modes
- Production deployment guide for VM/cloud environments
- Claude Desktop configuration for remote servers
## [2.0.0] - 2025-01-08
### Major Refactoring
- **BREAKING CHANGE**: Refocused project to serve only n8n node documentation
- Removed all workflow execution and management features
- Removed bidirectional n8n-MCP integration
- Simplified to be a read-only documentation server
### Added
- SQLite database with full-text search (FTS5) for node documentation
- Integration with n8n-docs repository for official documentation
- Automatic example workflow generation for each node type
- Comprehensive node information including:
- Source code
- Official documentation
- Usage examples
- Properties schema
- Credential definitions
### New MCP Tools
- `list_nodes` - List available nodes with filtering
- `get_node_info` - Get complete node information
- `search_nodes` - Full-text search across nodes
- `get_node_example` - Get example workflow for a node
- `get_node_source_code` - Get only source code
- `get_node_documentation` - Get only documentation
- `rebuild_database` - Rebuild entire node database
- `get_database_statistics` - Database statistics
### Infrastructure
- New database schema optimized for documentation storage
- `DocumentationFetcher` for n8n-docs repository integration
- `ExampleGenerator` for creating node usage examples
- `NodeDocumentationService` for database management
## [1.1.0] - 2024-01-07
### Added
- Node source code extraction capability via `get_node_source_code` tool
- List available nodes functionality with `list_available_nodes` tool
- `NodeSourceExtractor` utility for file system access to n8n nodes
- Resource endpoint `nodes://source/{nodeType}` for accessing node source code
- Docker test environment with mounted n8n node_modules
- Comprehensive test suite for AI Agent node extraction
- Test documentation in `docs/AI_AGENT_EXTRACTION_TEST.md`
### Enhanced
- MCP server can now access and extract n8n node implementations
- Support for extracting credential definitions alongside node code
- Package metadata included in extraction results
## [1.0.0] - 2024-01-07
### Initial Release
- Complete n8n-MCP integration implementation
- MCP server exposing n8n workflows as tools, resources, and prompts
- Custom n8n node for connecting to MCP servers
- Bidirectional data format conversion bridge
- Token-based authentication system
- Comprehensive error handling and logging
- Full test coverage for core components
- Docker support with production and development configurations
- Installation scripts for n8n custom node deployment
### MCP Tools
- `execute_workflow` - Execute n8n workflows
- `list_workflows` - List available workflows
- `get_workflow` - Get workflow details
- `create_workflow` - Create new workflows
- `update_workflow` - Update existing workflows
- `delete_workflow` - Delete workflows
- `get_executions` - Get execution history
- `get_execution_data` - Get execution details
### MCP Resources
- `workflow://active` - Active workflows
- `workflow://all` - All workflows
- `execution://recent` - Recent executions
- `credentials://types` - Credential types
- `nodes://available` - Available nodes
### MCP Prompts
- `create_workflow_prompt` - Workflow creation
- `debug_workflow_prompt` - Workflow debugging
- `optimize_workflow_prompt` - Workflow optimization
- `explain_workflow_prompt` - Workflow explanation

View File

@@ -1,163 +0,0 @@
# Docker stdio Fix Implementation Plan for n8n-MCP
Based on community research and successful MCP Docker deployments, here's a streamlined fix for the initialization timeout issue.
## Root Cause
Docker treats container stdout as a pipe (not TTY), causing block buffering. The MCP server's JSON-RPC responses sit in the buffer instead of being immediately sent to Claude Desktop, causing a 60-second timeout.
## Implementation Steps
### Step 1: Test Simple Interactive Mode
First, verify if just using `-i` flag solves the issue:
**Update README.md:**
```json
{
"mcpServers": {
"n8n-mcp": {
"command": "docker",
"args": [
"run",
"-i", // Interactive mode - keeps stdin open
"--rm",
"-e", "MCP_MODE=stdio",
"-e", "LOG_LEVEL=error",
"-e", "DISABLE_CONSOLE_OUTPUT=true",
"ghcr.io/czlonkowski/n8n-mcp:latest"
]
}
}
}
```
**Test command:**
```bash
echo '{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2024-11-05"},"id":1}' | \
docker run -i --rm \
-e MCP_MODE=stdio \
-e LOG_LEVEL=error \
-e DISABLE_CONSOLE_OUTPUT=true \
ghcr.io/czlonkowski/n8n-mcp:latest
```
Expected: Should receive a JSON response immediately.
### Step 2: Add Explicit Stdout Flushing (If Needed)
If Step 1 doesn't work, add minimal flushing to the Node.js server:
**File: `src/mcp/server-update.ts`**
Update the `run()` method:
```typescript
async run(): Promise<void> {
await this.ensureInitialized();
const transport = new StdioServerTransport();
await this.server.connect(transport);
// Ensure stdout is not buffered in Docker
if (!process.stdout.isTTY && process.env.IS_DOCKER) {
// Force unbuffered stdout
process.stdout.write('');
}
logger.info('n8n Documentation MCP Server running on stdio transport');
// Keep process alive
process.stdin.resume();
}
```
**File: `Dockerfile`**
Add environment variable:
```dockerfile
ENV IS_DOCKER=true
```
### Step 3: System-Level Unbuffering (Last Resort)
Only if Steps 1-2 fail, implement stdbuf wrapper:
**File: `docker-entrypoint.sh`**
```bash
#!/bin/sh
# Force line buffering for stdio communication
exec stdbuf -oL -eL node /app/dist/mcp/index.js
```
**File: `Dockerfile`**
```dockerfile
# Add stdbuf utility
RUN apk add --no-cache coreutils
# Copy and setup entrypoint
COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
```
## Testing Protocol
### 1. Local Docker Test
```bash
# Build test image
docker build -t n8n-mcp:test .
# Test with echo pipe
echo '{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2024-11-05"},"id":1}' | \
docker run -i --rm n8n-mcp:test | head -1
# Should see immediate JSON response
```
### 2. Claude Desktop Test
1. Update `claude_desktop_config.json` with new configuration
2. Restart Claude Desktop
3. Check Developer tab for "running" status
4. Test a simple MCP command
### 3. Debug if Needed
```bash
# Run with stderr output for debugging
docker run -i --rm \
-e MCP_MODE=stdio \
-e LOG_LEVEL=debug \
ghcr.io/czlonkowski/n8n-mcp:latest 2>debug.log
```
## Success Criteria
- [ ] No timeout errors in Claude Desktop logs
- [ ] MCP tools are accessible immediately
- [ ] No "Shutting down..." messages in stdout
- [ ] Simple `-i` flag configuration works
## Rollout Plan
1. **Test locally** with simple `-i` flag first
2. **Update Docker image** only if code changes needed
3. **Update README** with working configuration
4. **Community announcement** with simple Docker instructions
## Key Insights from Research
- Most MCP Docker deployments work with just `-i` flag
- Complex solutions often unnecessary
- Node.js typically doesn't need explicit unbuffering (unlike Python with `-u`)
- Claude Desktop only supports stdio for local servers (not HTTP)
- Proper testing can quickly identify if buffering is the actual issue
## What NOT to Do
- Don't add TTY flag (`-t`) - it's for terminal UI, not needed for MCP
- Don't implement complex multi-phase solutions
- Don't switch to HTTP transport (Claude Desktop doesn't support it locally)
- Don't modify MCP protocol handling
- Don't add unnecessary wrapper scripts unless proven necessary
The solution should be as simple as possible - likely just the `-i` flag in the Docker command.

View File

@@ -1,252 +0,0 @@
# Docker MCP Initialization Timeout Fix Plan
## Problem Summary
The n8n-MCP Docker container fails to work with Claude Desktop due to MCP initialization timeout:
1. Claude sends `initialize` request
2. Server receives it (logs show "Message from client: {"method":"initialize"...}")
3. Server appears to connect successfully
4. **No response is sent back to Claude**
5. Claude times out after 60 seconds
6. Container outputs "Shutting down..." which breaks JSON-RPC protocol
## Root Cause Analysis
### 1. **Stdout Buffering in Docker**
Docker containers often buffer stdout, especially when not running with TTY (`-t` flag). This is the most likely culprit:
- Node.js/JavaScript may buffer stdout when not connected to a TTY
- Docker's stdout handling differs from direct execution
- The MCP response might be stuck in the buffer
**Evidence:**
- Common Docker issue (moby/moby#1385, docker/compose#1549)
- Python requires `-u` flag for unbuffered output in Docker
- Different base images have different buffering behavior
### 2. **MCP SDK Server Connection Issue**
The server might not be properly completing the connection handshake:
```typescript
const transport = new StdioServerTransport();
await server.connect(transport); // This might not complete properly
```
### 3. **Missing Initialize Handler**
While the MCP SDK should handle `initialize` automatically, there might be an issue with:
- Handler registration order
- Server capabilities configuration
- Transport initialization timing
### 4. **Process Lifecycle Management**
The container might be:
- Exiting too early
- Not keeping the event loop alive
- Missing proper signal handling
## Fixing Plan
### Phase 1: Immediate Fixes (High Priority)
#### 1.1 Force Stdout Flushing
**File:** `src/mcp/server-update.ts`
Add explicit stdout flushing after server connection:
```typescript
async run(): Promise<void> {
await this.ensureInitialized();
const transport = new StdioServerTransport();
await this.server.connect(transport);
// Force flush stdout
if (process.stdout.isTTY === false) {
process.stdout.write('', () => {}); // Force flush
}
logger.info('n8n Documentation MCP Server running on stdio transport');
// Keep process alive
process.stdin.resume();
}
```
#### 1.2 Add TTY Support to Docker
**File:** `Dockerfile`
Add environment variable to detect Docker:
```dockerfile
ENV IS_DOCKER=true
ENV NODE_OPTIONS="--max-old-space-size=2048"
```
**File:** Update Docker command in README
```json
{
"mcpServers": {
"n8n-mcp": {
"command": "docker",
"args": [
"run",
"--rm",
"-i",
"-t", // Add TTY allocation
"--init", // Proper signal handling
"-e", "MCP_MODE=stdio",
"-e", "LOG_LEVEL=error",
"-e", "DISABLE_CONSOLE_OUTPUT=true",
"ghcr.io/czlonkowski/n8n-mcp:latest"
]
}
}
}
```
### Phase 2: Robust Fixes (Medium Priority)
#### 2.1 Implement Explicit Initialize Handler
**File:** `src/mcp/server-update.ts`
Add explicit initialize handler to ensure response:
```typescript
import {
InitializeRequestSchema,
InitializeResult
} from '@modelcontextprotocol/sdk/types.js';
private setupHandlers(): void {
// Add explicit initialize handler
this.server.setRequestHandler(InitializeRequestSchema, async (request) => {
logger.debug('Handling initialize request', request);
const result: InitializeResult = {
protocolVersion: "2024-11-05",
capabilities: {
tools: {}
},
serverInfo: {
name: "n8n-documentation-mcp",
version: "1.0.0"
}
};
// Force immediate flush
if (process.stdout.isTTY === false) {
process.stdout.write('', () => {});
}
return result;
});
// ... existing handlers
}
```
#### 2.2 Add Docker-Specific Stdio Handling
**File:** Create `src/utils/docker-stdio.ts`
```typescript
export class DockerStdioTransport extends StdioServerTransport {
constructor() {
super();
// Disable buffering for Docker
if (process.env.IS_DOCKER === 'true') {
process.stdout.setDefaultEncoding('utf8');
if (process.stdout._handle && process.stdout._handle.setBlocking) {
process.stdout._handle.setBlocking(true);
}
}
}
protected async writeMessage(message: string): Promise<void> {
await super.writeMessage(message);
// Force flush in Docker
if (process.env.IS_DOCKER === 'true') {
process.stdout.write('', () => {});
}
}
}
```
### Phase 3: Alternative Approaches (Low Priority)
#### 3.1 Use Wrapper Script
Create a Node.js wrapper that ensures proper buffering:
**File:** `docker-entrypoint.js`
```javascript
#!/usr/bin/env node
// Disable all buffering
process.stdout._handle?.setBlocking?.(true);
process.stdin.setRawMode?.(false);
// Import and run the actual server
require('./dist/mcp/index.js');
```
#### 3.2 Switch to HTTP Transport for Docker
Consider using HTTP transport instead of stdio for Docker deployments, as it doesn't have buffering issues.
## Testing Plan
1. **Local Testing:**
```bash
# Test with Docker TTY
docker run -it --rm ghcr.io/czlonkowski/n8n-mcp:latest
# Test initialize response
echo '{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2024-11-05"},"id":1}' | \
docker run -i --rm ghcr.io/czlonkowski/n8n-mcp:latest
```
2. **Claude Desktop Testing:**
- Apply fixes incrementally
- Test with each configuration change
- Monitor Claude Desktop logs
3. **Debug Output:**
Add temporary debug logging to stderr:
```typescript
console.error('DEBUG: Received initialize');
console.error('DEBUG: Sending response');
```
## Implementation Priority
1. **Immediate:** Add `-t` flag to Docker command (no code changes)
2. **High:** Force stdout flushing in server code
3. **Medium:** Add explicit initialize handler
4. **Low:** Create Docker-specific transport class
## Success Criteria
- Claude Desktop connects without timeout
- No "Shutting down..." message in JSON stream
- Tools are accessible after connection
- Connection remains stable
## References
- [Docker stdout buffering issue](https://github.com/moby/moby/issues/1385)
- [MCP TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk)
- [Python unbuffered mode in Docker](https://stackoverflow.com/questions/39486327/stdout-being-buffered-in-docker-container)
- [MCP initialization timeout issues](https://github.com/modelcontextprotocol/servers/issues/57)

View File

@@ -1,132 +0,0 @@
# HTTP Server Final Fix Documentation
## Problem Summary
The n8n-MCP HTTP server experienced two critical issues:
1. **"stream is not readable" error** - Caused by Express.json() middleware consuming the request stream
2. **"Server not initialized" error** - Caused by StreamableHTTPServerTransport's internal state management
## Solution Overview
We implemented a two-phase fix:
### Phase 1: Stream Preservation (v2.3.2)
- Removed global `express.json()` middleware
- Allowed StreamableHTTPServerTransport to read raw request stream
- This fixed the "stream is not readable" error but revealed the initialization issue
### Phase 2: Direct JSON-RPC Implementation
- Created `http-server-fixed.ts` that bypasses StreamableHTTPServerTransport
- Implements JSON-RPC protocol directly
- Handles MCP methods: initialize, tools/list, tools/call
- Maintains full protocol compatibility
## Implementation Details
### The Fixed Server (`http-server-fixed.ts`)
```javascript
// Instead of using StreamableHTTPServerTransport
const transport = new StreamableHTTPServerTransport({...});
// We handle JSON-RPC directly
req.on('data', chunk => body += chunk);
req.on('end', () => {
const jsonRpcRequest = JSON.parse(body);
// Handle request based on method
});
```
### Key Features:
1. **No body parsing middleware** - Preserves raw stream
2. **Direct JSON-RPC handling** - Avoids transport initialization issues
3. **Persistent MCP server** - Single instance handles all requests
4. **Manual method routing** - Implements initialize, tools/list, tools/call
### Supported Methods:
- `initialize` - Returns server capabilities
- `tools/list` - Returns available tools
- `tools/call` - Executes specific tools
## Usage
### Environment Variables:
- `MCP_MODE=http` - Enable HTTP mode
- `USE_FIXED_HTTP=true` - Use the fixed implementation
- `AUTH_TOKEN` - Authentication token (32+ chars recommended)
### Starting the Server:
```bash
# Local development
MCP_MODE=http USE_FIXED_HTTP=true AUTH_TOKEN=your-secure-token npm start
# Docker
docker run -d \
-e MCP_MODE=http \
-e USE_FIXED_HTTP=true \
-e AUTH_TOKEN=your-secure-token \
-p 3000:3000 \
ghcr.io/czlonkowski/n8n-mcp:latest
```
### Testing:
```bash
# Initialize
curl -X POST http://localhost:3000/mcp \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-secure-token" \
-d '{"jsonrpc":"2.0","method":"initialize","params":{},"id":1}'
# List tools
curl -X POST http://localhost:3000/mcp \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-secure-token" \
-d '{"jsonrpc":"2.0","method":"tools/list","id":2}'
# Call tool
curl -X POST http://localhost:3000/mcp \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-secure-token" \
-d '{"jsonrpc":"2.0","method":"tools/call","params":{"name":"get_node_info","arguments":{"nodeType":"httpRequest"}},"id":3}'
```
## Technical Details
### Why StreamableHTTPServerTransport Failed
1. **Stateful Design**: The transport expects to maintain session state
2. **Initialization Sequence**: Requires specific handshake before accepting requests
3. **Stream Consumption**: Conflicts with Express middleware patterns
4. **Version Issues**: Despite fixes in v1.10.1+, issues persist with stateless usage
### Why Direct Implementation Works
1. **No Middleware Conflicts**: We control the entire request lifecycle
2. **No State Requirements**: Each request is handled independently
3. **Protocol Compliance**: Still implements standard JSON-RPC 2.0
4. **Simplicity**: Fewer moving parts mean fewer failure points
## Performance Characteristics
- **Memory Usage**: ~10-20MB base, grows with database queries
- **Response Time**: <50ms for most operations
- **Concurrent Requests**: Handles multiple requests without session conflicts
- **Database Access**: Single persistent connection, no connection overhead
## Future Considerations
1. **Streaming Support**: Current implementation doesn't support SSE streaming
2. **Session Management**: Could add optional session tracking if needed
3. **Protocol Extensions**: Easy to add new JSON-RPC methods
4. **Migration Path**: Can switch back to StreamableHTTPServerTransport when fixed
## Conclusion
The fixed implementation provides a stable, production-ready HTTP server for n8n-MCP that:
- Works reliably without stream errors
- Maintains MCP protocol compatibility
- Simplifies debugging and maintenance
- Provides better performance characteristics
This solution demonstrates that sometimes bypassing problematic libraries and implementing core functionality directly is the most pragmatic approach.

View File

@@ -1,32 +0,0 @@
# Docker Fix for v2.6.2 - Missing Runtime Dependencies
## Issue
After v2.6.0, the Docker image started failing with:
```
Error: Cannot find module 'axios'
```
## Root Cause
In v2.6.0, we added n8n management tools that require:
- `axios` - For HTTP API calls to n8n instances
- `zod` - For workflow validation schemas
However, our ultra-optimized Docker image uses `package.runtime.json` which didn't include these new dependencies.
## Fix
Updated `package.runtime.json` to include:
```json
"axios": "^1.10.0",
"zod": "^3.25.32"
```
## Impact
- Docker image size increases slightly (~5MB) but remains much smaller than full n8n dependencies
- No changes needed to Dockerfile itself - just the runtime package list
- Users need to pull the latest Docker image after rebuild
## Prevention
When adding new features that require additional npm packages, always check:
1. Is the package needed at runtime?
2. If yes, add it to `package.runtime.json` for Docker builds
3. Test the Docker image before release

View File

@@ -1,135 +0,0 @@
# Phase 2 Improvements - v2.4.2
## 🎯 Overview
Following the successful implementation of operation-aware validation, Phase 2 adds professional-grade features that make the validation system even more powerful and flexible.
## ✅ Implemented Features
### 1. **Validation Profiles** 🎨
Different validation levels for different use cases:
```typescript
validate_node_operation({
nodeType: "nodes-base.slack",
config: { ... },
profile: "minimal" // or "runtime", "ai-friendly", "strict"
})
```
#### Available Profiles:
| Profile | Purpose | What it checks |
|---------|---------|----------------|
| **minimal** | Quick check | Only missing required fields |
| **runtime** | Pre-execution | Critical errors + security warnings |
| **ai-friendly** | Balanced (default) | Errors + helpful warnings |
| **strict** | Code review | Everything + best practices |
### 2. **New Node Validators** 🔧
Added comprehensive validators for commonly used nodes:
#### **Webhook Validator**
- Path format validation (no spaces, special chars)
- Response mode checks
- HTTP method validation
- Authentication warnings
#### **PostgreSQL Validator**
- SQL injection detection
- DELETE/UPDATE without WHERE warnings
- Operation-specific validation (insert, update, delete, execute)
- Query safety checks
#### **MySQL Validator**
- Similar to PostgreSQL
- MySQL-specific syntax checks
- Timezone configuration suggestions
### 3. **validate_node_minimal Tool** ⚡
Lightning-fast validation for just required fields:
```json
{
"nodeType": "nodes-base.slack",
"displayName": "Slack",
"valid": false,
"missingRequiredFields": ["Channel"]
}
```
- No warnings
- No suggestions
- No examples
- Just missing required fields
- Perfect for quick checks
### 4. **SQL Safety Features** 🛡️
Comprehensive SQL query validation:
- Detects template expressions that could be vulnerable
- Warns about DELETE/UPDATE without WHERE
- Catches dangerous operations (DROP, TRUNCATE)
- Suggests parameterized queries
- Database-specific checks (PostgreSQL $$ quotes, MySQL backticks)
## 📊 Impact
### Before Phase 2:
- Single validation mode
- Limited node coverage (4 nodes)
- No SQL safety checks
- Fixed validation behavior
### After Phase 2:
- 4 validation profiles for different needs
- 7+ nodes with specific validators
- Comprehensive SQL injection prevention
- Flexible validation based on use case
- Ultra-fast minimal validation option
## 🚀 Usage Examples
### Using Validation Profiles:
```javascript
// Quick check - just required fields
validate_node_minimal({
nodeType: "nodes-base.webhook",
config: { responseMode: "lastNode" }
})
// Result: Missing required field "path"
// Pre-execution validation
validate_node_operation({
nodeType: "nodes-base.postgres",
config: {
operation: "execute",
query: "DELETE FROM users WHERE id = ${userId}"
},
profile: "runtime"
})
// Result: SQL injection warning
// Strict validation for code review
validate_node_operation({
nodeType: "nodes-base.slack",
config: { /* valid config */ },
profile: "strict"
})
// Result: Suggestions for best practices
```
## 🎉 Summary
Phase 2 transforms the validation system from a simple checker into a comprehensive validation framework:
1. **Flexibility** - Choose validation level based on your needs
2. **Safety** - SQL injection detection and prevention
3. **Speed** - Minimal validation for quick checks
4. **Coverage** - More nodes with specific validation logic
5. **Intelligence** - Context-aware suggestions and warnings
The validation system now provides professional-grade safety and flexibility while maintaining the simplicity that makes it useful for AI agents.