mcp

package
v0.7.58 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package mcp is the harness's client of its one tool source: an MCP server reached over streamable HTTP with a bearer token. It lists the server's tools and calls them, and does nothing else the protocol offers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// URL is the server's streamable HTTP endpoint.
	URL string
	// Token returns the bearer token. It is called for every request.
	Token func() string
	// HTTP sends the requests.
	HTTP *http.Client
	// Name and Version identify the client to the server.
	Name, Version string
	// contains filtered or unexported fields
}

Client is a connection to one MCP server.

func (*Client) CallTool

func (c *Client) CallTool(ctx context.Context, name string, arguments json.RawMessage) (*Result, error)

CallTool runs one tool. arguments is the JSON object of its arguments. A tool that reports an error is a Result with IsError set; an *Error means the call did not reach the tool or the server refused it.

func (*Client) Initialize

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

Initialize opens the session. It must be called once before the others.

func (*Client) ListTools

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

ListTools returns every tool the server offers, following its pages.

type Content

type Content struct {
	// Type is text, image, resource, or a type the client passes over.
	Type string `json:"type"`
	Text string `json:"text"`
	// Data and MimeType hold an image, base64-encoded.
	Data     string `json:"data"`
	MimeType string `json:"mimeType"`
	// Resource is an embedded resource. Its text is content the server
	// marked as its own to pass on whole.
	Resource *struct {
		URI      string `json:"uri"`
		MimeType string `json:"mimeType"`
		Text     string `json:"text"`
	} `json:"resource"`
}

Content is one item of a tool's result.

type Error

type Error struct {
	// Status is the HTTP status, zero when there was none. Code is the
	// JSON-RPC error code, zero when the failure was not one.
	Status  int
	Code    int
	Message string
}

Error is a failure to reach the server, or the server's refusal.

func (*Error) Error

func (e *Error) Error() string

type Result

type Result struct {
	Content []Content `json:"content"`
	IsError bool      `json:"isError"`
}

Result is a tool call's result.

type Tool

type Tool struct {
	Name        string          `json:"name"`
	Description string          `json:"description"`
	InputSchema json.RawMessage `json:"inputSchema"`
}

Tool is a tool the server offers.

Jump to

Keyboard shortcuts

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