Documentation
¶
Overview ¶
Package ftl provides a zero-dependency SDK for building MCP tools with Go.
This SDK provides a thin layer over Spin Go SDK to implement the Model Context Protocol (MCP) for FTL tools.
Index ¶
- Constants
- func CreateTools(tools map[string]ToolDefinition)
- func IsAudioContent(c *ToolContent) bool
- func IsImageContent(c *ToolContent) bool
- func IsResourceContent(c *ToolContent) bool
- func IsTextContent(c *ToolContent) bool
- type ContentAnnotations
- type ResourceContents
- type ToolAnnotations
- type ToolContent
- func AudioContent(data, mimeType string, annotations *ContentAnnotations) ToolContent
- func ImageContent(data, mimeType string, annotations *ContentAnnotations) ToolContent
- func ResourceContent(resource *ResourceContents, annotations *ContentAnnotations) ToolContent
- func TextContent(text string, annotations *ContentAnnotations) ToolContent
- type ToolDefinition
- type ToolHandler
- type ToolMetadata
- type ToolResponse
Constants ¶
const ( ContentTypeText = "text" ContentTypeImage = "image" ContentTypeAudio = "audio" ContentTypeResource = "resource" )
Content type constants
Variables ¶
This section is empty.
Functions ¶
func CreateTools ¶
func CreateTools(tools map[string]ToolDefinition)
CreateTools creates a Spin HTTP handler for MCP tools.
Example:
func init() {
CreateTools(map[string]ToolDefinition{
"echo": {
Description: "Echo the input",
InputSchema: map[string]interface{}{
"type": "object",
"properties": map[string]interface{}{
"message": map[string]interface{}{
"type": "string",
"description": "The message to echo",
},
},
"required": []string{"message"},
},
Handler: func(input map[string]interface{}) ToolResponse {
message, _ := input["message"].(string)
return Text(fmt.Sprintf("Echo: %s", message))
},
},
})
}
func main() {}
func IsAudioContent ¶
func IsAudioContent(c *ToolContent) bool
IsAudioContent checks if content is audio type
func IsImageContent ¶
func IsImageContent(c *ToolContent) bool
IsImageContent checks if content is image type
func IsResourceContent ¶
func IsResourceContent(c *ToolContent) bool
IsResourceContent checks if content is resource type
func IsTextContent ¶
func IsTextContent(c *ToolContent) bool
IsTextContent checks if content is text type
Types ¶
type ContentAnnotations ¶
type ContentAnnotations struct {
// Target audience for this content
Audience []string `json:"audience,omitempty"`
// Priority of this content (0.0 to 1.0)
Priority float64 `json:"priority,omitempty"`
}
ContentAnnotations provides metadata for content items
type ResourceContents ¶
type ResourceContents struct {
// URI of the resource
URI string `json:"uri"`
// MIME type of the resource
MimeType string `json:"mimeType,omitempty"`
// Text content of the resource
Text string `json:"text,omitempty"`
// Base64-encoded binary content of the resource
Blob string `json:"blob,omitempty"`
}
ResourceContents represents resource data
type ToolAnnotations ¶
type ToolAnnotations struct {
// Optional title annotation
Title string `json:"title,omitempty"`
// Hint that the tool is read-only (doesn't modify state)
ReadOnlyHint bool `json:"readOnlyHint,omitempty"`
// Hint that the tool may perform destructive operations
DestructiveHint bool `json:"destructiveHint,omitempty"`
// Hint that the tool is idempotent (same input → same output)
IdempotentHint bool `json:"idempotentHint,omitempty"`
// Hint that the tool accepts open-world inputs
OpenWorldHint bool `json:"openWorldHint,omitempty"`
}
ToolAnnotations provides hints about tool behavior
type ToolContent ¶
type ToolContent struct {
// Content type discriminator
Type string `json:"type"`
// Text content (for type="text")
Text string `json:"text,omitempty"`
// Base64-encoded data (for type="image" or "audio")
Data string `json:"data,omitempty"`
// MIME type (for type="image" or "audio")
MimeType string `json:"mimeType,omitempty"`
// Resource contents (for type="resource")
Resource *ResourceContents `json:"resource,omitempty"`
// Optional annotations for this content
Annotations *ContentAnnotations `json:"annotations,omitempty"`
}
ToolContent represents content that can be returned by tools
func AudioContent ¶
func AudioContent(data, mimeType string, annotations *ContentAnnotations) ToolContent
AudioContent creates an audio content item
func ImageContent ¶
func ImageContent(data, mimeType string, annotations *ContentAnnotations) ToolContent
ImageContent creates an image content item
func ResourceContent ¶
func ResourceContent(resource *ResourceContents, annotations *ContentAnnotations) ToolContent
ResourceContent creates a resource content item
func TextContent ¶
func TextContent(text string, annotations *ContentAnnotations) ToolContent
TextContent creates a text content item
type ToolDefinition ¶
type ToolDefinition struct {
// Optional explicit tool name (overrides the map key)
Name string
// Optional human-readable title for the tool
Title string
// Optional description of what the tool does
Description string
// JSON Schema describing the expected input parameters
InputSchema map[string]interface{}
// Optional JSON Schema describing the output format
OutputSchema map[string]interface{}
// Optional annotations providing hints about tool behavior
Annotations *ToolAnnotations
// Optional metadata for tool-specific extensions
Meta map[string]interface{}
// Handler function for tool execution
Handler ToolHandler
}
ToolDefinition defines a tool's configuration
type ToolHandler ¶
type ToolHandler func(input map[string]interface{}) ToolResponse
ToolHandler is the function signature for tool handlers
type ToolMetadata ¶
type ToolMetadata struct {
// The name of the tool (must be unique within the gateway)
Name string `json:"name"`
// Optional human-readable title for the tool
Title string `json:"title,omitempty"`
// Optional description of what the tool does
Description string `json:"description,omitempty"`
// JSON Schema describing the expected input parameters
InputSchema map[string]interface{} `json:"inputSchema"`
// Optional JSON Schema describing the output format
OutputSchema map[string]interface{} `json:"outputSchema,omitempty"`
// Optional annotations providing hints about tool behavior
Annotations *ToolAnnotations `json:"annotations,omitempty"`
// Optional metadata for tool-specific extensions
Meta map[string]interface{} `json:"_meta,omitempty"`
}
ToolMetadata represents tool metadata returned by GET requests
type ToolResponse ¶
type ToolResponse struct {
// Array of content items returned by the tool
Content []ToolContent `json:"content"`
// Optional structured content matching the outputSchema
StructuredContent interface{} `json:"structuredContent,omitempty"`
// Indicates if this response represents an error
IsError bool `json:"isError,omitempty"`
}
ToolResponse represents the response format for tool execution
func Errorf ¶
func Errorf(format string, args ...interface{}) ToolResponse
Errorf creates a formatted error response
func Textf ¶
func Textf(format string, args ...interface{}) ToolResponse
Textf creates a formatted text response
func WithStructured ¶
func WithStructured(text string, structured interface{}) ToolResponse
WithStructured creates a response with structured content