Documentation
¶
Overview ¶
Package mcpserver is devctl serve: the agent-facing commands as MCP tools over streamable HTTP, acting on GitHub as the person who calls them, or, in App mode (AppMode), as the installation's workspace GitHub App through pro's lane, for one organization's principal alone.
A tool answers with the command's JSON document, devctl's envelope included, as structured content: the exit code is a field, and the call is an MCP error only for auth_required. A wait is one call that blocks until its verdict and sends notifications/progress on the caller's progressToken meanwhile, at an interval below the server's registered timeout, so the gateway restarts that timeout on each.
What only a laptop needs is not here: no version gate, no keychain or other credential store, no detached merge state on disk, no SIGHUP handling and no DEVCTL_TIME_SCALE.
Index ¶
- Constants
- func DexClientSubject(client string) string
- func Icon() mcp.Icon
- func NoreplyEmail(c Caller) string
- type AppMode
- type Caller
- type CallerTokens
- type Checkouts
- type Claim
- type Clusters
- type Config
- type Credentials
- type Dex
- type DexExchange
- type GitCheckouts
- type GitHubInstallations
- type GitHubSources
- func (g GitHubSources) PRMerge(_ context.Context, token string, transport http.RoundTripper) (PRMergeSources, error)
- func (g GitHubSources) PRWait(_ context.Context, token string, transport http.RoundTripper) (PRWaitSources, error)
- func (g GitHubSources) ReleasePromote(_ context.Context, token string, transport http.RoundTripper) (*releasepromote.Sources, error)
- func (g GitHubSources) ReleaseWait(_ context.Context, token string, transport http.RoundTripper) (*releasewait.Sources, error)
- type GitHubUsers
- type Installation
- type Installations
- type MainStatus
- type Metrics
- type MusterGrant
- type NoClusters
- type NoCredentials
- type PRMergeSources
- type PRWaitSources
- type Principal
- type PullRequest
- type Server
- type Sources
- type Users
Constants ¶
const ( ToolCIRerun = "ci_rerun" ToolCIRerunStatus = "ci_rerun_status" )
The commit-scoped GitHub Actions retry tools.
const ( ToolCommitWait = "commit_wait" ToolMainStatus = "main_status" )
The names of the commit tools.
const ( ToolReservationReserve = "reservation_reserve" ToolReservationList = "reservation_list" ToolReservationExtend = "reservation_extend" ToolReservationRelease = "reservation_release" )
The reservation tools' names: devctl reservation reserve, list, extend and release, as the person. reap stays the CI bot's.
const ( ToolPRWait = "pr_wait" ToolPRMergeStatus = "pr_merge_status" ToolReleaseWait = "release_wait" )
The tools' names.
const Anonymous = "anonymous"
Anonymous is the login of a call refused before its grant named the caller: one without a grant, or one refused as usage.
const DefaultAudience = "dex-k8s-authenticator"
DefaultAudience is the client the API server of a Giant Swarm management cluster accepts OIDC tokens of.
const DefaultCallerAudience = "devctl"
DefaultCallerAudience is devctl's own client at the issuer, the audience a caller's token must name.
const DefaultCallerSkew = 30 * time.Second
DefaultCallerSkew is how far a token's exp and nbf may be off the server's clock.
const DefaultGitBaseURL = "https://github.com"
DefaultGitBaseURL is where GitCheckouts clone from.
const DefaultInstallationsTTL = 5 * time.Minute
DefaultInstallationsTTL is how long a token's installations are kept.
const DefaultNoProgressTimeout = 20 * time.Second
DefaultNoProgressTimeout bounds a wait called without a progressToken, which no progress keeps alive: below muster's default registered timeout of 30 s with headroom for pr_merge's merge call.
const DefaultProgressInterval = 10 * time.Second
DefaultProgressInterval is how often a wait reports progress: below muster's default registered timeout of 30 s with headroom.
const DefaultTimeout = 30 * time.Minute
DefaultTimeout bounds a wait whose call names no timeout. It stays below the CLI's default so pr_merge's CI and release waits fit in MaxTimeout together.
const DefaultUsersTTL = 5 * time.Minute
DefaultUsersTTL is how long a token's user is kept.
const FallbackNextPoll = time.Minute
FallbackNextPoll is an observation's next poll when the lane does not answer its report: the slowest pace of a blocking wait.
const GrantHeaderPrefix = "X-Muster-Grant-" //nolint:gosec // G101: a header name, not a credential
GrantHeaderPrefix starts the header the gateway in front carries the person's token of one provider App in: muster attaches X-Muster-Grant-<app> for every App of the server's registration (spec.auth.providerApps) the person granted.
const IdentitySource = "platform"
IdentitySource is a promotion's identity source on the server: the token the platform handed over for the person.
const MaxTimeout = 55 * time.Minute
MaxTimeout bounds a wait's own timeout: below the hour muster keeps a progress-kept call alive at most, so the wait ends with devctl's own timeout verdict, not the gateway's.
const Name = "devctl"
Name is the server's name in its MCP implementation info.
const StatusGrantRequired = "grant_required"
StatusGrantRequired is the structuredContent status of a result that needs the person's grant of the Apps it names in "apps": muster answers it auth_required with each App's sign-in link (authUrl).
const ToolMainHistory = "main_history"
ToolMainHistory lists default-branch commits and their own check verdicts.
const ToolPRGet = "pr_get"
ToolPRGet is the pull request read's name, served in App mode.
const ToolPRMerge = "pr_merge"
ToolPRMerge is the merge tool's name.
const ToolReleasePromote = "release_promote"
ToolReleasePromote is the promotion tool's name, served with Config.ReleasePromote only.
const ToolRolloutWait = "rollout_wait"
ToolRolloutWait is the rollout wait's name.
Variables ¶
This section is empty.
Functions ¶
func DexClientSubject ¶ added in v8.174.0
DexClientSubject is the sub Dex gives a client's own token (client credentials): base64url, unpadded, of the protobuf message IDTokenSubject{user_id: client} with no conn_id, its bytes 0x0a, the varint length of client, and client.
func Icon ¶ added in v8.166.0
Icon is the server's icon in its implementation info: the Giant Swarm logo as an SVG data URI of any size, as mcp-toolkit's brand.GiantSwarmIcon returns it.
func NoreplyEmail ¶ added in v8.156.0
NoreplyEmail is the person's GitHub noreply address, the commits' author email: <id>+<login>@users.noreply.github.com.
Types ¶
type AppMode ¶ added in v8.174.0
type AppMode struct {
// Lane is the lane's address, from [prolane.ParseAddress]: the
// GitHub REST root, and GraphQL at <Lane>graphql.
Lane *url.URL
// Organization is the App's organization.
Organization string
// Owner is the GitHub account main_status lists the repositories of
// when its call names none: the App's home installation. Empty: the
// call names one.
Owner string
// Installation enables rollout_wait for this installation only.
Installation string
// InClusterConfig supplies its ServiceAccount configuration. Nil uses rest.InClusterConfig.
InClusterConfig func() (*rest.Config, error)
// Callers verify every MCP request's token. Required.
Callers *CallerTokens
// LaneClient sends the observations' reports to the lane; nil is a
// client with a 10 s timeout.
LaneClient *http.Client
}
AppMode is devctl serve acting as the installation's workspace GitHub App for one organization, without any GitHub credential of its own: every GitHub request goes to pro's lane, which sends it with the App installation's token, and every MCP request carries the organization's principal token, which Callers verify. Writes are off: the write tools are listed with their write annotations, so a dry run holds and records them, and refuse to run.
type Caller ¶
type Caller struct {
// Login is the person's GitHub login.
Login string
// ID is the person's GitHub user id, stable across a renamed login.
ID int64
}
Caller is the person a call is made for, as GitHub names the holder of their grant's token.
type CallerTokens ¶ added in v8.174.0
type CallerTokens struct {
// Issuer is the Dex's issuer URL. Required.
Issuer string
// Audience is devctl's client at the issuer; empty is
// DefaultCallerAudience.
Audience string
// Clients are the organization's principal clients. Required.
Clients []string
// Organization is the App's organization, which Clients stand for.
// Required.
Organization string
// Algorithms are the signing algorithms accepted; empty is RS256.
Algorithms []string
// Skew is the tolerance of exp and nbf; zero is DefaultCallerSkew.
Skew time.Duration
// Client reads the issuer's discovery document and keys; nil is a
// client with a 10 s timeout.
Client *http.Client
// Now is the clock; nil is time.Now.
Now func() time.Time
// contains filtered or unexported fields
}
CallerTokens verify the bearer token of every MCP request in App mode: an ID token of the Dex at Issuer that an organization's principal client got as itself (client credentials) for devctl's audience. The calling organization comes from this token alone, never from an argument, a header or a repository's owner.
A token passes when its signature verifies against the issuer's keys (OIDC discovery and its JWKS), iss is Issuer, aud contains Audience, exp and nbf are current within Skew, azp is one of Clients, and sub is Dex's subject of that client acting as itself (DexClientSubject), so a person who signed in through the client is refused.
func (*CallerTokens) Check ¶ added in v8.174.0
func (c *CallerTokens) Check() error
Check says whether the configuration is complete.
type Checkouts ¶ added in v8.156.0
type Checkouts interface {
// Clone checks out main of repository, owner/repo, into a new directory,
// fetching and pushing with token and committing as author. remove
// deletes the directory; the call runs it when it ends.
Clone(ctx context.Context, repository, token string, author Caller) (dir string, remove func(), err error)
}
Checkouts give a reservation call a checkout of its GitOps repository of its own, as the person.
type Claim ¶ added in v8.174.0
type Claim struct {
// Ours: the winner names the App's organization.
Ours bool `json:"ours"`
Installation int64 `json:"installation"`
Organization string `json:"organization"`
Runner string `json:"runner"`
Host string `json:"host"`
By string `json:"by"`
CommentID int64 `json:"commentId"`
CommentURL string `json:"commentUrl"`
CreatedAt time.Time `json:"createdAt"`
// Claims counts the standing markers.
Claims int `json:"claims"`
}
Claim is the standing claim on a pull request: the marker comment <!-- pro-claim {"installation":…,"organization":"…","runner":"…","host":"…","key":"…"} --> an App wrote. A person's comment that copies a marker is ignored, and of several the lowest comment id wins.
type Clusters ¶ added in v8.155.0
type Clusters interface {
// Open is the client of installation's management cluster acting as the
// caller in ctx, its requests going through wrap: auth_required without
// the person's token, not_applicable for an installation the server does
// not reach.
Open(ctx context.Context, installation string, wrap func(http.RoundTripper) http.RoundTripper) (dynamic.Interface, error)
// Installations are the names of the installations it reaches.
Installations() []string
}
Clusters open an installation's management cluster as the person a call is made for.
type Config ¶
type Config struct {
// Version is the version the server reports: the binary's.
Version string
// Credentials answer the person's GitHub token; nil is [NoCredentials].
Credentials Credentials
// Clusters open an installation's management cluster as the person;
// nil is [NoClusters].
Clusters Clusters
// Sources build the clients a wait reads with; nil is [GitHubSources]
// over Endpoints.
Sources Sources
// Endpoints are GitHub's and the registries'; zero is
// [agentcli.DefaultEndpoints].
Endpoints agentcli.Endpoints
// Clock is the waits' clock; nil is the wall clock at scale 1, never
// DEVCTL_TIME_SCALE.
Clock *agentcli.Clock
// ProgressInterval is how often a wait reports progress; zero is
// DefaultProgressInterval.
ProgressInterval time.Duration
// NoProgressTimeout bounds a wait called without a progressToken, so
// it answers within the gateway's registered timeout; zero is
// DefaultNoProgressTimeout.
NoProgressTimeout time.Duration
// Checkouts clone the GitOps repository of a reservation call; nil is
// [GitCheckouts] from GitHub into the system's temporary directory.
Checkouts Checkouts
// Merges are the merges of this server pr_merge_status reads; nil is an
// empty [mergejob.Memory]. pr_merge records its merges in them when they
// take a Put, as a Memory does. Nothing is kept on disk.
Merges mergejob.Jobs
// ReleasePromote serves release_promote, the selector of the one tool
// that cuts a stable release; off, the tool is not listed.
ReleasePromote bool
// Metrics count the calls; nil counts none.
Metrics *Metrics
// Logger logs one line per call; nil logs nothing.
Logger *slog.Logger
// App, when set, serves App mode instead of acting as a person:
// Credentials, Clusters and Sources are not used, every GitHub request
// goes to the lane, and every MCP request needs the token App.Callers
// verify. [AppMode.Check] must pass.
App *AppMode
}
Config configures a Server.
type Credentials ¶
type Credentials interface {
// GitHubToken is the person's token for the call in ctx; an
// [agentcli.ExitCoder] of [agentcli.ExitAuthRequired] when the server
// holds none for them.
GitHubToken(ctx context.Context) (string, error)
}
Credentials answer the GitHub token of the person a call is made for.
type Dex ¶ added in v8.155.0
type Dex struct {
// TokenEndpoint is Dex's token endpoint, https.
TokenEndpoint string `json:"tokenEndpoint"`
// Issuer is the issuer the exchanged token must name; empty is the
// token endpoint without /token.
Issuer string `json:"issuer,omitempty"`
// ConnectorID is the connector of Dex that trusts the hub's Dex, which
// issued the person's token.
ConnectorID string `json:"connectorId"`
// Audience is the client the API server accepts tokens of, asked for
// as a cross-client audience; empty is dex-k8s-authenticator.
Audience string `json:"audience,omitempty"`
// ClientIDFile and ClientSecretFile hold the client the exchange
// authenticates as, read when the server starts; without
// ClientSecretFile the client is a public one.
ClientIDFile string `json:"clientIdFile"`
ClientSecretFile string `json:"clientSecretFile,omitempty"`
}
Dex is the token exchange at an installation's Dex.
type DexExchange ¶ added in v8.155.0
type DexExchange struct {
// Client sends the exchanges; nil is http.DefaultClient.
Client *http.Client
// Now is the clock of the exchanged tokens' expiry; nil is time.Now.
Now func() time.Time
// contains filtered or unexported fields
}
DexExchange opens the installations it was given as the person: it exchanges the person's token, which the gateway in front forwards in Authorization (muster's forwardToken), at the installation's Dex for a token its API accepts, and sends that with every request. The cluster answers by the person's access; the server holds no kubeconfig and no credential of a cluster.
func NewDexExchange ¶ added in v8.155.0
func NewDexExchange(installations []Installation) (*DexExchange, error)
NewDexExchange validates installations and reads their client files.
func ReadInstallations ¶ added in v8.155.0
func ReadInstallations(path string) (*DexExchange, error)
ReadInstallations reads the installations file: a JSON object with an "installations" list. The client files are read here, once.
func (*DexExchange) Installations ¶ added in v8.155.0
func (d *DexExchange) Installations() []string
Installations implements Clusters.
func (*DexExchange) Open ¶ added in v8.155.0
func (d *DexExchange) Open(ctx context.Context, name string, wrap func(http.RoundTripper) http.RoundTripper) (dynamic.Interface, error)
Open implements Clusters.
type GitCheckouts ¶ added in v8.156.0
type GitCheckouts struct {
// BaseURL is the git host; empty is DefaultGitBaseURL.
BaseURL string
// Dir holds the clones; empty is the system's temporary directory.
Dir string
}
GitCheckouts clone with git: a shallow clone of main from BaseURL into a new directory under Dir. The person's token is the clone's credential, in its own git configuration only, never on a command line; the author is the person's GitHub login and noreply address.
type GitHubInstallations ¶
type GitHubInstallations struct {
BaseURL string
Client *http.Client
TTL time.Duration
Now func() time.Time
// contains filtered or unexported fields
}
GitHubInstallations read GET /user/installations at BaseURL and keep each token's answer for TTL.
func (*GitHubInstallations) Owners ¶
Owners implements Installations.
type GitHubSources ¶
type GitHubSources struct {
Endpoints agentcli.Endpoints
// NoAuthorization builds the GitHub clients without a token, for App
// mode's lane, which authorizes every request itself.
NoAuthorization bool
}
GitHubSources are the clients of GitHub and the registries at Endpoints. They hold no CircleCI client: the server has no CircleCI credential, so a pull request's CircleCI state is the commit statuses CircleCI posts to GitHub. The private registry is read anonymously.
func (GitHubSources) PRMerge ¶
func (g GitHubSources) PRMerge(_ context.Context, token string, transport http.RoundTripper) (PRMergeSources, error)
PRMerge implements Sources.
func (GitHubSources) PRWait ¶
func (g GitHubSources) PRWait(_ context.Context, token string, transport http.RoundTripper) (PRWaitSources, error)
PRWait implements Sources.
func (GitHubSources) ReleasePromote ¶
func (g GitHubSources) ReleasePromote(_ context.Context, token string, transport http.RoundTripper) (*releasepromote.Sources, error)
ReleasePromote implements Sources: the person's token, never renewed.
func (GitHubSources) ReleaseWait ¶
func (g GitHubSources) ReleaseWait(_ context.Context, token string, transport http.RoundTripper) (*releasewait.Sources, error)
ReleaseWait implements Sources: no CircleCI client, the wait reads CircleCI through the commit statuses of the tag's commit.
type GitHubUsers ¶ added in v8.154.0
type GitHubUsers struct {
BaseURL string
Client *http.Client
TTL time.Duration
Now func() time.Time
// contains filtered or unexported fields
}
GitHubUsers read GET /user at BaseURL and keep each token's answer for TTL: a token GitHub refuses is auth_required.
type Installation ¶ added in v8.155.0
type Installation struct {
// Name is the installation's name, the tool's argument.
Name string `json:"name"`
// APIServer is the URL of the management cluster's Kubernetes API.
APIServer string `json:"apiServer"`
// CAFile is the API's certificate authority, PEM; empty trusts the
// system's roots.
CAFile string `json:"caFile,omitempty"`
// Dex is the installation's Dex.
Dex Dex `json:"dex"`
}
Installation is one management cluster the server reaches as the person: its API, and its Dex, where the person's token is exchanged for one of that installation (RFC 8693) with the client the hub's muster presents there. The server holds no credential of the cluster itself.
type Installations ¶
Installations answer the accounts a GitHub App is installed on that the holder of a user token of it reaches.
type MainStatus ¶ added in v8.174.0
type MainStatus struct {
Repository string `json:"repository"`
Branch string `json:"branch"`
SHA string `json:"sha"`
CommittedAt time.Time `json:"committedAt"`
// Verdict is green, red, pending or no_checks.
Verdict string `json:"verdict"`
// State is GitHub's rollup state the verdict comes from.
State string `json:"state"`
}
MainStatus is main's verdict in one repository.
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics are the server's call metrics, labelled with the tool, the caller's GitHub login and user id (Anonymous and empty for a call whose grant named none), the repository (owner/repo; empty for a tool that names none or an argument refused as usage) and the verdict.
func NewMetrics ¶
func NewMetrics(registerer prometheus.Registerer) (*Metrics, error)
NewMetrics registers the server's metrics with registerer.
type MusterGrant ¶
type MusterGrant struct {
// App is the provider App's name in muster, the header's suffix.
App string
// GitHubApp is the GitHub App's name, as a refusal names it.
GitHubApp string
// Users answer the person the token acts as, the call's caller; nil
// names none and accepts the token unchecked.
Users Users
// Installations answer the owners the App is installed on that the
// person reaches; nil checks none.
Installations Installations
}
MusterGrant is the person's token of the GitHub App muster keeps as App: muster attaches it to every call the person granted it for. The token names the caller: a call without one GitHub accepts is refused. The server stores no token and runs no sign-in.
func (MusterGrant) GitHubToken ¶
func (g MusterGrant) GitHubToken(ctx context.Context) (string, error)
GitHubToken implements Credentials: the person's token of the App, with the caller it names put on the call; a grant_required auth_required without one or with one GitHub refuses, and not_applicable for a repository whose owner the App is not installed on.
type NoClusters ¶ added in v8.155.0
type NoClusters struct{}
NoClusters is the server that reaches no installation: every rollout wait is not_applicable.
func (NoClusters) Installations ¶ added in v8.155.0
func (NoClusters) Installations() []string
Installations implements Clusters.
func (NoClusters) Open ¶ added in v8.155.0
func (NoClusters) Open(_ context.Context, installation string, _ func(http.RoundTripper) http.RoundTripper) (dynamic.Interface, error)
Open implements Clusters.
type NoCredentials ¶
type NoCredentials struct{}
NoCredentials is the server with no hand-over of a person's token: every call that reads GitHub is auth_required.
func (NoCredentials) GitHubToken ¶
func (NoCredentials) GitHubToken(context.Context) (string, error)
GitHubToken implements Credentials.
type PRMergeSources ¶
type PRMergeSources struct {
GitHub prmerge.GitHub
Rate prwait.RateSource
Entries prwait.EntryFinder
// Policy is the repository's opt-out; nil reads the team files through
// GitHub, a *githubclient.Client.
Policy prmerge.Policy
}
PRMergeSources are what a merge reads and writes, its release wait aside, which reads Sources.ReleaseWait's.
type PRWaitSources ¶
type PRWaitSources struct {
GitHub prwait.GitHub
Rate prwait.RateSource
Entries prwait.EntryFinder
// Client is the client behind GitHub, which App mode's pr_get,
// commit_wait and main_status read with too; nil from a test double.
Client *githubclient.Client
}
PRWaitSources are what a pull request wait reads.
type Principal ¶ added in v8.174.0
type Principal struct {
// Organization is the App's organization, which the client stands for.
Organization string
// Client is the principal client, the token's azp.
Client string
}
Principal is the caller a verified token names: an organization's principal client acting as itself.
type PullRequest ¶ added in v8.174.0
type PullRequest struct {
Repository string `json:"repository"`
Number int `json:"number"`
Title string `json:"title"`
URL string `json:"url"`
Author string `json:"author"`
State string `json:"state"`
Merged bool `json:"merged"`
MergedAt *time.Time `json:"mergedAt"`
Draft bool `json:"draft"`
HeadSHA string `json:"headSha"`
HeadRef string `json:"headRef"`
BaseRef string `json:"baseRef"`
MergeableState string `json:"mergeableState"`
// ReviewDecision is GitHub's of an open pull request: APPROVED,
// CHANGES_REQUESTED or REVIEW_REQUIRED; empty when the base requires no
// review, and for a closed one.
ReviewDecision string `json:"reviewDecision"`
// ApprovedBy and ChangesRequested are the reviewers whose latest
// review approves, or requests changes.
ApprovedBy []string `json:"approvedBy"`
ChangesRequested []string `json:"changesRequested"`
Comments int `json:"comments"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
// Claim is the winning claim marker; nil without one.
Claim *Claim `json:"claim"`
}
PullRequest is a pull request as pr_get answers it.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is devctl serve's MCP server.
func (*Server) Handler ¶
Handler is the streamable HTTP handler of the server, at every path. Sessions and listings need no grant, so a person who has not granted the App yet sees the tools; every tool call is refused without one. In App mode every request needs the organization's principal token, listings included: one that does not verify is answered 401 before any tool runs.
type Sources ¶
type Sources interface {
PRWait(ctx context.Context, token string, transport http.RoundTripper) (PRWaitSources, error)
PRMerge(ctx context.Context, token string, transport http.RoundTripper) (PRMergeSources, error)
ReleaseWait(ctx context.Context, token string, transport http.RoundTripper) (*releasewait.Sources, error)
ReleasePromote(ctx context.Context, token string, transport http.RoundTripper) (*releasepromote.Sources, error)
}
Sources build the clients of one call from the person's token; the requests go through transport.