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
- func Unary[Req, Resp proto.Message](service *Service, fullMethod string, ...) (mcp.Operation, error)
- type MethodOption
- func WithDescription(description string) MethodOption
- func WithGroup(group string) MethodOption
- func WithHints(hints mcp.Hints) MethodOption
- func WithInputSchema(schema json.RawMessage) MethodOption
- func WithName(name string) MethodOption
- func WithOutputSchema(schema json.RawMessage) MethodOption
- func WithSummary(summary string) MethodOption
- func WithTimeout(timeout time.Duration) MethodOption
- type Option
- type Service
Constants ¶
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 ¶
WithLogger supplies the logger for private diagnostics.