mcp

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrintTestResults

func PrintTestResults(results []TestResult)

PrintTestResults prints formatted test results to stdout.

Types

type Client

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

Client communicates with one MCP server process over stdio (JSON-RPC 2.0).

func NewClient

func NewClient(ctx context.Context, name, command string, args []string, env map[string]string) (*Client, error)

NewClient spawns an MCP server subprocess and returns a connected client.

func (*Client) CallTool

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

CallTool invokes a tool and returns the text result.

func (*Client) Close

func (c *Client) Close() error

Close terminates the MCP server process.

func (*Client) Initialize

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

Initialize performs the MCP handshake (initialize + notifications/initialized).

func (*Client) ListTools

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

ListTools calls tools/list and returns the available tools.

func (*Client) Name

func (c *Client) Name() string

Name returns the configured server name.

func (*Client) Stderr

func (c *Client) Stderr() string

Stderr returns any stderr output from the server process.

type Manager

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

Manager manages the lifecycle of multiple MCP server connections and registers their tools into catpaw's ToolRegistry.

func NewManager

func NewManager() *Manager

NewManager creates an unstarted Manager.

func (*Manager) Close

func (m *Manager) Close()

Close shuts down all MCP server connections.

func (*Manager) IdentitySummary

func (m *Manager) IdentitySummary(defaultIdentity string) string

IdentitySummary returns a prompt-friendly summary of all MCP server identities.

func (*Manager) ServerCount

func (m *Manager) ServerCount() int

ServerCount returns the number of connected servers.

func (*Manager) ServerNames

func (m *Manager) ServerNames() []string

ServerNames returns sorted names of all connected servers.

func (*Manager) StartAll

func (m *Manager) StartAll(ctx context.Context, mcpCfg config.MCPConfig, registry *diagnose.ToolRegistry)

StartAll connects to all configured MCP servers, discovers their tools, and registers them into the ToolRegistry. Servers that fail to start are logged and skipped (best-effort).

type TestResult

type TestResult struct {
	Name     string
	Status   string // PASS, FAIL
	Identity string
	Tools    []string
	Allowed  []string
	Message  string
	Elapsed  time.Duration
}

TestResult holds the result of testing one MCP server.

func RunTest

func RunTest(mcpCfg config.MCPConfig) []TestResult

RunTest connects to each configured MCP server, performs the handshake, discovers tools, and returns structured results. Each server is tested independently; failures are isolated.

type Tool

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

Tool describes one tool exposed by an MCP server.

func (*Tool) ExtractParams

func (t *Tool) ExtractParams() []ToolParam

ExtractParams parses the inputSchema JSON Schema into a flat list of ToolParams.

type ToolContent

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

ToolContent represents one content block in a tool call response.

type ToolParam

type ToolParam struct {
	Name        string
	Type        string
	Description string
	Required    bool
}

ToolParam extracts parameter info from a tool's JSON Schema inputSchema.

Jump to

Keyboard shortcuts

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