-
Notifications
You must be signed in to change notification settings - Fork 2
Update 2.0 #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ANC-DOMINATER
wants to merge
39
commits into
mcpc-tech:main
Choose a base branch
from
ANC-DOMINATER:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Update 2.0 #4
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Replace SSE handler with streamable HTTP handler at /mcp endpoint - Keep /sse for backward compatibility (redirects to /mcp) - Update documentation to reflect modern MCP transport - Rename controller file to reflect new functionality
…ecution, remove handleConnecting timeout issues
…ibility" This reverts commit 5646b76.
…d request logging
…, and spec-compliant responses
…ion, and output limits
- Implement lazy Pyodide initialization to prevent server startup blocking - Add 60-second timeout protection for Python runtime initialization - Enhance error handling with proper JSON-RPC error responses - Add comprehensive health monitoring and request logging - Optimize Dockerfile for faster startup and better caching - Add execution timeout protection (4 minutes total) - Improve server robustness with global error handling - Add test script for validating MCP server functionality Fixes: HTTP 504 Gateway Timeout errors on DigitalOcean deployment Resolves: Python runtime initialization blocking server requests
…ility - Add keep-alive and cache-control headers for better client compatibility - Implement comprehensive request/response logging with timing - Add unique request IDs for better debugging - Enhanced error tracking with elapsed time measurements - Improved JSON-RPC error response formatting This should help diagnose and resolve MCP Client connection issues.
- Add /mcp-test endpoint for basic connectivity testing - Add /mcp-simple endpoint that returns immediate responses - Add streaming MCP handler for better client compatibility - Enhanced root endpoint with debug information - Add transfer-encoding chunked headers for streaming support These diagnostic endpoints will help identify the root cause of the MCP Client 504 errors.
- Add explicit type annotations (any) for Hono context parameters - Add Deno global declaration to fix compilation - Fix all controller parameter types in register.ts, mcp.controller.ts - Fix server.ts middleware and error handler types - Fix mcp-stream.controller.ts parameter types This resolves all the implicit 'any' type errors while maintaining functionality.
- Updated mcp.controller.ts with manual improvements - Updated Dockerfile configuration
✅ Type System & Error Resolution: - Added comprehensive type declarations for Deno, Hono, and Pyodide - Created src/types/deno.d.ts with full runtime type support - Created src/types/hono.d.ts with OpenAPIHono integration - Resolved all TypeScript compilation errors 🏗️ Production Architecture: - Added centralized config system (src/config.ts) with timeouts, limits, constants - Implemented structured logging with request tracking and performance monitoring - Added production-ready error handling with proper JSON-RPC responses - Enhanced security with comprehensive CORS and validation 🧹 Code Optimization: - Removed duplicate mcp-stream.controller.ts (redundant functionality) - Consolidated MCP protocol implementation - Simplified SSE controller with proper redirects - Eliminated duplicate imports and code patterns 🔧 Enhanced Features: - Full MCP Protocol 2025-06-18 compliance with backward compatibility - Request size validation (50KB code, 100MB output limits) - Execution timeouts (4min Python, 1min JavaScript) - Memory-efficient streaming with output truncation - Comprehensive health checks and monitoring endpoints
✅ Fixed Python Runtime Issues: - Fixed getPip() function to properly load micropip package before importing - Removed premature micropip loading from background initialization - Added better error handling and retry logic for micropip failures - Only load micropip when actually needed for package installation 🔧 Improvements: - Enhanced error messages and logging for Python runtime issues - More resilient dependency loading with graceful fallbacks - Prevents network timeout issues during server startup - Better separation of Pyodide core initialization vs package management This resolves the 'No module named micropip' error during server startup.
- Add COMPATIBILITY flags for legacy parameter support - Implement flexible parameter parsing (arguments/params/args) - Add n8n-specific compatibility headers and debug endpoint - Fix TypeScript compilation errors in MCP controller - Update DOM type definitions to resolve conflicts - Add test files to .gitignore
…x error from escaped newlines
- Add multiple CDN fallbacks for Pyodide package loading - Improve micropip loading with timeout protection - Add warning messages when package installation fails - Better error handling for network connectivity issues - Continues code execution even when packages can't be installed
- Remove complex CDN fallback logic that was causing issues - Use default Pyodide configuration for reliable package loading - Fix micropip loading by using standard initialization - Eliminate timeout promises that caused unhandled rejections
- Add timeout protection for micropip loading (30s) - Add timeout protection for package installation (60s batch, 30s individual) - Return null from getPip() instead of throwing when micropip fails - Wrap entire loadDeps() function in try-catch to prevent crashes - Add separate error handling for import analysis - Ensure server stability even when package loading fails completely
- Automatic package analysis and loading was causing server crashes - Keep loadDeps() improvements but only use when explicitly requested - Only attempt package installation when importToPackageMap is provided - This ensures server stability while still supporting manual package installation - Users can install packages manually in their code using micropip if needed
- Re-enable automatic package loading with smart hybrid approach - Pyodide packages (numpy, pandas, nltk, scipy, etc.) use loadPackage() - Other packages (sklearn, tensorflow, etc.) use micropip.install() - Proper distinction prevents crashes while enabling full functionality - Added comprehensive timeout protection (60s for Pyodide, 30s for micropip) - Maintains backward compatibility with importToPackageMap parameter - Should resolve nltk and sklearn import issues for user workflows
- Health check was using non-blocking Promise that never updated response - Changed to blocking Python status check with proper timeout - Added fallback check using getPyodide() to verify actual Pyodide availability - Python component should now properly report 'healthy' when initialized - Resolves issue where Python showed 'initializing' indefinitely
- Use specific Pyodide version 0.26.2 which includes Python 3.12 - Python 3.12 is more stable and has better package compatibility - Should resolve compatibility issues with newer Python 3.13 features - Reloaded dependencies to ensure correct version is used
- Downgraded Pyodide from 0.28.0 (Python 3.13.2) to 0.26.2 (Python 3.12.x) - Enhanced hybrid package loading: pyodidePackages vs micropipMappings - Fixed DOM type conflicts by replacing HTMLElement with Element - Resolved Node.js/Deno compatibility issues by removing node:process imports - Replaced process.env with Deno.env.get() and process.exit with Deno.exit() - Fixed ReadableStream async iterator issues with proper reader handling - Updated type references and compiler configuration for better compatibility - All TypeScript compilation errors resolved for stable Python 3.12 deployment
- Updated Dockerfile to use Pyodide 0.26.2 (Python 3.12) and longer health check timeouts - Reduced execution timeouts for n8n compatibility (90s Python, 30s JS) - Added Python warmup service for faster first-request performance - Implemented background pre-loading of common packages (nltk, sklearn) - Enhanced health check with warmup status reporting - Added timeout configurations for package loading (45s total, 20s individual) - Better cloud platform timeout handling for 504 error prevention
- Removed complex warmup service causing cloud deployment failures - Simplified server startup without background Python initialization - Fixed health check to not block on Python status during startup - Streamlined Dockerfile with faster health check intervals - Python packages will load on-demand as before (working approach) - Maintains Python 3.12 + optimized timeouts for n8n compatibility
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix MCP Protocol Implementation and Deploy to DigitalOcean
🎯 Overview
This PR fixes critical issues with the Model Context Protocol (MCP) implementation and successfully deploys the code-runner-mcp server to DigitalOcean App Platform. The changes resolve timeout errors, update to the latest MCP protocol version, and ensure proper tool execution.
🚀 Deployment
ANC-DOMINATER/code-runner-mcpfor deployment🔧 Technical Changes
1. MCP Protocol Implementation (
src/controllers/mcp.controller.ts)Before:
2024-11-05handleConnectingfunction causing timeoutsAfter:
2025-06-18handleConnecting2. Server Architecture (
src/server.ts,src/app.ts)Changes:
/code-runner3. Docker Configuration
Before: Used JSR package installation
RUN deno install -A -n code-runner-mcp jsr:@mcpc/code-runner-mcpAfter: Uses local source code
4. Transport Protocol Migration
Before: Server-Sent Events (SSE) - deprecated
After: Streamable HTTP with proper JSON-RPC handling
🛠️ Fixed Issues
Issue 1: MCP Tools Not Working
handleConnectingfunction caused routing loopsIssue 2: Protocol Version Mismatch
2025-06-18per official specificationIssue 3: Deployment Issues
Issue 4: Routing Problems
🧪 Testing Results
All MCP protocol methods now work correctly:
✅ Initialize
✅ Tools List
✅ Tool Execution
📁 Files Changed
src/controllers/mcp.controller.ts- New: Complete MCP protocol implementationsrc/controllers/register.ts- Updated routing registrationsrc/server.ts- Simplified server setupsrc/app.ts- Cleaned up app initializationDockerfile- Changed to use local source code.do/app.yaml- DigitalOcean deployment configuration🔍 Code Quality
🚦 Deployment Status
/healthendpoint)📋 Migration Notes
For users upgrading:
2025-06-18/mcpfor JSON-RPC requests🎉 Result
The MCP server is now fully functional and deployed to DigitalOcean:
This implementation provides a robust, scalable code execution service via the Model Context Protocol, suitable for AI assistants and automation tools.