types

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 1 Imported by: 0

Documentation

Overview

Package types provides shared types for powhttp-mcp. These types are used across multiple packages and are designed for external consumption.

Index

Constants

View Source
const (
	EdgeReasonTemporal            = "temporal"
	EdgeReasonSameTLS             = "same_tls"
	EdgeReasonSameH2              = "same_h2"
	EdgeReasonAuthChain           = "auth_chain"
	EdgeReasonSameAuth            = "same_auth"             // Same Authorization header value
	EdgeReasonSameSessionCookie   = "same_session_cookie"   // Same session cookie
	EdgeReasonSameAPIKey          = "same_api_key"          // Same API key header
	EdgeReasonSessionCookieOrigin = "session_cookie_origin" // Set-Cookie -> Cookie chain
)

Edge reason constants for flow graphs.

Variables

This section is empty.

Functions

func ToAny added in v1.3.0

func ToAny(v any) (any, error)

ToAny round-trips a typed value through JSON to produce an untyped any. Use this when a tool output field must be any (instead of json.RawMessage) to satisfy the MCP SDK's schema validation.

Types

type AuthSignals

type AuthSignals struct {
	CookiesPresent    bool     `json:"cookies_present"`
	BearerPresent     bool     `json:"bearer_present"`
	CustomAuthHeaders []string `json:"custom_auth_headers,omitempty"`
}

AuthSignals indicates authentication patterns detected.

type BodyFingerprint

type BodyFingerprint struct {
	ReqHash   string `json:"req_hash,omitempty"`
	ReqBytes  int    `json:"req_bytes"`
	RespHash  string `json:"resp_hash,omitempty"`
	RespBytes int    `json:"resp_bytes"`
}

BodyFingerprint contains SHA256 hashes and byte counts for request/response bodies.

type Cluster

type Cluster struct {
	ID              string           `json:"cluster_id"`
	Host            string           `json:"host"`
	Method          string           `json:"method"`
	PathTemplate    string           `json:"path_template"`
	Count           int              `json:"count"`
	Category        EndpointCategory `json:"category"`
	Stats           ClusterStats     `json:"stats"`
	ExampleEntryIDs []string         `json:"example_entry_ids,omitzero"`
	ContentTypeHint string           `json:"content_type_hint,omitempty"`
}

Cluster represents a single endpoint cluster.

type ClusterFilters added in v1.3.0

type ClusterFilters struct {
	Category EndpointCategory // Filter clusters by category
	MinCount int              // Minimum requests per cluster
}

ClusterFilters defines post-clustering filters that narrow the output clusters.

type ClusterKey

type ClusterKey struct {
	Host         string
	Method       string
	PathTemplate string
}

ClusterKey is the composite key for clustering: host + method + path_template.

type ClusterOptions

type ClusterOptions struct {
	NormalizeIDs           bool // Default true - convert numeric/uuid segments
	StripVolatileQueryKeys bool // Default true
	ExamplesPerCluster     int  // Default 3, max 10
	MaxClusters            int  // Default 200, max 2000
}

ClusterOptions defines clustering behavior options.

type ClusterScope

type ClusterScope struct {
	Host         string
	Method       string // Filter entries by HTTP method before clustering
	ProcessName  string
	PID          int
	TimeWindowMs int64
	SinceMs      int64
	UntilMs      int64
}

ClusterScope defines pre-clustering filters that narrow the input entries.

type ClusterStats added in v1.3.0

type ClusterStats struct {
	StatusProfile map[string]int `json:"status_profile,omitzero"` // e.g. {"2xx": 95, "4xx": 3}
	ErrorRate     float64        `json:"error_rate"`              // fraction of non-2xx (0.0-1.0)
	AvgRespBytes  int            `json:"avg_resp_bytes"`          // average response body size
	HasAuth       bool           `json:"has_auth"`                // any entry had auth signals
}

ClusterStats provides lightweight statistics for a cluster.

type DescribeRequest

type DescribeRequest struct {
	ClusterID   string
	SessionID   string
	MaxExamples int // Default 5
}

DescribeRequest contains parameters for endpoint description.

type DiffOptions

type DiffOptions struct {
	CompareHeaderOrder  bool     // Default true
	CompareHeaderValues bool     // Default true
	CompareTLS          bool     // Default true
	CompareHTTP2        bool     // Default true
	IgnoreHeaders       []string // Default from DefaultIgnoreHeaders
	IgnoreQueryKeys     []string // Default from DefaultIgnoreQueryKeys
	MaxBytes            int      // Default from config
}

DiffOptions controls diff behavior.

type DiffRequest

type DiffRequest struct {
	BaselineEntryID  string
	CandidateEntryID string
	SessionID        string // Default "active"
	Options          *DiffOptions
}

DiffRequest contains parameters for comparing two entries.

type DiffResult

type DiffResult struct {
	Baseline       *EntrySummary  `json:"baseline"`
	Candidate      *EntrySummary  `json:"candidate"`
	ImportantDiffs ImportantDiffs `json:"important_diffs"`
	NoisyDiffs     NoisyDiffs     `json:"noisy_diffs"`
}

DiffResult contains the structured comparison of two entries.

type EndpointCategory added in v1.3.0

type EndpointCategory string

EndpointCategory classifies an endpoint cluster by its role.

const (
	CategoryAPI   EndpointCategory = "api"
	CategoryPage  EndpointCategory = "page"
	CategoryAsset EndpointCategory = "asset"
	CategoryData  EndpointCategory = "data"
	CategoryOther EndpointCategory = "other"
)

type EndpointDescription

type EndpointDescription struct {
	ClusterID         string            `json:"cluster_id"`
	Host              string            `json:"host"`
	Method            string            `json:"method"`
	PathTemplate      string            `json:"path_template"`
	Count             int               `json:"count"`
	TypicalHeaders    []HeaderFrequency `json:"typical_headers,omitzero"`
	AuthSignals       AuthSignals       `json:"auth_signals"`
	QueryKeys         QueryKeyAnalysis  `json:"query_keys"`
	RequestBodyShape  any               `json:"request_body_shape,omitempty"`
	ResponseBodyShape any               `json:"response_body_shape,omitempty"`
	Examples          []ExampleEntry    `json:"examples,omitzero"`
}

EndpointDescription contains detailed information about an endpoint cluster.

type EntrySummary

type EntrySummary struct {
	EntryID     string       `json:"entry_id"`
	TsMs        int64        `json:"ts_ms"`
	Method      string       `json:"method"`
	URL         string       `json:"url"`
	Host        string       `json:"host"`
	Path        string       `json:"path"`
	Status      int          `json:"status"`
	HTTPVersion string       `json:"http_version"`
	ProcessName string       `json:"process_name"`
	PID         int          `json:"pid"`
	TLS         TLSSummary   `json:"tls"`
	HTTP2       HTTP2Summary `json:"http2,omitempty"`
	Sizes       SizeSummary  `json:"sizes,omitempty"`
}

EntrySummary is a compact entry representation for search results.

type ExampleEntry

type ExampleEntry struct {
	EntryID string        `json:"entry_id"`
	Summary *EntrySummary `json:"summary"`
}

ExampleEntry contains a sample entry from the cluster.

type ExtractRequest

type ExtractRequest struct {
	SessionID string
	Scope     *ClusterScope
	Filters   *ClusterFilters
	Options   *ClusterOptions
	Limit     int // Default 50, for returned clusters
	Offset    int
}

ExtractRequest contains parameters for cluster extraction.

type ExtractResponse

type ExtractResponse struct {
	Clusters   []Cluster `json:"clusters"`
	TotalCount int       `json:"total_count"`
	ScopeHash  string    `json:"scope_hash"`
}

ExtractResponse contains the extraction results.

type Fingerprint

type Fingerprint struct {
	Entry              *EntrySummary       `json:"entry"`
	HeadersOrdered     [][]string          `json:"headers_ordered,omitzero"`
	HeadersNormalized  map[string][]string `json:"headers_normalized,omitzero"`
	HTTP2PseudoHeaders [][]string          `json:"http2_pseudo_headers,omitempty"`
	Body               BodyFingerprint     `json:"body"`
	TLSSummary         *TLSFingerprint     `json:"tls_summary,omitempty"`
	HTTP2Summary       *HTTP2Fingerprint   `json:"http2_summary,omitempty"`
}

Fingerprint represents a canonical fingerprint for an HTTP entry.

type FingerprintOptions

type FingerprintOptions struct {
	IncludeTLSSummary   bool // Default true
	IncludeHTTP2Summary bool // Default true
	MaxBytes            int  // Default from config.ToolMaxBytesDefault
}

FingerprintOptions controls fingerprint generation behavior.

type FlowEdge

type FlowEdge struct {
	From   string `json:"from"`   // Entry ID
	To     string `json:"to"`     // Entry ID
	Reason string `json:"reason"` // temporal, same_tls, same_h2, auth_chain, same_auth, same_session_cookie, same_api_key, session_cookie_origin
}

FlowEdge represents a relationship between two entries.

type FlowGraph

type FlowGraph struct {
	Nodes []FlowNode `json:"nodes"`
	Edges []FlowEdge `json:"edges"`
}

FlowGraph represents a graph of related HTTP requests.

type FlowNode

type FlowNode struct {
	EntryID string        `json:"entry_id"`
	Summary *EntrySummary `json:"summary"`
}

FlowNode represents a single node in the flow graph.

type HTTP2Diff

type HTTP2Diff struct {
	BaselineStreamID  int  `json:"baseline_stream_id"`
	CandidateStreamID int  `json:"candidate_stream_id"`
	PseudoHeadersDiff bool `json:"pseudo_headers_diff"`
}

HTTP2Diff represents differences in HTTP/2 metadata.

type HTTP2Fingerprint

type HTTP2Fingerprint struct {
	ConnectionID string         `json:"connection_id,omitempty"`
	StreamID     int            `json:"stream_id,omitempty"`
	FrameCounts  map[string]int `json:"frame_counts,omitempty"`
}

HTTP2Fingerprint contains HTTP/2 connection details for fingerprint comparison.

type HTTP2Summary

type HTTP2Summary struct {
	ConnectionID string `json:"connection_id,omitempty"`
	StreamID     int    `json:"stream_id,omitempty"`
}

HTTP2Summary contains HTTP/2-related summary fields.

type HeaderFrequency

type HeaderFrequency struct {
	Name      string  `json:"name"`
	Frequency float64 `json:"frequency"` // 0.0 to 1.0
}

HeaderFrequency tracks how often a header appears.

type HeaderOrderDiff

type HeaderOrderDiff struct {
	BaselineOrder  []string      `json:"baseline_order,omitzero"`
	CandidateOrder []string      `json:"candidate_order,omitzero"`
	Moves          []OrderChange `json:"moves,omitempty"`
}

HeaderOrderDiff represents differences in header ordering.

type HeaderValueDiff

type HeaderValueDiff struct {
	Name      string   `json:"name"`
	Baseline  []string `json:"baseline,omitzero"`
	Candidate []string `json:"candidate,omitzero"`
}

HeaderValueDiff represents a difference in header values.

type ImportantDiffs

type ImportantDiffs struct {
	Protocol            *ProtocolDiff     `json:"protocol,omitempty"`
	TLS                 *TLSDiff          `json:"tls,omitempty"`
	HTTP2               *HTTP2Diff        `json:"http2,omitempty"`
	HeadersMissing      []string          `json:"headers_missing,omitempty"`
	HeadersExtra        []string          `json:"headers_extra,omitempty"`
	HeadersValueChanged []HeaderValueDiff `json:"headers_value_changed,omitempty"`
	HeaderOrderChanges  *HeaderOrderDiff  `json:"header_order_changes,omitempty"`
}

ImportantDiffs contains differences that are likely meaningful for anti-bot detection.

type InferSchemaOutput added in v1.3.0

type InferSchemaOutput struct {
	// Shape analysis result (contains content_category and format-specific fields)
	Shape any `json:"shape,omitzero"`

	// Summary of the inference process
	Summary InferSchemaSummary `json:"summary"`

	// Hint for the next step
	Hint string `json:"hint,omitempty"`
}

InferSchemaOutput is the aggregate output type for the powhttp_infer_schema tool. It spans types from both pkg/jsonschema and pkg/shape.

type InferSchemaSummary added in v1.3.0

type InferSchemaSummary struct {
	EntriesRequested int    `json:"entries_requested"`
	EntriesProcessed int    `json:"entries_processed"`
	EntriesSkipped   int    `json:"entries_skipped"`
	ContentCategory  string `json:"content_category"`
}

InferSchemaSummary describes the inference process.

type NoisyDiffs

type NoisyDiffs struct {
	IgnoredHeaders []string `json:"ignored_headers,omitempty"`
	QueryKeyDiffs  []string `json:"query_key_diffs,omitempty"`
}

NoisyDiffs contains differences that are typically not meaningful.

type OrderChange

type OrderChange struct {
	Header       string `json:"header"`
	BaselinePos  int    `json:"baseline_pos"`
	CandidatePos int    `json:"candidate_pos"`
}

OrderChange represents a header that moved position.

type ProtocolDiff

type ProtocolDiff struct {
	BaselineVersion  string `json:"baseline_version"`
	CandidateVersion string `json:"candidate_version"`
}

ProtocolDiff represents a difference in HTTP protocol version.

type QueryEntryResult added in v1.1.0

type QueryEntryResult struct {
	EntryID    string        `json:"entry_id"`
	Target     string        `json:"target"`
	ValueCount int           `json:"value_count"`
	Summary    *EntrySummary `json:"summary,omitempty"`
	Skipped    bool          `json:"skipped,omitempty"`
	SkipReason string        `json:"skip_reason,omitempty"`
}

QueryEntryResult contains per-entry query results.

type QueryKeyAnalysis

type QueryKeyAnalysis struct {
	Stable   []string `json:"stable,omitzero"`   // Keys present in most requests
	Volatile []string `json:"volatile,omitzero"` // Keys that vary (timestamps, nonces)
}

QueryKeyAnalysis categorizes query parameters.

type QueryRequest added in v1.1.0

type QueryRequest struct {
	SessionID   string
	EntryIDs    []string // Query specific entries
	ClusterID   string   // Or query all entries in a cluster
	Expression  string   // JQ expression
	Target      string   // "request", "response", or "both"
	Deduplicate bool
	MaxEntries  int // Default 20, max 100
	MaxResults  int // Default 1000
}

QueryRequest contains parameters for a body query operation.

type QueryResponse added in v1.1.0

type QueryResponse struct {
	Summary QuerySummary       `json:"summary"`
	Values  []any              `json:"values,omitzero"`
	Entries []QueryEntryResult `json:"entries,omitempty"`
	Errors  []string           `json:"errors,omitempty"`
	Hints   []string           `json:"hints,omitempty"`
}

QueryResponse contains the full response from a body query operation.

type QueryResult added in v1.1.0

type QueryResult struct {
	Values   []any    `json:"values"`           // Extracted values
	Errors   []string `json:"errors,omitempty"` // Per-item errors
	RawCount int      `json:"raw_count"`        // Count before deduplication
}

QueryResult contains the results of a body query.

type QuerySummary added in v1.1.0

type QuerySummary struct {
	EntriesProcessed int  `json:"entries_processed"`
	EntriesMatched   int  `json:"entries_matched"`
	EntriesSkipped   int  `json:"entries_skipped"`
	TotalValues      int  `json:"total_values"`
	UniqueValues     int  `json:"unique_values,omitempty"`
	Deduplicated     bool `json:"deduplicated"`
	Truncated        bool `json:"truncated,omitempty"`
}

QuerySummary contains summary statistics for a query.

type ResourceRef

type ResourceRef struct {
	URI  string `json:"uri"`
	MIME string `json:"mime"`
	Hint string `json:"hint,omitempty"`
}

ResourceRef points to an MCP resource.

type SchemaFormat

type SchemaFormat string

SchemaFormat represents the input format for schema definitions.

const (
	FormatGoStruct   SchemaFormat = "go_struct"
	FormatZod        SchemaFormat = "zod"
	FormatJSONSchema SchemaFormat = "json_schema"
)

Schema format constants.

type SearchFilters

type SearchFilters struct {
	Host            string
	PathContains    string
	URLContains     string
	Method          string
	Status          int
	HTTPVersion     string
	ProcessName     string
	PID             int
	HeaderName      string
	HeaderContains  string
	BodyContains    string
	TLSConnectionID string
	JA3             string
	JA4             string
	SinceMs         int64 // Unix timestamp in ms
	UntilMs         int64 // Unix timestamp in ms
	TimeWindowMs    int64 // Alternative to since/until (relative to now)
}

SearchFilters contains structured filter criteria.

type SearchRequest

type SearchRequest struct {
	SessionID string         // Session to search within
	Query     string         // Free text query
	Filters   *SearchFilters // Optional structured filters
	Limit     int            // Default 20, safety cap via MAX_SEARCH_RESULTS (default 10000)
	Offset    int            // Pagination offset
}

SearchRequest contains parameters for a search query.

type SearchResponse

type SearchResponse struct {
	Results    []SearchResult `json:"results"`
	TotalHint  int            `json:"total_hint,omitempty"`
	SyncedAtMs int64          `json:"synced_at_ms"`
	Scope      *SearchScope   `json:"scope,omitempty"`
	Capped     bool           `json:"-"` // true if results were truncated by safety cap
}

SearchResponse contains the search results.

type SearchResult

type SearchResult struct {
	Summary    *EntrySummary `json:"summary"`
	Score      float64       `json:"score"`
	Highlights []string      `json:"highlights,omitempty"`
	MatchedIn  []string      `json:"matched_in,omitempty"`
}

SearchResult represents a single search result.

type SearchScope added in v1.3.0

type SearchScope struct {
	BodyIndexEnabled   bool   `json:"body_index_enabled"`
	BodySearchCoverage string `json:"body_search_coverage,omitempty"`
}

SearchScope reports search coverage for transparency.

type SizeSummary

type SizeSummary struct {
	ReqBodyBytes    int    `json:"req_body_bytes"`
	RespBodyBytes   int    `json:"resp_body_bytes"`
	RespContentType string `json:"resp_content_type,omitempty"` // e.g., "application/json"
}

SizeSummary contains request/response body size information.

type TLSDiff

type TLSDiff struct {
	JA3Different     bool   `json:"ja3_different"`
	JA4Different     bool   `json:"ja4_different"`
	BaselineJA3      string `json:"baseline_ja3,omitempty"`
	CandidateJA3     string `json:"candidate_ja3,omitempty"`
	BaselineJA4      string `json:"baseline_ja4,omitempty"`
	CandidateJA4     string `json:"candidate_ja4,omitempty"`
	CipherDifferent  bool   `json:"cipher_different,omitempty"`
	VersionDifferent bool   `json:"version_different,omitempty"`
}

TLSDiff represents differences in TLS fingerprints.

type TLSFingerprint

type TLSFingerprint struct {
	ConnectionID string `json:"connection_id,omitempty"`
	TLSVersion   string `json:"tls_version,omitempty"`
	CipherSuite  string `json:"cipher_suite,omitempty"`
	JA3          string `json:"ja3,omitempty"`
	JA4          string `json:"ja4,omitempty"`
	ALPN         string `json:"alpn,omitempty"`
}

TLSFingerprint contains TLS connection details for fingerprint comparison.

type TLSSummary

type TLSSummary struct {
	ConnectionID string `json:"connection_id,omitempty"`
	JA3          string `json:"ja3,omitempty"`
	JA4          string `json:"ja4,omitempty"`
}

TLSSummary contains TLS-related summary fields.

type TraceOptions

type TraceOptions struct {
	TimeWindowMs int64 // Default 120000 (2 minutes)
	SamePIDOnly  bool  // Default true
	SameHostOnly bool  // Default true
}

TraceOptions defines flow tracing behavior options.

type TraceRequest

type TraceRequest struct {
	SessionID   string
	SeedEntryID string
	MaxDepth    int // Default 50, max 500
	Options     *TraceOptions
	Limit       int // Default 50 for returned nodes
}

TraceRequest contains parameters for flow tracing.

type ValidationResult

type ValidationResult struct {
	Valid  bool     `json:"valid"`
	Errors []string `json:"errors,omitempty"`
}

ValidationResult contains the result of validating a single value.

Jump to

Keyboard shortcuts

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