MCPcopy Index your code
hub / github.com/mwitkow/grpc-proxy

github.com/mwitkow/grpc-proxy @v0.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1 ↗ · + Follow
114 symbols 205 edges 6 files 18 documented · 16% 2 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

gRPC Proxy

This is an implementation of a gRPC Proxying Server in Golang, based on grpc-go. Features:

  • full support for all Streams: Unitary RPCs and Streams: One-Many, Many-One, Many-Many
  • pass-through mode: no overhead of encoding/decoding messages
  • customizable StreamDirector routing based on context.Context of the Stream, allowing users to return a grpc.ClientConn after dialing the backend of choice based on:
    • inspection of service and method name
    • inspection of user credentials in authorization header
    • inspection of custom user-features
    • inspection of TLS client cert credentials
  • integration tests

Example Use


director := func(ctx context.Context) (*grpc.ClientConn, error) {
    if err := CheckBearerToken(ctx); err != nil {
        return nil, grpc.Errorf(codes.PermissionDenied, "unauthorized access: %v", err)
    }
    stream, _ := transport.StreamFromContext(ctx)
    backend, found := PreDialledBackends[stream.Method()];
    if !found {
        return nil, grpc.Errorf(codes.Unimplemented, "the service %v is not implemented", stream.Method)
    }
    return backend, nil
}

proxy := grpcproxy.NewProxy(director)
proxy.Server(boundListener)

Status

This is alpha software, written as a proof of concept. It has been integration-tested, but please expect bugs.

The current implementation depends on a public interface to ClientConn.Picker(), which hopefully will be upstreamed in grpc-go#397.

Contributors

Names in no particular order:

License

grpc-proxy is released under the Apache 2.0 license. See LICENSE.txt.

Part of the main server loop are lifted from the grpc-go Server, which is copyrighted Google Inc. and licensed under MIT license.

Extension points exported contracts — how you extend this code

StreamDirector (FuncType)
StreamDirector returns a gRPC ClientConn for a stream of a given context. The service name, method name, and other `MD`
director.go
ProxyOption (FuncType)
A ProxyOption sets options.
options.go

Core symbols most depended-on inside this repo

Printf
called by 3
options.go
Write
called by 2
proxy.go
Serve
called by 2
proxy.go
Stop
called by 2
proxy.go
forwardDataFrames
called by 2
proxy.go
Println
called by 2
options.go
handleStream
called by 1
proxy.go
ProxyStream
called by 1
proxy.go

Shape

Method 72
Function 23
Struct 12
Interface 5
FuncType 2

Languages

Go100%

Modules by API surface

testservice/test.pb.go71 symbols
proxy_test.go19 symbols
options.go12 symbols
proxy.go10 symbols
patch/get_transport.go1 symbols
director.go1 symbols

Used by 2 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add grpc-proxy \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page