common

package
v0.0.168 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package common provides shared utilities for MCP tool implementations. It contains common helper functions used across all tool packages to avoid code duplication and ensure consistent behavior.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAccountFromArgs

func GetAccountFromArgs(ctx context.Context, args map[string]interface{}) string

GetAccountFromArgs extracts the account name from request arguments and context. For OAuth-authenticated requests, uses the authenticated user's email. Otherwise defaults to "default" or the explicitly provided account name.

Priority order:

  1. OAuth user email from context (set by OAuth middleware)
  2. Explicit "account" argument in request
  3. "default"

func InstrumentedToolHandler added in v0.0.36

func InstrumentedToolHandler(
	toolName string,
	sc *server.ServerContext,
	handler func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error),
) func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)

InstrumentedToolHandler wraps a tool handler with tracing, metrics and audit logging. It creates a trace span, records tool invocation metrics, and logs the invocation for audit purposes.

Usage:

s.AddTool(myTool, common.InstrumentedToolHandler("my_tool", sc, handler))

func InstrumentedToolHandlerWithService added in v0.0.36

func InstrumentedToolHandlerWithService(
	toolName string,
	serviceName string,
	operation string,
	sc *server.ServerContext,
	handler func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error),
) func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)

InstrumentedToolHandlerWithService is like InstrumentedToolHandler but also records the Google service and operation type for more detailed metrics and tracing.

This handler creates a trace span with service attributes and records both: - MCP tool invocation metrics (mcp_tool_invocations_total, mcp_tool_duration_seconds) - Google API operation metrics (google_api_operations_total, google_api_operation_duration_seconds)

Usage:

s.AddTool(myTool, common.InstrumentedToolHandlerWithService("my_tool", "gmail", "list", sc, handler))

Types

This section is empty.

Jump to

Keyboard shortcuts

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