logic_mcp_server.py is an MCP streamable HTTP server that provides persistent, namespace-scoped logical constraint checking for agentic what-if analysis.
It runs in HTTP mode only.
Runtime code is split into focused modules:
logic_mcp/transport_http.py(HTTP transport + server lifecycle)logic_mcp/engine.py(tool schemas, request handlers, solver engine)logic_mcp/store.py(persistent model store)logic_mcp/audit_log.py(JSONL audit logging)logic_mcp/errors.py,logic_mcp/paths.py(shared primitives)
It supports:
- Persistent
bundles(SMT2 fragments),rules(pyexprorsmt2), andexpectations - Persistent context inventory (
concepts,code_bindings) via atomiclogic_context_patch - Required top-level
motivationmetadata for all non-symbol inserted items - What-if checks with temporary hypothesis facts, lightweight assumptions, and rule patch overlays (
set_rules,remove_rules) - Baseline vs candidate evaluation with
sat/unsat/unknown - Unsat cores, witness models (scope-controlled), expectation checks, influence analysis, metrics, and delta reporting (by
detail_level) - Session reset via one lightweight call (
logic_reset) - Strict SMT2 command acceptance (
declare-*,define-fun*,assert,set-logic,set-option)
Persistent state is stored in logic_store/<sessionId>/session.json.
Session id is derived from the URL path segment in /sessions/<sessionId>/ (and never from tool payload fields).
Tool-call audit logs are written per session to logic_store/<sessionId>/log.jsonl.
Each line is a JSON object with shape:
{"time":"<timestamp>","call":<raw call JSON object>,"response":<raw response JSON object>}.
When raw call extraction fails and strict logging is enabled, call includes:
"call_parse_error":{"message":"...","raw_body":"..."}.
raw_body is stored as an escaped readable string (not base64), so each line remains valid JSONL.
- Python 3.11+
z3-solvermcpPython packageuvicorn(ASGI server runtime)
In this workspace, .venv_sys already contains runtime dependencies.
For a fresh environment, install mcp, z3-solver, and uvicorn in the Python runtime used to launch the server.
Start directly:
/home/node/project/.venv_sys/bin/python3 /home/node/project/logic_mcp_server.py --host 0.0.0.0 --port 8765It serves MCP over streamable HTTP at:
http://<host>:<port>/sessions/<sessionId>/http://<host>:<port>/healthz
Register the server once:
codex mcp add logic --url http://127.0.0.1:8765/sessions/dev-session-001/Each agent should be installed with its own session URL.
Verify configuration:
codex mcp list
codex mcp get logicRemove configuration:
codex mcp remove logicRun from the target project root ($PWD should be the project where agents run):
./install_logic_mcp.sh dev-session-001 http://127.0.0.1:8765The installer performs all of the following:
- Registers Codex MCP server
logicusing--url <base-url>/sessions/<session-id>/ - Installs
.logic_mcp_manifestinto the target project - Appends
.logic_mcp_manifest/AGENTS.snippet.mdintoAGENTS.md(idempotent)
Optional environment overrides:
PROJECT_DIR: target project root (default: currentPWD)LOGIC_MCP_BASE_URL: base network URL for the running server (default:http://127.0.0.1:8765)LOGIC_STRICT_RAW_CALL_LOGGING:1/0toggle for parse-error logging policy (default:1)MANIFEST_SOURCE_DIR: source manifest directory (default: script-local.logic_mcp_manifest)MANIFEST_TARGET_DIR: destination manifest directory (default:$PROJECT_DIR/.logic_mcp_manifest)AGENTS_FILE: targetAGENTS.mdpath (default:$PROJECT_DIR/AGENTS.md)SERVER_PATH: override server script path
- Sidecar source artifact:
LogiCar/logicar.py - Sidecar command websocket endpoint:
ws://<host>:<port>/supervisor/sidecar/ws - Download artifact list:
http://<host>:<port>/agents/bootstrap/sidecar/ - Download artifact file:
http://<host>:<port>/agents/bootstrap/sidecar/logicar.py
scripts/integration_test_http.sh: MCP initialize/call flow, session isolation, list/read behavior, and log fidelity.scripts/test_audit_parse_error.sh: strict parse-error logging behavior and JSONL-safe escaped raw body.
The manifest install places:
.logic_mcp_manifest/manifest.md.logic_mcp_manifest/examples.md.logic_mcp_manifest/AGENTS.snippet.md
Files expected at project root after install:
AGENTS.md(contains the Logic MCP snippet)
The server exposes 11 tools:
logic_set_rulelogic_remove_rulelogic_set_bundlelogic_remove_bundlelogic_set_expectationlogic_remove_expectationlogic_resetlogic_checklogic_context_patchlogic_listlogic_read
tools/list includes:
- tool
titleand long-formdescription - field-level input schema descriptions
- common output envelope schemas
- tool annotations (
readOnlyHint,destructiveHint,idempotentHint,openWorldHint) - execution hint (
taskSupport)
Beyond tools, the server exposes:
resources/list/resources/read:logic://guide/overviewlogic://guide/incremental-strategylogic://guide/manifestlogic://guide/exampleslogic://guide/use-caseslogic://guide/use-case-indexlogic://session/current/snapshotlogic://session/current/playbook
resources/templates/list:logic://session/{session_id}/inventory/{detail_level}(detail_levelisminimal|compact|more; optional query:show,limit,cursor)logic://session/{session_id}/item/{item_id}(optional query:detail_level, includingfull)logic://session/{session_id}/playbook/{focus}
prompts/list/prompts/get:logic_orientlogic_capture_discoverylogic_experiment_looplogic_graph_handoff
completion/complete:- argument suggestions for common prompt/template fields (
detail_level,show,focus,session_id,item_id)
- argument suggestions for common prompt/template fields (
MCP already carries tool name, so the simplest payloads do not need a tool field.
{
"id": "decl_times",
"bundle": [
"(declare-const start_time_sim1_ms Int)",
"(declare-const start_time_sim2_ms Int)"
],
"motivation": {
"rationale": "Shared declarations for simulation start-time rules"
}
}{
"id": "sim_start_exact",
"lang": "pyexpr",
"rule": "start_time_sim1_ms == start_time_sim2_ms",
"intent": "Express start-time equality invariant",
"motivation": {
"rationale": "Capture discovered invariant from requirements"
}
}{
"id": "exp_exact_implies_nonneg",
"kind": "entails",
"a_ref": "sim_start_exact",
"b_ref": "sim_start_exact",
"motivation": {
"rationale": "Guard against refactor drift in expectation links"
}
}{
"hypothesis": {
"facts": {
"start_time_sim1_ms": 0,
"start_time_sim2_ms": "?t2"
},
"assumptions": [
{
"id": "a_threshold",
"lang": "pyexpr",
"rule": "start_time_sim2_ms >= start_time_sim1_ms"
}
],
"patch": {
"set_rules": {
"sim1_first": {
"lang": "pyexpr",
"rule": "start_time_sim2_ms > start_time_sim1_ms"
}
},
"remove_rules": []
}
},
"detail_level": "compact",
"return_model": true,
"model_scope": "facts",
"include_metrics": true
}{
"confirm": "reset-session",
"wipe_logs": true
}{
"ops": [
{
"op": "set_code_binding",
"id": "cb_pricing",
"set": {
"path": "src/pricing.py",
"from": {"line": 12},
"to": {"line": 26},
"line_excerpt": "compute_price(amount, tax_rate)",
"related_rule_ids": ["sim_start_exact"],
"related_expectation_ids": [],
"related_concept_ids": [],
"motivation": {
"rationale": "Primary pricing implementation location for this rule"
}
}
}
]
}{
"show": ["all"],
"detail_level": "compact",
"limit": 50
}{
"id": "sim_start_exact",
"detail_level": "full"
}Minimal single-ID lookup:
{
"id": "sim_start_exact"
}All tools return:
- Success:
{ "ok": true }or{ "ok": true, "result": { ... } }(optionally withwarnings: [...]) - Failure:
{ "ok": false, "error": { "code": "...", "message": "...", "details": { ... } } }
- Add declarations with
logic_set_bundle. - Add persistent invariants with
logic_set_rule. - Add omission checks with
logic_set_expectation. - Add context links with
logic_context_patch. - Run what-if checks via
logic_checkwith temporary patch/facts overlays. - Inspect inventories via
logic_list(minimal|compact|more). - Read specific IDs in detail via
logic_read(usefullwhen needed).
The accepted reduced-surface contract is documented in context-feature-spec.md.