Skip to main content
Golf v0.2.0 introduces powerful built-in utilities that enhance your tool development experience.

Overview

Golf utilities provide four core capabilities:
  1. Context Access - Direct access to FastMCP context without manual parameter passing
  2. Elicitation - Interactive user prompting and input collection
  3. Sampling - LLM interactions and text generation with multiple modes
  4. Authentication Integration - Seamless token extraction
All utilities automatically handle context management using Python’s contextvars for thread-safe, async-aware access to FastMCP features.

Context access

Get current context

The get_current_context() function provides direct access to the FastMCP context without requiring explicit context parameter passing.

Context with logging

Error handling

Elicitation utilities

Elicitation utilities enable your tools to interact with users, collect additional information, and create dynamic conversational experiences.

Basic elicitation

Type-safe elicitation

Confirmation dialogs

Advanced elicitation with error handling

Sampling utilities

Sampling utilities provide direct access to LLM capabilities within your tools, enabling text generation, analysis, and AI-powered processing with multiple modes.

Basic sampling

Structured sampling

The sample_structured() function uses a lower temperature (0.1) for more consistent, formatted outputs.

Context-enhanced sampling

The sample_with_context() function automatically appends context data to prompts.

Advanced sampling with parameters

Sampling error handling

Authentication integration

Golf utilities seamlessly integrate with the authentication system for secure API forwarding.

Basic token forwarding

Combined context and auth

Error handling best practices

Comprehensive error handling