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 ¶
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:
- OAuth user email from context (set by OAuth middleware)
- Explicit "account" argument in request
- "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.