utils

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 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:

  1. initialize → obtain Mcp-Session-Id
  2. 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

func GetNonEmptyLines(output string) []string

GetNonEmptyLines converts given command output string into individual objects according to line breakers, and ignores the empty elements in it.

func GetProjectDir

func GetProjectDir() (string, error)

GetProjectDir will return the directory where the project is

func GetRequest added in v0.2.0

func GetRequest(url string) ([]byte, http.Header, int, error)

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

func LoadImageToKindClusterWithName(name string) error

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

func ParseSSEBody(body []byte) []byte

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

func PortForwardPod(ctx context.Context, namespace, podName string, port int) (int, error)

PortForwardPod creates a port forward to a specific pod

func PortForwardService

func PortForwardService(ctx context.Context, namespace, serviceName string, port int) (int, error)

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 Run

func Run(cmd *exec.Cmd) (string, error)

Run executes the provided command within this context

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

type RequestFunc func(baseURL string) (body []byte, statusCode int, err error)

RequestFunc defines a function that makes an HTTP request given a base URL (host:port)

type ServiceTarget added in v0.2.0

type ServiceTarget struct {
	Namespace   string
	ServiceName string
	Port        int
}

ServiceTarget identifies a Kubernetes service to connect to.

Jump to

Keyboard shortcuts

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