mcp

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package mcp provides MCP client for external context sources.

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 manages communication with an MCP server.

func NewClient

func NewClient(command string, args []string, env map[string]string) (*Client, error)

NewClient creates a new MCP client by spawning the server process.

func (*Client) Call

func (c *Client) Call(ctx context.Context, method string, params any, result any) error

Call makes a synchronous RPC call.

func (*Client) CallTool

func (c *Client) CallTool(ctx context.Context, name string, args map[string]any) ([]ToolContent, error)

CallTool invokes a tool on the MCP server.

func (*Client) Close

func (c *Client) Close() error

Close shuts down the MCP client.

func (*Client) Initialize

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

Initialize sends the initialize request to the MCP server.

func (*Client) ListTools

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

ListTools returns the available tools from the MCP server.

func (*Client) Notify

func (c *Client) Notify(method string, params any) error

Notify sends a notification (no response expected).

type RPCError

type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data,omitempty"`
}

RPCError represents a JSON-RPC error.

func (*RPCError) Error

func (e *RPCError) Error() string

type Request

type Request struct {
	JSONRPC string `json:"jsonrpc"`
	ID      int64  `json:"id"`
	Method  string `json:"method"`
	Params  any    `json:"params,omitempty"`
}

Request represents a JSON-RPC request.

type Response

type Response struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      int64           `json:"id"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   *RPCError       `json:"error,omitempty"`
}

Response represents a JSON-RPC response.

type Source

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

Source fetches context from an MCP server.

func NewSource

func NewSource(name string, cfg ctx.MCPServerConfig) (*Source, error)

NewSource creates a new MCP source from configuration.

func (*Source) Close

func (s *Source) Close() error

Close shuts down the MCP client.

func (*Source) Fetch

func (s *Source) Fetch(c context.Context) (*ctx.ContextData, error)

Fetch retrieves context from the MCP server.

func (*Source) Name

func (s *Source) Name() string

Name returns the source identifier.

func (*Source) String

func (s *Source) String() string

String returns a human-readable description.

func (*Source) Type

func (s *Source) Type() ctx.SourceType

Type returns the source type.

type Tool

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

Tool represents an MCP tool.

type ToolContent

type ToolContent struct {
	Type string `json:"type"`
	Text string `json:"text,omitempty"`
}

ToolContent represents content returned by a tool.

Jump to

Keyboard shortcuts

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