Files
crush-code-agent-ide/vendor/github.com/mark3labs/mcp-go/server/sampling.go
Carlos Alexandro Becker 3e820ececc chore(deps): update mcp-go (#155)
* chore(deps): update mcp-go

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* fix: vendoring

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2025-07-11 15:29:10 -03:00

38 lines
1.1 KiB
Go

package server
import (
"context"
"fmt"
"github.com/mark3labs/mcp-go/mcp"
)
// EnableSampling enables sampling capabilities for the server.
// This allows the server to send sampling requests to clients that support it.
func (s *MCPServer) EnableSampling() {
s.capabilitiesMu.Lock()
defer s.capabilitiesMu.Unlock()
}
// RequestSampling sends a sampling request to the client.
// The client must have declared sampling capability during initialization.
func (s *MCPServer) RequestSampling(ctx context.Context, request mcp.CreateMessageRequest) (*mcp.CreateMessageResult, error) {
session := ClientSessionFromContext(ctx)
if session == nil {
return nil, fmt.Errorf("no active session")
}
// Check if the session supports sampling requests
if samplingSession, ok := session.(SessionWithSampling); ok {
return samplingSession.RequestSampling(ctx, request)
}
return nil, fmt.Errorf("session does not support sampling")
}
// SessionWithSampling extends ClientSession to support sampling requests.
type SessionWithSampling interface {
ClientSession
RequestSampling(ctx context.Context, request mcp.CreateMessageRequest) (*mcp.CreateMessageResult, error)
}