Back to MCP directory
publicPublicdnsLocal runtime

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

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client