Search

Project overview

On this page

A high-performance MCP (Model Context Protocol) server written in Zig, designed to bridge Large Language Models with a Prolog inference engine for deterministic logical reasoning.

Features

  • CLI entrypoint with init, serve, upgrade, and all 29 MCP tools exposed as subcommands (e.g. zpm remember-fact, zpm query-logic)
  • Self-upgrade via zpm upgrade with SHA256 verification, atomic install, and --channel stable|dev selection
  • Per-project .zpm/ directory for isolated configuration and persistence
  • MCP protocol version 2026-07-28 over STDIO transport with server/discover
  • Tool registration and discovery via tools/list
  • Echo tool for health-check and smoke testing
  • Prolog inference engine with Trealla C API integration
  • Knowledge management tools: assert facts and define rules via MCP
  • Exploration tools: query Prolog goals and trace transitive dependencies via MCP
  • Supervision tools: verify knowledge base consistency and explain proof chains via MCP
  • Knowledge schema discovery: inspect file-loaded static facts and rules alongside asserted predicates, with clause counts and types, in each selected memory
  • Delete tools: retract individual facts or clear entire categories from the knowledge base
  • Update tools: atomically replace individual facts or upsert facts with pattern matching
  • Truth Maintenance System: manage assumptions and automatically propagate belief changes via MCP
  • Knowledge base persistence: durable storage via write-ahead journal and fresh-engine-validated snapshots with automatic recovery
  • Named memory segments for domain-isolated knowledge bases with independent WAL/snapshot persistence, read-only mount mode, project and global scope, cross-memory queries via Prolog module qualification, and discoverable memory selectors in MCP schemas and CLI help
  • Persistent mount manifest (.zpm/mounts.json) for durable memory configuration across CLI invocations
  • Documentation site with Hugo/Thulite (Doks) and GitHub Pages auto-deployment
  • Zero external runtime dependencies (statically linked, including Prolog library)

Quick Start

Prerequisites

  • Zig >= 0.17.1
  • C compiler (gcc or clang)

Install

Install the latest pre-built binary with a single command:

curl -fsSL https://raw.githubusercontent.com/awf-project/zpm/main/scripts/install.sh | sh

Supported platforms: Linux (x86_64, arm64), macOS (x86_64, arm64).

Build from Source

Clone the repository with its Trealla Prolog submodule, which provides ZPM’s inference engine:

git clone --recurse-submodules https://github.com/awf-project/zpm.git
cd zpm

For an existing clone, initialize the submodule before building:

git submodule update --init --recursive

Then build and test:

# Build the server binary
make build

# Run unit tests
make test

# Run functional (end-to-end) tests
make functional-test

The built binary is located at zig-out/bin/zpm.

CLI Usage

# Display help (zpm with no args also prints help, but exits 1)
zpm --help

# Show version (use the subcommand; --version/-v fall through to help)
zpm version

# Initialize a project directory
zpm init

# Start the MCP server (STDIO transport)
zpm serve

# Upgrade to the latest release (verifies SHA256, atomic replace)
zpm upgrade
zpm upgrade --channel dev --dry-run

# Invoke MCP tools directly from the shell
zpm remember-fact --fact "task_status(f017, done)"
zpm query-logic --goal "task_status(X, done)" --format json
zpm save-snapshot --name "before-deploy"

# Manage memory segments
zpm memory create --name feature_auth
zpm memory create --name shared_profiles --scope global
zpm memory list
zpm remember-fact --fact "task_done(login)" --memory feature_auth
zpm query-logic --goal "task_done(X)" --memory feature_auth
zpm get-knowledge-schema --memory feature_auth
zpm memory mount --name feature_auth --mode ro

The optional --memory flag selects a mounted segment. Omitting it keeps unqualified reads in the default memory. Memory-aware MCP tools advertise the optional string memory argument in tools/list, so clients can discover it before calling a tool. Use zpm get-knowledge-schema --memory <name> to inspect predicates in a named segment; see Schema Discovery for an example.

See the CLI Reference for the full list of tool subcommands and flags.

Connect via MCP Client

Add zpm to your MCP client configuration. For example, in Claude Code’s settings.json:

{
  "mcpServers": {
    "zpm": {
      "command": "zpm",
      "args": ["serve"]
    }
  }
}

Commands

CommandDescription
make buildBuild the server binary
make checkRun all checks (lint + test + e2e)
make cleanRemove build artifacts
make fmtFormat source code
make functional-testRun end-to-end MCP protocol tests
make lintCheck formatting
make testRun unit tests (inline Zig tests)
make upgrade-testRun upgrade end-to-end tests

MCP Tools

ToolDescriptionArguments
assume_factAssert a fact under a named assumption with automatic justification trackingassumption (string, required), fact (string, required), memory (string, optional)
clear_contextClear all facts from the knowledge base matching a patterncategory (string, required), memory (string, optional)
create_memoryCreate a named memory segment backed by a dedicated Prolog modulename (string, required), scope (string, optional)
define_ruleAssert a Prolog rule into the knowledge basehead (string, required), body (string, required), memory (string, optional)
echoReturns the provided message (health-check)message (string, required)
explain_whyTrace proof tree for a fact and return structured deduction chainfact (string, required), max_depth (integer, optional), memory (string, optional)
find_predicate_referencesLocate all usage sites of a Prolog predicate in the knowledge basefunctor (string, required), arity (integer, optional), memory (string, optional), include_cross_memory_refs (boolean, optional)
forget_factRemove a single fact from the knowledge basefact (string, required), memory (string, optional)
get_belief_statusQuery whether a belief is currently supported and which assumptions justify itfact (string, required), memory (string, optional)
get_justificationQuery all facts supported by a named assumptionassumption (string, required), memory (string, optional)
get_kb_overviewSingle-call snapshot of the default knowledge base: static and asserted user predicates with sample clauses, assumptions, snapshots, and persistence healthsample_size (integer, optional)
get_knowledge_schemaList file-loaded static and asserted user predicates in the selected memory with arity, type (fact/rule/both), and clause countmemory (string, optional)
get_persistence_statusQuery the persistence layer status including journal size, last snapshot, and operational mode(no required arguments)
list_assumptionsList all currently active assumptions and their associated factsmemory (string, optional)
list_memoriesList all discoverable memories with scope, mount status, and mode(no required arguments)
list_snapshotsList all available knowledge base snapshots with metadatamemory (string, optional)
mount_memoryMount a named memory segment for use, optionally in read-only modename (string, required), mode (string, optional)
query_logicExecute a Prolog goal and return all variable bindings as JSONgoal (string, required), memory (string, optional)
remember_factAssert a Prolog fact into the knowledge basefact (string, required), memory (string, optional)
rename_predicateAtomically rename a Prolog functor across facts, rules, and TMS justificationsold_functor (string, required), new_functor (string, required), arity (integer, optional), memory (string, optional), dry_run (boolean, optional), propagate_cross_memory_refs (boolean, optional)
restore_snapshotRestore knowledge base from a named snapshot and replay subsequent journal entriesname (string, required), memory (string, optional)
retract_assumptionRetract a named assumption and propagate its removal through the knowledge baseassumption (string, required), memory (string, optional)
retract_assumptionsRetract all assumptions matching a glob-style patternpattern (string, required), memory (string, optional)
save_snapshotCreate a named point-in-time snapshot of the knowledge basename (string, required), memory (string, optional)
trace_dependencyTrace transitive dependencies from a start node using path/2 rulesstart_node (string, required), memory (string, optional)
unmount_memoryUnmount a named memory, flushing WAL and freeing resourcesname (string, required)
update_factAtomically replace an existing fact (retract old, assert new)old_fact (string, required), new_fact (string, required), memory (string, optional)
upsert_factReplace a fact matching functor+first arg, or insert if not foundfact (string, required), memory (string, optional)
verify_consistencyCheck knowledge base for integrity violationsscope (string, optional), memory (string, optional)

Documentation

Browse the documentation online at https://docs.awf-project.ai/zpm/ or in the docs/ directory:

To preview the documentation site locally:

Install Hugo 0.169.0, Node.js 26, and the native Dart Sass CLI 1.108.1 first. Ensure hugo and sass are on PATH; Thulite 3 requires Dart Sass with the embedded protocol.

cd site && npm ci && npm run dev

Run npm run build from site/ for the production build used by CI.

License

See LICENSE.

View original on GitHub