Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4a8cc58
fixes
ANC-DOMINATER Sep 1, 2025
f6122b8
Fix routing: Mount endpoints at root path instead of /code-runner
ANC-DOMINATER Sep 1, 2025
15293e1
Add /mcp endpoint alias for MCP Inspector compatibility
ANC-DOMINATER Sep 1, 2025
996fe3c
Fix MCP message route path for root mounting
ANC-DOMINATER Sep 1, 2025
fe184e4
Fix: Use local source code instead of JSR package in Docker
ANC-DOMINATER Sep 2, 2025
7e12bc4
Migrate from SSE to Streamable HTTP for MCP transport
ANC-DOMINATER Sep 2, 2025
e46d8f9
Fix MCP endpoint: Add basic JSON-RPC response for testing
ANC-DOMINATER Sep 2, 2025
6767b89
Fix: Remove duplicate controller file and use correct MCP implementat…
ANC-DOMINATER Sep 2, 2025
4cc82c9
Remove fallbacks: Only expose actual server capabilities and tools
ANC-DOMINATER Sep 2, 2025
fc8496c
Implement proper MCP JSON-RPC protocol with tools/list and tools/call…
ANC-DOMINATER Sep 2, 2025
b546b36
Fix MCP protocol implementation: update to 2025-06-18, direct tool ex…
ANC-DOMINATER Sep 2, 2025
2c676f1
update 2.0
ANC-DOMINATER Sep 2, 2025
75261b8
Add CORS support for n8n MCP client connectivity - enable browser-bas…
ANC-DOMINATER Sep 2, 2025
5646b76
Add protocol version negotiation and debugging for n8n compatibility
ANC-DOMINATER Sep 2, 2025
2ae3c8d
Revert "Add protocol version negotiation and debugging for n8n compat…
ANC-DOMINATER Sep 2, 2025
0d5cc59
update fixes
ANC-DOMINATER Sep 2, 2025
43285ab
Add debugging and n8n compatibility - protocol version negotiation an…
ANC-DOMINATER Sep 2, 2025
daa2895
Fix MCP protocol: proper version negotiation, improved error handling…
ANC-DOMINATER Sep 4, 2025
03169e4
Fix Python execution errors: add robust error handling, input validat…
ANC-DOMINATER Sep 4, 2025
e55b022
Fix HTTP 504 timeout issues in MCP server
ANC-DOMINATER Sep 24, 2025
6bee317
Add enhanced debugging and connection headers for MCP client compatib…
ANC-DOMINATER Sep 24, 2025
cd67766
Add comprehensive MCP diagnostic endpoints
ANC-DOMINATER Sep 24, 2025
6ae34eb
Fix TypeScript type errors across the codebase
ANC-DOMINATER Sep 24, 2025
ab22c32
Manual updates to MCP controller and Dockerfile
ANC-DOMINATER Sep 24, 2025
982eb01
Fix TypeScript compilation errors for deployment
ANC-DOMINATER Sep 24, 2025
e2424b1
πŸš€ Production-ready MCP server with comprehensive type fixes
ANC-DOMINATER Sep 24, 2025
50c416b
πŸ› Fix Pyodide micropip initialization issues
ANC-DOMINATER Sep 24, 2025
2ef34ed
feat: Add n8n hybrid MCP protocol compatibility
ANC-DOMINATER Sep 24, 2025
a08da16
fix: Add string unescaping for n8n compatibility - fixes Python synta…
ANC-DOMINATER Sep 24, 2025
bc2219d
fix: Improve micropip loading and CDN reliability
ANC-DOMINATER Sep 24, 2025
ea36715
fix: Simplify Pyodide initialization to use default CDN
ANC-DOMINATER Sep 24, 2025
292d9ee
fix: Add comprehensive error handling and timeouts to prevent crashes
ANC-DOMINATER Sep 24, 2025
bcefeb4
fix: Disable automatic package loading for production stability
ANC-DOMINATER Sep 24, 2025
02cb5e2
feat: Implement hybrid Pyodide/micropip package loading
ANC-DOMINATER Sep 24, 2025
1a5420d
fix: Correct Python health check to properly report status
ANC-DOMINATER Sep 24, 2025
69d33d7
feat: Pin Pyodide to v0.26.2 for Python 3.12 stability
ANC-DOMINATER Sep 24, 2025
b71f560
feat: downgrade to Python 3.12 for stability and fix TypeScript errors
ANC-DOMINATER Sep 24, 2025
315fb2e
feat: optimize for cloud deployment with better timeouts
ANC-DOMINATER Sep 24, 2025
efaf526
fix: revert to simple deployment config to fix cloud startup
ANC-DOMINATER Sep 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .do/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Simple DigitalOcean App Platform configuration
name: code-runner-mcp
services:
- name: web
source_dir: /
github:
repo: ANC-DOMINATER/code-runner-mcp
branch: main
deploy_on_push: true
dockerfile_path: Dockerfile
http_port: 9000
instance_count: 1
instance_size_slug: basic-xxs
envs:
- key: PORT
value: "9000"
- key: DENO_PERMISSION_ARGS
value: "--allow-net"
- key: NODEFS_ROOT
value: "/tmp"
- key: NODEFS_MOUNT_POINT
value: "/tmp"
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.do
TEST_SUMMARY.md
PULL_REQUEST_TEMPLATE.md

# Test files
test-mcp.bat
test-mcp.ps1
test-mcp.js
test-mcp.py
79 changes: 79 additions & 0 deletions DEPLOY_DIGITALOCEAN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# πŸš€ Deploy to DigitalOcean App Platform

## Quick & Simple Deployment (5 minutes)

### Step 1: Prepare Your Repository
Ensure your code is pushed to GitHub:
```bash
git add .
git commit -m "Prepare for DigitalOcean deployment"
git push origin main
```

### Step 2: Deploy via DigitalOcean Console
1. Go to [DigitalOcean App Platform](https://cloud.digitalocean.com/apps)
2. Click **"Create App"**
3. Connect your GitHub repository: `ANC-DOMINATER/code-runner-mcp`
4. Choose branch: `main`
5. Auto-deploy on push: βœ… **Enabled**

### Step 3: Configure App Settings
**Service Configuration:**
- **Service Type**: Web Service
- **Source**: Dockerfile
- **HTTP Port**: 9000
- **Instance Size**: Basic ($5/month)
- **Instance Count**: 1

**Environment Variables:**
```
PORT=9000
DENO_PERMISSION_ARGS=--allow-net
NODEFS_ROOT=/tmp
NODEFS_MOUNT_POINT=/tmp
```

### Step 4: Deploy
Click **"Create Resources"** - Deployment will take 3-5 minutes.

## 🎯 What You Get
- βœ… **Automatic HTTPS** certificate
- βœ… **Custom domain** support (yourapp.ondigitalocean.app)
- βœ… **Auto-scaling** based on traffic
- βœ… **Health monitoring** with automatic restarts
- βœ… **Zero-downtime** deployments
- βœ… **Integrated logging** and metrics

## πŸ’° Cost
- **Basic Plan**: $5/month for 512MB RAM, 1 vCPU
- **Scales automatically** based on usage
- **Pay only for what you use**

## πŸ”— Access Your API
Once deployed, your MCP server will be available at:
```
https://your-app-name.ondigitalocean.app
```

**MCP Inspector Connection:**
- **Transport Type**: Streamable HTTP βœ… (Recommended)
- **URL**: `https://monkfish-app-9ciwk.ondigitalocean.app/mcp`

**API Endpoints:**
- Root: `https://your-app-name.ondigitalocean.app/`
- Health: `https://your-app-name.ondigitalocean.app/health`
- Documentation: `https://your-app-name.ondigitalocean.app/docs`
- **MCP (Streamable HTTP)**: `https://your-app-name.ondigitalocean.app/mcp` βœ…
- MCP Messages: `https://your-app-name.ondigitalocean.app/messages`
- ~~SSE (Deprecated)~~: `https://your-app-name.ondigitalocean.app/sse`

## πŸ”„ Auto-Deployment
Every push to `main` branch automatically triggers a new deployment.

## πŸ“Š Monitor Your App
- View logs in DigitalOcean console
- Monitor performance metrics
- Set up alerts for downtime

---
**That's it! Your MCP server is live! πŸŽ‰**
28 changes: 25 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
FROM denoland/deno:latest

# Set environment variables for better performance with Python 3.12
ENV DENO_DIR=/deno-cache
ENV DENO_INSTALL_ROOT=/usr/local
ENV NODE_ENV=production

# Create working directory
WORKDIR /app

RUN deno cache jsr:@mcpc/code-runner-mcp
# Create deno cache directory with proper permissions
RUN mkdir -p /deno-cache && chmod 755 /deno-cache

# Copy dependency files first for better caching
COPY deno.json ./

# Copy your local source code
COPY . .

# Cache the main server file and dependencies
RUN deno cache src/server.ts || echo "Cache completed"

# Expose port
EXPOSE 9000

# Simple health check for cloud deployment
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD curl -f http://localhost:9000/health || exit 1

# Run the app
ENTRYPOINT ["deno", "run", "--allow-all", "jsr:@mcpc/code-runner-mcp/bin"]
# Run the server with simplified configuration
ENTRYPOINT ["deno", "run", "--allow-all", "src/server.ts"]
170 changes: 170 additions & 0 deletions PULL_REQUEST.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# 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

- **Platform**: DigitalOcean App Platform
- **URL**: https://monkfish-app-9ciwk.ondigitalocean.app
- **Status**: βœ… Successfully deployed and working
- **Repository**: Forked to `ANC-DOMINATER/code-runner-mcp` for deployment

## πŸ”§ Technical Changes

### 1. MCP Protocol Implementation (`src/controllers/mcp.controller.ts`)

**Before**:
- Used outdated protocol version `2024-11-05`
- Relied on `handleConnecting` function causing timeouts
- Tools were not executing (MCP error -32001: Request timed out)

**After**:
- βœ… Updated to latest protocol version `2025-06-18`
- βœ… Direct tool execution without routing through `handleConnecting`
- βœ… Proper JSON-RPC responses matching MCP specification
- βœ… Fixed timeout issues - tools now execute successfully

```typescript
// New implementation handles tools/call directly:
if (body.method === "tools/call") {
const { name, arguments: args } = body.params;

if (name === "python-code-runner") {
const stream = await runPy(args.code, options);
// Process stream and return results...
}
}
```

### 2. Server Architecture (`src/server.ts`, `src/app.ts`)

**Changes**:
- Fixed routing to mount endpoints at root path instead of `/code-runner`
- Simplified server initialization
- Removed complex routing layers that caused 404 errors

### 3. Docker Configuration

**Before**: Used JSR package installation
```dockerfile
RUN deno install -A -n code-runner-mcp jsr:@mcpc/code-runner-mcp
```

**After**: Uses local source code
```dockerfile
COPY . .
RUN deno cache src/server.ts
ENTRYPOINT ["deno", "run", "--allow-all", "src/server.ts"]
```

### 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
- **Problem**: MCP error -32001 (Request timed out) when executing tools
- **Root Cause**: `handleConnecting` function caused routing loops
- **Solution**: Direct tool execution with proper stream handling

### Issue 2: Protocol Version Mismatch
- **Problem**: Using outdated MCP protocol version
- **Solution**: Updated to `2025-06-18` per official specification

### Issue 3: Deployment Issues
- **Problem**: JSR package installation failed, repository access denied
- **Solution**: Forked repository, use local source code in Docker

### Issue 4: Routing Problems
- **Problem**: 404 errors due to incorrect path mounting
- **Solution**: Mount all endpoints at root path

## πŸ§ͺ Testing Results

All MCP protocol methods now work correctly:

### βœ… Initialize
```bash
curl -X POST "/mcp" -d '{"jsonrpc": "2.0", "id": 1, "method": "initialize"}'
# Returns: Protocol version 2025-06-18, proper capabilities
```

### βœ… Tools List
```bash
curl -X POST "/mcp" -d '{"jsonrpc": "2.0", "id": 2, "method": "tools/list"}'
# Returns: python-code-runner, javascript-code-runner with schemas
```

### βœ… Tool Execution
```bash
# Python execution
curl -X POST "/mcp" -d '{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "python-code-runner",
"arguments": {"code": "print(\"Hello World!\")"}
}
}'
# Returns: {"content":[{"type":"text","text":"Hello World!"}]}

# JavaScript execution
curl -X POST "/mcp" -d '{
"jsonrpc": "2.0",
"id": 4,
"method": "tools/call",
"params": {
"name": "javascript-code-runner",
"arguments": {"code": "console.log(\"Hello JS!\")"}
}
}'
# Returns: {"content":[{"type":"text","text":"Hello JS!\n"}]}
```

## πŸ“ Files Changed

- `src/controllers/mcp.controller.ts` - **New**: Complete MCP protocol implementation
- `src/controllers/register.ts` - Updated routing registration
- `src/server.ts` - Simplified server setup
- `src/app.ts` - Cleaned up app initialization
- `Dockerfile` - Changed to use local source code
- `.do/app.yaml` - DigitalOcean deployment configuration

## πŸ” Code Quality

- βœ… Proper error handling with JSON-RPC error codes
- βœ… TypeScript type safety maintained
- βœ… Stream processing for tool execution
- βœ… Environment variable support
- βœ… Clean separation of concerns

## 🚦 Deployment Status

- **Build**: βœ… Successful
- **Health Check**: βœ… Passing (`/health` endpoint)
- **MCP Protocol**: βœ… All methods working
- **Tool Execution**: βœ… Both Python and JavaScript runners working
- **Performance**: βœ… No timeout issues

## πŸ“‹ Migration Notes

For users upgrading:
1. MCP clients should use protocol version `2025-06-18`
2. Endpoint remains `/mcp` for JSON-RPC requests
3. Tool schemas unchanged - backward compatible
4. No breaking changes to tool execution API

## πŸŽ‰ Result

The MCP server is now fully functional and deployed to DigitalOcean:
- **URL**: https://monkfish-app-9ciwk.ondigitalocean.app/mcp
- **Status**: Production ready
- **Tools**: Python and JavaScript code execution working
- **Protocol**: Latest MCP specification compliant

This implementation provides a robust, scalable code execution service via the Model Context Protocol, suitable for AI assistants and automation tools.
Loading