Cover image
Try Now
2025-04-14

ProtoC插件从.proto定义生成MPC服务器。

3 years

Works with Finder

0

Github Watches

0

Github Forks

0

Github Stars

protoc-gen-mcpserver

A Protobuf compiler plugin that generates Go code for serving MCP (Model-Code-Protocol) tools from Protobuf service definitions.

Overview

This tool auto-generates the necessary Go code to create MCP server with tools tools, which can be consumed by AI assistants like Claude, all starting from a proto definition. It enables you to:

  • Define your tools using Protocol Buffers
  • Automatically generate the necessary MCP server code
  • Implement only the business logic for your service methods

Installation

Clone this repository and install the plugin:

go install github.com/wricardo/protoc-gen-mcpserver@latest

Or build from source:

git clone https://github.com/wricardo/protoc-gen-mcpserver.git
cd protoc-gen-mcpserver
go install

Make sure protoc-gen-mcpserver is in your PATH.

Usage

1. Define your service in a .proto file

Create a Protocol Buffer file that defines your service and message types:

syntax = "proto3";

package yourpackage;

option go_package = "yourmodule/yourpackage;yourpackage";

service YourService {
  rpc YourMethod(YourRequest) returns (YourResponse);
}

message YourRequest {
  string parameter1 = 1;
  string parameter2 = 2;
}

message YourResponse {
  string result = 1;
}

2. Configure buf.gen.yaml

Use buf to generate code from your protobuf definitions. Create a buf.gen.yaml file:

version: v2
managed:
  enabled: true
plugins:
  - name: go
    out: ./
    opt: paths=source_relative
  - name: mcpserver
    out: ./
    opt: paths=source_relative

3. Generate the code

Run the code generation:

buf generate

This will create:

  • Standard Go Protobuf code
  • An additional .mcpserver.go file with MCP server integration

4. Implement your service

Create a struct that implements the interface defined in the generated code:

package main

import (
	"context"
	"log"
	
	. "yourmodule/yourpackage"
)

type YourServiceImpl struct {}

func (s *YourServiceImpl) YourMethod(ctx context.Context, req YourRequest) (*YourResponse, error) {
	// Implement your business logic here
	return &YourResponse{
		Result: "Processed: " + req.Parameter1 + " " + req.Parameter2,
	}, nil
}

func main() {
	// Use the generated ServeStdio function to start the MCP server
	err := ServeStdio("your-mcp-tool", "1.0.0", &YourServiceImpl{})
	if err != nil {
		log.Fatal(err)
	}
}

5. Build and run your MCP server

Build your implementation:

go build -o your-mcp-tool

Your tool can now be executed by MCP-compatible clients.

How It Works

The plugin generates:

  1. Interface definitions for your service
  2. Registration functions to add your methods as MCP tools
  3. Helper functions for serving the MCP protocol over stdio

Each method in your gRPC service becomes an MCP tool, with request fields automatically mapped to tool parameters.

Example

Check out the included example to see a complete working implementation:

cd example
buf generate
cd example-mcp
go build -o example-mcp
./example-mcp

License

MIT License

相关推荐

  • av
  • 毫不费力地使用一个命令运行LLM后端,API,前端和服务。

  • 1Panel-dev
  • 🔥1Panel提供了直观的Web接口和MCP服务器,用于在Linux服务器上管理网站,文件,容器,数据库和LLMS。

  • WangRongsheng
  • 🧑‍🚀 llm 资料总结(数据处理、模型训练、模型部署、 o1 模型、mcp 、小语言模型、视觉语言模型)|摘要世界上最好的LLM资源。

  • rulego
  • ⛓️Rulego是一种轻巧,高性能,嵌入式,下一代组件编排规则引擎框架。

  • Byaidu
  • PDF科学纸翻译带有保留格式的pdf -基于ai完整保留排版的pdf文档全文双语翻译

  • sigoden
  • 使用普通的bash/javascript/python函数轻松创建LLM工具和代理。

  • hkr04
  • 轻巧的C ++ MCP(模型上下文协议)SDK

  • RockChinQ
  • 😎简单易用、🧩丰富生态 -大模型原生即时通信机器人平台| 适配QQ / 微信(企业微信、个人微信) /飞书 /钉钉 / discord / telegram / slack等平台| 支持chatgpt,deepseek,dify,claude,基于LLM的即时消息机器人平台,支持Discord,Telegram,微信,Lark,Dingtalk,QQ,Slack

  • dmayboroda
  • 带有可配置容器的本地对话抹布

  • modelscope
  • 开始以更轻松的方式开始构建具有LLM授权的多代理应用程序。

    Reviews

    3.3 (3)
    Avatar
    user_88ZUqNcW
    2025-04-24

    protoc-gen-mcpserver is an outstanding tool by wricardo, tailored for efficient and seamless integration into your development workflow. Its robustness and flexibility make it an invaluable asset for managing microservice communications. Highly recommended for anyone looking to streamline their server-side protocol buffer generation!

    Avatar
    user_bV6GENmX
    2025-04-24

    protoc-gen-mcpserver is a fantastic tool developed by wricardo. It has tremendously streamlined my workflow, making server generation for my projects quicker and more efficient. The setup was straightforward, and the detailed documentation provided a seamless experience. Highly recommended for anyone looking to enhance their development process.

    Avatar
    user_wbPwxsHV
    2025-04-24

    As a loyal user of MCP applications, I am thoroughly impressed with protoc-gen-mcpserver by wricardo. This tool has significantly streamlined my workflow, offering robust functionality and seamless integration. The performance is top-notch, and it greatly simplifies the development process. I highly recommend it to anyone looking to enhance their productivity in MCP environments.