编译器资源服务

一个基于Model Context Protocol (MCP)的服务,提供对Godbolt Compiler Explorer REST API端点的访问,支持多种编程语言的编译和代码格式化功能。

  • by Benestar
  • Python
  • 本地部署
  • 6 星标
  • 更新于
在 GitHub 查看 Benestar/godbolt-mcp

使用说明

Godbolt编译器浏览器MCP

A. 模型上下文协议(MCP) 提供访问权限的服务器 Godbolt编译器资源管理器 REST API端点。与 FastMCP Python库。

安装

  1. 克隆此存储库:
git clone <repository-url>
cd godbolt-mcp
  1. 创建并激活虚拟环境:
python -m venv venv
source venv/bin/activate
  1. 安装依赖项:
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客户端