Skip to main content
Glama

countinghouse

Keep raw data out of your agent's context. countinghouse runs the data-heavy part of a task as one local, reviewed MCP tool, and only the result reaches the model.

Agents do multi-step data work by passing everything through the model: a tool returns megabytes of logs or source, the model reads all of it, then hands it to the next tool. That is slow, it costs more as the data grows, and anything sensitive in that data (a credential in a log, a customer record) has now been sent to the model.

countinghouse is an MCP runtime where tools call other tools. A chain of steps (fetch, clean, redact, analyze) is published as a single tool with a single schema. The data in between moves between worker threads on your machine and never passes through the model; the model gets a short answer in a fixed shape.

  • The raw data stays put. A composite's output has a fixed schema, and its author decides what fits in it: the first pack's carries only short summaries and metadata, never a source file or a whole log.

  • The same steps every time. The glue is reviewed, versioned code, not a script the model writes fresh on each run. Every inner call is authenticated, schema-checked and metered like an outer one.

  • Cost that doesn't grow with the data. In our benchmark, one composite call cost about the same for 200 lines as for 3,200, while calling the tools one by one cost about 15 times as much at 3,200 lines as at 200, and about 80 times the composite.

  • A plain MCP tool. Nothing depends on a platform feature or beta, so it works in any MCP client, whichever backend that client's model runs on.

Use it

The quickest way is a ready-made pack, installed into your agent by ch-local:

npx @countinghouse/ch-local@latest install --pack ci-failure-triage

Then connect your client (see ch-local's Quick start).

The first pack answers "why did CI fail?" for GitHub Actions: it reads the failed runs and their logs on your machine and gives the agent only the lines that explain the failure, and whether it is new, flaky or recurring.

To build your own composite tools on the runtime, read on.

Related MCP server: CI Investigator MCP

Why this is a primitive, not a feature

MCP's shape is client-calls-tool, and that is the whole of it. When one tool needs another, the orchestrating model is the only thing that can join them: tool A returns to the model, the model reads the result, the model passes it to tool B. Every intermediate byte is billed, attended to, and retained.

Code execution — the model writing a script for a sandbox to run — answers part of this, and deserves a fair hearing rather than a strawman. The differences that matter are narrower than speed. Its glue is a script written fresh each run, so its guarantee is behavioral where a published tool's is structural. Its tool calls still cross process boundaries even when the model doesn't. And if tool A needs B halfway through its own execution, A must split into A_part1 and A_part2 — A's private intermediate state becomes a public interface the script has to receive and hand back. Cohesive logic that belonged inside one tool becomes three calls and glue regenerated on every run. Such a composite cannot be published as a tool at all. It can only exist as a script.

The structural part is the one worth having. Point an agent at a repository and ask it to find hardcoded credentials: the scan tool returns megabytes of source into the context window, the model reads all of it, then hands it to the secret detector. To find out whether you had leaked a credential, you sent the credential to a third party. Written as a composite tool instead, the source moves between worker threads and a few kilobytes of findings come back — and the guarantee is not that the model behaved. Open the tool's output schema: there is no field that can hold a source file. There is no shape for it to travel in.

See it

Needs Node.js 22.16 or later (CI runs the suite on 22.16, 24.15, the newest 24.x and the newest 26.x, the stdio tests on the newest 24.x, and the sandbox, file broker and single-thread tests on the newest 22.x, 24.0 and 24.14). Below 24.15 a compatibility shim routes require.resolve through the sandbox's hooks; multi-tenant hosting of third-party modules should run 24.15 or later, where Node's own hook covers it. It also needs a Redis reachable at redis://127.0.0.1:6379 (metering, rate limiting and session state; --redisUrl points elsewhere). No other external service — authentication is file-backed by default.

# no Redis running? this is enough for local evaluation
docker run -d --name countinghouse-redis -p 6379:6379 redis:7

git clone https://github.com/mchen6/countinghouse.git
cd countinghouse && npm install

npm run demo:repo-review

Working on countinghouse itself rather than trying it out? docs/development-setup.md covers running the test suite, enabling the tracked git hooks (they need one config line after cloning), and the two guards that are designed to fail on you.

That loads four modules: one composite tool that reads a repository, scans it for credentials and audits its dependencies, plus the three inner tools it calls. Point an MCP client at it:

claude mcp add --transport http countinghouse http://127.0.0.1:9527/mcp \
  --header "X-CH-Key: demo-key"

Then aim it at a repository you would not paste into a chat window, and watch what does and doesn't come back. Measured on this repo: 6.08 MB of response composed client-side versus 10.7 KB through the composite tool — 579× fewer bytes, all of the difference being source code that stayed inside the process. (This repository grows over time, so the absolute figures drift from run to run; see examples/repo-review/README.md for how to reproduce them and the reduction factor they carry.)

The demo reads examples/repo-review/auth.json, a file committed on purpose. It grants demo-key the composite tool and nothing else: the three inner tools are absent from that key's tools/list, and calling one directly is refused — while the same call through repo-review works and bills demo-key for all three hops. That is the encapsulation the composite exists to demonstrate. It is a demo credential, usable only against a server you started yourself on 127.0.0.1; replace it before this is reachable from anywhere else.

Full walkthrough, the honest comparison against code execution, and a recorded round trip from Claude Code: examples/repo-review/. For the mechanism on a toy payload, docs/composite-tools.md.

A second worked example, examples/log-triage/, shows the other shape: a composite whose metered hop count grows with its input — two hops per log file — and is capped by the caller. Start it with npm run demo:log-triage.

Installing from npm instead of cloning gets you the runtime and the bundled demo modules, without the repo's example directory:

npm install countinghouse
npx countinghouse --workerThread --bindAddr 127.0.0.1 \
  --loadModule ./node_modules/countinghouse/pre-installed-packages/echo-device-module

The first run generates auth.json with a demo API key, owner-only, and prints where it is (never the key). It grants wildcard access to every device with no expiry — replace it before any real deployment. The runtime reads auth.json only when it is yours alone (mode 0600): it holds keys in the clear. See docs/authentication.md.

Writing one

A module is a directory — package.json, api.json (names, descriptions, schema pointers), schema.json (JSON Schema 2020-12), and one handler file per action. A handler is a function of (input, ctx):

// handlers/greetService/hello.js
module.exports = async (input, ctx) => ({
  output: {text: `hello ${input.name}`}
});

input is already validated against the schema. ctx carries the authenticated caller, this device's identity, a logger, and ctx.serviceClient — which is how a module calls another module:

module.exports = async (input, ctx) => {
  // clientFor/invoke are thin promise wrappers around ctx.serviceClient and
  // client.invoke; `as` is the identity each hop is authorized with.
  const scan   = await clientFor(ctx, SCAN_DEVICE_ID,   SCAN_SERVICE);
  const detect = await clientFor(ctx, DETECT_DEVICE_ID, DETECT_SERVICE);

  const files   = await invoke(scan,   'scan',   {root: input.root}); // megabytes, in-process
  const secrets = await invoke(detect, 'detect', {files});            // never leaves the process

  return {output: {findings: secrets.findings}};                      // kilobytes, to the client
};

Each inner hop is authorized as a fixed internal identity (via as) and billed to the outer caller — the split that lets a composite expose one tool while the tools underneath it stay private. Full reference: docs/module-development.md. Migrating a 5.x module is one command: npx countinghouse-migrate-module ./my-module (4.x specs need npx countinghouse-migrate-spec first — see MIGRATION.md).

Developing on countinghouse itself: run git config core.hooksPath .githooks after cloning, since git does not clone hooks. The pre-commit hook runs lint and the golden tools/list check (~10s), so no commit can move the MCP surface without saying so. CI enforces the same thing.

What else the runtime gives you

Per-module isolation

Each module runs in its own worker_threads.Worker — independent V8 heap, message-passing boundary. Read the threat model before assuming more than that.

Multi-tenant auth

Every request carries an API key; AuthProvider decides which devices it can see and call, and tools/list is filtered per key. Backends: file (default, zero-config), sqlite, couchdb.

Optional metering

MeteringProvider records every call and every inner hop, with platform metering as the sole billing authority so composed calls cannot double-charge. Off by default — --mcpToolCallCost is 0 until you set it.

Tasks

A long-running action (longRunning) runs as a task: the MCP 2026-07-28 io.modelcontextprotocol/tasks extension (tasks/get/update/cancel) for a client that declares it, and the legacy era's tasks (tasks/get/result/list/cancel), over a job engine that predates both.

Rate limiting

Per-API-key and global calls/second caps.

Stateless transport

Streamable HTTP only. Legacy HTTP+SSE is deliberately not implemented.

Local mode

--store local runs with no Redis: metering, a module's ctx.redis data and jobs in files under --storePath and in memory, for a client machine. Over --stdio (being built) without an auth file it runs as one user: one key, made at start and written nowhere, every call recorded and none refused for balance or rate. See docs/deployment.md.

Flags and endpoints: docs/cli-and-api-reference.md. Which guarantee applies on which entry path: docs/cross-cutting-matrix.md.

Architecture

flowchart TB
    client["MCP client<br/>(Claude Code, Inspector, ...)"]

    subgraph runtime["countinghouse runtime (single Node process)"]
        gateway["MCP gateway<br/>(lib/mcp/gateway.js)<br/>JSON-RPC 2.0 over POST /mcp"]
        dm["DeviceManager<br/>(main thread)"]
        meter[("MeteringProvider<br/>recordCall / checkBalance / rateLimit")]

        subgraph w1["worker_threads.Worker"]
            m1["device module<br/>(e.g. secret-detect)"]
        end
        subgraph w2["worker_threads.Worker"]
            m2["composite module<br/>(e.g. repo-review)"]
        end

        gateway --> dm
        dm <-->|"message channel<br/>(structured postMessage)"| w1
        dm <-->|"message channel"| w2
        w2 -.->|"in-process composition:<br/>module calls another<br/>module's action directly"| w1
        dm --> meter
    end

    client -->|"tools/list, tools/call,<br/>tasks/*"| gateway

Modules call each other over the same message channel the runtime already uses to route every action call, so one tools/call fans out into several metered inner hops without intermediate data leaving the process. Those hops go worker-to-worker directly by default, skipping the main thread (--no-directPeerChannels routes them through it instead) — see docs/direct-peer-channels.md. The rationale behind this and other architecture decisions is collected in docs/design-decisions.md.

On performance, honestly. In-process hops are cheaper than crossing a process boundary — at 1MB payloads, one hop costs 3.30 ms in-process against 44.2 ms over stdio and 16.0 ms over HTTP. But the largest per-hop saving measured is 13.9 ms, so any tool whose own work takes more than ~139 ms sees even that as under 10% of the call. Per call, transport rounds to nothing. What does not round away is the CPU across a session: a hundred such hops cost 7.72 seconds of CPU in-process against 91.5 over stdio. That is capacity, not latency. (Medians of three runs, 2-vCPU VMware guest, Intel i7-6600U, Node v24.21.0, commit 3d9599d.) Tables, methodology and caveats.

On token cost, honestly. With a model as the client, one composite call cost $0.024–0.026 per run at every size measured. The same model chaining the four inner tools itself paid 5.95×, 19.77× and 81.06× that, growing with the data (medians of three runs, table "all valid runs"). In every leaf-chaining run, the synthetic personal data planted in the logs reached the model's context; in no composite run did it. Code mode with typed wrappers came close to the composite (1.47–1.77× its cost, no leaks); without output types it leaked in 6 of 9 runs. One model (claude-sonnet-5-5), one task, synthetic logs, commit 622438f. Method, results and every caveat. On 9 recently failed CI runs in public Python projects, Claude Code using the CI triage pack through ch-local was fully correct at least as often as with GitHub's MCP server, the gh CLI or Code Mode, at a fifth to a third of their token cost (results).

Follow-up: One call instead of eighteen — what a composite MCP tool costs

Status, and what isn't built

In-process composition works only between modules on the same runtime. Modules must be written to this runtime's format — though not by hand: start with --authoringTools and a coding agent can design, validate, load and call a module for you, using the four authoring tools and the skill this repo ships at .claude/skills/countinghouse-module/. npx countinghouse-validate ./my-module is the same check from a shell — see docs/module-authoring.md. An importer for servers built on the official MCP TypeScript SDK is planned and does not exist yet.

Module isolation is worker_threads plus an in-process sandbox: separate V8 heap, a per-module file namespace brokered by the main thread (since 8.0.0), and a shared OS process, network and process global. It is meant for modules from developers you have a relationship with. It is not a security boundary, and not comparable to containers, gVisor or micro-VMs. docs/security-model.md states plainly what it does and does not provide, and what would be required to go further. It is a layer on top of a container, not a replacement for one: docs/deployment.md gives the deployment posture and a reference setup. Upgrading from 7.x: docs/upgrading-to-8.md.

Origin

countinghouse is the codebase of CDIF (Common Device Interconnect Framework), a UPnP-inspired IoT and web-service integration layer first built in 2015, carried forward and refit for MCP. Two unrelated problems — describing and invoking heterogeneous devices, and describing and invoking heterogeneous agent tools — converged on nearly the same shape: a discovery document, a JSON-Schema-typed call contract, a uniform invocation endpoint. The story, and what a decade of production actually bought, is in docs/index.md. The original repo is archived at mchen6/cdif with history intact.

License

Apache-2.0.

Available Tools

6 tools
countinghouse_load_moduleA

Your own module loads only once you add it yourself: this answers with the command to run in your own terminal (ch-local add-module ). It loads nothing itself.

Inputs: name (required), path (required), version. Returns: name, loaded, version, toolNames, +1 more

countinghouse_overviewA

What countinghouse has installed here: each pack's state (ready, off or not loaded), what it does, its tools and example requests, and what is still missing, such as a credential the user adds in their own terminal. Read-only: it changes nothing. Takes no arguments.

Inputs: no named parameters. Returns: packs, store, notice, update, +3 more

countinghouse_settingsA

Read or change this countinghouse's settings within their bounds: get lists each setting, its bounds and the last 50 entries of the settings history; set changes one. It can tighten a guarding setting (a smaller output cap, a shorter timeout, a module turned off) but never loosen one: only the user does that, with the ch-local command, in their own terminal. On a runtime that serves several sessions, it can undo this session's own lowering, up to the value for all sessions. A loaded module's own settings are listed too, as module.. (64 rows a call, the modules' on/off rows first; pass nextCursor back as cursor for more): an enum, number or true/false one changes on request; text, and any the module marks, are changed only by the user, with the ch-local command, in their own terminal. Ask the user before changing one.

Inputs: action (required), name, scope, value, +1 more.

countinghouse_usage_reportA

What this countinghouse has done for you: per tool, server, scenario or module, the calls, the server calls made for them, and the bytes read from servers and returned to the model, from this process and, where a usage directory is kept, earlier ones that wrote to it. On a shared runtime, the calls of this session only; in a session's own ch-local runtime, this session's calls since that runtime started. countinghouse-usage --usageDir <the usage directory> in a terminal covers every session that writes there. Token columns are an estimate (utf8 bytes / 4).

Inputs: since, until, groupBy. Returns: days, groups, method, source, +7 more

countinghouse_validate_moduleA

Check your own module's folder without running its code: package.json, api.json, schema.json, and that each action has its handler file. Returns every problem found, each naming the stage and the way out. Its code runs only once you add the module with ch-local add-module in your own terminal.

Inputs: path (required). Returns: ok, module, problems

countinghouse_validate_planA

Check a proposed module design -- device, services, actions -- before writing any files. Reports naming problems, duplicates, missing descriptions and collisions with tools already on this runtime, plus the tool names the plan would produce.

Inputs: device (required), services (required), calls. Returns: ok, problems, toolNames

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.9/5.0

    Scored across 6 tools

    Disambiguation4/5

    Each tool targets a clearly different concern: module validation on disk, plan validation pre-write, usage metrics, installed-pack overview, settings, and load instructions. The only mild overlap is between validate_module and validate_plan, but the descriptions sharply separate them (existing folder vs proposed design).

    Naming Consistency4/5

    All tools share the countinghouse_ prefix and snake_case, which is highly consistent. Minor deviation: some names are verb_noun (validate_module, load_module) while others are bare nouns (overview, settings, usage_report), but the pattern is still predictable.

    Tool Count5/5

    Six tools is well-scoped for a runtime manager: validate, plan, load, settings, usage, overview. Each earns its place with no filler or redundant entry points.

    Completeness4/5

    The lifecycle is largely covered: design validation, file validation, load instructions, settings, usage, and inventory. Gaps are minor and mostly by design (privileged actions like add-module are terminal-only), though there is no explicit uninstall/remove or direct enable/disable operation beyond settings.

    Maintenance

    ActivityActive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers