Documentation
¶
Overview ¶
Package leadflow is a fabricated CRM MCP server used to demonstrate the agent-defined-UI leads console. It carries no build tag, because both the e2e-tagged scenarios and the plain `go test` suite import it. It is not platform code — nothing in pkg/, cmd/oap, or any service depends on it — so it lives under the obviously-demo pkg/web/uidemo/ prefix, and outside examples/ so tests may import it.
Deployed shape: pkg/x/safehttp's SSRF guard refuses loopback/link-local/ RFC1918-private destinations, so an MCPServer CR's spec.server.url cannot point at a cluster-internal Service. internal/cmd/leadflowfake is meant to run somewhere the cluster can reach by a public address; this package's own tests reach it over loopback through the plain-client seam (mcpdispatch's WithHTTPClient / mcpprobe.Client.HTTP), never through the guarded client.
Index ¶
Constants ¶
const ( ToolListLeads = "list_leads" ToolStageBreakdown = "stage_breakdown" ToolAdvanceLeadStage = "advance_lead_stage" // ToolSearchAccounts is a READONLY tool answering with an ENVELOPE — // {"results":[…],"total":…,"paging":{…}}, each record's fields under // "properties" — rather than the bare array ToolListLeads returns. // Envelope-wrapped responses are the REST norm, so this one is shaped like // a third-party CRM search to give the selector path (pkg/web/uiselect) // something real to extract from end to end. ToolSearchAccounts = "search_accounts" )
The tool names, exported so a CR author — and this package's own wiring test — spell them identically to what the server announces, rather than re-typing the literal in a second place.
Variables ¶
var Stages = []string{"new", "qualified", "proposal", "won"}
Stages is the closed pipeline vocabulary, in order. AdvanceStage moves a lead to the next entry and refuses to move past the last one.
Functions ¶
This section is empty.
Types ¶
type AccountPaging ¶
type AccountPaging struct {
Next string `json:"next,omitempty"`
}
AccountPaging is search_accounts' paging cursor. Next is always empty in this fixture — there is only ever one page of the seeded book — but the key is present so a selector written against the envelope's shape (not just its populated fields) has something real to skip past.
type AccountProperties ¶
AccountProperties is one search_accounts record's fields, nested one level down under "properties" — the shape a component's selector ("results[].properties") must reach through, rather than the flat Lead shape ToolListLeads returns directly.
type AccountRecord ¶
type AccountRecord struct {
Properties AccountProperties `json:"properties"`
}
AccountRecord is one element of search_accounts' "results" array.
type Book ¶
type Book struct {
// contains filtered or unexported fields
}
Book is the in-memory lead store. Safe for concurrent use: the console resolves several bindings concurrently on one page load.
func NewBook ¶
func NewBook() *Book
NewBook returns the deterministic seeded book (seed.go). Deterministic because a test asserting a stage count cannot depend on a clock.
func (*Book) AdvanceStage ¶
AdvanceStage moves one lead one stage forward. An unknown id, or a lead already at the last stage, is an error — never a silent no-op, because the console surfaces the outcome on the control that fired it. The book is left unchanged on every error path.
func (*Book) Filter ¶
Filter returns a fresh copy of the leads whose Updated falls within [from, to] and whose Stage equals stage. An empty bound is unbounded on that side; an empty stage matches every stage. The RFC3339 bounds are compared LEXICOGRAPHICALLY, valid only because seed.go's timestamps share one timezone and precision, so string order and chronological order agree. Filter never errors — a malformed from/to is rejected by validateRange before reaching it.
The returned slice is an independent copy: Lead is a plain value type, so a later AdvanceStage never retroactively changes a slice a caller holds.
type Call ¶
Call is one recorded tool invocation, exposed via Server.Calls so a test can prove the CRM observed specific arguments rather than inferring it from the response shape alone — a stub that ignores its arguments but returns a plausible narrower result would otherwise pass a rows-shrink-under-a-narrower-window assertion for the wrong reason.
type Lead ¶
type Lead struct {
Value string `json:"value"` // stable id, also an ap:select option value
Label string `json:"label"` // display text for both the table and the select
Stage string `json:"stage"` // one of Stages
Owner string `json:"owner"` // sales rep the lead is assigned to
Updated string `json:"updated"` // RFC3339 date-time
}
Lead is one row of the fabricated pipeline. The value/label pair is deliberately part of the ROW rather than a separate lookup: an ap:table binds rows and picks display columns by key, while an ap:select binds options and reads value/label, so one tool result serves both controls and the console needs no second "list the ids" tool.
type Options ¶
type Options struct {
Book *Book // nil ⇒ NewBook()
// MaxRows caps how many leads list_leads returns. A SERVER-side constant,
// not a tool argument: a binding parameter can only produce a JSON string
// (uibindings.SubstituteParams) and the app-tool path has no InputSchema
// validation to catch a string where a number is declared, so a row cap
// expressed as an argument would be a trap rather than a demonstration.
MaxRows int // 0 ⇒ defaultMaxRows
// Logger receives a line for every tool call plus the bound address at
// startup (internal/cmd/leadflowfake). nil ⇒ slog.Default().
Logger *slog.Logger
}
Options configures a server instance.
type SearchAccountsEnvelope ¶
type SearchAccountsEnvelope struct {
Results []AccountRecord `json:"results"`
Total int `json:"total"` // match count across all pages
Paging AccountPaging `json:"paging"`
}
SearchAccountsEnvelope is search_accounts' response shape: a wrapper object, a results array, and a paging cursor — the REST norm ToolSearchAccounts exists to exercise.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the fake CRM. Handler serves MCP Streamable HTTP; mount it at the path the MCPServer CR's url names.
func (*Server) Book ¶
Book returns the server's lead store, e.g. for a test to inspect state a tool call mutated.
type StageCount ¶
StageCount is one entry of stage_breakdown's result: one per Stages element, always — see stageBreakdown.