mcptool

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package mcptool adapts a Model Context Protocol (MCP) server into agentcore.Tool values, using the official modelcontextprotocol/go-sdk client over the Streamable HTTP transport.

It is a thin, policy-free bridge: Connect opens a session, Session.Tools lists the server's tools as executable [agentcore.Tool]s keyed by their un-namespaced names, and each tool's Execute performs a CallTool round-trip and returns the joined text content. Higher-level policy — allow-list filtering, namespacing, collision handling, connect timeouts, and metering — belongs to the composition layer that builds on this package.

Index

Constants

View Source
const DefaultClientName = "datum-assistant-service"

DefaultClientName is the MCP client name announced during initialization.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Endpoint is the Streamable HTTP endpoint of the MCP server.
	Endpoint string
	// HTTPClient overrides the HTTP client used for the transport. Nil uses a
	// client whose transport adds the Accept header some stateless servers
	// require (see [acceptRoundTripper]).
	HTTPClient *http.Client
	// ClientName overrides the announced client name. Empty uses
	// [DefaultClientName].
	ClientName string
	// ClientVersion is the announced client version. Empty uses "0".
	ClientVersion string
	// Headers are set on every request of this session, but only on requests
	// to Endpoint's own host, so a redirect off the endpoint cannot carry a
	// credential meant for it. Which headers an endpoint deserves is
	// internal/capability's policy, not this package's.
	Headers map[string]string
	// EnableStandaloneSSE opts into the server-initiated SSE stream. It is off
	// by default because the per-request, request/response usage here needs no
	// server-initiated notifications, and some stateless servers reject the
	// standalone GET.
	EnableStandaloneSSE bool
}

Options configures a Connect call. Endpoint is required.

type Session

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

Session is a connected MCP client session. It is not safe for concurrent use. Close it when done.

func Connect

func Connect(ctx context.Context, opts Options) (*Session, error)

Connect opens a session to the MCP server described by opts.

func (*Session) Close

func (s *Session) Close() error

Close ends the session.

func (*Session) Tools

func (s *Session) Tools(ctx context.Context) (map[string]agentcore.Tool, error)

Tools lists the server's tools as executable [agentcore.Tool]s keyed by their un-namespaced names. The listing auto-paginates.

Jump to

Keyboard shortcuts

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