Documentation
¶
Overview ¶
Package mcpfront is the externally-reachable MCP surface: the OAuth minter, the /mcp bearer middleware, and the typed ops layer.
Index ¶
- Constants
- Variables
- func ValidateLifetime(d time.Duration) error
- type AccessTokenAuthz
- type ArtifactSummary
- type Deps
- type GetArtifactIn
- type GetArtifactOut
- type GetSessionIn
- type GetSessionOut
- type GetTranscriptIn
- type GetTranscriptOut
- type GrantWriter
- type ListArtifactsIn
- type ListArtifactsOut
- type ListSessionsIn
- type ListSessionsOut
- type MintParams
- type Minted
- type Minter
- type SearchHit
- type SearchMemoryIn
- type SearchMemoryOut
- type SessionSummary
- type TranscriptEntry
Constants ¶
const MaxLifetime = 365 * 24 * time.Hour
MaxLifetime is the longest lifetime a minted token may be given. It bounds --accesstoken-lifetime at webd startup and Minter.Lifetime at every mint: a bearer credential that outlives a year is a misconfiguration, not a policy anyone chose.
Variables ¶
var Version = "dev"
Version is the MCP Implementation.Version this server reports to a connecting client. Not currently wired to -ldflags, matching every other in-repo MCP server's own buildVersion var (internal/cmd/workshop, internal/cmd/websearchd, internal/cmd/apiadapter) — a fixed string is enough until this surface has its own release story.
Functions ¶
func ValidateLifetime ¶
ValidateLifetime reports whether d is a usable token lifetime: positive and no longer than MaxLifetime. Zero or negative would mint tokens that are already expired — a 200 from /oauth/token followed by a 401 on every /mcp call, with nothing pointing at the cause.
Types ¶
type AccessTokenAuthz ¶
type AccessTokenAuthz interface {
CheckAccessTokenOp(ctx context.Context, chk spicedb.AccessTokenCheck, fullyConsistent bool) (spicedb.AccessTokenDecision, error)
CheckAccessTokenMirror(ctx context.Context, tokenID string, owner identity.CanonicalUserID, permission string, fullyConsistent bool) (bool, error)
FilterAccessTokenCoveredClasses(ctx context.Context, tokenID string, classIDs []string, fullyConsistent bool) (map[string]bool, error)
}
AccessTokenAuthz is the SpiceDB half of an authorized /mcp tool call. Declared here (not imported as spicedb.Client directly) so a fake is trivial to construct in tests — the same shape as mint.go's GrantWriter. Satisfied by *spicedb.Client; see the compile-time guard below.
type ArtifactSummary ¶
type Deps ¶
type Deps interface {
K8s() client.Client
// AccessTokenAuthz is the SpiceDB half of an authorized tool call (the
// three-legged intersection check, the role mirror, and the scope
// filter). nil means SpiceDB is not configured.
AccessTokenAuthz() AccessTokenAuthz
// AccessTokenNamespace is where AccessToken CRs live — the SAME
// namespace pkg/web/mcpfront's Minter creates them in (webd's
// --accesstoken-namespace), so the bearer middleware's hash lookup finds
// every token a mint on this process could have produced.
AccessTokenNamespace() string
OperatorURL() string
MemoryToken() string
Artifacts() *artifacts.Service
// LookupReadableSessions answers which sessions owner may read. v1
// enumerates the interactable set — interact implies read_transcript for
// a root session — rather than a dedicated read-only lookup; see the
// webd implementation's own doc comment.
LookupReadableSessions(ctx context.Context, owner identity.CanonicalUserID) (spicedb.InteractableSessions, error)
// FetchArtifact fetches an artifact's rendered content bytes: resolve
// artifactID to its head revision's render, then fetch that render's
// bytes, the same two-step webd's own ContentRender/FetchRender pair does
// for the browser live-view. Returns the bytes and the render's MIME type.
FetchArtifact(ctx context.Context, ns, name, artifactID string) ([]byte, string, error)
// ExternalBaseURL is the trusted-origin base URL this process is reached
// at. Used both to build the protected-resource metadata's "resource"/
// "authorization_servers" fields and the WWW-Authenticate challenge's
// resource_metadata URL every 401 carries.
ExternalBaseURL() string
Logger() logr.Logger
}
Deps is what internal/cmd/webd's umbrella must implement for the /mcp plugin to mount. ui.Routes casts the generic webui.Deps to this interface; a failed cast, or a nil AccessTokenAuthz(), means NO routes are returned at all — an unconfigured SpiceDB yields no MCP surface, fail closed by absence rather than by every handler call refusing one request at a time.
type GetArtifactIn ¶
type GetArtifactOut ¶
type GetArtifactOut struct {
Artifact ArtifactSummary `json:"artifact"`
Content string `json:"content,omitempty"`
// ContentTruncated is true when the artifact's content exceeded
// maxArtifactContentBytes and was cut to fit.
ContentTruncated bool `json:"contentTruncated,omitempty"`
}
type GetSessionIn ¶
type GetSessionOut ¶
type GetSessionOut struct {
Session SessionSummary `json:"session"`
}
type GetTranscriptIn ¶
type GetTranscriptOut ¶
type GetTranscriptOut struct {
Entries []TranscriptEntry `json:"entries"`
Total int `json:"total"`
}
type GrantWriter ¶
type GrantWriter interface {
WriteAccessTokenGrant(ctx context.Context, g spicedb.AccessTokenGrant) error
DeleteAccessTokenTuples(ctx context.Context, tokenID string) error
}
GrantWriter is the SpiceDB half of minting: write the token's complete tuple set, or tear it back down on a compensating failure. Satisfied by *spicedb.Client; declared here (not imported from spicedb) so Minter's dependency is exactly the two calls it makes, and a fake is trivial to write in tests.
type ListArtifactsIn ¶
type ListArtifactsOut ¶
type ListArtifactsOut struct {
Artifacts []ArtifactSummary `json:"artifacts"`
}
type ListSessionsIn ¶
type ListSessionsIn struct {
Agent string `json:"agent,omitempty"` // agentclass name filter
State string `json:"state,omitempty"` // "running"|"ended"|"" for all
Limit int `json:"limit,omitempty"` // default 50, cap 200
}
ListSessionsIn / SessionSummary / ListSessionsOut, GetSessionIn/Out, GetTranscriptIn/TranscriptEntry/Out, SearchMemoryIn/SearchHit/Out, ListArtifactsIn/ArtifactSummary/Out and GetArtifactIn/Out are the shared typed contract the six /mcp tools expose — also the contract the Phase-2 CLI backend imports directly (see task-10-brief.md), so field names and JSON tags here are the wire format, not an implementation detail. Phase-1 narrowing, recorded: the spec's time-range filtering (e.g. startedAfter/startedBefore) is NOT implemented here — Agent/State/Limit are the only filters. A caller wanting a time window filters client-side over StartedAt on the returned SessionSummary rows.
type ListSessionsOut ¶
type ListSessionsOut struct {
Sessions []SessionSummary `json:"sessions"`
// Truncated is true when the owner can read more sessions than this tool
// enumerates (see coveredSessions), so matching sessions may be missing
// from Sessions — including all of them, for a token scoped to a class
// whose sessions fell outside the enumerated set. A session known by
// (namespace, name) is still reachable through get_session.
Truncated bool `json:"truncated,omitempty"`
}
type MintParams ¶
type MintParams struct {
Owner identity.CanonicalUserID
Role string
ScopeClasses []string
Unfiltered bool
ClientName string
ClientID string
}
MintParams is what the OAuth token endpoint has decided to grant: the subject who approved it, the role/scope ladder they chose, and the client display fields the AccessToken CR surfaces back to an admin.
type Minted ¶
Minted is the result of a successful mint. Value is the ONE AND ONLY time the plaintext bearer value is ever surfaced — it is never stored (the CR carries only its hash) and never retrievable again.
type Minter ¶
type Minter struct {
SpiceDB GrantWriter
K8s client.Client
// Namespace is where the AccessToken CR is created (webd flag
// --accesstoken-namespace, default "agentprimitives-system").
Namespace string
// Lifetime is how long a minted token lives (webd flag
// --accesstoken-lifetime, default 90*24h). Must satisfy ValidateLifetime.
Lifetime time.Duration
// Clock stands in for time.Now in tests; nil uses the real clock (see now()).
Clock func() time.Time
}
Minter mints an AccessToken: a SpiceDB grant (the authorization truth) plus an AccessToken CR (the authentication record — hash, owner, display metadata, expiry). See MintAccessToken's doc for why the two are written in that order and what happens when the second half fails.
func (*Minter) MintAccessToken ¶
MintAccessToken mints a fresh token for p: a random value + id, a SpiceDB grant carrying the role/scope, and an AccessToken CR carrying the value's hash plus display metadata.
Tuples are written FIRST, then the CR is created. This ordering matters: the /mcp bearer middleware authenticates a request by looking up the AccessToken CR's hash and then checking SpiceDB (fully consistent) for the matching grant. Writing SpiceDB first means the token is fully usable the instant this call returns — there is no reconciler race where a freshly minted token's first use could find tuples not yet written. Writing the CR first would invert that: a client could present a token that authenticates (the CR exists) before it is actually authorized, or worse, a crash between the two writes would leave a CR with no backing grant that could later be mistaken for a revoked-but-still-recognized token.
If the CR create fails after the grant is written, this compensates by deleting the SpiceDB tuples it just wrote (best effort) and returns both errors joined — a grant with no corresponding CR is unreachable (nothing can ever present the matching bearer value) but would otherwise clutter SpiceDB forever.
type SearchMemoryIn ¶
type SearchMemoryIn struct {
Query string `json:"query"`
// Namespace+Name together name a single session to search; both empty
// searches every session this token's owner may read_transcript.
Namespace string `json:"namespace,omitempty"`
Name string `json:"name,omitempty"`
Limit int `json:"limit,omitempty"`
}
type SearchMemoryOut ¶
type SearchMemoryOut struct {
Hits []SearchHit `json:"hits"`
// (memory.ErrNoSearchProviders) — distinct from "no hits", so a caller
// doesn't read an empty result as "nothing matched".
SearchUnavailable bool `json:"searchUnavailable,omitempty"`
// Truncated is true when a session-less search covered only the
// maxSearchDerivedScopes most recently started sessions (or the owner's
// readable set was itself truncated): older sessions were not searched.
// Name a session explicitly to search it.
Truncated bool `json:"truncated,omitempty"`
}
type SessionSummary ¶
type SessionSummary struct {
Namespace string `json:"namespace"`
Name string `json:"name"`
Class string `json:"class"`
Phase string `json:"phase"`
StartedAt time.Time `json:"startedAt"`
// Channel summarizes spec.inputChannel: kind, key, and the kind-specific
// External routing metadata, copied verbatim. Omitted for a kubectl-driven
// session with no input channel.
Channel map[string]string `json:"channel,omitempty"`
}