conversion

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 8 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 ConcatenateResourceContents added in v0.10.1

func ConcatenateResourceContents(contents []mcp.ResourceContents) (data []byte, mimeType string)

ConcatenateResourceContents concatenates all MCP resource content items into a single byte slice and returns the MIME type of the first item.

MCP resources may return multiple content chunks (text or blob). Text chunks are appended as UTF-8 bytes; blob chunks are base64-decoded per the MCP spec. If base64 decoding fails, the malformed chunk is skipped and a warning is logged (appending raw base64 bytes would produce corrupted binary data). The MIME type is taken from the first content item; subsequent items are expected to share the same type (the MCP spec does not define per-chunk types).

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.
  • Audio content: ignored (not supported for template substitution)
  • Resource content: ignored (handled separately, not converted to map)
  • Unknown content types: ignored (warnings logged at conversion boundaries)

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

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 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 ConvertPromptMessages added in v0.10.1

func ConvertPromptMessages(messages []mcp.PromptMessage) string

ConvertPromptMessages flattens MCP prompt messages into a single string with the format "[role] text\n". Messages without a role omit the prefix. Only text content is included; non-text content is silently discarded (Phase 1 limitation — vmcp.PromptGetResult carries a flat string, not structured messages).

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 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 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.

Types

This section is empty.

Jump to

Keyboard shortcuts

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