Skip to main content

Module mcp_server

Module mcp_server 

Source
Expand description

MCP (Model Context Protocol) server implementation.

Speaks JSON-RPC 2.0 over stdin/stdout. AI coding assistants (Claude Code, Cursor, etc.) connect to difflore mcp-server as an MCP stdio transport to query team rules and historical review verdicts while generating code.

Structs§

HookRuleContext
Injectable rule context produced by fetch_relevant_rules_for_hook.

Functions§

detect_active_model
Read the active agent model from the standard env vars Claude Code, Cursor and the Anthropic SDK populate. Returns the first non-empty match in priority order. Lower-cased so callers can do substring checks without re-normalising.
fetch_relevant_rules_for_hook
Hook-path rule fetch. Returns rendered text + injection count without the JSON-RPC envelope so the hook shim (or any other in-process consumer) can pull rules in one function call.
haiku_auto_disable_active
True when (a) the active model resolves to haiku and (b) the user hasn’t opted back in via DIFFLORE_FORCE_RULES_ON_HAIKU. Exposed for difflore doctor so it can report “auto-applied” instead of “recommended”.
is_haiku_model
True when the detected model id looks like a Haiku variant (any generation). Substring match keeps us forward-compatible with future haiku revs without a hard-coded list.
origin_to_kind
Classify a skill’s origin column into a timeline kind. The mapping is the same one rule_hits_by_origin uses — one source of truth so the telemetry aggregate and the timeline stream stay aligned.
parse_file_patterns
Parse the JSON-encoded file_patterns column into a Vec<String>. Malformed / missing → empty vec. Matches the permissive behaviour of retrieval::pattern_allows — a rule with a broken pattern list never disappears silently, it just shows up with no patterns in the index.
predict_pr_scope
Predict a PR’s likely edit scope from the local imported review corpus.
predict_pr_scope_for_repos
Repo-scoped sibling of predict_pr_scope.
run
Run the MCP server event loop. Reads JSON-RPC messages line-by-line from stdin and writes responses to stdout. Runs until stdin is closed.