inprocess_sampling

command
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: MIT Imports: 6 Imported by: 0

README

InProcess Sampling Example

This example demonstrates how to use sampling with in-process MCP client/server communication.

Overview

The example shows:

  • Creating an MCP server with sampling enabled
  • Adding a tool that uses sampling to request LLM completions
  • Creating an in-process client with a sampling handler
  • Making tool calls that trigger sampling requests

Key Components

Server Side
  • mcpServer.EnableSampling() - Enables sampling capability
  • Tool handler calls mcpServer.RequestSampling() to request LLM completions
  • Sampling requests are handled directly by the client's sampling handler
Client Side
  • MockSamplingHandler - Implements the SamplingHandler interface
  • NewInProcessClientWithSamplingHandler() - Creates client with sampling support
  • The handler receives sampling requests and returns mock LLM responses

Running the Example

go run main.go

Expected Output

Tool result: LLM Response (model: mock-llm-v1): Mock LLM response to: 'What is the capital of France?'

Real LLM Integration

To integrate with a real LLM service (OpenAI, Anthropic, etc.), replace the MockSamplingHandler with an implementation that calls your preferred LLM API. See the client sampling documentation for examples with real LLM providers.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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