返回 MCP 目录
public公开dns本地运行

pforge

pforge是一个使用YAML配置声明式构建MCP服务器的框架,基于Rust的pmcp SDK,支持通过配置文件生成优化的Rust代码,并提供多种工具处理器类型和语言桥接功能。

article

README

🚀 pforge

pforge是一个声明式框架,可借助YAML配置来构建模型上下文协议(MCP)服务器,简化了服务器的创建过程,提高开发效率。

CI crates.io crates.io License: MIT

🚀 快速开始

新建项目

pforge new my-server
cd my-server

运行服务器

pforge serve

搭建好的项目包含一个可用的示例处理程序。你可以编辑 pforge.yaml 文件来添加更多工具,然后在 src/handlers/ 中实现处理程序。

✨ 主要特性

  • 声明式配置:使用YAML配置文件定义MCP服务器,避免编写样板代码。
  • 多语言支持:提供Deno/TypeScript桥接,未来还将支持Python、Go和Node.js。
  • 多种处理程序类型:支持原生、CLI、HTTP和管道处理程序类型。
  • 代码生成:从YAML配置生成优化的Rust代码。

📦 安装指南

从crates.io安装

cargo install pforge-cli

从源代码安装

git clone https://github.com/paiml/pforge
cd pforge
cargo install --path crates/pforge-cli

💻 使用示例

基础用法

YAML配置示例

forge:
  name: my-server
  version: 0.1.0
  transport: stdio

tools:
  - type: native
    name: greet
    description: "Greet someone"
    handler:
      path: handlers::greet_handler
    params:
      name: { type: string, required: true }

Deno/TypeScript桥接示例

import { PforgeBridge } from "https://raw.githubusercontent.com/paiml/pforge/main/bridges/deno/bridge.ts";

const bridge = new PforgeBridge();

bridge.register({
  name: "greet",
  description: "Greet a user by name",
  handler: (input: { name: string }) => ({
    success: true,
    data: { message: `Hello, ${input.name}!` },
  }),
});

const result = await bridge.execute("greet", { name: "Alice" });
console.log(result.data);

📚 详细文档

🔧 技术细节

pforge构建在pmcp(rust-mcp-sdk)之上,作为一个框架提供了从YAML配置到Rust代码的生成、处理程序注册和状态管理等功能。

┌─────────────────────────────────┐
│   pforge (Framework Layer)      │
│   - YAML → Rust codegen         │
│   - Handler registry            │
│   - State management            │
└─────────────────────────────────┘
              ↓
┌─────────────────────────────────┐
│   pmcp (Protocol SDK)           │
│   - MCP protocol implementation │
│   - Transport handling          │
└─────────────────────────────────┘
  • 何时直接使用pmcp:当你需要对MCP协议细节进行细粒度控制或希望避免代码生成时。
  • 何时使用pforge:当你希望通过声明式配置快速开发MCP服务器并减少代码编写时。

📄 许可证

本项目采用MIT许可证,详情请见 LICENSE

致谢

本项目基于Pragmatic AI Labs的 pmcp 构建。

help

运行方式说明

cloud

托管运行

托管运行通常表示这个 MCP Server 由服务方环境承载,用户一般按页面提供的连接方式或授权流程接入,不需要在本地长期启动一个 MCP 进程

  1. 打开服务方连接页
  2. 完成授权或复制端点
  3. 在 MCP 客户端中连接
terminal

本地运行 / 其它方式

本地运行通常需要用户在自己的电脑或服务器上安装依赖,把 server_config 复制到 MCP 客户端,并按 env_schema 补齐环境变量、密钥或其它配置

  1. 复制 server_config
  2. 安装所需依赖
  3. 补齐环境变量后重启客户端