Documentation
¶
Overview ¶
Package mcp implements the MCP server mode: a thin, stateless adapter that exposes the same core sensors as MCP tools (PRD section 10). It reimplements no audit logic — every tool call translates to the same engine the CLI uses — and relies on prompt caching to neutralize the stateless overhead.
Skeleton: this declares the [Server] contract. No transport (stdio/HTTP) or tool dispatch is implemented yet.
Index ¶
- func NewServer() *mcpsdk.Server
- func Serve(ctx context.Context) error
- type ConfirmSurfaceRequest
- type ConfirmSurfaceResponse
- type CoverageRequest
- type CoverageResponse
- type FileInput
- type FrontierPending
- type ResolvedClean
- type ScanAllRequest
- type ScanAllResponse
- type ScanAllSummary
- type ScanEndpointRequest
- type ScanEndpointResponse
- type ScanRequest
- type ScanResponse
- type SurfaceIDORRequest
- type SurfaceResponse
- type Tool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewServer ¶
NewServer builds the codefit MCP server with its tools registered. Each tool is a THIN adapter: it hands the SDK's typed request to the core handler that already exists and is tested, and returns the core's result as structured output. No audit logic lives here — the MCP layer only connects the protocol to the engine (PRD §15). The server is stateless: every tool call is independent and carries everything it needs.
Types ¶
type ConfirmSurfaceRequest ¶
type ConfirmSurfaceRequest struct {
Confirmations []surface.Confirmation `json:"confirmations"`
}
ConfirmSurfaceRequest carries the agent's verdicts back to codefit.
type ConfirmSurfaceResponse ¶
type ConfirmSurfaceResponse struct {
Findings []findings.Finding `json:"findings"`
Dismissed []surface.Confirmation `json:"dismissed"`
Uncertain []surface.Confirmation `json:"uncertain"`
Invalid []surface.Confirmation `json:"invalid"`
}
ConfirmSurfaceResponse is the integration result: probabilistic findings plus the traceability buckets. Stateless — built purely from the verdicts sent.
func HandleConfirmSurface ¶
func HandleConfirmSurface(req ConfirmSurfaceRequest) ConfirmSurfaceResponse
HandleConfirmSurface integrates the agent's verdicts: codefit-confirm-surface. It recomputes each surface id to validate the verdict before integrating, and keeps no session.
type CoverageRequest ¶
type CoverageRequest struct {
Language string `json:"language"`
}
CoverageRequest is the input to codefit-coverage.
type CoverageResponse ¶
CoverageResponse carries the coverage manifest: what is audited deterministically vs reasoned over surface vs not covered.
func HandleCoverage ¶
func HandleCoverage(req CoverageRequest) (CoverageResponse, error)
HandleCoverage returns the coverage manifest for the language. Thin adapter: the manifest is the provider's single source of truth.
type FileInput ¶
FileInput is one source file a surface tool reasons over (path + content), so the tool stays stateless — the caller passes the bytes, codefit reads nothing.
type FrontierPending ¶
type FrontierPending struct {
Count int `json:"count"`
Note string `json:"note,omitempty"`
Endpoints []report.FrontierEndpoint `json:"endpoints,omitempty"`
}
FrontierPending declares the endpoints codefit did NOT resolve locally: the data left the handler body, so codefit concluded nothing and the agent must follow it in the code. They are named (not detailed) with a Note explaining why they are not detailed and how to fetch any of them. This is not hiding — it is prioritising while declaring the rest.
type ResolvedClean ¶
type ResolvedClean struct {
Count int `json:"count"`
Note string `json:"note,omitempty"`
Endpoints []report.ResolvedCleanEndpoint `json:"endpoints,omitempty"`
}
ResolvedClean declares the endpoints codefit resolved locally and found clean (controls present, no gap). They are NAMED with a verification fact, not detailed. This is an affirmation — codefit looked and it is clean — not a generic "not detailed" bucket; that is why it is separate from FrontierPending.
type ScanAllRequest ¶
ScanAllRequest is the input to codefit-scan-all: a project root and language. codefit walks the project, runs the deterministic sensor and the surface queries, and returns the complete per-endpoint picture.
type ScanAllResponse ¶
type ScanAllResponse struct {
Summary ScanAllSummary `json:"summary"`
Actionable []report.EndpointReport `json:"actionable"`
ResolvedClean ResolvedClean `json:"resolved_clean"`
FrontierPending FrontierPending `json:"frontier_pending"`
}
ScanAllResponse is the agent-first synthesis as an ACTIONABLE summary, not the raw item dump. It has three buckets, one per resolution level, all decided by facts codefit already computes (ADR 0008):
- Actionable — resolved locally AND has a gap: full detail, the agent acts.
- ResolvedClean — resolved locally, NO gap: named + a verification fact; codefit checked and the controls are present.
- FrontierPending — not resolved locally (the data left the handler body): named; the agent follows it in the code.
ResolvedClean and FrontierPending are kept DISTINCT on purpose: one affirms codefit verified the controls, the other states codefit could not conclude — epistemological opposites the agent must distinguish (flattening them would be the old frontier-wording error). Full detail of any named endpoint is always one codefit-scan-endpoint call away.
func HandleScanAll ¶
func HandleScanAll(req ScanAllRequest) (ScanAllResponse, error)
HandleScanAll runs the full audit over the project and returns the actionable summary plus the named frontier-pending list. It reuses the real security sensor (the deterministic rules plus the three surface queries already run together there), groups the result by endpoint, and partitions by the local-resolution fact — it adds no detection, only the aggregation and the split.
type ScanAllSummary ¶
type ScanAllSummary struct {
Endpoints int `json:"endpoints"`
DeterministicFindings int `json:"deterministic_findings"`
SurfaceItems int `json:"surface_items"`
CertainConcerns int `json:"certain_concerns"`
}
ScanAllSummary is the at-a-glance count, not a judgment.
type ScanEndpointRequest ¶
type ScanEndpointRequest struct {
Root string `json:"root"`
Language string `json:"language"`
File string `json:"file"`
}
ScanEndpointRequest is the input to codefit-scan-endpoint: a project root, language, and the file (relative to root, as it appears in scan-all's File fields) to re-analyse on demand.
type ScanEndpointResponse ¶
type ScanEndpointResponse struct {
File string `json:"file"`
Found bool `json:"found"`
Endpoints []report.EndpointReport `json:"endpoints,omitempty"`
Note string `json:"note,omitempty"`
}
ScanEndpointResponse carries the full per-endpoint detail for one file: every handler in it with all its concerns (signals, reason_to_review, certainty, fact fields) — the same concern contract as scan-all. Found is false when the file has no auditable concerns (not a route handler, or nothing to enumerate).
func HandleScanEndpoint ¶
func HandleScanEndpoint(req ScanEndpointRequest) (ScanEndpointResponse, error)
HandleScanEndpoint re-analyses a single file on demand and returns its endpoints with full detail. STATELESS: it re-runs the static analysis over the project and filters to the requested file — it retrieves nothing stored. codefit does not keep the surface items waiting to be asked for; it recomputes the request. Static analysis is cheap, and re-running the same pipeline guarantees the detail here is identical to what scan-all would have shown for that endpoint (ADR 0008).
type ScanRequest ¶
ScanRequest is the input to codefit-scan-security: a project root and language.
type ScanResponse ¶
type ScanResponse struct {
Findings []findings.Finding `json:"findings"`
Surface []findings.SurfaceItem `json:"surface"`
Score int `json:"score"`
Blocked bool `json:"blocked"`
}
ScanResponse is the deterministic + surface result over the project (the §11 contract): flat findings and surface, the dimension score, and whether the project is blocked (an unconsented critical security finding).
func HandleScanSecurity ¶
func HandleScanSecurity(req ScanRequest) (ScanResponse, error)
HandleScanSecurity runs the security sensor over the project and returns the flat findings + surface. A thin adapter: it resolves the provider, runs the sensor (the deterministic rules + the surface queries, already wired there), and returns its result — no detection logic lives here.
type SurfaceIDORRequest ¶
type SurfaceIDORRequest struct {
Files []FileInput `json:"files"`
}
SurfaceIDORRequest is the input to codefit-surface-idor.
type SurfaceResponse ¶
type SurfaceResponse struct {
Surface []findings.SurfaceItem `json:"surface"`
}
SurfaceResponse is the §11 surface contract: the items the agent must reason.
func HandleSurfaceAuthz ¶
func HandleSurfaceAuthz(req SurfaceIDORRequest) (SurfaceResponse, error)
HandleSurfaceAuthz enumerates the broken-authorization surface across the given files. It orders the items so the actionable ones — where no known authz helper was detected — come FIRST, the rest after (where a check exists, the agent verifies sufficiency). It does NOT reduce the list: the complete enumeration is preserved, only reordered, so findings surface instead of being buried in volume. Ordering by a fact is not a severity judgment — codefit does not say "no check is worse", it just surfaces the fact for the agent.
func HandleSurfaceIDOR ¶
func HandleSurfaceIDOR(req SurfaceIDORRequest) (SurfaceResponse, error)
HandleSurfaceIDOR enumerates the IDOR surface across the given files and returns it in the canonical JSON contract. Files that are not handled by a provider (or carry no IDOR surface) contribute nothing.
func HandleSurfaceOverfetch ¶
func HandleSurfaceOverfetch(req SurfaceIDORRequest) (SurfaceResponse, error)
HandleSurfaceOverfetch enumerates the over-fetching surface and orders by STRUCTURAL CERTAINTY, reusing the queryable facts — it does NOT filter:
1st local find, no select (structurally confirmed over-fetch — actionable) 2nd local find, with select (limited) 3rd frontier (service — codefit cannot see the find; kept last, honest)
The complete enumeration is preserved; only the order changes, lowering the uncertain (frontier) without dropping them — the unchecked-first principle on the local/frontier axis (ADR 0005). Ordering by a fact is not severity: codefit ranks by what it can assert with most certainty, the agent judges.
type Tool ¶
type Tool string
Tool is the name of an MCP tool codefit exposes. All tools use the codefit- prefix; the codefit-surface-* family enumerates surface for the agent to reason about rather than detecting (PRD section 11).
const ( ToolScanSecurity Tool = "codefit-scan-security" ToolScanDB Tool = "codefit-scan-db" ToolCheckCVEs Tool = "codefit-check-cves" ToolCheckPractices Tool = "codefit-check-practices" ToolScanTests Tool = "codefit-scan-tests" ToolSurfaceIDOR Tool = "codefit-surface-idor" ToolSurfaceAuthz Tool = "codefit-surface-authz" ToolSurfaceOverfetch Tool = "codefit-surface-overfetch" ToolConfirmSurface Tool = "codefit-confirm-surface" ToolReviewCode Tool = "codefit-review-code" ToolScanAll Tool = "codefit-scan-all" ToolScanEndpoint Tool = "codefit-scan-endpoint" ToolBaseline Tool = "codefit-baseline" ToolCoverage Tool = "codefit-coverage" )