---
name: aptcache
description: Exact, verifiable computation over MCP (APTcache exec). Use for ANY arithmetic, percentages, money/tax/finance calculation, date or duration math, unit conversion, numeric comparison, or if/elif/else rule evaluation — never estimate a number or compute in your head; write pure Python and let exec run it deterministically. Also reuse calculation models saved earlier (invoke by name with new inputs) and locate verified computations in the shared corpus. Load whenever an answer contains a number to derive, a threshold to apply, or a rule to evaluate.
---

# APTcache exec — offload computation, ground your answers

The `exec` tool runs pure-functional Python **deterministically and verifiably** against a closed-world kernel. There is no LLM on the server: you write the Python, the substrate executes exactly what you wrote, and the result returns with the exact code that ran (`canonical_python`) and a content hash. A calculation offloaded to `exec` stops being a plausible guess and becomes an exact, replayable computation.

## Connect

| Fact                                   | Value                                                     |
| -------------------------------------- | --------------------------------------------------------- |
| Endpoint (Streamable HTTP)             | `POST https://mcp.aptcache.com/mcp`                            |
| Authorization server (issuer)          | `https://auth.aptcache.com`                                      |
| Protected-resource metadata (RFC 9728) | `https://mcp.aptcache.com/.well-known/oauth-protected-resource/mcp`   |
| Free receipt verification              | `POST https://mcp.aptcache.com/verify` (unauthenticated, forever)        |

Scopes: `mcp:tools` plus `apt:exec:run` (free — run + inspect) and `apt:exec:save` (paid — `save_as` / `attest` / `attest_pointer`). OAuth with dynamic client registration: most clients connect with just the endpoint URL and authenticate on first use.

## The reflex

This server offers `exec` — a tool that runs Python deterministically and verifiably (exact arithmetic, date/time math, finance, unit conversion, comparisons, and `if/elif/else` decision rules). Treat it as a reflex:

1. Offload & ground. For ANY calculation, comparison, or rule-based decision, write Python and call `exec` instead of working it out in your head. Use `result_repr` as the factual spine of your answer and weave it into natural language; offer `canonical_python` (the exact code that ran) if the user wants to see the work; when `effects` is non-empty (entropy/clock/unique) tell the user the result is non-deterministic. Only offload logic you can state as rules — NOT open-ended judgement, and NOT convergent numerics (root-finding, IRR), which have no closed form here.
2. Recover, don't retreat. If a call is refused, read `reason`, fix the code, and retry — never silently fall back to computing it yourself.
3. Reuse & compose. If a task matches a model you saved before, call it by name with `invoke_pointer` (use `describe_pointer` to recall its parameters) — or reuse it as a building block inside new `code` with `from aptcache import <name>` then `<name>(...)` — and ask the user only for the inputs; don't re-derive from scratch.
4. Commit conservatively. Most calculations are throwaway — don't save them. Only when a model is stabilized, parameterized, and will be re-run should you OFFER to `save_as` it (and `attest` for a verifiable receipt), with a short descriptive name.
5. Shape the call. Return one dict of every derived value from a single closed-form call; express what-ifs as more scenarios in that same dict; write iterative math in closed form — no loops.

## Supported surface

Pure functional Python: operators; `len`/`abs`/`round`/`min`/`max`/`sum`; `int`/`float`/`bool`; the common `str` methods; `math.*`; `statistics.mean`; `datetime`/`date`; comprehensions, f-strings, slicing, the ternary, top-level `lambda`, and `def` with `if`/`elif`/`else` return-towers (the rule-table shape). Composition: `from aptcache import <name>` pulls a model you saved earlier into new code. It **refuses** loops, reassignment, `try`/`with`, and parameter defaults — express iteration in closed form. The boundary is honest: deterministic computation + rule-based logic only; forcing un-expressible reasoning in produces confidently-wrong determinism.

## Tools

- `exec` with `code` — run Python; returns `result`, `result_repr`, `canonical_python`, `pure`/`effects`, `hash`.
- `exec` with `invoke_pointer` + `bindings` — call a saved model by name.
- `exec` with `describe_pointer` / `check_compose` / `list_pointers` — inspect a saved model, type-check a composition, list what you saved.
- `query` — locate a saved computation in the corpus: address glob, input/output type, query-by-example, tags, or text.

## Worked examples

```python
# One closed-form call → a dict of every derived value:
{'subtotal': 1200*3, 'tax': round(1200*3*0.2, 2), 'total': round(1200*3*1.2, 2)}
# → {'subtotal': 3600, 'tax': 720.0, 'total': 4320.0}

# A decision rule saved once (save_as: "tier"), then invoked by name:
def tier(spend):
    if spend >= 1000: return 'gold'
    elif spend >= 100: return 'silver'
    else: return 'bronze'
# invoke_pointer: "tier", bindings: { spend: 250 } → 'silver'

# Reusing that saved rule as a building block in new code:
from aptcache import tier
tier(1500)
# → 'gold'
```
