mcp

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Overview

Package mcp provides MCP upstream integration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewUpstream

func NewUpstream() upstream.Upstream

NewUpstream creates a new instance of Upstream.

func SetConnectForTesting

func SetConnectForTesting(f func(client *mcp.Client, ctx context.Context, transport mcp.Transport, roots []mcp.Root) (ClientSession, error))

SetConnectForTesting provides a hook for injecting a mock mcp.Client.Connect function during tests. This should only be used for testing purposes.

func SetNewClientForTesting

func SetNewClientForTesting(f func(impl *mcp.Implementation) *mcp.Client)

SetNewClientForTesting provides a hook for injecting a mock mcp.Client during tests. This should only be used for testing purposes.

func SetNewClientImplForTesting

func SetNewClientImplForTesting(f func(client *mcp.Client, stdioConfig *configv1.McpStdioConnection, httpAddress string, httpClient *http.Client) client.MCPClient)

SetNewClientImplForTesting provides a hook for injecting a mock MCP client implementation during tests. This should only be used for testing purposes.

Types

type BundleDockerTransport

type BundleDockerTransport struct {
	Image      string
	Command    string
	Args       []string
	Env        []string
	Mounts     []mount.Mount
	WorkingDir string
}

BundleDockerTransport implements the mcp.Transport interface to connect to a service running inside a Docker container from a bundle. It supports mounts and environment variables.

func (*BundleDockerTransport) Connect

Connect establishes a connection to the service within the Docker container.

type ClientSession

type ClientSession interface {
	// ListTools lists the tools available in the session.
	ListTools(ctx context.Context, params *mcp.ListToolsParams) (*mcp.ListToolsResult, error)
	// ListPrompts lists the prompts available in the session.
	ListPrompts(ctx context.Context, params *mcp.ListPromptsParams) (*mcp.ListPromptsResult, error)
	// ListResources lists the resources available in the session.
	ListResources(ctx context.Context, params *mcp.ListResourcesParams) (*mcp.ListResourcesResult, error)
	// GetPrompt retrieves a prompt from the session.
	GetPrompt(ctx context.Context, params *mcp.GetPromptParams) (*mcp.GetPromptResult, error)
	// ReadResource reads a resource from the session.
	ReadResource(ctx context.Context, params *mcp.ReadResourceParams) (*mcp.ReadResourceResult, error)
	// CallTool calls a tool in the session.
	CallTool(ctx context.Context, params *mcp.CallToolParams) (*mcp.CallToolResult, error)
	// Close closes the session.
	Close() error
}

ClientSession defines an interface that abstracts the capabilities of an mcp.ClientSession. This is used primarily for testing, allowing mock sessions to be injected.

type DockerTransport

type DockerTransport struct {
	StdioConfig *configv1.McpStdioConnection
}

DockerTransport implements the mcp.Transport interface to connect to a service running inside a Docker container. It manages the container lifecycle.

func (*DockerTransport) Connect

func (t *DockerTransport) Connect(ctx context.Context) (mcp.Connection, error)

Connect establishes a connection to the service within the Docker container.

type Manifest

type Manifest struct {
	ManifestVersion string          `json:"manifest_version"`
	Name            string          `json:"name"`
	Version         string          `json:"version"`
	Description     string          `json:"description"`
	Server          ManifestServer  `json:"server"`
	UserConfig      json.RawMessage `json:"user_config"`
}

Manifest represents the structure of the manifest.json file in an MCP bundle.

type ManifestMcpConfig

type ManifestMcpConfig struct {
	Command string            `json:"command"`
	Args    []string          `json:"args"`
	Env     map[string]string `json:"env"`
}

ManifestMcpConfig represents the MCP configuration in the manifest.

type ManifestServer

type ManifestServer struct {
	Type       string            `json:"type"`
	EntryPoint string            `json:"entry_point"`
	McpConfig  ManifestMcpConfig `json:"mcp_config"`
}

ManifestServer represents the server configuration in the manifest.

type StreamableHTTP

type StreamableHTTP struct {
	// Address is the HTTP address of the MCP service.
	Address string
	// Client is the HTTP client to use for the connection.
	Client *http.Client
}

StreamableHTTP implements the mcp.Transport interface for HTTP connections.

func (*StreamableHTTP) RoundTrip

func (t *StreamableHTTP) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes an HTTP request and returns the response.

type Upstream

type Upstream struct{}

Upstream implements the upstream.Upstream interface for services that are themselves MCP-compliant. It connects to the downstream MCP service, discovers its tools, prompts, and resources, and registers them with the current server, effectively acting as a proxy or aggregator.

func (*Upstream) Register

func (u *Upstream) Register(
	ctx context.Context,
	serviceConfig *configv1.UpstreamServiceConfig,
	toolManager tool.ManagerInterface,
	promptManager prompt.ManagerInterface,
	resourceManager resource.ManagerInterface,
	isReload bool,
) (string, []*configv1.ToolDefinition, []*configv1.ResourceDefinition, error)

Register handles the registration of another MCP service as an upstream. It determines the connection type (stdio or HTTP), connects to the downstream service, lists its available tools, prompts, and resources, and registers them with the appropriate managers.

func (*Upstream) Shutdown

func (u *Upstream) Shutdown(_ context.Context) error

Shutdown is a no-op for the MCP upstream, as the connections it manages are transient and established on a per-call basis. There are no persistent connections to tear down.

Jump to

Keyboard shortcuts

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