Documentation
¶
Index ¶
- Variables
- func CallTool(g gomega.Gomega, target ServiceTarget, path, toolName string, ...) (string, error)
- func CollectDiagnostics(prefix string) string
- func FetchTools(g gomega.Gomega, target ServiceTarget, path string) []string
- func GetNonEmptyLines(output string) []string
- func GetProjectDir() (string, error)
- func GetRequest(url string) ([]byte, http.Header, int, error)
- func LoadImageToKindClusterWithName(name string) error
- func MakeServiceRequest(target ServiceTarget, requestFunc RequestFunc) (body []byte, statusCode int, err error)
- func ParseSSEBody(body []byte) []byte
- func PortForwardPod(ctx context.Context, namespace, podName string, port int) (int, error)
- func PortForwardService(ctx context.Context, namespace, serviceName string, port int) (int, error)
- func PostRequest(url string, payload any, extraHeaders map[string]string) ([]byte, http.Header, int, error)
- func Run(cmd *exec.Cmd) (string, error)
- func WaitForServiceReady(ctx context.Context, target ServiceTarget) error
- type RequestFunc
- type ServiceTarget
- type ToolCallRejected
Constants ¶
This section is empty.
Variables ¶
var MCPInitializeParams = map[string]interface{}{ "protocolVersion": "2024-11-05", "capabilities": map[string]interface{}{}, "clientInfo": map[string]interface{}{ "name": "test-client", "version": "1.0.0", }, }
MCPInitializeParams are the standard parameters for an MCP initialize request.
Functions ¶
func CallTool ¶ added in v0.3.0
func CallTool( g gomega.Gomega, target ServiceTarget, path, toolName string, arguments map[string]interface{}, ) (string, error)
CallTool performs the MCP protocol sequence to invoke a single tool:
- initialize → obtain Mcp-Session-Id
- tools/call → pass Mcp-Session-Id header
It returns the concatenated text content of the tool result and a non-nil *ToolCallRejected error if the gateway received the call but refused to dispatch it (non-200 HTTP, JSON-RPC error envelope, or result.isError==true). Transport-level failures and malformed responses are still reported via g so callers can embed CallTool inside Eventually for retry semantics.
func CollectDiagnostics ¶ added in v0.3.0
CollectDiagnostics writes pod logs, events, and a cluster-wide dump of interesting custom resources to a timestamped directory under $TMPDIR. It enumerates user namespaces automatically (skipping kube-* and cert-manager). The directory path is printed to GinkgoWriter and returned.
Intended for use from AfterEach on test failure.
func FetchTools ¶ added in v0.2.0
func FetchTools(g gomega.Gomega, target ServiceTarget, path string) []string
FetchTools performs the MCP protocol sequence to list tools from a server:
- initialize → obtain Mcp-Session-Id
- tools/list → pass Mcp-Session-Id header
It returns the sorted list of tool names. Failures are reported via g so callers can embed this inside Eventually.
func GetNonEmptyLines ¶
GetNonEmptyLines converts given command output string into individual objects according to line breakers, and ignores the empty elements in it.
func GetProjectDir ¶
GetProjectDir will return the directory where the project is
func GetRequest ¶ added in v0.2.0
GetRequest sends a GET request and returns the response body, status code, and error. This function does not treat non-200 status codes as errors, allowing callers to explicitly check for specific status codes like 404.
func LoadImageToKindClusterWithName ¶
LoadImageToKindClusterWithName loads a local docker image to the kind cluster
func MakeServiceRequest ¶
func MakeServiceRequest( target ServiceTarget, requestFunc RequestFunc, ) (body []byte, statusCode int, err error)
MakeServiceRequest establishes a port-forward to the service, makes an HTTP request, and cleans up. The requestFunc receives the base URL (e.g., "http://localhost:12345") and performs the actual request. Non-2xx HTTP status codes are returned successfully (not treated as errors), allowing callers to verify specific status codes like 404.
func ParseSSEBody ¶
ParseSSEBody extracts JSON payloads from an SSE response body. It returns the concatenated JSON from all "data: ..." lines, or the original body if no SSE data lines are found (plain JSON response).
func PortForwardPod ¶
PortForwardPod creates a port forward to a specific pod
func PortForwardService ¶
PortForwardService creates a port forward to a service by resolving it to a pod
func PostRequest ¶ added in v0.2.0
func PostRequest( url string, payload any, extraHeaders map[string]string, ) ([]byte, http.Header, int, error)
PostRequest sends a POST request with additional headers and returns the response body, response headers, status code, and error. Use this when you need to inspect or forward response headers (e.g. Mcp-Session-Id).
func WaitForServiceReady ¶ added in v0.2.0
func WaitForServiceReady(ctx context.Context, target ServiceTarget) error
WaitForServiceReady waits until the service has at least one running pod.
Types ¶
type RequestFunc ¶
RequestFunc defines a function that makes an HTTP request given a base URL (host:port)
type ServiceTarget ¶ added in v0.2.0
ServiceTarget identifies a Kubernetes service to connect to.
type ToolCallRejected ¶ added in v0.3.0
type ToolCallRejected struct {
HTTPStatus int
RPCError map[string]interface{}
IsMcpError bool
Content interface{}
BodyPreview string
}
ToolCallRejected is returned by CallTool when the gateway received the tools/call request but refused to dispatch it — for example, because an authorization filter blocked the tool. Tests assert on this concrete type (rather than any non-nil error) so that unrelated failures do not silently satisfy a "should be rejected" expectation. Exactly one of HTTPStatus, RPCError, or IsMcpError describes the reason; the others are zero-valued.
IsMcpError corresponds to the `isError` field on the MCP CallToolResult, defined in the MCP specification (revision 2024-11-05) under "Server Features → Tools → Error Handling": a tool execution error is reported in-band on the tool result with `isError: true`, distinct from a JSON-RPC protocol error. See https://modelcontextprotocol.io/specification/2024-11-05/server/tools#error-handling
func (*ToolCallRejected) Error ¶ added in v0.3.0
func (e *ToolCallRejected) Error() string