Documentation
¶
Overview ¶
Package mcpserver is the `tokenhound mcp` front door: a stdio Model Context Protocol server with exactly four tools (scan, verify_status, fix_plan and report). It calls the public tokenhound API only, keeps the last Report of each session in memory and never returns file contents or a full key: results carry redacted keys, locations, ids, counts and dollars, as printable ASCII.
Index ¶
- func New(cfg Config) *mcp.Server
- func Serve(ctx context.Context, in io.Reader, out io.Writer, cfg Config) error
- type Config
- type FindingRow
- type FixPlanInput
- type FixPlanResult
- type FixStep
- type ReportInput
- type ReportResult
- type ScanInput
- type ScanResult
- type StatusRow
- type VerifyStatusInput
- type VerifyStatusResult
- type WarningInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// LoadOptions resolves the configuration of one scan rooted at root (the scan
// directory). verify is false when the tool call asks for an offline scan, else
// nil (config decides); newOnly is true for new_only, else nil. The CLI applies
// --config and --no-verify (a ceiling: verify never turns it back on).
LoadOptions func(root string, verify, newOnly *bool) (tokenhound.Options, error)
// Scan starts a scan (tokenhound.Scan when nil).
Scan func(ctx context.Context, opts tokenhound.Options) (*tokenhound.Results, error)
// Getwd returns the server's working directory, the scan root when the client
// declares no roots (os.Getwd when nil).
Getwd func() (string, error)
// Deterministic pins timestamps and durations of every Report.
Deterministic bool
// ToolVersion is reported in the Report meta and the server info.
ToolVersion string
// Logger receives log lines; it must write to stderr, never stdout (discarded when
// nil).
Logger *slog.Logger
// ProgressInterval is the shortest gap between progress notifications (250 ms
// when 0).
ProgressInterval time.Duration
}
Config wires the server to its environment.
type FindingRow ¶
type FindingRow struct {
ID string `json:"id" jsonschema:"finding id, th_ plus 16 hex characters; pass it to fix_plan"`
Provider string `json:"provider" jsonschema:"provider id"`
Status string `json:"status" jsonschema:"live, dead, unknown, rate-limited or not-verified"`
Confidence string `json:"confidence" jsonschema:"high, medium or low"`
Redacted string `json:"redacted" jsonschema:"redacted form of the key; the full key is never returned"`
DollarsPerDay float64 `json:"dollars_per_day" jsonschema:"dollars at risk per day (potential dollars for an unverified key, 0 for a dead one)"`
FirstLocation string `json:"first_location" jsonschema:"path:line of the first place the key was seen"`
NewVsBaseline *bool `json:"new_vs_baseline,omitempty" jsonschema:"false when the finding is in the baseline file; absent without a baseline"`
}
FindingRow is one finding of a scan result.
type FixPlanInput ¶
type FixPlanInput struct {
ID string `json:"id" jsonschema:"finding id from the last scan (th_ plus 16 hex characters)"`
}
FixPlanInput are the arguments of fix_plan.
type FixPlanResult ¶
type FixPlanResult struct {
ID string `json:"id" jsonschema:"finding id"`
Provider string `json:"provider" jsonschema:"provider id"`
Status string `json:"status" jsonschema:"verification status"`
Redacted string `json:"redacted" jsonschema:"redacted form of the key"`
Steps []FixStep `json:"steps" jsonschema:"the steps to contain the key, in order"`
}
FixPlanResult is the structured result of fix_plan.
type FixStep ¶
type FixStep struct {
N int `json:"n" jsonschema:"1-based step number"`
Kind string `json:"kind" jsonschema:"revoke, replace, purge, check_usage or scopekeeper"`
Title string `json:"title" jsonschema:"what to do"`
Detail string `json:"detail,omitempty" jsonschema:"plain-text detail; lines separated by newlines"`
URL string `json:"url,omitempty" jsonschema:"provider page for the step"`
Command string `json:"command,omitempty" jsonschema:"plain-text command to run"`
Locations []string `json:"locations,omitempty" jsonschema:"path:line of each place the step applies to"`
}
FixStep is one step of a fix plan.
type ReportInput ¶
type ReportInput struct {
Format string `json:"format" jsonschema:"json, sarif, badge (SVG) or card (PNG image)"`
}
ReportInput are the arguments of report.
type ReportResult ¶
type ReportResult struct {
Format string `json:"format" jsonschema:"the rendered format"`
MIMEType string `json:"mime_type" jsonschema:"media type of the rendered output"`
Bytes int `json:"bytes" jsonschema:"size of the rendered output in bytes"`
}
ReportResult is the structured result of report.
type ScanInput ¶
type ScanInput struct {
Path string `` /* 238-byte string literal not displayed */
Staged bool `json:"staged,omitempty" jsonschema:"also scan the staged changes of the git repository at path"`
History bool `json:"history,omitempty" jsonschema:"also scan the added lines of every commit of the git repository at path"`
Since string `json:"since,omitempty" jsonschema:"limit history to commits after this commit, branch or tag (implies history)"`
Image string `json:"image,omitempty" jsonschema:"container image to scan (not available in this version)"`
Agents bool `json:"agents,omitempty" jsonschema:"also scan this machine's coding agent files and the agent files under path"`
Verify *bool `` /* 136-byte string literal not displayed */
NewOnly bool `json:"new_only,omitempty" jsonschema:"list only findings that are not in the baseline file"`
}
ScanInput are the arguments of the scan tool.
type ScanResult ¶
type ScanResult struct {
Headline string `json:"headline" jsonschema:"the summary sentence, as tokenhound scan --quiet prints it"`
Grade string `json:"grade" jsonschema:"exposure grade A to F"`
GradeReasons []string `json:"grade_reasons" jsonschema:"why the grade was given"`
Live int `json:"live" jsonschema:"unsuppressed live keys"`
Dead int `json:"dead" jsonschema:"unsuppressed dead keys"`
Unverified int `json:"unverified" jsonschema:"unsuppressed keys not verified, unknown or rate-limited"`
Suppressed int `json:"suppressed" jsonschema:"suppressed findings (ignore file, inline allow, test key)"`
Baselined int `json:"baselined" jsonschema:"unsuppressed findings already in the baseline file"`
DollarsAtRiskPerDay float64 `json:"dollars_at_risk_per_day" jsonschema:"summed dollars at risk per day of the live keys"`
Partial bool `json:"partial" jsonschema:"true when the scan stopped at its timeout and results are incomplete"`
Findings []FindingRow `json:"findings" jsonschema:"unsuppressed findings in report order, live first"`
Warnings []WarningInfo `json:"warnings" jsonschema:"non-fatal problems of the scan"`
}
ScanResult is the structured result of scan.
type StatusRow ¶
type StatusRow struct {
ID string `json:"id" jsonschema:"finding id"`
Status string `json:"status" jsonschema:"live, dead, unknown, rate-limited or not-verified"`
StatusReason string `json:"status_reason" jsonschema:"why the status was given, for example unpaired or verification_off"`
Verified bool `json:"verified" jsonschema:"true when a verification call answered"`
}
StatusRow is the verification status of one finding.
type VerifyStatusInput ¶
type VerifyStatusInput struct {
IDs []string `json:"ids,omitempty" jsonschema:"finding ids from the last scan; empty means every unsuppressed finding"`
Refresh bool `json:"refresh,omitempty" jsonschema:"run the last scan again first and keep its results"`
}
VerifyStatusInput are the arguments of verify_status.
type VerifyStatusResult ¶
type VerifyStatusResult struct {
Findings []StatusRow `json:"findings" jsonschema:"one entry per requested finding"`
}
VerifyStatusResult is the structured result of verify_status.
type WarningInfo ¶
type WarningInfo struct {
Code string `json:"code" jsonschema:"documented warning code, for example timeout"`
Location string `json:"location" jsonschema:"where the warning applies"`
DetailCode string `json:"detail_code" jsonschema:"detail code"`
}
WarningInfo is one warning of a scan result.