MCP cover image
See in Github
2025-04-14

Protoc plugin to generate a MPC Server from .proto definitions.

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

相关推荐

  • Aurity Ltd
  • Create and Publish Business Websites in seconds. AI will gather all the details about your website and generate link to your website.

  • John Rafferty
  • Text your favorite pet, after answering 10 questions about their everyday lives!

  • seabiscuit.ai
  • Discover A More Robust Business: Craft tailored value proposition statements, develop a comprehensive business model canvas, conduct detailed PESTLE analysis, and gain strategic insights on enhancing business model elements like scalability, cost structure, and market competition strategies. (v1.18)

  • Carl Oscar Aaro
  • Structured recipes for food and desserts – ingredient lists and step-by-step recipe instructions from any input. Become surprised, try something new or breathe life into grandma's old recipe notebook.

  • Ian O'Connell
  • Provide players' names or enter Quickstart to start the game!

  • Convincible Ltd
  • You're in a stone cell – can you get out? A classic choose-your-adventure interactive fiction game, based on a meticulously-crafted playbook. With a medieval fantasy setting, infinite choices and outcomes, and dice!

  • analogchat.com
  • Efficient Spotify assistant for personalized music data.

  • WangRongsheng
  • 🧑‍🚀 全世界最好的LLM资料总结(Agent框架、辅助编程、数据处理、模型训练、模型推理、o1 模型、MCP、小语言模型、视觉语言模型) | Summary of the world's best LLM resources.

  • av
  • Effortlessly run LLM backends, APIs, frontends, and services with one command.

  • 1Panel-dev
  • 🔥 1Panel provides an intuitive web interface and MCP Server to manage websites, files, containers, databases, and LLMs on a Linux server.

  • Azure
  • The Azure MCP Server, bringing the power of Azure to your agents.

  • langgenius
  • Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.

  • caio-moliveira
  • This project was created to demonstrate how we can connect with different Model Context Protocols (MCPs).

  • alibaba
  • an easy-to-use dynamic service discovery, configuration and service management platform for building AI cloud native applications.

  • rulego
  • ⛓️RuleGo is a lightweight, high-performance, embedded, next-generation component orchestration rule engine framework for Go.

  • Byaidu
  • PDF scientific paper translation with preserved formats - 基于 AI 完整保留排版的 PDF 文档全文双语翻译,支持 Google/DeepL/Ollama/OpenAI 等服务,提供 CLI/GUI/MCP/Docker/Zotero

    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.