protoc-gen-mcp
Health Warn
- License — License: Apache-2.0
- Description — Repository has a description
- Active repo — Last push 0 days ago
- Low visibility — Only 8 GitHub stars
Code Pass
- Code scan — Scanned 12 files during light audit, no dangerous patterns found
Permissions Pass
- Permissions — No dangerous permissions requested
No AI report is available for this listing yet.
Generate MCP servers from protobuf: tools, prompts and resources for Go, Python, Kotlin, Java and TypeScript
protoc-gen-mcp
protoc-gen-mcp generates Go, Python, Kotlin, Java, TypeScript and Swift MCP
bindings from protobuf definitions — covering tools, prompts, and
resources. Protobuf is the source of truth: RPCs become tools, annotated
messages become prompts and resources, and the generated code validates
ProtoJSON payloads against generated JSON Schema before calling your typed
handlers. JavaScript projects consume the compiled TypeScript output.
Supported MCP Primitives
| Primitive | Go | Python | Kotlin | Java | TypeScript | Swift |
|---|---|---|---|---|---|---|
| Tools | ✅ Full | ✅ Full | ✅ Full | ✅ Full | ✅ Full | ✅ Full |
| Prompts | ✅ Full | ✅ Full | ✅ Full | ✅ Full | ✅ Full | ✅ Full |
| Resources | ✅ Full | ✅ Full | ✅ Full | ✅ Full | ✅ Full | ✅ Full |
| Protobuf server factory | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| MCP Apps UI / CSP | ✅ | ✅ | ✅¹ | ✅¹ | ✅ | ✅ |
| Markdown, HTML, binary resources | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| OAuth/JWKS and tool scopes | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Every target serves the same resources contract: ProtoJSON or raw text/blob
bodies, percent-decoded template parameters, annotations, icons and the MCP
Apps _meta.ui of a resource. Only Go embeds source_file at build time;
the other targets read it through a generated handler that returns the file
body.
Every target generates a file-scoped server factory fromoption (mcp.options.v1.server): Python create_<file>_mcp_server(handlers),
TypeScript create<File>MCPServer(handlers), Swiftnew<File>MCPServer(handlers) async throws, Kotlinsuspend new<File>MCPServer(handlers) and Java<ProtoFile>Mcp.install<File>MCPServer(transportProvider, handlers). ¹ The
Kotlin SDK 0.11 and the stdio transport of the Java SDK 1.1 cannot expresscapabilities.extensions, so they advertise MCP Apps undercapabilities.experimental; Java over HTTP serves capabilities.extensions
like Go. Tools and resources carry _meta.ui everywhere. Every target servesoption (mcp.options.v1.server).oauth and per-tool required_scopes over
stateless Streamable HTTP with the same metadata, 401 challenge and 403
step-up, checked by one shared contract.
Each target uses the official MCP SDK of its language: the Go MCP SDK,
the Python mcp SDK with google.protobuf, io.modelcontextprotocol.sdk:mcp
for Java, io.modelcontextprotocol:kotlin-sdk-server for Kotlin, and@modelcontextprotocol/sdk with Protobuf-ES and Ajv for TypeScript, andmodelcontextprotocol/swift-sdk with swift-protobuf for Swift.
Install
The latest release is
v1.1.0.
Install the plugin with Go 1.26+:
go install github.com/easyp-tech/protoc-gen-mcp/cmd/[email protected]
or download a prebuilt binary from the release:protoc-gen-mcp-<version>-<os>-<arch>.tar.gz for linux and darwin
and protoc-gen-mcp-<version>-windows-<arch>.zip, each for amd64 andarm64, plus protoc-gen-mcp-<version>-checksums.txt. Putprotoc-gen-mcp on PATH.
Easyp is the recommended driver. With plainprotoc the plugin is --mcp_out, and --mcp_opt=lang= selects the target
(go by default, or python, java, kotlin, typescript, swift). mcp/options/v1/options.proto must be on the
include path, for example from a clone of this repository at the release
tag:
# Go, next to protoc-gen-go output
protoc -I . -I path/to/protoc-gen-mcp \
--go_out=. --go_opt=paths=source_relative \
--mcp_out=. --mcp_opt=paths=source_relative \
proto/weather/v1/weather.proto
# Python; also generate the options module the generated code imports
protoc -I . -I path/to/protoc-gen-mcp \
--python_out=. --mcp_out=. --mcp_opt=lang=python \
proto/weather/v1/weather.proto mcp/options/v1/options.proto
Generated code imports a small runtime of its language; see
Runtime packages.
Quickstart: run the full Go showcase
The protobuf-first showcase
runs one server with generated tools, prompts, JSON/text/blob resources,
embedded SKILL.md, an MCP Apps UI resource, CSP/permissions, and OAuth
resource-server configuration. With Go 1.26+, from a clone of the
repository:
git clone https://github.com/easyp-tech/protoc-gen-mcp.git
cd protoc-gen-mcp
# Terminal A: explicitly enable local development-only OAuth tokens.
go run ./examples/11_protobuf_first_mcp -transport=http -demo-auth
# Terminal B: use the official MCP Go SDK client.
go run ./examples/11_protobuf_first_mcp/client -token=demo-read
go run ./examples/11_protobuf_first_mcp/client -token=demo-write
A read-only token cannot invoke the write-scoped tool; a write token can.-demo-auth is intentionally insecure and loopback-only; never expose these
tokens publicly. Sample issuer/JWKS URLs in the protobuf fixture are
placeholders, not an identity provider.
To inspect any generated server interactively, point the official
MCP Inspector at its
command, for examplenpx -y @modelcontextprotocol/inspector go run ./examples/1_helloworld.
Generation With Easyp
The intended workflow is easyp, not
manual protoc invocation. One config can drive protoc-gen-go, the standard
Python generator, Protobuf-ES and protoc-gen-mcp. If your config uses the
standard Go plugin, install it first:
go install google.golang.org/protobuf/cmd/[email protected]
Example easyp.yaml with every target enabled (keep only the ones you need):
deps:
- github.com/easyp-tech/protoc-gen-mcp
generate:
inputs:
- directory:
path: proto
root: "."
plugins:
# Go
- name: go
out: .
opts:
paths: source_relative
- command: ["go", "run", "github.com/easyp-tech/protoc-gen-mcp/cmd/[email protected]"]
out: .
opts:
paths: source_relative
# Python
- name: python
with_imports: true
out: .
- command: ["go", "run", "github.com/easyp-tech/protoc-gen-mcp/cmd/[email protected]"]
out: .
opts:
lang: python
# python_handler: protobuf # raw *_pb2 handlers
# python_handler: dataclass+protobuf # both, raw ones in *_mcp_pb.py
# Java and Kotlin both need protobuf Java output; Kotlin also needs
# protobuf Kotlin output (examples 6 and 7)
- name: java
with_imports: true
out: src/generated/main/java
- name: kotlin # Kotlin only
out: src/generated/main/kotlin
- command: ["go", "run", "github.com/easyp-tech/protoc-gen-mcp/cmd/[email protected]"]
out: src/generated/main/java # src/generated/main/kotlin for lang=kotlin
opts:
paths: source_relative
lang: java # or kotlin
# TypeScript
- command: ["./node_modules/.bin/protoc-gen-es"]
with_imports: true
out: src/generated
opts:
target: ts
import_extension: js
- command: ["go", "run", "github.com/easyp-tech/protoc-gen-mcp/cmd/[email protected]"]
out: src/generated
opts:
lang: typescript
# Swift, master only until v1.1.0: protoc-gen-swift must be on PATH
- name: swift
out: Sources/App/Generated
- command: ["go", "run", "github.com/easyp-tech/protoc-gen-mcp/cmd/protoc-gen-mcp@master"]
out: Sources/App/Generated
opts:
paths: source_relative
lang: swift
easyp --cfg easyp.yaml mod download
easyp --cfg easyp.yaml generate -p proto -r .
Pin a release tag (not @latest) for reproducible builds. Protos used only for Python,
JVM, TypeScript or Swift do not need a go_package option; the plugin
synthesizes the metadata it needs. mcp.options.v1 declares its owngo_package, so no Easyp override is required.
Language notes:
- Python supports
python_runtime=google.protobuf. The defaultpython_handler=dataclasshands your code dataclasses from*_mcp.py, withUNSET(notNone) for absent optional fields and explicitoneofwrapper
variants.python_handler=protobufuses raw*_pb2messages instead, anddataclass+protobufemits both. Generation also writes a smallmcp/__init__.pybridge somcp.options.*modules coexist with the officialmcpSDK package. Enablewith_imports: trueon the Python plugin when your
protos import other packages. Generated modules import theprotoc-gen-mcp-runtimepackage, which holds the tool, prompt and resource
registries; it is not on PyPI yet, so install the wheel attached to the
release (see Runtime packages). Generated code checks
on import that the runtime matches it. Withoption (mcp.options.v1.server)a module also exportscreate_<file>_mcp_http_app(server, verifier=None), an ASGI app (for
example for uvicorn) that serves stateless Streamable HTTP through the SDK
session manager and, withoauth, enforces bearer tokens, RFC 9728
metadata and per-toolrequired_scopesexactly like the Go handler;verifieris an SDKTokenVerifier, and without one the built-in RS256
JWKS verifier is used. - Java (
lang=java) generates one<ProtoFile>Mcpsidecar per proto next
to protobuf Java output. Kotlin (lang=kotlin) needs Java protobuf
output, Kotlin protobuf output, and the MCP sidecar together. Generated
sidecars depend ontech.easyp:protoc-gen-mcp-runtime(Java) ortech.easyp:protoc-gen-mcp-runtime-kotlin(Kotlin), which hold the
registries and dispatch; sidecars of several proto files share one registry
per transport or server. Withoption (mcp.options.v1.server)a Java
sidecar also exportsnew<File>MCPHttpServlet(server[, verifier]): fill atech.easyp.mcp.runtime.McpHttpServerwithinstall<File>MCPServerand
mount the returned servlet at/*in any Jakarta Servlet 6 container. MCP
is served by the SDKHttpServletStatelessServerTransport; withoauththe
servlet adds bearer authentication, RFC 9728 metadata and the per-toolrequired_scopesstep-up of the Go handler.verifieris atech.easyp.mcp.runtime.oauth.TokenVerifier; when it is null the built-in
RS256 JWKS verifier (nimbus-jose-jwt, fromtech.easyp:protoc-gen-mcp-runtime-oauth) is used. Handlers read the token
withMcpRuntime.currentAccessToken(); theMcpAsyncServerExchange
argument is null over stateless HTTP. A Kotlin file with the server option
exportsApplication.install<File>MCPHttp(handlers, verifier = null)for
Ktor: a route that builds a fresh server per request on the SDKStreamableHttpServerTransport(as the SDK's own stateless endpoint does)
and adds the same metadata, bearer check and scope step-up; suspend
handlers read the token withcurrentAccessToken(). - TypeScript (
lang=typescript) expects Protobuf-ES_pb.tsfiles in the
same tree, generated withimport_extension=jsfor Node ESM andmoduleResolution: NodeNext. JavaScript projects import the compiled.jsoutput and.d.tsdeclarations; there is nolang=javascript.
Generated files import@easyp-tech/protoc-gen-mcp-runtime, which keeps
the tool, prompt and resource registries; it is not on npm yet, so install
the tarball attached to the release (see
Runtime packages).@modelcontextprotocol/sdk,@bufbuild/protobufandajvare its peer dependencies, so the server and
the runtime share one SDK. Withoption (mcp.options.v1.server)a file also
exportscreate<File>MCPHttpHandler(handlers, verifier?), a request
listener fornode:httpor express that builds a fresh server per request
(the stateless SDK transport requires it) and, withoauth, uses the SDKrequireBearerAuthplus the runtime scope gate and RFC 9728 metadata;verifierdefaults to the built-in RS256 JWKS verifier onjose. - Swift (
lang=swift) writes<file>.mcp.swiftnext to the<file>.pb.swiftofprotoc-gen-swift
(swift-protobuf 1.39+), in the same module. The runtime ships from this
repository as a Swift package resolved by git, like the Go module, so no
registry is involved:.package(url: "https://github.com/easyp-tech/protoc-gen-mcp.git", from: "1.1.0"),
with the productsProtocGenMCPRuntimeand, for files with a server option,ProtocGenMCPHTTP. Handlers areSendableprotocols withasync throws
methods that receive aToolContextcarrying the bearer token. Start a
server withserve(server, transport:), which advertises MCP Apps undercapabilities.extensionsthrough a transport wrapper because the SDK's typed
capabilities cannot express it.new<File>MCPHTTPHandler(handlers, verifier:)
returns a framework-neutralMCPHTTPHandler(SDKHTTPRequestin,MCPHTTPResponseout) to mount in Hummingbird, Vapor or SwiftNIO; it uses
the SDKStatelessHTTPServerTransportand, withoauth, the RS256 JWKS
verifier on jwt-kit. swift-protobuf cannot print default values, so
generated field tables complete ProtoJSON output like protojsonEmitDefaultValues.TASK_SUPPORT_REQUIREDis rejected as for Go.
See examples/9_swift_standalone.
Runtime packages
The runtimes are versioned with the plugin, but none of them is published
to a package registry yet: there is no PyPI, npm or Maven Central release.
Every GitHub release carries the Python wheel and the npm tarball, so
install them straight from the release:
pip install https://github.com/easyp-tech/protoc-gen-mcp/releases/download/v1.1.0/protoc_gen_mcp_runtime-1.1.0-py3-none-any.whl
npm install https://github.com/easyp-tech/protoc-gen-mcp/releases/download/v1.1.0/easyp-tech-protoc-gen-mcp-runtime-1.1.0.tgz
The JVM runtimes (tech.easyp:protoc-gen-mcp-runtime,protoc-gen-mcp-runtime-kotlin and protoc-gen-mcp-runtime-oauth) are not
attached to the release. Build them from a checkout of the release tag withgradle -p runtime/jvm publishToMavenLocal and add mavenLocal() to your
repositories, or use them through a Gradle includeBuild of runtime/jvm
as examples 6 and 7 do. Swift resolves its runtime from this repository by
git (see above). The examples in this repository use the in-repo runtimes
directly.
Generated API
Every target exposes a typed handler interface per service and a registration
helper. Tool names are {namespace}_{method}; dots in either segment become
underscores, so namespace weather.v1 and RPC GetForecast becomeweather_v1_GetForecast.
| Target | Handler | Registration |
|---|---|---|
| Go | <Service>ToolHandler |
Register<Service>Tools(server *mcp.Server, impl, opts...) error |
| Python | <Service>ToolHandler protocol |
register_<service>_tools(server, impl, *, namespace=None) |
| Kotlin | <Service>ToolHandler |
register<Service>Tools(server, impl, namespace: String? = null) |
| Java | <ProtoFile>Mcp.<Service>ToolHandler |
<ProtoFile>Mcp.register<Service>Tools(transportProvider, impl, namespace) |
| TypeScript | <Service>ToolHandler |
register<Service>Tools(server, impl, namespace?) |
| Swift | <Service>ToolHandler protocol |
register<Service>Tools(server, impl, namespace: String? = nil) async throws |
Prompts and resources are declared on messages, so their Go registration is
file-scoped: Register<File>Prompts(server, impl, opts...) andRegister<File>Resources(ctx, server, impl, opts...), where <File> is the
CamelCase proto basename. A static resource (uri) needs Read<Msg>(ctx); a
template resource (uri_template) needs List<Msg>s(ctx) andRead<Msg>(ctx, params...) with percent-decoded template values.
The other targets follow the same shape:
| Target | Prompts | Resources |
|---|---|---|
| Python | register_<file>_prompts(server, impl, *, namespace=None) |
register_<file>_resources(server, impl, *, namespace=None) |
| Kotlin | register<File>Prompts(server, impl, namespace) |
suspend fun register<File>Resources(server, impl, namespace) |
| Java | <ProtoFile>Mcp.register<File>Prompts(transportProvider, impl, namespace) |
<ProtoFile>Mcp.register<File>Resources(transportProvider, impl, namespace) |
| TypeScript | register<File>Prompts(server, impl, namespace?) |
register<File>Resources(server, impl, namespace?) |
| Swift | register<File>Prompts(server, impl, namespace:) async throws |
register<File>Resources(server, impl, namespace:) async throws |
Resource handlers return the generated message type of the target (a Python
dataclass or *_pb2 message, a Protobuf-ES message, a Java/Kotlin protobuf
message). Like Go, Kotlin lists template instances once, at registration, so
its Server must declare the resources and prompts capabilities; Python,
TypeScript and Java list them on every resources/list and declare the
capabilities themselves.
At runtime the generated code validates arguments against the input schema,
unmarshals them with ProtoJSON, calls your handler, marshals the response with
ProtoJSON, validates it against the output schema, and returns it as bothstructuredContent and text content. Handler errors become tool results withisError: true.
Minimal Go server:
package main
import (
"context"
"log"
weatherv1 "github.com/acme/weather/gen/weather/v1"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
type handler struct{}
func (handler) Forecast(_ context.Context, req *weatherv1.GetForecastRequest) (*weatherv1.GetForecastResponse, error) {
return &weatherv1.GetForecastResponse{ReportId: "forecast-1"}, nil
}
func main() {
server := mcp.NewServer(&mcp.Implementation{Name: "weather-mcp", Version: "v0.1.0"}, nil)
if err := weatherv1.RegisterWeatherAPITools(server, handler{}); err != nil {
log.Fatal(err)
}
if err := server.Run(context.Background(), &mcp.StdioTransport{}); err != nil {
log.Fatal(err)
}
}
The examples show the same wiring for Python, Java,
Kotlin, TypeScript and Swift (master).
Go: HTTP, protobuf-defined servers, Apps and OAuth
Generated registration accepts *mcp.Server from the official Go SDK, which
owns transports, sessions and protocol negotiation. A plain Streamable HTTP
endpoint:
handler := mcp.NewStreamableHTTPHandler(
func(*http.Request) *mcp.Server { return server },
&mcp.StreamableHTTPOptions{Stateless: true},
)
mux := http.NewServeMux()
mux.Handle("/mcp", http.NewCrossOriginProtection().Handler(handler))
_ = http.ListenAndServe("127.0.0.1:8080", mux)
That endpoint is unprotected. For public servers, declare the file-level(mcp.options.v1.server) option instead: it carries name, version, MCP Apps
capabilities and OAuth resource-server settings, and the generator emits a
typed New<File>MCPServer(ctx, handlers) factory plusNew<File>MCPHTTPHandler(server, verifier). OAuth verifies RS256 access JWTs
against a configured HTTPS JWKS endpoint, issuer and audience, or calls your
own auth.TokenVerifier. Per-RPC required_scopes add authorization; a
missing scope returns HTTP 403 insufficient_scope before dispatch, so SDK
clients can step up and retry. Never put bearer tokens or client secrets in
protobuf options.
Resources can also carry raw bodies: set mime_type and content_field to a
singular string or bytes field for dynamic text or blobs, or source_file
for a static file that the generator embeds with go:embed (no handler
needed). A static resource with mime_type: "text/html;profile=mcp-app" andapp_ui CSP/permissions becomes an MCP Apps UI. Go rejectsexecution.task_support: TASK_SUPPORT_REQUIRED because the Go SDK does not
implement the Tasks lifecycle; other values stay synchronous. The
showcase exercises all of this.
Schema Contract
Generated inputSchema and outputSchema follow ProtoJSON:
int64,uint64,fixed64,sfixed64,sint64are JSON strings; 32-bit
integers are JSON integersfloat/doubleaccept numbers and the stringsNaN,Infinity,-Infinitybytesare base64 strings and enums use value namesTimestampis an RFC 3339 string,Durationa string such as"3600s",FieldMaska field-mask stringStruct,ValueandListValueaccept arbitrary JSON;Anyuses the object
form with@type- recursive messages use
$defs/$ref;oneofgroups become JSON Schema
constraints
Requiredness is proto3-driven: a singular field without optional is required;optional, repeated, map and oneof fields are not, and they accept
explicit JSON null so clients that pre-validate cached schemas stay
compatible with ProtoJSON unset semantics. Field options do not change
requiredness.
Supported scope: proto3 only, unary RPCs only, and the well-known types Any,Empty, Timestamp, Duration, FieldMask, Struct, Value, ListValue
and all scalar wrappers. Streaming RPCs and other google.protobuf messages
fail at generation time.
Metadata Options
Import mcp/options/v1/options.proto to control generation. The proto file
documents every field; this is the summary.
- File
option (mcp.options.v1.server):name(default: the proto
basename),version(defaultv0.0.1),apps.enabled(unset follows
whether the file uses MCP Apps), andoauthwithresource_url,authorization_servers,scopes,issuer,jwks_uri,audienceandmcp_path(default/mcp). Every target then generates the file's server
factory and Streamable HTTP handler. - Service
option (mcp.options.v1.service):namespace,description,
defaulticons. - Method
option (mcp.options.v1.method):name,title,description,hidden,annotations(title,read_only_hint,destructive_hint,idempotent_hint,open_world_hint),icons,execution.task_support,app_ui(resource_uri,visibility) for MCP Apps tool_meta.ui, andrequired_scopesfor per-tool OAuth scopes. Omitted hints stay omitted;
some clients render their own defaults, so set hints such asdestructive_hint: falseexplicitly when it matters. - Field
[(mcp.options.v1.field)]:description, typedexamples,default_value, string constraints (pattern,format,min_length,max_length), number constraints (minimum,maximum,exclusive_minimum,exclusive_maximum,multiple_of), array constraints
(min_items,max_items,unique_items),read_only. - Message
option (mcp.options.v1.message):title,description,examples. Enumoption (mcp.options.v1.enum):title,description. Enum value[(mcp.options.v1.enum_value)]:description,hidden(typically for_NONEsentinels). Oneofoption (mcp.options.v1.oneof):description,required. - Prompt
option (mcp.options.v1.prompt)on a message:name,title,description,icons. Fields become prompt arguments;optionalones are
not required. - Resource
option (mcp.options.v1.resource)on a message: exactly one ofurioruri_template({param}placeholders),name,description,mime_type(defaultapplication/json),annotations(audience,priority),icons,content_field(a singularstringorbytesfield
served as raw text or blob),source_file(a static file body: Go embeds
it, the other targets return it from a generated handler method) andapp_ui(csp,permissions,domain,prefers_border) for MCP Apps
UI resources. All of them work in every target.
Comments are metadata too: plain lines become descriptions, Example: <json>
adds one schema example and Examples: a | b adds several. Typed examples
in field options take precedence.
service WeatherAPI {
option (mcp.options.v1.service) = { namespace: "weather" };
// Forecast returns a weather report.
rpc Forecast(GetForecastRequest) returns (GetForecastResponse) {
option (mcp.options.v1.method) = {
name: "GetForecast"
title: "Get forecast"
annotations: { read_only_hint: true }
};
}
}
message GetForecastRequest {
// city is required because it is singular and not `optional`.
string city = 1 [(mcp.options.v1.field) = {
examples: [{ string_value: "Paris" }]
min_length: 2
}];
optional string units = 2 [(mcp.options.v1.field) = {
default_value: { string_value: "metric" }
}];
oneof selector {
option (mcp.options.v1.oneof) = { required: true };
string city_alias = 3;
int64 city_id = 4;
}
}
Agent Skill
Install the skills.sh agent skill to let your AI coding
assistant build MCP servers with protoc-gen-mcp:
npx skills add easyp-tech/protoc-gen-mcp-skill
The skill lives in
easyp-tech/protoc-gen-mcp-skill.
Development
go build ./cmd/protoc-gen-mcp
(cd runtime/typescript && npm ci && npm run build) # TypeScript runtime, consumed through file:
(cd internal/codegen/testdata/node && npm ci) # TypeScript test harness
go test ./...
JVM tests need JDK 17+ and Gradle 9.2+ and Swift tests a Swift 6.4+
toolchain; both skip otherwise. Fixtures and examples are regenerated witheasyp (easyp.test.yaml, easyp.test.swift.yaml with protoc-gen-swift onPATH, easyp.showcase.yaml,examples/Makefile); AGENTS.md lists every command and the
repository layout. Releases publish the protoc-gen-mcp binary through
GoReleaser; downstream projects compile generated sources
against their language SDKs.
License
Apache License 2.0. See LICENSE.
Reviews (0)
Sign in to leave a review.
Leave a reviewNo results found