testutil

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package testutil provides shared test utilities for protomcp tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FixturePath

func FixturePath(relPath string) string

FixturePath returns the absolute path to a fixture file relative to the repo root.

func RepoRoot

func RepoRoot() string

RepoRoot returns the absolute path to the repository root by walking up from this source file.

func SetupPythonPath

func SetupPythonPath()

SetupPythonPath configures PYTHONPATH so that the generated protobuf code is importable by Python fixture scripts.

Types

type Capabilities

type Capabilities struct {
	Tools *ToolsCapability `json:"tools,omitempty"`
}

type ContentItem

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

type InitializeResult

type InitializeResult struct {
	ProtocolVersion string       `json:"protocolVersion"`
	Capabilities    Capabilities `json:"capabilities"`
	ServerInfo      ServerInfo   `json:"serverInfo"`
}

type JSONRPCError

type JSONRPCError struct {
	Code    int             `json:"code"`
	Message string          `json:"message"`
	Data    json.RawMessage `json:"data,omitempty"`
}

JSONRPCError is a JSON-RPC 2.0 error object.

type JSONRPCRequest

type JSONRPCRequest struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      json.RawMessage `json:"id,omitempty"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
}

JSONRPCRequest is a minimal JSON-RPC 2.0 request.

type JSONRPCResponse

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

JSONRPCResponse is a minimal JSON-RPC 2.0 response.

type MCPTool

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

type PMCPResult

type PMCPResult struct {
	Resp    JSONRPCResponse
	Raw     []byte
	Latency time.Duration
}

PMCPResult holds a parsed JSON-RPC response plus the raw bytes and the round trip latency.

type ServerInfo

type ServerInfo struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

type StdioPMCP

type StdioPMCP struct {
	Cmd    *exec.Cmd
	Stdin  io.WriteCloser
	Reader *bufio.Scanner
	// contains filtered or unexported fields
}

StdioPMCP wraps a running pmcp process and provides helpers for sending JSON-RPC requests over its stdio transport.

func StartPMCP

func StartPMCP(tb testing.TB, args ...string) *StdioPMCP

StartPMCP builds (if needed) and starts the pmcp binary with the given args.

func (*StdioPMCP) Initialize

func (p *StdioPMCP) Initialize(tb testing.TB)

Initialize sends a proper MCP initialize handshake (initialize + initialized notification).

func (*StdioPMCP) Send

func (p *StdioPMCP) Send(tb testing.TB, method string, params interface{}) PMCPResult

Send sends a JSON-RPC request and reads the response synchronously.

func (*StdioPMCP) SendNotification

func (p *StdioPMCP) SendNotification(tb testing.TB, method string, params interface{})

SendNotification sends a JSON-RPC notification (no ID, no response).

type ToolsCallResult

type ToolsCallResult struct {
	Content []ContentItem `json:"content"`
	IsError bool          `json:"isError,omitempty"`
}

type ToolsCapability

type ToolsCapability struct {
	ListChanged bool `json:"listChanged"`
}

type ToolsListResult

type ToolsListResult struct {
	Tools []MCPTool `json:"tools"`
}

Jump to

Keyboard shortcuts

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