toolmetadata

package
v0.35.2 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 2 Imported by: 2

README

Tool Metadata

A standard format for defining MCP tool metadata that can be loaded from any source (TOML, JSON, YAML, database, API, etc.).

Format

The metadata format consists of two main structures:

ToolMetadata
type ToolMetadata struct {
    Description  string           // Tool description
    Keywords     []string         // Keywords for discovery mode
    Parameters   []ToolParameter  // Tool parameters
    Discoverable bool            // Enable discovery mode
    UI           *mcp.UIToolMeta // MCP Apps UI resource link (optional)
    Icons        []mcp.Icon      // Icons for the tools/list descriptor (optional)
    Title        string          // Display name (optional)
    ReadOnly     *bool           // readOnlyHint (optional)
    Destructive  *bool           // destructiveHint (optional)
    Idempotent   *bool           // idempotentHint (optional)
    OpenWorld    *bool           // openWorldHint (optional)
}

Title and the four hints become the tool's title and annotations in tools/list. A nil hint is left out, so clients assume the spec default: not read-only, possibly destructive, not idempotent, open world. The hints tell a client how careful to be (for example, whether to ask before a call); they are not access control.

ToolParameter
type ToolParameter struct {
    Name        string  // Parameter name
    Type        string  // Parameter type (see "Supported Parameter Types" below)
    Description string  // Parameter description
    Required    bool    // Whether parameter is required
}

TOML Example

description = "Execute a shell command and return the output"
keywords = ["shell", "command", "execute", "run"]
discoverable = true

[[parameters]]
name = "command"
type = "string"
description = "The shell command to execute"
required = true

[[parameters]]
name = "args"
type = "array:string"
description = "Command arguments"
required = false

[[parameters]]
name = "timeout"
type = "int"
description = "Timeout in seconds (default: 30)"
required = false

Usage Example

package main

import (
    "github.com/paularlott/mcp"
    "github.com/paularlott/mcp/toolmetadata"
    "github.com/BurntSushi/toml"
)

func main() {
    // Parse TOML file
    var meta toolmetadata.ToolMetadata
    if _, err := toml.DecodeFile("execute_command.toml", &meta); err != nil {
        panic(err)
    }

    // Build MCP tool
    tool, err := toolmetadata.BuildMCPTool("execute_command", &meta)
    if err != nil {
        panic(err)
    }

    // Register with MCP server
    server := mcp.NewServer()
    server.RegisterTool(tool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
        // Tool implementation
        return mcp.NewToolResultText("output"), nil
    })
}

JSON Example

{
  "description": "Execute a shell command and return the output",
  "keywords": ["shell", "command", "execute", "run"],
  "discoverable": true,
  "parameters": [
    {
      "name": "command",
      "type": "string",
      "description": "The shell command to execute",
      "required": true
    },
    {
      "name": "timeout",
      "type": "int",
      "description": "Timeout in seconds (default: 30)",
      "required": false
    }
  ]
}

Supported Parameter Types

Each type emits a valid JSON Schema type (string, integer, number, boolean, or an array of those).

  • string - String parameter
  • int, integer - Whole number (JSON Schema integer)
  • float, number - Integer or floating point (JSON Schema number)
  • bool, boolean - Boolean parameter
  • array:string - Array of strings
  • array:int, array:integer - Array of whole numbers (items: integer)
  • array:float, array:number - Array of numbers (items: number)
  • array:bool, array:boolean - Array of booleans

Unknown type strings cause BuildMCPTool to return an error, so invalid metadata is caught up front rather than producing silently incorrect schemas.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildMCPTool

func BuildMCPTool(toolName string, meta *ToolMetadata) (_ *mcp.ToolBuilder, err error)

BuildMCPTool creates an mcp.ToolBuilder from ToolMetadata. Returns an error if any parameter declares an unknown type, or if meta.UI carries an invalid resourceURI or visibility value — ToolBuilder. UIResource/Visibility validate those by panicking (they're meant to catch a Go caller's own typo, e.g. a literal "ui://..." string), which would be the wrong failure mode here: meta.UI came from parsed data (a .toml file, a decorator's keyword arguments, ...), not a Go call site, so an invalid value is reported the same way any other bad metadata in this function is — as a returned error — by recovering that specific panic.

Types

type ToolMetadata

type ToolMetadata struct {
	Description  string
	Keywords     []string
	Parameters   []ToolParameter
	Discoverable bool

	// UI links the tool to a companion UI resource per the MCP Apps extension
	// (SEP-1865). When set, BuildMCPTool calls ToolBuilder.UIResource so the
	// tool's _meta.ui.resourceUri is populated. See mcp.UIToolMeta.
	UI *mcp.UIToolMeta

	// Icons attaches visual identifiers to the tool's tools/list descriptor.
	// See mcp.Icon.
	Icons []mcp.Icon

	// Title is the tool's human-readable display name (the spec's
	// Tool.title). Empty means none.
	Title string

	// The behaviour hints (the spec's Tool.annotations). Each is optional:
	// nil leaves the hint out, so clients assume the spec default (not
	// read-only, possibly destructive, not idempotent, open world). They
	// are hints only; what a tool may do must be enforced by the server.
	ReadOnly    *bool // readOnlyHint: the tool does not modify its environment
	Destructive *bool // destructiveHint: it may perform destructive updates
	Idempotent  *bool // idempotentHint: repeating a call has no further effect
	OpenWorld   *bool // openWorldHint: it interacts with external entities
}

ToolMetadata defines metadata for an MCP tool

type ToolParameter

type ToolParameter struct {
	Name        string
	Type        string
	Description string
	Required    bool
}

ToolParameter defines a single parameter for an MCP tool

Jump to

Keyboard shortcuts

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