Skip to main content
Glama

project-mcp-tools

一个 Python 框架,可通过三种协议同时暴露开发者工具:MCP(Model Context Protocol)、REST APICLI——全部来自同一个共享的工具注册表。

概述

project-mcp-tools 解决了为不同消费者维护独立工具后端的问题。使用 @tool() 装饰器编写一次工具,它就会立即提供给以下使用者:

  • 通过 MCP 协议(由 FastMCP 驱动)提供给 AI 助手

  • 通过 REST API(由 FastAPI + uvicorn 驱动)提供给 HTTP 客户端

  • 通过 CLI(由 argparse 驱动)提供给 终端用户

内置工具涵盖 C++ 开发(编译、静态分析、格式化、类/测试脚手架、include 树分析)、Python 格式化校验以及 git 操作——所有这些都通过 subprocess 执行实现进程隔离。

安装

要求: Python 3.14+、uv 包管理器

# Clone the repository
git clone <repository-url>
cd project-mcp-tools

# Install dependencies
uv sync

使用

MCP 服务器

启动一个 AI 助手可以连接的 FastMCP 服务器:

uv run mcp-server

配置你的 MCP 客户端以使用此服务器。例如,在 宿主项目(你希望工具操作的项目,而不是 project-mcp-tools 目录本身)根目录下的 opencode.json 中:

{
  "mcp": {
    "project-mcp-tools": {
      "type": "local",
      "command": ["uv", "--directory", "project-mcp-tools", "run", "mcp-server", "--target-project", "../my-host-project"]
    }
  }
}

重要提示: --directory 告诉 uv 在哪里找到 project-mcp-tools 包(pyproject.toml、依赖、venv)。--target-project 为 MCP 进程及其所有子进程设置工作目录——这是工具实际要操作的项目。该路径相对于 project-mcp-tools/ 解析(因为 uv --directory 会改变工作目录)。如果没有这种区分,git/cpp/python 工具就会在 project-mcp-tools/ 内部操作,而不是在你的宿主项目中。

REST API 服务器

http://0.0.0.0:8000 上启动一个 FastAPI 服务器:

uv run api --target-project ../my-host-project

每个工具都以 POST /tools/<tool_name> 的形式暴露。来自工具函数签名的查询参数会成为 JSON 请求体中的字段。

示例请求:

curl -X POST http://localhost:8000/tools/git_quick_upload \
  -H "Content-Type: application/json" \
  -d '{"message": "my commit"}'

Swagger UI 可通过 http://localhost:8000/docs 访问。

CLI

从终端调用任意工具:

uv run cli --target-project ../my-host-project git_quick_upload --message "your commit message"

--target-project 必须放在工具名称之前。不引用宿主项目的工具(例如 get_random_number)可以在不带 --target-project 的情况下调用。

工具目录

通用

工具

签名

描述

create_image

(description: str, file_name: str | None = None) -> str

根据给定的文本描述,使用 Gemini(模型 gemini-3.1-flash-lite-image)生成图像。保存到 resources/images/

describe_image

(image_path: str, description: str) -> str

使用 Gemini 视觉能力(固定模型 gemini-flash-lite-latest)解释目标项目中的图像,供不具备视觉能力的模型使用。image_path 相对于目标项目

debug

() -> str

返回环境调试信息(cwd、路径、环境变量)

get_random_number

(start: int = 1, end: int = 100) -> str

返回 start 与 end 之间的随机数

Git

工具

签名

描述

git_discard_changes

() -> str

丢弃所有未提交的更改并移除未跟踪的文件。恢复到 HEAD

git_pull_submodules

() -> str

将所有子模块更新到最新的远程提交(要求子模块处于干净状态);指针更新保持未提交

git_quick_upload

(message: str) -> str

执行 git pullgit add .git commit -m <message>git push

Python

工具

签名

描述

python_analyze

() -> str

对工具目录中的所有 *.py 文件应用 python_code_verifier

python_clear

() -> str

移除当前目录下的所有 __pycache__ 目录

python_code_verifier

(files: list[str]) -> str

校验指定文件的 Python 格式规则

C++

工具

签名

描述

cpp_analyze

() -> str

对所有 .cpp/.hpp 文件应用格式化修复,然后运行 cppcheck 静态分析

cpp_code_verifier

(files: list[str]) -> str

校验指定文件的 C++ 格式规则

cpp_compile

() -> str

使用 Clang 并行编译整个 C++ 项目

cpp_create_class

(class_hierarchy: str, include_list: list[str] = [], using_list: list[str] = [], create_header_only: bool = False) -> str

根据层级字符串(例如 "game/player")生成一个新的 C++ 类

cpp_create_test

(hierarchy: str, flg_adhoc: bool = False, include_list: list[str] = []) -> str

生成一个 C++ 测试文件

cpp_analyze_include_tree

(file_path: str = None) -> str

显示 C++ 文件的递归 include 依赖树。默认使用项目主文件

cpp_generate_opengl_html

() -> str

生成 opengl.htm,即 OpenGL 4.6 核心模式的单文件 HTML 树状视图。从目标项目读取 include/glad/snake_case.hpp,将官方 Khronos refpages 获取到 /tmp/generate-opengl-html,并将输出写入目标项目根目录

会话

工具

签名

描述

session_context_usage

(session_id: str | None = None, context_limit: int | None = None) -> str

报告当前 opencode 聊天会话正在使用多少模型上下文窗口(context_usedcontext_percent、模型上限)。直接读取 opencode 数据库;自动检测目标项目中的活动会话。参见 opencode 知识库

项目结构

project-mcp-tools/
├── main.py                    # Entry point — builds tool_manager, starts servers
├── pyproject.toml             # Project config, dependencies, entry points
├── tools/                     # Core engine package
│   ├── __init__.py
│   ├── tool_manager.py        # Core orchestrator — shared registry, tool folder loading, subprocess dispatch, CLI/API/MCP exposure
│   ├── tool.py                # @tool() decorator, ToolInfo/ParameterInfo models, response contract helpers
│   ├── path_manager.py        # Project/target root resolution — injectable, no global state
│   └── folder_scanner.py      # Auto-discovers @tool-decorated functions in directories
├── general/                    # General-purpose tools (no host project dependency)
│   ├── create_image.py         # Gemini image generation tool
│   ├── describe_image.py       # Gemini image interpretation tool
│   ├── debug.py                # Environment debugging tool
│   └── get_random_number.py    # Random number generator
├── sak/
│   ├── common.py              # Utilities (process creation, JSON, assertions)
│   └── fso/                   # File system objects
├── lib/
│   ├── base_verifier.py       # Abstract regex-based code formatter
│   ├── project_config.py      # Global project configuration
│   ├── project_file.py        # Abstract source file with license header management
│   └── template.py            # Jinja-like template engine with imports and lists
├── cpp/
│   ├── analyze.py             # C++ full analysis tool
│   ├── code_verifier.py       # C++ formatting verification tool
│   ├── compile.py             # C++ parallel compilation tool
│   ├── create_class.py        # C++ class scaffolding tool
│   ├── create_test.py         # C++ test scaffolding tool
│   ├── include_tree.py        # C++ include dependency tree tool
│   └── cpp_lib/               # C++ domain library (compiler, model, verifier, build)
├── python/
│   ├── analyze.py             # Python full analysis tool
│   ├── code_verifier.py       # Python formatting verification tool
│   └── python_lib/            # Python domain library (model, verifier, config)
├── session/
│   ├── context_usage.py       # opencode session context usage tool
│   └── session_lib/           # Session domain library (opencode database reader)
├── git/
│   ├── discard_changes.py     # Git reset + clean tool
│   └── quick_upload.py        # Git pull/add/commit/push tool
├── resources/
│   └── images/               # Generated images (from create_image tool)
├── .agents/
│   └── skills/               # AI assistant skills (compliance audit, uv package manager)
└── docs/
    ├── templates/             # Template files for class/test scaffolding (user zone)
    ├── example/               # Usage examples (e.g. google-genai.py) (user zone)
    └── agent/                 # AI-managed knowledge base (architecture, guides, workflows, status)
        ├── architecture.md    # System architecture and design decisions
        ├── development/       # Tool development guide
        ├── style-guide/       # Coding style guides
        ├── workflow/          # Workflow documentation
        └── status.md          # Agent task status

架构

系统围绕一个核心的 tool_manager 对象构建,该对象持有共享工具注册表,并处理全部三种传输方式(CLI、REST API 和 MCP)。

有关系统架构、设计决策和目标项目机制的详细说明,请参阅 系统架构 指南。

添加新工具

要添加新工具,请在现有工具文件夹(或新文件夹)中创建一个 Python 文件,并用 @tool() 装饰你的函数。

有关工具层和领域库结构的分步教程与指南,请参阅 工具开发指南

配置

全局配置和领域特定配置集中在代码库中。有关配置键和值的完整列表,请参阅 系统架构 - 集中式配置

编码规范

本项目中的所有代码都必须遵守严格的指南,包括所有标识符一律使用 snake_case,以及特定的空格规则。有关完整的指南,请参阅 Python 风格指南

许可证

GNU General Public License v3.0——详情请参阅源文件中的许可证头。

-
license - not tested
-
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

  • Package intelligence MCP for AI agents — 22 tools, 19 ecosystems, AGPL SDK, free.

  • Free public MCP for AI agents — 193 tools, 44 workflows. No API key.

  • AI Reasoning Cache & Consensus Layer with 11 MCP tools via Streamable HTTP.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/maxwellaguiarsilva/project-mcp-tools'

If you have feedback or need assistance with the MCP directory API, please join our Discord server