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 ¶
- Variables
- func EmitJSON(w io.Writer, v any) error
- func PromptGet(w io.Writer, res *mcp.GetPromptResult) error
- func PromptsList(w io.Writer, res *mcp.ListPromptsResult, plain bool) error
- func ResourceRead(w io.Writer, res *mcp.ReadResourceResult) error
- func ResourcesList(w io.Writer, res *mcp.ListResourcesResult, ...) error
- func ServerInfo(w io.Writer, res *mcp.InitializeResult) error
- func ToolCall(out, errOut io.Writer, res *mcp.CallToolResult) error
- func ToolsList(w io.Writer, res *mcp.ListToolsResult, plain bool) error
- func WriteTable(w io.Writer, t *table.Table) error
Constants ¶
This section is empty.
Variables ¶
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 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 ¶
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. Any non-text content blocks are JSON-encoded to out. When the result reports IsError, everything is written to errOut and ErrToolError is returned.
Types ¶
This section is empty.