Help us shape the future of Go! Take the 2026 Go Developer Survey

client

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvHTTPURL   = "MCP_CLIENT_TEST_HTTP_URL"
	EnvHTTPToken = "MCP_CLIENT_TEST_HTTP_AUTHORIZATION_TOKEN"
	EnvSSEURL    = "MCP_CLIENT_TEST_SSE_URL"
	EnvSSEToken  = "MCP_CLIENT_TEST_SSE_AUTHORIZATION_TOKEN"
)

Test environment variable names

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	DSL        *types.ClientDSL
	MCPClient  *goclient.Client
	InitResult *types.InitializeResponse // Store the initialization result
	// contains filtered or unexported fields
}

Client the MCP Client

func New

func New(dsl *types.ClientDSL) (*Client, error)

New create a new MCP Client (without establishing connection)

func (*Client) CallTool

func (c *Client) CallTool(ctx context.Context, name string, arguments interface{}, extraArgs ...interface{}) (*types.CallToolResponse, error)

CallTool invokes a specific tool on the server extraArgs are ignored for HTTP/SSE/STDIO transports (only used for Process transport)

func (*Client) CallTools

func (c *Client) CallTools(ctx context.Context, tools []types.ToolCall, extraArgs ...interface{}) (*types.CallToolsResponse, error)

CallTools calls multiple tools in sequence Tools are executed one by one, ensuring order and avoiding race conditions extraArgs are ignored for HTTP/SSE/STDIO transports (only used for Process transport)

func (*Client) CallToolsParallel

func (c *Client) CallToolsParallel(ctx context.Context, tools []types.ToolCall, extraArgs ...interface{}) (*types.CallToolsResponse, error)

CallToolsParallel calls multiple tools concurrently All tools are executed in parallel for better performance Note: Results order matches the input order, but execution is concurrent extraArgs are ignored for HTTP/SSE/STDIO transports (only used for Process transport)

func (*Client) CancelRequest

func (c *Client) CancelRequest(ctx context.Context, requestID interface{}) error

CancelRequest cancels a specific request

func (*Client) ClearAllHandlers

func (c *Client) ClearAllHandlers()

ClearAllHandlers removes all registered handlers

func (*Client) CompleteProgress

func (c *Client) CompleteProgress(ctx context.Context, token uint64) error

CompleteProgress marks a progress token as complete and removes it

func (*Client) Connect

func (c *Client) Connect(ctx context.Context, options ...types.ConnectionOptions) error

Connect establishes connection to the MCP server

func (*Client) CreateProgress

func (c *Client) CreateProgress(ctx context.Context, total uint64) (uint64, error)

CreateProgress creates a progress token for tracking

func (*Client) Disconnect

func (c *Client) Disconnect(ctx context.Context) error

Disconnect closes the connection to the MCP server

func (*Client) GetEventHandlers

func (c *Client) GetEventHandlers() map[string]int

GetEventHandlers returns a copy of current event handlers (for debugging/inspection)

func (*Client) GetInitResult

func (c *Client) GetInitResult() *types.InitializeResponse

GetInitResult returns the stored initialization result

func (*Client) GetLogLevel

func (c *Client) GetLogLevel() types.LogLevel

GetLogLevel returns the current log level

func (*Client) GetMetaInfo

func (c *Client) GetMetaInfo() gouTypes.MetaInfo

GetMetaInfo returns the meta information of the client

func (*Client) GetNotificationHandlers

func (c *Client) GetNotificationHandlers() map[string]int

GetNotificationHandlers returns a copy of current notification handlers (for debugging/inspection)

func (*Client) GetProgress

func (c *Client) GetProgress(token uint64) (*types.Progress, error)

GetProgress returns the current progress for a given token

func (*Client) GetPrompt

func (c *Client) GetPrompt(ctx context.Context, name string, arguments map[string]interface{}) (*types.GetPromptResponse, error)

GetPrompt gets a specific prompt with given arguments

func (*Client) GetSample

func (c *Client) GetSample(ctx context.Context, itemType types.SampleItemType, itemName string, index int) (*types.SampleData, error)

GetSample retrieves a specific sample by index

func (*Client) Info

func (c *Client) Info() *types.ClientInfo

Info returns basic client information

func (*Client) Initialize

func (c *Client) Initialize(ctx context.Context) (*types.InitializeResponse, error)

Initialize initializes the MCP client and exchanges capabilities with the server

func (*Client) Initialized

func (c *Client) Initialized(ctx context.Context) error

Initialized sends the initialized notification to the server Note: In mcp-go v0.32.0, this is typically handled automatically after Initialize

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected checks if the client is connected to the server

func (*Client) IsInitialized

func (c *Client) IsInitialized() bool

IsInitialized checks if the client has been initialized

func (*Client) ListProgress

func (c *Client) ListProgress() map[uint64]*types.Progress

ListProgress returns all active progress tokens

func (*Client) ListPrompts

func (c *Client) ListPrompts(ctx context.Context, cursor string) (*types.ListPromptsResponse, error)

ListPrompts lists all available prompts

func (*Client) ListResources

func (c *Client) ListResources(ctx context.Context, cursor string) (*types.ListResourcesResponse, error)

ListResources lists all available resources

func (*Client) ListSamples

func (c *Client) ListSamples(ctx context.Context, itemType types.SampleItemType, itemName string) (*types.ListSamplesResponse, error)

ListSamples lists available training samples for a tool or resource

func (*Client) ListTools

func (c *Client) ListTools(ctx context.Context, cursor string) (*types.ListToolsResponse, error)

ListTools requests a list of available tools from the server

func (*Client) OnError

func (c *Client) OnError(handler types.ErrorHandler)

OnError registers an error handler

func (*Client) OnEvent

func (c *Client) OnEvent(eventType string, handler func(event types.Event))

OnEvent registers an event handler for a specific event type

func (*Client) OnNotification

func (c *Client) OnNotification(method string, handler types.NotificationHandler)

OnNotification registers a notification handler for a specific method

func (*Client) ReadResource

func (c *Client) ReadResource(ctx context.Context, uri string) (*types.ReadResourceResponse, error)

ReadResource reads a specific resource

func (*Client) RemoveEventHandler

func (c *Client) RemoveEventHandler(eventType string, handler func(event types.Event))

RemoveEventHandler removes an event handler for a specific event type

func (*Client) RemoveNotificationHandler

func (c *Client) RemoveNotificationHandler(method string, handler types.NotificationHandler)

RemoveNotificationHandler removes a notification handler for a specific method

func (*Client) SetLogLevel

func (c *Client) SetLogLevel(ctx context.Context, level types.LogLevel) error

SetLogLevel sets the log level for the server

func (*Client) State

func (c *Client) State() types.ConnectionState

State returns the current connection state

func (*Client) SubscribeResource

func (c *Client) SubscribeResource(ctx context.Context, uri string) error

SubscribeResource subscribes to resource updates

func (*Client) TriggerErrorStandard

func (c *Client) TriggerErrorStandard(ctx context.Context, err error)

TriggerErrorStandard triggers all registered error handlers with a standard error

func (*Client) TriggerEvent

func (c *Client) TriggerEvent(event types.Event)

TriggerEvent triggers all registered event handlers for a specific event type

func (*Client) TriggerNotification

func (c *Client) TriggerNotification(ctx context.Context, notification types.Message)

TriggerNotification triggers all registered notification handlers for a specific method

func (*Client) UnsubscribeResource

func (c *Client) UnsubscribeResource(ctx context.Context, uri string) error

UnsubscribeResource unsubscribes from resource updates

func (*Client) UpdateProgress

func (c *Client) UpdateProgress(ctx context.Context, token uint64, progress uint64) error

UpdateProgress updates the progress for a given token

type TestConfig

type TestConfig struct {
	HTTPUrl        string
	HTTPToken      string
	SSEUrl         string
	SSEToken       string
	SkipHTTPTests  bool
	SkipSSETests   bool
	SkipStdioTests bool
}

TestConfig holds test configuration

type TestConnectionOptions

type TestConnectionOptions struct {
	WithSessionID     bool
	WithCustomHeaders bool
	WithTimeout       bool
	SessionID         string
	CustomHeaders     map[string]string
	ConnectionTimeout time.Duration
}

TestConnectionOptions provides common connection options for testing

type TestDSLInfo

type TestDSLInfo struct {
	Transport   types.TransportType
	Name        string
	URL         string
	HasToken    bool
	Command     string
	EnabledCaps []string
}

TestDSLInfo holds information about test DSL for logging

type TransportTestCase

type TransportTestCase struct {
	Name          string
	Transport     types.TransportType
	DSL           *types.ClientDSL
	ShouldSkip    bool
	SkipReason    string
	ExpectError   bool
	ExpectedError string
	Timeout       time.Duration
}

TransportTestCase represents a test case for a specific transport type

Jump to

Keyboard shortcuts

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