MCPcopy
hub / github.com/connectrpc/connect-go

github.com/connectrpc/connect-go @v1.20.0 sqlite

repository ↗ · DeepWiki ↗ · release v1.20.0 ↗
1,370 symbols 6,520 edges 85 files 486 documented · 35%
README

Connect

Build Report Card GoDoc Slack OpenSSF Best Practices

Connect is a slim library for building browser and gRPC-compatible HTTP APIs. You write a short Protocol Buffer schema and implement your application logic, and Connect generates code to handle marshaling, routing, compression, and content type negotiation. It also generates an idiomatic, type-safe client. Handlers and clients support three protocols: gRPC, gRPC-Web, and Connect's own protocol.

The Connect protocol is a simple protocol that works over HTTP/1.1 or HTTP/2. It takes the best portions of gRPC and gRPC-Web, including streaming, and packages them into a protocol that works equally well in browsers, monoliths, and microservices. Calling a Connect API is as easy as using curl. Try it with our live demo:

curl \
    --header "Content-Type: application/json" \
    --data '{"sentence": "I feel happy."}' \
    https://demo.connectrpc.com/connectrpc.eliza.v1.ElizaService/Say

Handlers and clients also support the gRPC and gRPC-Web protocols, including streaming, headers, trailers, and error details. gRPC-compatible server reflection and health checks are available as standalone packages. Instead of cURL, we could call our API with a gRPC client:

go install github.com/bufbuild/buf/cmd/buf@latest
buf curl --protocol grpc \
    --data '{"sentence": "I feel happy."}' \
    https://demo.connectrpc.com/connectrpc.eliza.v1.ElizaService/Say

Under the hood, Connect is just Protocol Buffers and the standard library: no custom HTTP implementation, no new name resolution or load balancing APIs, and no surprises. Everything you already know about net/http still applies, and any package that works with an http.Server, http.Client, or http.Handler also works with Connect.

For more on Connect, see the announcement blog post, the documentation on connectrpc.com (especially the Getting Started guide for Go), the demo service, or the protocol specification.

A small example

Curious what all this looks like in practice? From a Protobuf schema, we generate a small RPC package. Using that package, we can build a server. This example is available at internal/example:

package main

import (
  "context"
  "log"
  "net/http"

  "connectrpc.com/connect"
  pingv1 "connectrpc.com/connect/internal/gen/connect/ping/v1"
  "connectrpc.com/connect/internal/gen/simple/connect/ping/v1/pingv1connect"
  "connectrpc.com/validate"
)

type PingServer struct {
  pingv1connect.UnimplementedPingServiceHandler // returns errors from all methods
}

func (ps *PingServer) Ping(ctx context.Context, req *pingv1.PingRequest) (*pingv1.PingResponse, error) {
  return &pingv1.PingResponse{
    Number: req.Number,
  }, nil
}

func main() {
  mux := http.NewServeMux()
  // The generated constructors return a path and a plain net/http
  // handler.
  mux.Handle(
    pingv1connect.NewPingServiceHandler(
      &PingServer{},
      // Validation via Protovalidate is almost always recommended
      connect.WithInterceptors(validate.NewInterceptor()),
    ),
  )
  p := new(http.Protocols)
  p.SetHTTP1(true)
  // For gRPC clients, it's convenient to support HTTP/2 without TLS.
  p.SetUnencryptedHTTP2(true)
  s := &http.Server{
    Addr:      "localhost:8080",
    Handler:   mux,
    Protocols: p,
  }
  if err := s.ListenAndServe(); err != nil {
    log.Fatalf("listen failed: %v", err)
  }
}

With that server running, you can make requests with any gRPC or Connect client. To write a client using Connect:

package main

import (
  "context"
  "log"
  "net/http"

  pingv1 "connectrpc.com/connect/internal/gen/connect/ping/v1"
  "connectrpc.com/connect/internal/gen/simple/connect/ping/v1/pingv1connect"
)

func main() {
  client := pingv1connect.NewPingServiceClient(
    http.DefaultClient,
    "http://localhost:8080/",
  )
  req := &pingv1.PingRequest{Number: 42}
  res, err := client.Ping(context.Background(), req)
  if err != nil {
    log.Fatalln(err)
  }
  log.Println(res)
}

Of course, http.ListenAndServe and http.DefaultClient aren't fit for production use! See Connect's deployment docs for a guide to configuring timeouts, connection pools, observability, and h2c.

Ecosystem

Status: Stable

This module is stable. It supports:

  • The two most recent major releases of Go (the same versions of Go that continue to receive security patches).
  • APIv2 of Protocol Buffers in Go (google.golang.org/protobuf).

Within those parameters, connect follows semantic versioning. We will not make breaking changes in the 1.x series of releases.

Legal

Offered under the Apache 2 license.

Extension points exported contracts — how you extend this code

StreamingHandlerConn (Interface)
StreamingHandlerConn is the server's view of a bidirectional message exchange. Interceptors for streaming RPCs may wrap [7 …
connect.go
Interceptor (Interface)
An Interceptor adds logic to a generated handler or client, like the decorators or middleware you may have seen in other [7 …
interceptor.go
ClientOption (Interface)
A ClientOption configures a [Client]. In addition to any options grouped in the documentation below, remember that any [15 …
option.go
PingServiceClient (Interface)
PingServiceClient is a client for the connect.ping.v1.PingService service. [6 implementers]
internal/gen/simple/connect/ping/v1/pingv1connect/ping.connect.go
ExampleV1BetaClient (Interface)
ExampleV1BetaClient is a client for the example.ExampleV1beta service. [14 implementers]
cmd/protoc-gen-connect-go/internal/testdata/v1beta1service/gen/v1beta1service.connect.go
Codec (Interface)
Codec marshals structs (typically generated from a schema) to and from bytes. [3 implementers]
codec.go
CallInfo (Interface)
CallInfo represents information relevant to an RPC call. [3 implementers]
context.go
Decompressor (Interface)
A Decompressor is a reusable wrapper that decompresses an underlying data source. The standard library's [*gzip.Reader] [2 …
compression.go

Core symbols most depended-on inside this repo

Nil
called by 437
internal/assert/assert.go
Equal
called by 435
internal/assert/assert.go
True
called by 179
internal/assert/assert.go
NotNil
called by 160
internal/assert/assert.go
Client
called by 123
internal/memhttp/memhttp.go
URL
called by 123
internal/memhttp/memhttp.go
Send
called by 118
connect.go
Header
called by 112
connect.go

Shape

Method 722
Function 396
Struct 186
Interface 53
FuncType 7
TypeAlias 6

Languages

Go100%

Modules by API surface

connect_ext_test.go118 symbols
protocol_connect.go93 symbols
option.go82 symbols
internal/gen/connect/ping/v1/ping.pb.go75 symbols
connect.go73 symbols
protocol_grpc.go55 symbols
context.go42 symbols
protocol.go41 symbols
duplex_http_call.go38 symbols
codec.go33 symbols
error.go29 symbols
cmd/protoc-gen-connect-go/main.go29 symbols

Dependencies from manifests, versioned

buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/gov1.36.9-202509121410 · 1×
buf.build/go/protovalidatev1.0.0 · 1×
buf.build/go/protoyamlv0.6.0 · 1×
cel.dev/exprv0.24.0 · 1×
connectrpc.com/conformancev1.0.5 · 1×
connectrpc.com/connectv1.19.0 · 1×
connectrpc.com/validatev0.6.0 · 1×
github.com/andybalholm/brotliv1.2.0 · 1×
github.com/antlr4-go/antlr/v4v4.13.1 · 1×
github.com/desertbit/timerv0.0.0-2018010715543 · 1×
github.com/golang/snappyv1.0.0 · 1×

For agents

$ claude mcp add connect-go \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact