harpoon

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Module = fx.Module(
	"harpoon",
	fx.Provide(newHarpoonService, newHarpoonGuardedMux, newHostBusSubscriber, newHostBus),
	fx.Invoke(registerAdditionalTransport, startHostRegistration),
)

Module wires the harpoon MCP server.

Functions

This section is empty.

Types

type CallBuffer

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

CallBuffer keeps a fixed-size ring buffer of recent calls.

func NewCallBuffer

func NewCallBuffer() *CallBuffer

NewCallBuffer constructs a ring buffer for recent calls.

func (*CallBuffer) RecordCall

func (b *CallBuffer) RecordCall(entry CallEntry)

RecordCall records a call entry into the ring buffer.

func (*CallBuffer) Snapshot

func (b *CallBuffer) Snapshot(limit int, label string) []CallEntry

Snapshot returns up to limit entries, newest first, optionally filtered by label.

type CallEntry

type CallEntry struct {
	Timestamp               time.Time `json:"timestamp"`
	Label                   string    `json:"label"`
	URL                     string    `json:"url"`
	Method                  string    `json:"method"`
	Status                  int       `json:"status"`
	LatencyMS               int       `json:"latency_ms"`
	ResponseContentType     string    `json:"response_content_type,omitempty"`
	ReqBytes                int       `json:"req_bytes"`
	RespBytes               int       `json:"resp_bytes"`
	Error                   string    `json:"error,omitempty"`
	RequestBody             string    `json:"request_body,omitempty"`
	ResponseBody            string    `json:"response_body,omitempty"`
	ResponseBodyTransformed string    `json:"response_body_transformed,omitempty"`
	BodyIsBase64            bool      `json:"body_is_base64,omitempty"`
}

CallEntry captures a recent harpoon call for the admin UI.

type Registry

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

Registry stores allowed targets keyed by label.

func NewRegistry

func NewRegistry(logger *slog.Logger, allowPlaintext bool, targets []Target) (*Registry, error)

NewRegistry constructs a registry seeded with the provided targets and a default limit.

func NewRegistryWithLimit

func NewRegistryWithLimit(logger *slog.Logger, allowPlaintext bool, targets []Target, limit int) (*Registry, error)

NewRegistryWithLimit constructs a registry with a maximum number of targets.

func (*Registry) AllowsURL

func (r *Registry) AllowsURL(candidate *url.URL) bool

AllowsURL reports whether the URL exactly matches any registered target after normalization.

func (*Registry) Count

func (r *Registry) Count() int

Count reports the number of registered targets.

func (*Registry) ExplainBlockedRedirect

func (r *Registry) ExplainBlockedRedirect(candidate *url.URL) *redirectMismatchDetails

ExplainBlockedRedirect classifies why a redirect target missed the allow list.

func (*Registry) Lookup

func (r *Registry) Lookup(label string) (Target, bool)

Lookup returns the target for a label.

func (*Registry) RegisterTarget

func (r *Registry) RegisterTarget(target Target) error

RegisterTarget adds a target to the registry after validation.

func (*Registry) Resolve

func (r *Registry) Resolve(label string) (*url.URL, error)

Resolve returns the target URL for a label.

func (*Registry) SummarizeTargets

func (r *Registry) SummarizeTargets() []map[string]string

SummarizeTargets returns a stable, log-friendly projection of targets.

func (*Registry) TargetForURL

func (r *Registry) TargetForURL(candidate *url.URL) (Target, bool)

TargetForURL returns the configured target whose URL exactly matches candidate.

func (*Registry) Targets

func (r *Registry) Targets() []Target

Targets returns a copy of the registered targets in registration order.

func (*Registry) WaitForTarget

func (r *Registry) WaitForTarget(ctx context.Context, label string) (Target, error)

WaitForTarget blocks until a target with the provided label is registered or ctx expires.

type Server

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

Server provides MCP tools for constrained HTTP access.

func NewServer

func NewServer(cfg *config.HarpoonConfig, registry *Registry, buffer *CallBuffer, logger *slog.Logger, opts ...ServerOption) (*Server, error)

NewServer constructs a harpoon MCP server.

func (*Server) MCPServer

func (s *Server) MCPServer() *mcp.Server

MCPServer builds an MCP server with harpoon tools registered.

type ServerOption

type ServerOption func(*serverOptions)

ServerOption configures optional server behavior.

func WithHTTPTransport

func WithHTTPTransport(rt http.RoundTripper) ServerOption

WithHTTPTransport sets the HTTP transport used for Harpoon outbound calls.

func WithMeter

func WithMeter(meter metric.Meter) ServerOption

WithMeter configures the meter used for Harpoon metrics.

type Target

type Target struct {
	Label           string
	Description     string
	Category        string
	Source          string
	Tags            []string
	InclusionReason string
	BaseURL         *url.URL
	UnixSocketPath  string
}

Target describes a registered outbound HTTP target.

type TargetRegistrar

type TargetRegistrar func(*Registry) error

TargetRegistrar allows programmatic target registration during startup.

func WithTarget

func WithTarget(target Target) TargetRegistrar

WithTarget returns a registrar that registers the provided target.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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