topos.mcp.formatting¶
Response formatters for the Topos MCP server.
Converts ClassificationResult and distance results into the Pydantic
return models defined in schemas.py.
- topos.mcp.formatting.lattice_to_str(value)[source]
- topos.mcp.formatting.str_to_lattice(value)[source]
- topos.mcp.formatting.build_preference_walk(prefs, current)[source]
Materialize a
PreferenceWalkfor the result schema.
- topos.mcp.formatting.build_guidance(result)[source]
Priority-aware next-step hint for agents.
Phrased against the three free generators (SIMPLE, COMPOSABLE, SECURE).
- topos.mcp.formatting.build_agent_contract(result, *, coupling_available, security_findings, acknowledged_risks, grade_capped, warnings=None)[source]
Return compact loop-control fields for MCP agents.
- topos.mcp.formatting.mdg_unavailable_message(warnings)[source]
The ‘COMPOSABLE not scored’ note surfaced when no MDG is available.
- topos.mcp.formatting.build_pillars(result, coupling_available, *, warnings=None)[source]
Build the lean per-pillar (simple, composable, secure) summary.
Each pillar carries only
achieved+score. The full metric and interpretation detail is NOT duplicated here — it lives once in the parent’s flatraw_metrics/interpretation(see_PILLAR_METRIC_PREFIXESfor the namespacing).warningsis unused now that themdg.unavailablenote is injected into the flat interpretation byto_evaluation_result; kept for call-site stability.
- topos.mcp.formatting.to_evaluation_result(result, coupling_available, *, preferences=None, priority_source=PrioritySource.DEFAULT, warnings=None, security_findings=None, acknowledged_risks=None, adjusted_verdict=None, include_agent_contract=True, verbose=True)[source]
Convert a
ClassificationResultinto the Pydantic return model.When
verboseisFalsethe structured channel omits the 16 raw-metric floats and trimsinterpretationto failing generators only (see_failing_interpretation). Measurement showedraw_metrics+interpretationmake up ~55% of the default structured payload, and clients routinely injectstructured_contentinto context, so gating both channels (not just the markdown) is what earns the keep here.
- topos.mcp.formatting.to_tool_result(model, markdown)[source]
Return a dual-channel
ToolResult: markdown for the LLM, JSON for code.contentis the compact markdown the LLM reads (FastMCP wraps the bare string in aTextContent);structured_contentis the model’s JSON-mode dump for programmatic clients.Empirically verified FastMCP behavior (see
tests/mcp/test_evaluate.pyand a probe overmcp.call_tool+to_mcp_tool().model_dump()):When a tool is annotated
-> ToolResult, FastMCP emits nooutputSchemafor it — this is intentional and shrinks the eager tool-definition surface (outputSchema is optional per the MCP spec). Tools wanting to keep an outputSchema can instead annotate-> Modelwhile still returning thisToolResult(both channels are honored at runtime regardless of the annotation).structured_contentis still delivered on the wire.contentis the markdown text, not the model JSON.
- topos.mcp.formatting.render_evaluation_md(e, title=None, *, verbose=True)[source]