runtime

package
v0.2.40 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: Apache-2.0 Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package runtime provides helpers imported by code generated by protoc-gen-go-mcp.

These functions handle the boundary between MCP request/response types and proto messages:

Keep this package minimal — every dependency here is a transitive dep for all consumers of generated code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindElicitResult added in v0.2.20

func BindElicitResult[T any, PT interface {
	*T
	proto.Message
}](content map[string]any) (PT, error)

BindElicitResult unmarshals an elicitation result content map into a typed proto message. Returns a pointer to the populated message.

Usage in generated code:

approval, err := runtime.BindElicitResult[SummaryApproval](result.Content)
// approval is *SummaryApproval

func BindParams added in v0.2.8

func BindParams(params map[string]string, msg proto.Message) error

BindParams populates a proto message from URI template parameters. Each key is a field path (dot-separated for nested fields, e.g. "pos.q") and each string value is coerced to the target field type.

func BindPromptArgs added in v0.2.9

func BindPromptArgs(args map[string]any, msg proto.Message) error

BindPromptArgs populates a proto message from prompt argument values. Prompt arguments arrive as map[string]any (JSON-decoded). Each value is re-marshaled to JSON and the full map is unmarshaled via protojson.

func BindProto

func BindProto(req core.ToolRequest, msg proto.Message) error

BindProto unmarshals MCP tool request arguments into a proto message. Arguments arrive as JSON (from the LLM) and are decoded via protojson.

func ProtoPromptResult added in v0.2.9

func ProtoPromptResult(msg proto.Message) (core.PromptResult, error)

ProtoPromptResult marshals a proto message to JSON and returns it as a PromptResult with a single assistant text message.

func ProtoResourceResult

func ProtoResourceResult(msg proto.Message, uri, mimeType string) (core.ResourceResult, error)

ProtoResourceResult marshals a proto message and returns it as a ResourceResult with the given URI and MIME type.

For JSON resources (application/json), the message is serialized via protojson. For non-JSON resources (text/html, text/yaml, text/markdown, etc.), the function extracts a raw string from a single "content" field if present. This ensures the MCP resource text contains the actual content, not a JSON wrapper — matching what a hand-written resource handler would return.

func ProtoStructuredResult

func ProtoStructuredResult(msg proto.Message) (core.ToolResult, error)

ProtoStructuredResult marshals a proto message and returns it as a StructuredResult. The text field contains the JSON string; structuredContent contains the parsed object.

func ProtoSummaryStructuredResult added in v0.2.9

func ProtoSummaryStructuredResult(msg proto.Message, summaryTemplate string) (core.ToolResult, error)

ProtoSummaryStructuredResult marshals a proto message and returns it as a StructuredResult where the text content is a rendered summary template. The template uses {field_name} placeholders interpolated from the response message's JSON representation.

func ProtoTextResult

func ProtoTextResult(msg proto.Message) (core.ToolResult, error)

ProtoTextResult marshals a proto message to JSON and returns it as a TextResult.

func RPCError

func RPCError(err error) (core.ToolResult, error)

RPCError wraps an RPC error as an MCP error result. If the error is a gRPC status error, the status code and any attached details (proto Any messages) are extracted and returned as structured error content so agents can parse and recover programmatically. For non-gRPC errors, falls back to a plain text error result.

Types

This section is empty.

Jump to

Keyboard shortcuts

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