Skip to content

Tools API Reference

Complete API reference for the tools package.

Toolkit

NewToolkit

Creates a new toolkit instance.

func NewToolkit(client DataHubClient, opts ...Option) *Toolkit

Parameters:

  • client: A DataHub client implementing the DataHubClient interface
  • opts: Optional configuration options

Example:

toolkit := tools.NewToolkit(datahubClient)

RegisterAll

Registers all available tools with the MCP server.

func (t *Toolkit) RegisterAll(server *mcp.Server)

Register

Registers specific tools with the MCP server.

func (t *Toolkit) Register(server *mcp.Server, names ...ToolName)

Example:

toolkit.Register(server, tools.ToolSearch, tools.ToolGetEntity)

RegisterWith

Registers a tool with per-tool options.

func (t *Toolkit) RegisterWith(server *mcp.Server, name ToolName, opts ...PerToolOption)

Options

WithMiddleware

Adds global middleware to all tools.

func WithMiddleware(mw ToolMiddleware) Option

WithToolMiddleware

Adds middleware to a specific tool.

func WithToolMiddleware(name ToolName, mw ToolMiddleware) Option

Tool Names

Available tool name constants:

const (
    ToolSearch           ToolName = "datahub_search"
    ToolGetEntity        ToolName = "datahub_get_entity"
    ToolGetSchema        ToolName = "datahub_get_schema"
    ToolGetLineage       ToolName = "datahub_get_lineage"
    ToolGetQueries       ToolName = "datahub_get_queries"
    ToolGetGlossaryTerm  ToolName = "datahub_get_glossary_term"
    ToolListTags         ToolName = "datahub_list_tags"
    ToolListDomains      ToolName = "datahub_list_domains"
    ToolListDataProducts ToolName = "datahub_list_data_products"
    ToolGetDataProduct   ToolName = "datahub_get_data_product"
)

Middleware

ToolMiddleware Interface

type ToolMiddleware interface {
    Before(ctx context.Context, tc *ToolContext) (context.Context, error)
    After(ctx context.Context, tc *ToolContext, result *mcp.CallToolResult, err error) (*mcp.CallToolResult, error)
}

BeforeFunc

Creates middleware that runs before tool execution.

func BeforeFunc(fn func(ctx context.Context, tc *ToolContext) (context.Context, error)) ToolMiddleware

AfterFunc

Creates middleware that runs after tool execution.

func AfterFunc(fn func(ctx context.Context, tc *ToolContext, result *mcp.CallToolResult, err error) (*mcp.CallToolResult, error)) ToolMiddleware

Helper Functions

TextResult

Creates a text result.

func TextResult(text string) *mcp.CallToolResult

JSONResult

Creates a JSON result.

func JSONResult(v any) (*mcp.CallToolResult, error)

ErrorResult

Creates an error result.

func ErrorResult(msg string) *mcp.CallToolResult