mcp

package
v0.0.0-...-adf2613 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: Apache-2.0 Imports: 44 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(globalSettings *configv1.GlobalSettings) upstream.Upstream

NewUpstream creates a new instance of Upstream.

Parameters:

  • globalSettings (*configv1.GlobalSettings): The parameter.

Returns:

  • upstream.Upstream: The result.

Side Effects:

  • None.

Summary: Initializes NewUpstream operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

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.

Parameters:

  • f func(client *mcp.Client ([]mcp.Root): The parameter.
  • ctx context.Context ([]mcp.Root): The parameter.
  • transport mcp.Transport ([]mcp.Root): The parameter.
  • roots ([]mcp.Root): The parameter.

Returns:

  • ClientSession: The result.
  • error): The result.

Side Effects:

  • None.

Summary: Updates SetConnectForTesting operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

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.

Parameters:

  • f func(impl (*mcp.Implementation): The parameter.

Returns:

  • *mcp.Client): The result.

Side Effects:

  • None.

Summary: Updates SetNewClientForTesting operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

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.

Parameters:

  • f func(client *mcp.Client (*http.Client): The parameter.
  • stdioConfig *configv1.McpStdioConnection (*http.Client): The parameter.
  • httpAddress string (*http.Client): The parameter.
  • httpClient (*http.Client): The parameter.

Returns:

  • client.MCPClient): The result.

Side Effects:

  • None.

Summary: Updates SetNewClientImplForTesting operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

Types

type BundleDockerTransport

type BundleDockerTransport struct {
	Image      string
	Command    string
	Args       []string
	Env        []string
	Mounts     []mount.Mount
	WorkingDir string
	// contains filtered or unexported fields
}

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.

Summary: Represents a BundleDockerTransport.

func (*BundleDockerTransport) Connect

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

Parameters:

  • ctx (context.Context): The context for the request.

Returns:

  • mcp.Connection: The result.
  • error: An error if the operation fails.

Errors:

  • Returns an error if ...

Side Effects:

  • None.

Summary: Executes Connect operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

type BundleLocalTransport

type BundleLocalTransport struct {
	Command    string
	Args       []string
	Env        []string
	WorkingDir string
}

BundleLocalTransport implements mcp.Transport for running a bundle locally via exec.

Summary: Represents a BundleLocalTransport.

func (*BundleLocalTransport) Connect

Connect establishes a connection to the local process.

Parameters:

  • ctx (context.Context): The context for the request.

Returns:

  • mcp.Connection: The result.
  • error: An error if the operation fails.

Errors:

  • Returns an error if the command fails to start.

Side Effects:

  • Starts a local process.

Summary: Executes Connect operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

type ClientSession

type ClientSession interface {
	// ListTools lists the tools available in the session.
	//
	// ctx is the context for the request.
	// params is the params.
	//
	// Returns the result.
	// Returns an error if the operation fails.
	ListTools(ctx context.Context, params *mcp.ListToolsParams) (*mcp.ListToolsResult, error)
	// ListPrompts lists the prompts available in the session.
	//
	// ctx is the context for the request.
	// params is the params.
	//
	// Returns the result.
	// Returns an error if the operation fails.
	ListPrompts(ctx context.Context, params *mcp.ListPromptsParams) (*mcp.ListPromptsResult, error)
	// ListResources lists the resources available in the session.
	//
	// ctx is the context for the request.
	// params is the params.
	//
	// Returns the result.
	// Returns an error if the operation fails.
	ListResources(ctx context.Context, params *mcp.ListResourcesParams) (*mcp.ListResourcesResult, error)
	// GetPrompt retrieves a prompt from the session.
	//
	// ctx is the context for the request.
	// params is the params.
	//
	// Returns the result.
	// Returns an error if the operation fails.
	GetPrompt(ctx context.Context, params *mcp.GetPromptParams) (*mcp.GetPromptResult, error)
	// ReadResource reads a resource from the session.
	//
	// ctx is the context for the request.
	// params is the params.
	//
	// Returns the result.
	// Returns an error if the operation fails.
	ReadResource(ctx context.Context, params *mcp.ReadResourceParams) (*mcp.ReadResourceResult, error)
	// CallTool calls a tool in the session.
	//
	// ctx is the context for the request.
	// params is the params.
	//
	// Returns the result.
	// Returns an error if the operation fails.
	CallTool(ctx context.Context, params *mcp.CallToolParams) (*mcp.CallToolResult, error)
	// Close closes the session.
	//
	// Returns an error if the operation fails.
	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.

Summary: Represents a ClientSession.

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.

Summary: Represents a DockerTransport.

func (*DockerTransport) Connect

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

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

Parameters:

  • ctx (context.Context): The context for the request.

Returns:

  • mcp.Connection: The result.
  • error: An error if the operation fails.

Errors:

  • Returns an error if ...

Side Effects:

  • None.

Summary: Executes Connect operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

type Manifest

type Manifest struct {
	// ManifestVersion is the version of the manifest format.
	ManifestVersion string `json:"manifest_version"`
	// Name is the name of the bundle.
	Name string `json:"name"`
	// Version is the version of the bundle.
	Version string `json:"version"`
	// Description is a description of the bundle.
	Description string `json:"description"`
	// Server contains configuration for the MCP server within the bundle.
	Server ManifestServer `json:"server"`
	// UserConfig contains default configuration for the user.
	UserConfig json.RawMessage `json:"user_config"`
}

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

Summary: Represents a Manifest.

type ManifestMcpConfig

type ManifestMcpConfig struct {
	// Command is the command to run the server.
	Command string `json:"command"`
	// Args are the arguments to pass to the command.
	Args []string `json:"args"`
	// Env is a map of environment variables to set for the server.
	Env map[string]string `json:"env"`
}

ManifestMcpConfig represents the MCP configuration in the manifest.

Summary: Represents a ManifestMcpConfig.

type ManifestServer

type ManifestServer struct {
	// Type is the type of the server (e.g., "node", "python").
	Type string `json:"type"`
	// EntryPoint is the entry point script or command for the server.
	EntryPoint string `json:"entry_point"`
	// McpConfig contains specific configuration for running the MCP server.
	McpConfig ManifestMcpConfig `json:"mcp_config"`
}

ManifestServer represents the server configuration in the manifest.

Summary: Represents a ManifestServer.

type SessionRegistry

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

SessionRegistry manages the mapping between upstream MCP sessions and downstream tool sessions. This allows requests from upstream (like sampling) to be routed to the correct downstream client.

Summary: Represents a SessionRegistry.

func NewSessionRegistry

func NewSessionRegistry() *SessionRegistry

NewSessionRegistry creates a new SessionRegistry.

Returns:

  • *SessionRegistry: The result.

Side Effects:

  • None.

Summary: Initializes NewSessionRegistry operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

func (*SessionRegistry) Get

func (r *SessionRegistry) Get(upstreamSession mcp.Session) (tool.Session, bool)

Get retrieves the downstream session associated with an upstream session.

Parameters:

  • upstreamSession (mcp.Session): The parameter.

Returns:

  • tool.Session: The result.
  • bool: The result.

Side Effects:

  • None.

Summary: Retrieves Get operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

func (*SessionRegistry) Register

func (r *SessionRegistry) Register(upstreamSession mcp.Session, downstreamSession tool.Session)

Register registers a mapping between an upstream session and a downstream session.

Parameters:

  • upstreamSession (mcp.Session): The parameter.
  • downstreamSession (tool.Session): The parameter.

Returns:

  • None.

Side Effects:

  • None.

Summary: Executes Register operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

func (*SessionRegistry) Unregister

func (r *SessionRegistry) Unregister(upstreamSession mcp.Session)

Unregister removes the mapping for an upstream session.

Parameters:

  • upstreamSession (mcp.Session): The parameter.

Returns:

  • None.

Side Effects:

  • None.

Summary: Executes Unregister operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

type StdioTransport

type StdioTransport struct {
	Command *exec.Cmd
}

StdioTransport implements mcp.Transport for a local command, capturing stderr to provide better error messages on failure.

Summary: Represents a StdioTransport.

func (*StdioTransport) Connect

func (t *StdioTransport) Connect(_ context.Context) (mcp.Connection, error)

Connect starts the command and returns a connection.

Parameters:

  • _ (context.Context): The parameter.

Returns:

  • mcp.Connection: The result.
  • error: An error if the operation fails.

Errors:

  • Returns an error if ...

Side Effects:

  • None.

Summary: Executes Connect operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

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.

Summary: Represents a StreamableHTTP.

func (*StreamableHTTP) RoundTrip

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

RoundTrip executes an HTTP request and returns the response.

Parameters:

  • req (*http.Request): The parameter.

Returns:

  • *http.Response: The result.
  • error: An error if the operation fails.

Errors:

  • Returns an error if ...

Side Effects:

  • None.

Summary: Executes RoundTrip operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

type Upstream

type Upstream struct {

	// BundleBaseDir is the directory where bundles are extracted.
	BundleBaseDir string
	// contains filtered or unexported fields
}

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.

Summary: Represents a Upstream.

func (*Upstream) CheckHealth

func (u *Upstream) CheckHealth(ctx context.Context) error

CheckHealth performs a health check on the upstream service.

Parameters:

  • ctx (context.Context): The context for the request.

Returns:

  • error: An error if the operation fails.

Errors:

  • Returns an error if ...

Side Effects:

  • None.

Summary: Executes CheckHealth operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

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.

Parameters:

  • ctx (context.Context): The context for the request.
  • serviceConfig (*configv1.UpstreamServiceConfig): The serviceConfig parameter.
  • toolManager (tool.ManagerInterface): The toolManager parameter.
  • promptManager (prompt.ManagerInterface): The promptManager parameter.
  • resourceManager (resource.ManagerInterface): The resourceManager parameter.
  • isReload (bool): The isReload parameter.

Returns:

  • string: The resulting string.
  • []*configv1.ToolDefinition: The resulting []*configv1.ToolDefinition.
  • []*configv1.ResourceDefinition: The resulting []*configv1.ResourceDefinition.
  • error: An error if the operation fails.

Errors:

  • Returns an error if the operation fails or is invalid.

Side Effects:

  • None

Summary: Executes Register operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

func (*Upstream) Shutdown

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

Shutdown cleans up any temporary resources associated with the upstream, such as extracted bundle directories.

Parameters:

  • _ (context.Context): The parameter.

Returns:

  • error: An error if the operation fails.

Errors:

  • Returns an error if ...

Side Effects:

  • None.

Summary: Executes Shutdown operation.

Parameters:

  • TODO: Document parameters.

Returns:

  • TODO: Document returns.

Errors:

  • TODO: Document errors.

Side Effects:

  • None.

Jump to

Keyboard shortcuts

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