diff --git a/servers/cmake_mcp/mcp-rpm.yaml b/servers/cmake_mcp/mcp-rpm.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a4992229a9697f92b221e8d6702b37b7abffd7ab --- /dev/null +++ b/servers/cmake_mcp/mcp-rpm.yaml @@ -0,0 +1,23 @@ +name: "cmake_mcp" +summary: "CMake构建工具MCP服务" +description: | + 提供CMake项目配置、构建、安装和清理功能的MCP服务 + 支持以下功能: + - 配置CMake项目 + - 构建项目(支持并行构建) + - 安装构建目标 + - 清理构建目录 + +dependencies: + system: + - python3 + - python3-mcp + - cmake + - make + - gcc + - gcc-c++ + +files: + required: + - mcp_config.json + - src/server.py \ No newline at end of file diff --git a/servers/cmake_mcp/mcp_config.json b/servers/cmake_mcp/mcp_config.json new file mode 100644 index 0000000000000000000000000000000000000000..45df2d9d6fed42194a43585221c7d363d53047a4 --- /dev/null +++ b/servers/cmake_mcp/mcp_config.json @@ -0,0 +1,18 @@ +{ + "mcpServers": { + "cmake_mcp": { + "command": "uv", + "args": [ + "--directory", + "/opt/mcp-servers/servers/cmake_mcp/src", + "run", + "server.py" + ], + "disabled": false, + "autoApprove": [ + "*" + ], + "description": "提供CMake构建工具链的MCP服务" + } + } +} \ No newline at end of file diff --git a/servers/cmake_mcp/src/server.py b/servers/cmake_mcp/src/server.py new file mode 100644 index 0000000000000000000000000000000000000000..12cd806d4e765387fe1d8b62a5a4d9fad4cf02f7 --- /dev/null +++ b/servers/cmake_mcp/src/server.py @@ -0,0 +1,91 @@ +import os +import subprocess +from mcp.server.fastmcp import FastMCP + +mcp = FastMCP("CMake构建工具") + +def run_cmd(cmd: list, cwd: str = None) -> dict: + """执行命令并返回结果""" + try: + result = subprocess.run( + cmd, + cwd=cwd, + check=True, + capture_output=True, + text=True + ) + return {"status": "success", "output": result.stdout} + except subprocess.CalledProcessError as e: + return {"error": str(e), "output": e.stderr} + +@mcp.tool() +def configure(project_path: str, build_type: str = "Debug", build_dir: str = "build") -> dict: + """ + 配置CMake项目 + :param project_path: 项目根目录路径(包含CMakeLists.txt) + :param build_type: 构建类型(Debug|Release|RelWithDebInfo|MinSizeRel) + :param build_dir: 构建目录名称(相对于项目路径) + :return: 执行结果字典 + """ + full_build_dir = os.path.join(project_path, build_dir) + os.makedirs(full_build_dir, exist_ok=True) + + cmake_cmd = [ + "cmake", + f"-DCMAKE_BUILD_TYPE={build_type}", + ".." + ] + return run_cmd(cmake_cmd, full_build_dir) + +@mcp.tool() +def build(project_path: str, build_dir: str = "build", target: str = None, parallel: int = None) -> dict: + """ + 构建CMake项目 + :param project_path: 项目根目录路径 + :param build_dir: 构建目录名称 + :param target: 指定构建目标(可选) + :param parallel: 并行构建线程数(可选) + :return: 执行结果字典 + """ + full_build_dir = os.path.join(project_path, build_dir) + build_cmd = ["cmake", "--build", "."] + + if target: + build_cmd.extend(["--target", target]) + if parallel: + build_cmd.extend(["--parallel", str(parallel)]) + + return run_cmd(build_cmd, full_build_dir) + +@mcp.tool() +def install(project_path: str, build_dir: str = "build", prefix: str = None) -> dict: + """ + 安装构建目标 + :param project_path: 项目根目录路径 + :param build_dir: 构建目录名称 + :param prefix: 安装前缀路径(可选) + :return: 执行结果字典 + """ + full_build_dir = os.path.join(project_path, build_dir) + install_cmd = ["cmake", "--install", "."] + + if prefix: + install_cmd.extend(["--prefix", prefix]) + + return run_cmd(install_cmd, full_build_dir) + +@mcp.tool() +def clean(project_path: str, build_dir: str = "build") -> dict: + """ + 清理构建目录 + :param project_path: 项目根目录路径 + :param build_dir: 构建目录名称 + :return: 执行结果字典 + """ + full_build_dir = os.path.join(project_path, build_dir) + if os.path.exists(full_build_dir): + return run_cmd(["cmake", "--build", ".", "--target", "clean"], full_build_dir) + return {"status": "skipped", "message": f"构建目录 {build_dir} 不存在"} + +if __name__ == "__main__": + mcp.run() \ No newline at end of file diff --git a/servers/cross_distro_packaging_mcp/mcp-rpm.yaml b/servers/cross_distro_packaging_mcp/mcp-rpm.yaml new file mode 100644 index 0000000000000000000000000000000000000000..3ffec8598fa332caa50eb13ff183b3631970c655 --- /dev/null +++ b/servers/cross_distro_packaging_mcp/mcp-rpm.yaml @@ -0,0 +1,19 @@ +name: "cross_distro_packaging_mcp" +summary: "跨发行版打包MCP Server" +description: | + 提供跨发行版打包功能 + +dependencies: + system: + - python3 + - docker-compose + - python3-mcp + packages: + - rpm-build + +files: + required: + - mcp_config.json + - src/server.py + optional: + - src/requirements.txt diff --git a/servers/cross_distro_packaging_mcp/mcp_config.json b/servers/cross_distro_packaging_mcp/mcp_config.json new file mode 100644 index 0000000000000000000000000000000000000000..29102a698cfe68118a09c23193fd5463f0589c50 --- /dev/null +++ b/servers/cross_distro_packaging_mcp/mcp_config.json @@ -0,0 +1,17 @@ +{ + "mcpServers": { + "dependency_analyzer_mcp": { + "command": "uv", + "args": [ + "--directory", + "/opt/mcp-servers/servers/cross_distro_packaging_mcp/src", + "run", + "server.py" + ], + "disabled": false, + "alwaysAllow": [ + ] + } + } +} + diff --git a/servers/cross_distro_packaging_mcp/src/server.py b/servers/cross_distro_packaging_mcp/src/server.py new file mode 100644 index 0000000000000000000000000000000000000000..b9ddeff4ed21f0b9d3ba6298af9da125868f9c44 --- /dev/null +++ b/servers/cross_distro_packaging_mcp/src/server.py @@ -0,0 +1,101 @@ +import os +import subprocess +import json +from mcp.server.fastmcp import FastMCP + +mcp = FastMCP("跨发行版打包工具") + +def build_with_fpm(source_dir, package_name, version, output_format="rpm"): + """ + 使用fpm工具构建软件包 + :param source_dir: 源代码目录 + :param package_name: 包名 + :param version: 版本号 + :param output_format: 输出格式(rpm/deb等) + :return: 构建结果 + """ + try: + # 检查是否需要sudo权限 + need_sudo = False + if any(path.startswith(('/usr', '/etc', '/var', '/opt')) + for path in [source_dir] + + [os.path.join(source_dir, f) for f in os.listdir(source_dir)]): + need_sudo = True + + cmd = ['fpm', '-s', 'dir', '-t', output_format, + '-n', package_name, '-v', version, + '-C', source_dir] + + if need_sudo: + cmd = ['sudo'] + cmd + + result = subprocess.run( + cmd, + check=True, capture_output=True, text=True + ) + return { + "status": "success", + "output": result.stdout, + "package": f"{package_name}-{version}.{output_format}" + } + except subprocess.CalledProcessError as e: + return {"status": "error", "error": str(e), "output": e.stderr} + +def build_with_checkinstall(source_dir, package_name, version): + """ + 使用checkinstall构建安装包 + :param source_dir: 源代码目录 + :param package_name: 包名 + :param version: 版本号 + :return: 构建结果 + """ + try: + os.chdir(source_dir) + result = subprocess.run( + ['checkinstall', '--pkgname', package_name, + '--pkgversion', version, '--default'], + check=True, capture_output=True, text=True + ) + return { + "status": "success", + "output": result.stdout, + "package": f"{package_name}-{version}.rpm" + } + except subprocess.CalledProcessError as e: + return {"status": "error", "error": str(e), "output": e.stderr} + +@mcp.tool() +def build_rpm_package(source_dir: str, package_name: str, version: str) -> dict: + """ + 构建RPM包 + :param source_dir: 源代码目录路径 + :param package_name: 包名 + :param version: 版本号 + :return: 构建结果(JSON格式) + """ + return build_with_fpm(source_dir, package_name, version, "rpm") + +@mcp.tool() +def build_deb_package(source_dir: str, package_name: str, version: str) -> dict: + """ + 构建DEB包 + :param source_dir: 源代码目录路径 + :param package_name: 包名 + :param version: 版本号 + :return: 构建结果(JSON格式) + """ + return build_with_fpm(source_dir, package_name, version, "deb") + +@mcp.tool() +def build_with_checkinstall_tool(source_dir: str, package_name: str, version: str) -> dict: + """ + 使用checkinstall构建安装包 + :param source_dir: 源代码目录路径 + :param package_name: 包名 + :param version: 版本号 + :return: 构建结果(JSON格式) + """ + return build_with_checkinstall(source_dir, package_name, version) + +if __name__ == "__main__": + mcp.run() \ No newline at end of file diff --git a/servers/ctest_mcp/README.md b/servers/ctest_mcp/README.md new file mode 100644 index 0000000000000000000000000000000000000000..c7a50b873efdc97e764849440f10e0f143e81341 --- /dev/null +++ b/servers/ctest_mcp/README.md @@ -0,0 +1,48 @@ +# CMake测试工具MCP服务器 + +基于ctest命令的MCP服务器,提供CMake测试套件管理功能。 + +## 功能 + +- 运行CMake测试套件 +- 列出所有可用测试 +- 生成测试覆盖率报告 +- 支持并行测试 +- 支持测试过滤和超时设置 + +## 安装 + +1. 确保已安装CMake和ctest: + ```bash + sudo yum install cmake + ``` + +2. 安装Python依赖: + ```bash + pip install -r src/requirements.txt + ``` + +## 使用示例 + +```bash +# 运行所有测试 +mcp ctest-mcp run_tests --build_dir /path/to/build_dir + +# 运行特定测试 +mcp ctest-mcp run_tests --build_dir /path/to/build_dir --tests test1 test2 + +# 并行运行测试 +mcp ctest-mcp run_tests --build_dir /path/to/build_dir --parallel 4 + +# 列出所有测试 +mcp ctest-mcp list_tests --build_dir /path/to/build_dir + +# 生成覆盖率报告 +mcp ctest-mcp test_coverage --build_dir /path/to/build_dir +``` + +## 工具函数说明 + +- `run_tests(build_dir, tests=None, parallel=None, output_on_failure=True, verbose=False, timeout=None)`: 运行CMake测试套件 +- `list_tests(build_dir, verbose=False)`: 列出所有可用测试 +- `test_coverage(build_dir, output_file=None)`: 生成测试覆盖率报告 \ No newline at end of file diff --git a/servers/ctest_mcp/mcp-rpm.yaml b/servers/ctest_mcp/mcp-rpm.yaml new file mode 100644 index 0000000000000000000000000000000000000000..03e336e6c9dc0acfeec870299ba80e21084e007d --- /dev/null +++ b/servers/ctest_mcp/mcp-rpm.yaml @@ -0,0 +1,24 @@ +name: "ctest-mcp" +summary: "MCP server for CMake test management" +description: | + Provides MCP tools for managing CMake test suites, + including running tests, listing available tests, + and generating test coverage reports. + +dependencies: + system: + - python3 + - uv + - python3-mcp + - jq + - cmake + packages: + - rpm-build + +files: + required: + - mcp_config.json + - src/server.py + optional: + - src/requirements.txt + - README.md \ No newline at end of file diff --git a/servers/ctest_mcp/mcp_config.json b/servers/ctest_mcp/mcp_config.json new file mode 100644 index 0000000000000000000000000000000000000000..4d4004d95ac5bc2e5dafb25d15438b39937ef5d4 --- /dev/null +++ b/servers/ctest_mcp/mcp_config.json @@ -0,0 +1,16 @@ +{ + "mcpServers": { + "ctestMcp": { + "command": "uv", + "args": [ + "--directory", + "/opt/mcp-servers/servers/ctestMcp/src", + "run", + "server.py" + ], + "disabled": false, + "alwaysAllow": [ + ] + } + } +} \ No newline at end of file diff --git a/servers/ctest_mcp/src/requirements.txt b/servers/ctest_mcp/src/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..9452262868f47ad45ed20202a17970f217fb669d --- /dev/null +++ b/servers/ctest_mcp/src/requirements.txt @@ -0,0 +1,2 @@ +fastmcp>=1.0.0 +pydantic>=1.10.0 \ No newline at end of file diff --git a/servers/ctest_mcp/src/server.py b/servers/ctest_mcp/src/server.py new file mode 100644 index 0000000000000000000000000000000000000000..f2c847d5e7657d15ec76892d9adb2d889f64c455 --- /dev/null +++ b/servers/ctest_mcp/src/server.py @@ -0,0 +1,139 @@ +#!/usr/bin/env python3 +# 标准库导入 +import argparse +import json +import os +import subprocess +from pathlib import Path +from typing import Any, Dict, List, Optional + +# 第三方库导入 +from pydantic import Field + +# 本地模块导入 +from mcp.server.fastmcp import FastMCP + +mcp = FastMCP("ctestMcp") + +@mcp.tool() +def run_tests( + build_dir: str = Field(..., description="CMake构建目录路径"), + tests: Optional[List[str]] = Field(default=None, description="要运行的测试名称列表(默认运行所有)"), + parallel: Optional[int] = Field(default=None, description="并行测试数量"), + output_on_failure: bool = Field(default=True, description="测试失败时显示输出"), + verbose: bool = Field(default=False, description="详细输出模式"), + timeout: Optional[int] = Field(default=None, description="单个测试超时时间(秒)") +) -> Dict[str, Any]: + """运行CMake测试套件 + + 示例用法: + 1. 运行所有测试: run_tests build_dir=/path/to/build + 2. 运行特定测试: run_tests build_dir=/path/to/build tests=["test1","test2"] + 3. 并行运行测试: run_tests build_dir=/path/to/build parallel=4 + """ + cmd = ["ctest", "--test-dir", build_dir] + + if tests: + cmd.extend(["-R", "|".join(tests)]) + + if parallel: + cmd.extend(["-j", str(parallel)]) + + if output_on_failure: + cmd.append("--output-on-failure") + + if verbose: + cmd.append("-VV") + + if timeout: + cmd.extend(["--timeout", str(timeout)]) + + try: + result = subprocess.run( + cmd, + capture_output=True, + text=True, + check=False # 测试失败时返回非零状态码 + ) + + return { + "success": True, + "output": result.stdout.strip(), + "error": result.stderr.strip(), + "exit_code": result.returncode + } + except Exception as e: + return { + "success": False, + "error": str(e) + } + +@mcp.tool() +def list_tests( + build_dir: str = Field(..., description="CMake构建目录路径"), + verbose: bool = Field(default=False, description="显示详细测试信息") +) -> Dict[str, Any]: + """列出所有可用测试 + + 示例用法: + 1. 列出测试: list_tests build_dir=/path/to/build + 2. 详细列表: list_tests build_dir=/path/to/build verbose=true + """ + cmd = ["ctest", "--test-dir", build_dir, "-N"] + + if verbose: + cmd.append("-V") + + try: + result = subprocess.run( + cmd, + capture_output=True, + text=True, + check=True + ) + return {"success": True, "output": result.stdout.strip()} + except subprocess.CalledProcessError as e: + return {"success": False, "error": e.stderr.strip()} + except Exception as e: + return {"success": False, "error": str(e)} + +@mcp.tool() +def test_coverage( + build_dir: str = Field(..., description="CMake构建目录路径"), + output_file: Optional[str] = Field(default=None, description="覆盖率输出文件路径") +) -> Dict[str, Any]: + """生成测试覆盖率报告 + + 示例用法: + 1. 生成覆盖率: test_coverage build_dir=/path/to/build + 2. 指定输出文件: test_coverage build_dir=/path/to/build output_file=coverage.xml + """ + cmd = ["ctest", "--test-dir", build_dir, "-T", "Coverage"] + + if output_file: + cmd.extend(["--output", output_file]) + + try: + result = subprocess.run( + cmd, + capture_output=True, + text=True, + check=False # 覆盖率可能返回非零状态码 + ) + return { + "success": True, + "output": result.stdout.strip(), + "error": result.stderr.strip(), + "exit_code": result.returncode + } + except Exception as e: + return {"success": False, "error": str(e)} + +def init_config(): + """初始化配置""" + # 这里可以添加服务初始化逻辑 + pass + +if __name__ == "__main__": + init_config() + mcp.run() \ No newline at end of file diff --git a/servers/dep_to_rpm_mcp/mcp-rpm.yaml b/servers/dep_to_rpm_mcp/mcp-rpm.yaml new file mode 100644 index 0000000000000000000000000000000000000000..decae60d0b1b9c9c0386368882237dba03ab0bbf --- /dev/null +++ b/servers/dep_to_rpm_mcp/mcp-rpm.yaml @@ -0,0 +1,20 @@ +name: "dep-to-rpm" +summary: "MCP server for changing dep files to rpm files" +description: | + Provides tools for changing dep files to rpm files + +dependencies: + system: + - python3 + - uv + - python3-mcp + - rpm + - dnf + - python3-pip + +files: + required: + - mcp_config.json + - src/server.py + optional: + - src/requirements.txt diff --git a/servers/dep_to_rpm_mcp/mcp_config.json b/servers/dep_to_rpm_mcp/mcp_config.json new file mode 100644 index 0000000000000000000000000000000000000000..36a069de54699e39f4077678c8f7a00a5514bb69 --- /dev/null +++ b/servers/dep_to_rpm_mcp/mcp_config.json @@ -0,0 +1,16 @@ +{ + "mcpServers": { + "dependency_analyzer_mcp": { + "command": "uv", + "args": [ + "--directory", + "/opt/mcp-servers/servers/dep_to_rpm_mcp/src", + "run", + "server.py" + ], + "disabled": false, + "alwaysAllow": [ + ] + } + } +} diff --git a/servers/dep_to_rpm_mcp/src/server.py b/servers/dep_to_rpm_mcp/src/server.py new file mode 100644 index 0000000000000000000000000000000000000000..b68c3a6e6c63d29668811ac8b7bce0cfc35419ba --- /dev/null +++ b/servers/dep_to_rpm_mcp/src/server.py @@ -0,0 +1,117 @@ +import os +import subprocess +import json +import logging +from pathlib import Path +from typing import Optional, TypedDict +from mcp.server.fastmcp import FastMCP + +# 初始化日志 +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) + +# 子进程调用通用参数 +SUBPROCESS_KWARGS = { + 'check': True, + 'capture_output': True, + 'text': True, + 'encoding': 'utf-8' +} + +class ConversionResult(TypedDict, total=False): + status: str + output: str + rpm_file: str + error: str + +mcp = FastMCP("deb转rpm工具") + +def check_dependencies() -> bool: + """检查是否安装了alien和rpm-build + + Returns: + bool: 如果所有依赖都安装返回True,否则返回False + """ + tools = ['alien', 'rpmbuild'] + missing = [] + + for tool in tools: + try: + subprocess.run([tool, '--version'], **SUBPROCESS_KWARGS) + except (subprocess.CalledProcessError, FileNotFoundError) as e: + logger.error(f"依赖检查失败: {tool} 未安装") + missing.append(tool) + + if missing: + logger.error(f"缺少必要依赖: {', '.join(missing)}") + return False + return True + +def convert_deb_to_rpm(deb_path: str, output_dir: Optional[str] = None) -> ConversionResult: + """将deb包转换为rpm包 + + Args: + deb_path: deb包路径 + output_dir: 输出目录(可选) + + Returns: + ConversionResult: 包含转换结果或错误信息的字典 + """ + deb_path_obj = Path(deb_path) + if not deb_path_obj.exists(): + error_msg = f"文件 {deb_path} 不存在" + logger.error(error_msg) + return {"error": error_msg} + + if not check_dependencies(): + error_msg = "缺少依赖: 请先安装alien和rpm-build" + logger.error(error_msg) + return {"error": error_msg} + + try: + cmd = ['alien', '-r', str(deb_path_obj)] + if output_dir: + output_dir_obj = Path(output_dir) + output_dir_obj.mkdir(parents=True, exist_ok=True) + cmd.extend(['--output-dir', str(output_dir_obj)]) + + logger.info(f"开始转换: {deb_path}") + result = subprocess.run(cmd, **SUBPROCESS_KWARGS) + + rpm_file = deb_path_obj.with_suffix('.rpm') + if output_dir: + rpm_file = output_dir_obj / rpm_file.name + + logger.info(f"转换成功: 生成RPM文件 {rpm_file}") + return { + "status": "success", + "output": result.stdout, + "rpm_file": str(rpm_file) + } + except subprocess.CalledProcessError as e: + logger.error(f"转换失败: {e.stderr}") + return { + "error": str(e), + "output": e.stderr + } + except Exception as e: + logger.error(f"转换过程中发生意外错误: {str(e)}") + return { + "error": f"内部错误: {str(e)}" + } + +@mcp.tool() +def deb_to_rpm(deb_path: str, output_dir: Optional[str] = None) -> ConversionResult: + """将deb包转换为rpm包 + + Args: + deb_path: deb包路径 + output_dir: 输出目录(可选) + + Returns: + dict: 转换结果(JSON格式) + """ + return convert_deb_to_rpm(deb_path, output_dir) + +if __name__ == "__main__": + mcp.run() \ No newline at end of file diff --git a/servers/gcc_mcp/mcp-rpm.yaml b/servers/gcc_mcp/mcp-rpm.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9684d62e77e9aa3b8b95972459e00dcf83c463d9 --- /dev/null +++ b/servers/gcc_mcp/mcp-rpm.yaml @@ -0,0 +1,19 @@ +name: "gcc_mcp" +summary: "gcc编译管理工具" +description: | + GCC编译管理工具,提供以下功能:1、列出GCC常用编译选项(优化/警告/调试等) 2、使用指定选项编译源代码 3、获取GCC版本信息 4、支持多种C/C++标准 5、生成可执行文件或共享库 + + +dependencies: + system: + - python3 + - uv + - python3-mcp + - firewalld + +files: + required: + - mcp_config.json + - src/gcc_mcp.py + optional: + - src/requirements.txt diff --git a/servers/gcc_mcp/mcp_config.json b/servers/gcc_mcp/mcp_config.json new file mode 100644 index 0000000000000000000000000000000000000000..105a612347bed6d91e1e7b1f3ecaced550f39fd4 --- /dev/null +++ b/servers/gcc_mcp/mcp_config.json @@ -0,0 +1,15 @@ +{ + "mcpServers": { + "firewall_manager_mcp": { + "command": "uv", + "args": [ + "--directory", + "/opt/mcp-servers/servers/gcc_mcp/src", + "run", + "gcc_mcp.py" + ], + "disabled": false, + "alwaysAllow": [] + } + } +} diff --git a/servers/gcc_mcp/src/gcc_mcp.py b/servers/gcc_mcp/src/gcc_mcp.py new file mode 100644 index 0000000000000000000000000000000000000000..b5a2ec8ba86fb3ed77795243dc15aa26c83a03e8 --- /dev/null +++ b/servers/gcc_mcp/src/gcc_mcp.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python3 +import subprocess +from typing import List, Dict, Optional +from mcp.server.fastmcp import FastMCP, Context + +mcp = FastMCP("GCC Compiler Options Manager") + +# GCC常用编译选项分类 +GCC_OPTIONS = { + "optimization": [ + {"name": "-O0", "description": "不优化(默认)"}, + {"name": "-O1", "description": "基本优化"}, + {"name": "-O2", "description": "更多优化"}, + {"name": "-O3", "description": "激进优化"}, + {"name": "-Os", "description": "优化代码大小"}, + {"name": "-Ofast", "description": "快速优化(可能违反标准)"} + ], + "warning": [ + {"name": "-Wall", "description": "启用所有常见警告"}, + {"name": "-Wextra", "description": "启用额外警告"}, + {"name": "-Werror", "description": "将警告视为错误"}, + {"name": "-w", "description": "禁用所有警告"} + ], + "debug": [ + {"name": "-g", "description": "生成调试信息"}, + {"name": "-ggdb", "description": "生成GDB专用调试信息"}, + {"name": "-g3", "description": "生成更多调试信息"} + ], + "language": [ + {"name": "-std=c89", "description": "C89标准"}, + {"name": "-std=c99", "description": "C99标准"}, + {"name": "-std=c11", "description": "C11标准"}, + {"name": "-std=c++98", "description": "C++98标准"}, + {"name": "-std=c++11", "description": "C++11标准"}, + {"name": "-std=c++14", "description": "C++14标准"}, + {"name": "-std=c++17", "description": "C++17标准"}, + {"name": "-std=c++20", "description": "C++20标准"} + ], + "other": [ + {"name": "-shared", "description": "生成共享库"}, + {"name": "-fPIC", "description": "位置无关代码"}, + {"name": "-pthread", "description": "支持多线程"}, + {"name": "-D", "description": "定义宏"}, + {"name": "-I", "description": "添加头文件搜索路径"}, + {"name": "-L", "description": "添加库文件搜索路径"}, + {"name": "-l", "description": "链接指定库"} + ] +} + +@mcp.tool() +def list_options(ctx: Context, category: Optional[str] = None) -> Dict: + """列出GCC编译选项""" + if category: + if category in GCC_OPTIONS: + return {category: GCC_OPTIONS[category]} + return {"error": f"Invalid category: {category}"} + return GCC_OPTIONS + +@mcp.tool() +def compile(ctx: Context, source: str, options: List[str], output: Optional[str] = None) -> Dict: + """使用指定选项编译源代码""" + cmd = ["gcc", source] + if output: + cmd.extend(["-o", output]) + cmd.extend(options) + + try: + result = subprocess.run( + cmd, + check=True, + capture_output=True, + text=True + ) + return { + "status": "success", + "output": result.stdout.strip(), + "executable": output if output else "a.out" + } + except subprocess.CalledProcessError as e: + return { + "status": "error", + "error": e.stderr.strip() + } + +@mcp.tool() +def get_version(ctx: Context) -> str: + """获取GCC版本信息""" + try: + result = subprocess.run( + ["gcc", "--version"], + check=True, + capture_output=True, + text=True + ) + return result.stdout.split('\n')[0] + except subprocess.CalledProcessError as e: + return f"Error: {e.stderr.strip()}" + +if __name__ == "__main__": + mcp.run() \ No newline at end of file diff --git a/servers/isocut_mcp/mcp-rpm.yaml b/servers/isocut_mcp/mcp-rpm.yaml index fa453ab34e6c88802f01365e7233cbf35e9f2a97..da52b1689ba364fae7a99ca47560b89d5feb88e4 100644 --- a/servers/isocut_mcp/mcp-rpm.yaml +++ b/servers/isocut_mcp/mcp-rpm.yaml @@ -2,19 +2,34 @@ name: isocutmcp version: 1.0.0 release: 1 summary: MCP server for ISO customization tools +description: | + This MCP Server provides tools for customizing ISO images, + including: + 1、ISO content modification + 2、Boot configuration + 3、Package management + 4、Custom script injection + license: MIT vendor: Your Company packager: Your Name -requires: - - python3 >= 3.6 - - isocut - - python3-fastmcp +dependencies: + system: + - python3 >= 3.6 + - isocut + - python3-fastmcp + - python3-mcp + packages: + - rpm-build files: - - /opt/isocutmcp/msrc/server.py - - /opt/isocutmcp/msrc/mcp_config.json - - /opt/isocutmcp/README.md + required: + - /opt/isocutmcp/src/server.py + - /opt/isocutmcp/mcp_config.json + optional: + - /opt/isocutmcp/README.md + - /opt/isocutmcp/src/requirements.txt postinstall: | #!/bin/bash diff --git a/servers/json_parser_mcp/mcp-rpm.yaml b/servers/json_parser_mcp/mcp-rpm.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2e90e974d3facbf84c50fce5d045f688dc24884b --- /dev/null +++ b/servers/json_parser_mcp/mcp-rpm.yaml @@ -0,0 +1,19 @@ +name: "json_parser_mcp" +summary: "json打包解包工具" +description: | + JSON解析和处理MCP服务,提供以下功能:1、JSON格式化:支持缩进控制和键排序 2、JSON查询:使用jq语法提取数据 3、格式验证:检查JSON有效性 4、格式转换:支持转为CSV/YAML/XML + + +dependencies: + system: + - python3 + - uv + - python3-mcp + - firewalld + +files: + required: + - mcp_config.json + - src/server.py + optional: + - src/requirements.txt diff --git a/servers/json_parser_mcp/mcp_config.json b/servers/json_parser_mcp/mcp_config.json new file mode 100644 index 0000000000000000000000000000000000000000..b2d25ac69a5473c2d3cd5e029d10291dab861b02 --- /dev/null +++ b/servers/json_parser_mcp/mcp_config.json @@ -0,0 +1,15 @@ +{ + "mcpServers": { + "firewall_manager_mcp": { + "command": "uv", + "args": [ + "--directory", + "/opt/mcp-servers/servers/json_parser_mcp/src", + "run", + "server.py" + ], + "disabled": false, + "alwaysAllow": [] + } + } +} diff --git a/servers/json_parser_mcp/src/server.py b/servers/json_parser_mcp/src/server.py new file mode 100644 index 0000000000000000000000000000000000000000..3dcddf8b67a228a355a84233c2fbb57ed7fa75bc --- /dev/null +++ b/servers/json_parser_mcp/src/server.py @@ -0,0 +1,162 @@ +#!/usr/bin/env python3 +from pydantic import Field +from typing import Dict, Any, Optional, Union +from mcp.server.fastmcp import FastMCP +import subprocess +import json +import argparse +import os +from pathlib import Path + +mcp = FastMCP("jsonParserMcp") + +@mcp.tool() +def format_json( + input_data: Union[str, Dict[str, Any]] = Field(..., description="要格式化的JSON字符串或字典"), + indent: int = Field(default=2, ge=0, le=8, description="缩进空格数 (0-8)"), + sort_keys: bool = Field(default=False, description="是否按键名排序") +) -> Dict[str, Any]: + """格式化JSON数据 + + 示例用法: + 1. 格式化JSON字符串: format_json input_data='{"name":"John","age":30}' + 2. 带缩进和排序: format_json input_data='{"b":2,"a":1}' indent=4 sort_keys=true + """ + # 输入校验 + if not input_data: + return {"success": False, "error": "输入数据不能为空"} + + # 预处理输入数据 + if isinstance(input_data, str): + if not input_data.strip(): + return {"success": False, "error": "JSON字符串不能为空"} + try: + data = json.loads(input_data) + except json.JSONDecodeError as e: + return {"success": False, "error": f"无效的JSON格式: {str(e)}"} + else: + data = input_data + + # 核心格式化逻辑 + try: + formatted = json.dumps( + data, + indent=indent, + sort_keys=sort_keys, + ensure_ascii=False + ) + except TypeError as e: + return {"success": False, "error": f"数据序列化失败: {str(e)}"} + + return {"success": True, "formatted": formatted} + +@mcp.tool() +def query_json( + input_data: Union[str, Dict] = Field(..., description="要查询的JSON数据"), + jq_filter: str = Field(..., description="jq过滤表达式"), + raw_output: bool = Field(default=False, description="返回原始字符串而非JSON") +) -> Dict[str, Any]: + """使用jq语法查询JSON数据 + + 示例用法: + 1. 获取所有名字: query_json input_data='{"users":[{"name":"John"}]}' jq_filter='.users[].name' + 2. 原始输出: query_json input_data='{"a":1}' jq_filter='.a' raw_output=true + """ + try: + if isinstance(input_data, dict): + input_str = json.dumps(input_data) + else: + input_str = input_data + + cmd = ["jq", jq_filter] + result = subprocess.run( + cmd, + input=input_str, + capture_output=True, + text=True, + check=True + ) + + if raw_output: + return {"success": True, "result": result.stdout.strip()} + else: + return {"success": True, "result": json.loads(result.stdout)} + except subprocess.CalledProcessError as e: + return {"success": False, "error": e.stderr.strip()} + except Exception as e: + return {"success": False, "error": str(e)} + +@mcp.tool() +def validate_json( + input_data: str = Field(..., description="要验证的JSON字符串") +) -> Dict[str, Any]: + """验证JSON格式是否正确 + + 示例用法: + 1. 验证JSON: validate_json input_data='{"valid":true}' + """ + try: + json.loads(input_data) + return {"success": True} + except json.JSONDecodeError as e: + return {"success": False, "error": str(e)} + except Exception as e: + return {"success": False, "error": str(e)} + +@mcp.tool() +def convert_json( + input_data: Union[str, Dict, List] = Field(..., description="输入数据"), + to_format: str = Field(..., description="目标格式(csv, yaml, xml)"), + options: Optional[Dict] = Field(default=None, description="转换选项") +) -> Dict[str, Any]: + """将JSON转换为其他格式 + + 示例用法: + 1. 转CSV: convert_json input_data='[{"a":1},{"a":2}]' to_format=csv + 2. 转YAML: convert_json input_data='{"key":"value"}' to_format=yaml + """ + try: + if isinstance(input_data, str): + data = json.loads(input_data) + else: + data = input_data + + if to_format == "csv": + import csv + import io + output = io.StringIO() + if isinstance(data, list): + writer = csv.DictWriter(output, fieldnames=data[0].keys()) + writer.writeheader() + writer.writerows(data) + else: + writer = csv.writer(output) + for k, v in data.items(): + writer.writerow([k, v]) + return {"success": True, "result": output.getvalue()} + + elif to_format == "yaml": + import yaml + return {"success": True, "result": yaml.dump(data)} + + elif to_format == "xml": + from dicttoxml import dicttoxml + return {"success": True, "result": dicttoxml(data).decode()} + + else: + return {"success": False, "error": f"不支持的格式: {to_format}"} + + except Exception as e: + return {"success": False, "error": str(e)} + +def init_config(): + """初始化配置""" + # 检查jq是否安装 + try: + subprocess.run(["jq", "--version"], check=True, capture_output=True) + except Exception: + print("警告: jq工具未安装,部分功能可能受限") + +if __name__ == "__main__": + init_config() + mcp.run() \ No newline at end of file