Allows for the compilation of C++ code and retrieval of the resulting assembly output, supporting various compiler options and MSVC.
Provides an interface to the Compiler Explorer (godbolt.org) API to compile code and fetch assembly results through a Model Context Protocol tool.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@CPPCon MCP ServerShow me the assembly for int square(int x) { return x * x; } with /O2"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
CPPCon MCP Server
This project implements a Model Context Protocol (MCP) server that provides a tool to compile C++ code using the Compiler Explorer (godbolt.org) API. It allows clients to request the assembly output for given C++ code and compiler options, supporting both standard tool invocation and Server-Sent Events (SSE) for streaming results.
Features
MCP Compliant: Built using
mcp-server[fastmcp], ensuring adherence to the Model Context Protocol.get_assemblyExposes a tool that compiles C++ code using MSVC (via godbolt.org) and returns the generated assembly.SSE Support: Provides a Server-Sent Events endpoint (
/sse) for streaming compilation status and results.Tool Discovery: Exposes a
/capabilitiesendpoint for clients to discover available tools and their schemas.Client Messaging: Supports a
/messageendpoint for general client-to-server communication.
Setup
Prerequisites
Python 3.11 or higher
Installation
Create a virtual environment (recommended):
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`Install dependencies:
pip install "mcp-server[fastmcp]" uvicorn requests pydantic
Running the Server
To start the MCP server, execute the server.py script:
The server will run on http://127.0.0.1:8000 by default.
Usage
The server exposes several endpoints compliant with the Model Context Protocol.
1. Get Server Capabilities
Clients can discover the server's capabilities, including available tools, by sending a GET request to the /capabilities endpoint.
2. Invoke get_assembly Tool (Standard POST)
To get the assembly output for C++ code in a single request/response cycle, send a POST request to the /tool/get_assembly endpoint.
Example Request:
3. Stream get_assembly Results (Server-Sent Events)
For streaming compilation status and results, connect to the /sse endpoint using GET. The code and options for compilation are passed as URL query parameters. An optional sessionId can also be provided for client tracking.
Example Request:
The server will stream events in the following format:
In case of an error, an event: error will be sent:
4. Send Client Messages
Clients can send general messages to the server via a POST request to the /message endpoint. These messages can be used for various client-initiated communications.
Example Request:
The server will respond with: