format

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0 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 format turns MCP SDK result types into human- or machine-readable output. Formatters are pure data formatting: no colors, no emoji, no output-mode logic. Callers decide human-vs-JSON by calling a formatter directly or serializing the result with EmitJSON.

Index

Constants

This section is empty.

Variables

View Source
var ErrToolError = errors.New("tool returned an error")

ErrToolError is returned by ToolCall when the server reports the tool call as failed (CallToolResult.IsError). The result content itself is written to the caller's error writer.

Functions

func EmitJSON

func EmitJSON(w io.Writer, v any) error

EmitJSON writes v as indented JSON followed by a trailing newline.

func JevVerdicts added in v1.3.0

func JevVerdicts(w io.Writer, verdicts []jev.Verdict, plain bool) error

JevVerdicts renders one line per verdict, data-driven: a field renders only when the server supplied it, and plain mode swaps the middle-dot separator for "|" so the output stays byte-ASCII. Rich and plain share the same line shapes — escalation is data (exit semantics live in the caller).

func PromptGet

func PromptGet(w io.Writer, res *mcp.GetPromptResult) error

PromptGet renders a prompts/get result: the description (if any) followed by one line per message. Text content is printed raw; any other content block is JSON-encoded.

func PromptsList

func PromptsList(w io.Writer, res *mcp.ListPromptsResult, plain bool) error

PromptsList renders a prompts/list result as a table of names and descriptions.

func ResourceRead

func ResourceRead(w io.Writer, res *mcp.ReadResourceResult) error

ResourceRead renders a resources/read result: text contents are printed raw; blob contents are written to w as their raw (already base64-decoded) bytes.

func ResourcesList

func ResourcesList(w io.Writer, res *mcp.ListResourcesResult, tmpl *mcp.ListResourceTemplatesResult, plain bool) error

ResourcesList renders resources/list and resources/templates/list results as two tables (templates only when the second result is non-empty).

func ServerInfo

func ServerInfo(w io.Writer, res *mcp.InitializeResult) error

ServerInfo renders an initialize result as labeled lines describing the server, its version, the negotiated protocol version, and capabilities. For JSON output, callers serialize the InitializeResult itself with EmitJSON.

func ToolCall

func ToolCall(out, errOut io.Writer, res *mcp.CallToolResult) error

ToolCall renders a tools/call result. Text content blocks are printed raw to out. If there is no text content but StructuredContent is present, it is marshaled as JSON to out. Image and audio content blocks render as one compact ASCII summary line each ([mime content, N bytes]); any other non-text content blocks are JSON-encoded to out. When the result reports IsError, everything is written to errOut and ErrToolError is returned.

func ToolsList

func ToolsList(w io.Writer, res *mcp.ListToolsResult, plain bool) error

ToolsList renders a tools/list result as a table of names and descriptions.

func WriteTable

func WriteTable(w io.Writer, t *table.Table) error

WriteTable renders t to w followed by a newline (Render does not end in one) and propagates write errors. Shared by this package's formatters and by cli's compat report.

Types

This section is empty.

Jump to

Keyboard shortcuts

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