Skip to content

VB9331/mcp_server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

c_compile MCP服务部署文档

1. 项目结构

d:\codeWork\mcp_server\c_compile
│
├── server.py           # MCP服务主程序
├── pyproject.toml      # Python项目配置
├── uv.lock             # 依赖锁定文件
├── .python-version     # Python版本说明
├── README.md           # 本文档
├── .gitignore
├── c_test_output.exe   # 示例编译输出
└── c_test/
    ├── function.c
    ├── function.h
    ├── libc_test.lib
    └── main.c

2. 环境准备

2.1 安装 Python

建议使用 Python 3.8 及以上版本。可通过 Python 官网 下载并安装。

2.2 安装依赖

进入 c_compile 目录,执行:

pip install uv

2.3 安装 GCC 编译器

  • Windows 推荐 MSYS2MinGW-w64
  • 安装后请将 gcc 所在目录加入系统 PATH 环境变量。

2.4 安装 MCP 相关依赖

确保已安装 mcp.server.fastmcp 相关包:

pip install modelcontextprotocol

3. 启动服务

c_compile 目录下运行:

uv run server.py

python server.py

服务将以 MCP stdio 模式启动。

4. MCP 服务配置示例

cline_mcp_settings.json 中配置如下:

"c_compile": {
  "timeout": 60,
  "type": "stdio",
  "command": "uv",
  "args": [
    "--directory",
    "D:\\codeWork\\mcp_server\\c_compile",
    "run",
    "server.py"
  ]
}

5. 服务功能说明

  • 支持多文件 C 源码编译
  • 支持生成可执行文件、静态库(.a/.lib)
  • 支持链接静态库并执行
  • 支持参数自定义输出文件名

6. 示例调用

编译可执行文件

{
  "method": "compile",
  "params": {
    "source_files": [
      "c_test/main.c",
      "c_test/function.c"
    ],
    "output_name": "c_test_output.exe"
  }
}

生成静态库

{
  "method": "create_static_lib",
  "params": {
    "source_files": [
      "c_test/function.c"
    ],
    "lib_name": "libc_test.a"
  }
}

编译并链接静态库并执行

{
  "method": "compile_with_static_lib",
  "params": {
    "source_files": [
      "c_test/main.c"
    ],
    "lib_files": [
      "c_test/libc_test.a"
    ],
    "output_name": "c_test_output.exe"
  }
}

7. 常见问题

  • 找不到 gcc 命令:请检查 gcc 是否安装并已加入 PATH。
  • 权限问题:确保有写入输出目录的权限。
  • 依赖缺失:请根据报错信息补充安装相关 Python 包或 C 头文件。

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors