Help us shape the future of Go! Take the 2026 Go Developer Survey

grpc

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package grpc binds a gRPC service's unary methods to MCP operations without bypassing the authorisation its interceptors enforce (spec 0002).

A bound operation calls the generated server method in-process, wrapped in the service's own unary interceptors, with the identity the MCP host verified established on the context the way the transport's auth interceptor establishes it, the same authorisation predicate applied, and the invocation's deadline and trace carried into the call. Arguments and results are the request and response messages in protojson, and the operation's schemas are derived from the message descriptors.

Import it as mcpgrpc beside google.golang.org/grpc.

Index

Constants

View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout bounds a bound call unless a method sets its own (spec 0002 OQ1).

Variables

This section is empty.

Functions

func Unary

func Unary[Req, Resp proto.Message](service *Service, fullMethod string, call func(context.Context, Req) (Resp, error), opts ...MethodOption) (mcp.Operation, error)

Unary binds one unary method, given by its full name ("/pkg.Service/Method") and the generated server method that implements it, as an operation. The method must be unary and registered in the global protobuf registry, and Req and Resp must be its request and response messages; anything else is refused here rather than at the first call.

Types

type MethodOption

type MethodOption func(*methodConfig) error

MethodOption overrides one bound method's description or budget.

func WithDescription

func WithDescription(description string) MethodOption

WithDescription adds the longer description a model reads on inspection.

func WithGroup

func WithGroup(group string) MethodOption

WithGroup replaces the group, which defaults to the service name.

func WithHints

func WithHints(hints mcp.Hints) MethodOption

WithHints sets the behavioural hints; the binding derives none.

func WithInputSchema

func WithInputSchema(schema json.RawMessage) MethodOption

WithInputSchema replaces the input schema derived from the request message.

func WithName

func WithName(name string) MethodOption

WithName replaces the operation name derived from the full method.

func WithOutputSchema

func WithOutputSchema(schema json.RawMessage) MethodOption

WithOutputSchema replaces the output schema derived from the response message.

func WithSummary

func WithSummary(summary string) MethodOption

WithSummary replaces the one-line summary a model searches by.

func WithTimeout

func WithTimeout(timeout time.Duration) MethodOption

WithTimeout replaces DefaultTimeout for this method. An earlier deadline on the invocation still wins.

type Option

type Option func(*serviceConfig) error

Option configures a Service at construction. Repeated options fail.

func WithAuthorize

func WithAuthorize(fn authn.AuthorizeFunc) Option

WithAuthorize applies the predicate the service gives its auth interceptor through transportgrpc.WithGRPCAuthorize. It runs after the host's identity is established on the call's context, so both paths decide alike; a false fails the call as unavailable. Without it, an authenticated caller is admitted, as an auth interceptor without a predicate admits one.

func WithInterceptors

func WithInterceptors(interceptors ...transitgrpc.Interceptor) Option

WithInterceptors runs the given interceptors' unary halves around every bound call, first outermost, as grpc.ChainUnaryInterceptor runs them. Pass the service's chain minus its auth interceptor: authentication has already happened at the MCP host's edge and there is no RPC metadata credential to re-verify (spec 0002 D3). Repeating the option appends.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger supplies the logger for private diagnostics.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is what every bound method of one gRPC service shares: the authorisation predicate its interceptors apply, the interceptors that run around each call, and a logger. It is immutable after New.

func New

func New(opts ...Option) (*Service, error)

New builds the shared part of a service's bindings.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL