conversion

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package conversion provides utilities for converting between MCP SDK types and vmcp wrapper types. This package centralizes conversion logic to ensure consistency and eliminate duplication.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContentArrayToMap

func ContentArrayToMap(content []vmcp.Content) map[string]any

ContentArrayToMap converts a vmcp.Content array to a map for template variable substitution. This is used by composite tool workflows and backend result handling.

Conversion rules:

  • First text content: key="text"
  • Subsequent text content: key="text_1", "text_2", etc.
  • Image content: key="image_0", "image_1", etc.
  • First resource content: key="resource" (text resources use .Text, blob resources use .Data)
  • Subsequent resource content: key="resource_1", "resource_2", etc.
  • Audio content: ignored (not supported for template substitution)
  • Resource links: ignored (not supported for template substitution)
  • Unknown content types: ignored (warnings logged at conversion boundaries)

This ensures consistent behavior between client response handling and workflow step output processing.

func ConvertMCPAnnotations added in v0.13.0

func ConvertMCPAnnotations(ann *mcp.Annotations) *vmcp.ContentAnnotations

ConvertMCPAnnotations converts mcp.Annotations to vmcp.ContentAnnotations. Returns nil if the input is nil or all fields are zero-valued.

func ConvertMCPContent added in v0.10.1

func ConvertMCPContent(content mcp.Content) vmcp.Content

ConvertMCPContent converts a single mcp.Content item to vmcp.Content. Unknown content types are returned as vmcp.Content{Type: "unknown"}.

func ConvertMCPContents added in v0.10.1

func ConvertMCPContents(contents []mcp.Content) []vmcp.Content

ConvertMCPContents converts a slice of mcp.Content to []vmcp.Content. Returns an empty (non-nil) slice for a nil or empty input.

func ConvertMCPPromptMessages added in v0.13.0

func ConvertMCPPromptMessages(messages []mcp.PromptMessage) []vmcp.PromptMessage

ConvertMCPPromptMessages converts []mcp.PromptMessage to []vmcp.PromptMessage, preserving individual message roles and content types.

func ConvertMCPResourceContents added in v0.13.0

func ConvertMCPResourceContents(contents []mcp.ResourceContents) []vmcp.ResourceContent

ConvertMCPResourceContents converts []mcp.ResourceContents to []vmcp.ResourceContent, preserving the text vs blob distinction and per-item metadata.

func ConvertPromptArguments added in v0.10.1

func ConvertPromptArguments(arguments map[string]any) map[string]string

ConvertPromptArguments converts map[string]any to map[string]string by formatting each value with fmt.Sprintf("%v", v). Required by the MCP GetPrompt API which accepts only string-typed arguments.

func ConvertToolAnnotations added in v0.11.3

func ConvertToolAnnotations(ann mcp.ToolAnnotation) *vmcp.ToolAnnotations

ConvertToolAnnotations converts mcp.ToolAnnotation to *vmcp.ToolAnnotations. Returns nil if all fields are zero-valued (empty Title, all hint pointers nil).

func ConvertToolInputSchema added in v0.10.1

func ConvertToolInputSchema(schema mcp.ToolInputSchema) map[string]any

ConvertToolInputSchema converts a mcp.ToolInputSchema to map[string]any via a JSON round-trip, capturing all fields (type, properties, required, $defs, additionalProperties, etc.) without enumerating them manually. Falls back to {type: schema.Type} if marshalling fails.

func ConvertToolOutputSchema added in v0.11.3

func ConvertToolOutputSchema(schema mcp.ToolOutputSchema) map[string]any

ConvertToolOutputSchema converts a mcp.ToolOutputSchema to map[string]any via a JSON round-trip, same pattern as ConvertToolInputSchema. Returns nil if the schema has no meaningful type (empty Type field).

func FromMCPMeta

func FromMCPMeta(meta *mcp.Meta) map[string]any

FromMCPMeta converts MCP SDK meta to map[string]any for vmcp wrapper types. This preserves the _meta field from backend MCP server responses.

Returns nil if meta is nil or empty, following the MCP specification that _meta is optional and should be omitted when empty.

func ToMCPAnnotations added in v0.13.0

func ToMCPAnnotations(ann *vmcp.ContentAnnotations) *mcp.Annotations

ToMCPAnnotations converts vmcp.ContentAnnotations to mcp.Annotations. Returns nil if the input is nil or all fields are zero-valued.

func ToMCPContent added in v0.11.0

func ToMCPContent(content vmcp.Content) mcp.Content

ToMCPContent converts a single vmcp.Content item to mcp.Content. Unknown content types are converted to empty text with a warning.

func ToMCPContents added in v0.11.0

func ToMCPContents(contents []vmcp.Content) []mcp.Content

ToMCPContents converts a slice of vmcp.Content to []mcp.Content.

func ToMCPMeta

func ToMCPMeta(meta map[string]any) *mcp.Meta

ToMCPMeta converts vmcp meta map to MCP SDK meta for forwarding to clients. This reconstructs the _meta field when sending responses back through the MCP protocol.

Returns nil if meta is nil or empty, following the MCP specification that _meta is optional and should be omitted when empty.

func ToMCPPromptMessages added in v0.13.0

func ToMCPPromptMessages(messages []vmcp.PromptMessage) []mcp.PromptMessage

ToMCPPromptMessages converts []vmcp.PromptMessage to []mcp.PromptMessage.

func ToMCPResourceContents added in v0.13.0

func ToMCPResourceContents(contents []vmcp.ResourceContent) []mcp.ResourceContents

ToMCPResourceContents converts []vmcp.ResourceContent to []mcp.ResourceContents, reconstructing the text vs blob distinction.

func ToMCPToolAnnotations added in v0.11.3

func ToMCPToolAnnotations(annotations *vmcp.ToolAnnotations) mcp.ToolAnnotation

ToMCPToolAnnotations converts *vmcp.ToolAnnotations back to mcp.ToolAnnotation. Returns a zero-valued mcp.ToolAnnotation if annotations is nil.

Types

This section is empty.

Jump to

Keyboard shortcuts

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