Enables execution of C++ code using OnlineGDB's online compiler, including running code with custom input, testing solutions against multiple test cases, code optimization analysis, and test case generation for competitive programming problems.
Supports solving Data Structures and Algorithms problems from Codeforces through C++ code execution and automated testing capabilities.
Supports solving Data Structures and Algorithms problems from LeetCode through C++ code execution and automated testing capabilities.
OnlineGDB MCP Server for C++ Code Execution
A HTTP-based Model Context Protocol (MCP) server that enables AI agents to execute C++ code using OnlineGDB's online compiler. Perfect for solving Data Structures and Algorithms (DSA) problems from competitive programming sites like Codeforces, LeetCode, etc.
Note: This server uses HTTP transport instead of STDIO for better reliability and easier integration.
Features
Core Functionality
Execute C++ Code: Run C++ code with custom input using OnlineGDB compiler
Submit Solutions: Test complete solutions against multiple test cases
Code Optimization: Analyze code for performance improvements
Test Case Generation: Generate comprehensive test cases for problems
Agent Capabilities
Self-Correction: Agent can execute code, see errors, and iterate on solutions
Multiple Test Cases: Validate solutions against various inputs
Performance Analysis: Get execution time and memory usage feedback
Error Handling: Detailed compilation and runtime error reporting
Installation
Clone and Setup
Build the Project
Install Dependencies The server requires Puppeteer for browser automation:
Usage
Starting the Server
The server will start on port 3000 (or PORT environment variable) and provide:
HTTP MCP Protocol endpoint:
POST /mcpREST API endpoints:
GET /tools/list,GET /healthWeb interface:
GET /
Available Tools
1. execute_cpp_code
Execute C++ code with optional input:
2. submit_solution
Test a complete solution against multiple test cases:
3. optimize_code
Analyze code for performance improvements:
4. generate_test_cases
Generate test cases for a problem:
Integration with AI Agents
Claude MCP Configuration
Add to your Claude MCP configuration (use HTTP transport instead of STDIO):
Option 1: HTTP Transport (Recommended)
Option 2: Direct HTTP calls in your MCP client
Agent Workflow Example
Problem Analysis: Agent receives a coding problem
Solution Development: Agent writes initial C++ solution
Code Execution: Agent uses
execute_cpp_codeto test basic functionalityComprehensive Testing: Agent uses
submit_solutionwith multiple test casesError Analysis: If tests fail, agent analyzes errors and iterates
Optimization: Agent uses
optimize_codeto improve performanceFinal Validation: Agent runs final solution against all test cases
Example Agent Conversation
Code Templates
Basic C++ Template for Competitive Programming
Function-Based Template
Testing
Run Comprehensive Tests
Manual Testing
Troubleshooting
Common Issues
Server won't start
Check if port 3000 is already in use
Set PORT environment variable:
PORT=3001 npm startEnsure dependencies are installed:
npm install
Puppeteer Installation Fails
Ensure you have the required system dependencies
Try
npm install puppeteer --unsafe-perm=true
OnlineGDB Not Loading
Check internet connection
OnlineGDB might be temporarily unavailable
Try increasing timeout limits
Code Execution Timeouts
Increase
timeLimitparameterCheck for