Godbolt编译器浏览器MCP
A. 模型上下文协议(MCP) 提供访问权限的服务器 Godbolt编译器资源管理器 REST API端点。与 FastMCP Python库。
安装
- 克隆此存储库:
git clone
cd godbolt-mcp- 创建并激活虚拟环境:
python -m venv venv
source venv/bin/activate- 安装依赖项:
pip install -r requirements.txt用法
独立使用
直接运行MCP服务器:
python godbolt_mcp.py添加到MCP兼容代理
将服务器添加到MCP配置中(使用虚拟环境Python):
{
"mcpServers": {
"godbolt-compiler-explorer": {
"command": "/absolute/path/to/godbolt-mcp/venv/bin/python",
"args": ["/absolute/path/to/godbolt-mcp/godbolt_mcp.py"]
}
}
}备注:替换 /absolute/path/to/godbolt-mcp 使用安装目录的实际绝对路径。
可用工具
资源(只读访问)
resource://languages-列出所有支持的编程语言resource://compilers/{language_id}-获取特定语言的可用编译器resource://libraries/{language_id}-获取特定语言的可用库resource://formats-列出可用的代码格式化程序resource://asm/{instruction_set}/{opcode}-获取装配说明文档resource://version-获取编译器资源管理器版本信息
工具(动作)
compile_code(compiler_id, source, user_arguments=None, files=None, libraries=None)-编译源代码compile_cmake(compiler_id, source, user_arguments=None, files=None, libraries=None)-编译CMake项目format_code(formatter, source)-格式化源代码
例子
这 examples/ 文件夹包含可用于测试MCP服务器的示例源文件:
hello.cpp-简单的C++“Hello World”程序hello.rs-简单的Rust“Hello World”程序
使用MCP兼容代理尝试以下提示,为示例文件生成汇编代码:
以C++为例:
Compile the hello.cpp file from the examples folder with GCC and show me the exact generated assembly code with optimization level -O2.以Rust为例:
Compile the hello.rs file from the examples folder with the latest Rust compiler and show me the exact generated assembly code with release optimizations.依赖项
fastmcp>=0.2.0-MCP服务器框架httpx>=0.25.0-API请求的HTTP客户端
