client

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Copyright 2026 Teradata

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Package client implements the MCP client for connecting to MCP servers.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Package client implements MCP client prompts support.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Package client implements MCP client resources support.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Package client implements MCP client tools support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents an MCP client connection to a server

func NewClient

func NewClient(config Config) *Client

NewClient creates a new MCP client

func (*Client) CallTool

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

CallTool invokes a tool with given arguments Returns interface{} to avoid import cycles in shuttle package (actual type is *protocol.CallToolResult)

func (*Client) Close

func (c *Client) Close() error

Close closes the client connection

func (*Client) GetPrompt

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

GetPrompt retrieves a prompt with arguments

func (*Client) Initialize

func (c *Client) Initialize(ctx context.Context, clientInfo protocol.Implementation) error

Initialize performs the MCP handshake

func (*Client) IsInitialized

func (c *Client) IsInitialized() bool

IsInitialized returns whether the client is initialized

func (*Client) ListPrompts

func (c *Client) ListPrompts(ctx context.Context) ([]protocol.Prompt, error)

ListPrompts returns all available prompts from the server

func (*Client) ListResources

func (c *Client) ListResources(ctx context.Context) ([]protocol.Resource, error)

ListResources returns all available resources from the server

func (*Client) ListTools

func (c *Client) ListTools(ctx context.Context) ([]protocol.Tool, error)

ListTools returns all available tools from the server

func (*Client) Ping

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

Ping sends a ping to check connection health

func (*Client) ReadResource

func (c *Client) ReadResource(ctx context.Context, uri string) (*protocol.ReadResourceResult, error)

ReadResource reads a resource by URI

func (*Client) ServerCapabilities

func (c *Client) ServerCapabilities() protocol.ServerCapabilities

ServerCapabilities returns the server capabilities

func (*Client) ServerInfo

func (c *Client) ServerInfo() protocol.Implementation

ServerInfo returns the server implementation info

func (*Client) SetSamplingHandler

func (c *Client) SetSamplingHandler(handler SamplingHandler)

SetSamplingHandler registers a handler for sampling requests

func (*Client) SubscribeResource

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

SubscribeResource subscribes to resource changes

func (*Client) UnsubscribeResource

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

UnsubscribeResource unsubscribes from resource changes

type Config

type Config struct {
	Transport transport.Transport
	Logger    *zap.Logger

	// Client info
	Name    string
	Version string

	// Capabilities
	SupportsSampling bool
	SupportsRoots    bool

	// Timeouts
	RequestTimeout time.Duration // Default: 30s
}

Config configures the MCP client

type InstrumentedClient

type InstrumentedClient struct {
	// contains filtered or unexported fields
}

InstrumentedClient wraps an MCP Client with observability instrumentation. It captures detailed traces and metrics for every MCP operation, including: - Operation type and parameters - Execution duration and success/failure - Result data and errors - Server identification

This wrapper is transparent and can wrap any Client.

func NewInstrumentedClient

func NewInstrumentedClient(client *Client, tracer observability.Tracer, serverName string) *InstrumentedClient

NewInstrumentedClient creates a new instrumented MCP client.

func (*InstrumentedClient) CallTool

func (ic *InstrumentedClient) CallTool(ctx context.Context, name string, arguments map[string]interface{}) (interface{}, error)

CallTool calls a tool with observability instrumentation. Returns interface{} to avoid import cycles (actual type is *protocol.CallToolResult)

func (*InstrumentedClient) Close

func (ic *InstrumentedClient) Close() error

Close delegates to the underlying client.

func (*InstrumentedClient) GetPrompt

func (ic *InstrumentedClient) GetPrompt(ctx context.Context, name string, arguments map[string]interface{}) (*protocol.GetPromptResult, error)

GetPrompt gets a prompt with observability instrumentation.

func (*InstrumentedClient) Initialize

func (ic *InstrumentedClient) Initialize(ctx context.Context, clientInfo protocol.Implementation) error

Initialize performs the MCP handshake with observability instrumentation.

func (*InstrumentedClient) IsInitialized

func (ic *InstrumentedClient) IsInitialized() bool

IsInitialized delegates to the underlying client.

func (*InstrumentedClient) ListPrompts

func (ic *InstrumentedClient) ListPrompts(ctx context.Context) ([]protocol.Prompt, error)

ListPrompts lists available prompts with observability instrumentation.

func (*InstrumentedClient) ListResources

func (ic *InstrumentedClient) ListResources(ctx context.Context) ([]protocol.Resource, error)

ListResources lists available resources with observability instrumentation.

func (*InstrumentedClient) ListTools

func (ic *InstrumentedClient) ListTools(ctx context.Context) ([]protocol.Tool, error)

ListTools lists available tools with observability instrumentation.

func (*InstrumentedClient) Ping

func (ic *InstrumentedClient) Ping(ctx context.Context) error

Ping delegates to the underlying client.

func (*InstrumentedClient) ReadResource

func (ic *InstrumentedClient) ReadResource(ctx context.Context, uri string) (*protocol.ReadResourceResult, error)

ReadResource reads a resource with observability instrumentation.

func (*InstrumentedClient) SetSamplingHandler

func (ic *InstrumentedClient) SetSamplingHandler(handler SamplingHandler)

SetSamplingHandler delegates to the underlying client.

func (*InstrumentedClient) SubscribeResource

func (ic *InstrumentedClient) SubscribeResource(ctx context.Context, uri string) error

SubscribeResource subscribes to resource updates with observability instrumentation.

func (*InstrumentedClient) UnsubscribeResource

func (ic *InstrumentedClient) UnsubscribeResource(ctx context.Context, uri string) error

UnsubscribeResource delegates to the underlying client.

type Notification

type Notification struct {
	Method string
	Params json.RawMessage
}

Notification represents a notification from the server

type ProgressHandler

type ProgressHandler func(progress, total float64)

ProgressHandler is called for progress updates

type SamplingHandler

type SamplingHandler func(ctx context.Context, params protocol.SamplingParams) (*protocol.SamplingResult, error)

SamplingHandler is called when server requests LLM completion

Jump to

Keyboard shortcuts

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