Skip to main content
Glama
README.md
# facadec

[![CI](https://github.com/L00PLeGeNd/facadec/actions/workflows/ci.yml/badge.svg)](https://github.com/L00PLeGeNd/facadec/actions/workflows/ci.yml)
[![Playground](https://img.shields.io/badge/playground-live-0f766e)](https://l00plegend.github.io/facadec/)

**Facade Compiler for MCP** — compile a fat tool catalog into three tools an agent can actually afford to see.

`search_tools` · `describe_tool` · `call_tool`

**[Live playground](https://l00plegend.github.io/facadec/)** · [Verify in Cursor](#verify-in-cursor)

![facadec playground](assets/playground.jpg)

<video src="assets/demo.mp4" controls width="880" autoplay muted loop playsinline>
  <a href="assets/demo.mp4">Watch the continuous terminal demo (mp4)</a>
</video>

## The pitch

Modern agents keep wiring more MCP servers. Each server dumps more schemas into the prompt. Past a handful of tools the model pays for:

- token bloat before the task starts
- sibling-tool confusion (`search_issues` vs `search_code` vs `search_docs`)
- brittle selection that looks fine in demos and fails under real catalogs

`facadec` treats that as a **compiler problem**, not a prompt-engineering problem. It collects upstream tools, selects for the task, rewrites descriptions, consolidates near-duplicates, and emits a stable three-tool facade. The host only ever lists those three. Under the hood, calls still reach the original tools.

## Before / after

Example catalog: `examples/config.example.json` · tasks: `bench/tasks/example-tasks.json`

| Mode | Tools exposed | Token estimate | Hit rate |
| --- | --- | --- | --- |
| Raw | 42 | 2174 | 8/8 |
| Compiled | 3 meta-tools | 198 | 8/8 |

**11.0x** smaller tool surface on the example suite, with the same 8/8 hit rate.

```bash
npm install
npm run benchmark
```

## Architecture

```text
 upstream MCP / mocks
         │
         ▼
     collect ──► canonical catalog
         │
         ▼
 select → rewrite → consolidate → facade
         │
         ▼
 search_tools / describe_tool / call_tool
         │
         ▼
   Cursor / any MCP host
```

| Stage | Job |
| --- | --- |
| Collect | Pull tools from mocks or live MCP (`stdio` / `http` / `sse`) |
| Select | Rank by domain + action for the current query |
| Rewrite | Shorten and disambiguate descriptions |
| Consolidate | Group near-duplicates into families |
| Facade | Always expose the same three meta-tools |
| Serve | MCP stdio runtime with optional live `call_tool` forwarding |
| Benchmark | Raw vs compiled tokens and hit rate |

## Verify in Cursor

Host surface is always three tools. Prove it locally:

```bash
npm run verify:cursor
```

Expected:

```text
tools/list: call_tool, describe_tool, search_tools
search_tools: hit filesystem.read_file
describe_tool: schema ok
call_tool: mock dispatch ok
Cursor-equivalent MCP handshake: PASS
```

## Use with Cursor

Merge into `~/.cursor/mcp.json` (set `cwd` to this repo):

```json
{
  "mcpServers": {
    "facadec": {
      "command": "npx",
      "args": [
        "tsx",
        "src/cli.ts",
        "serve",
        "--config",
        "examples/config.example.json"
      ],
      "cwd": "/absolute/path/to/facadec"
    }
  }
}
```

Template: [`examples/mcp.cursor.json`](examples/mcp.cursor.json).

## Quick start

```bash
npm install
npm run benchmark
npm run serve
npm run web:dev
```

Compile one query:

```bash
npx tsx src/cli.ts compile --config examples/config.example.json --query "Find and read the repository README file."
```

Live upstream collect + call:

```bash
npm run collect:live
npm run serve:live
```

## CLI

```bash
facadec collect   --config <path> [--live]
facadec compile   --config <path> --query <text> [--limit <n>] [--live]
facadec serve     --config <path> [--query <seed>] [--demo <query>] [--jsonl] [--live]
facadec benchmark --config <path> --tasks <path> [--limit <n>] [--live]
```

- `mockTools` keep demos offline by default
- `--live` collects from real MCP servers and forwards `call_tool`
- `serve` defaults to MCP stdio
- `--demo` prints a one-shot search → describe → call walkthrough

## Not another router

Routers and lazy loaders stop at retrieval. `facadec` compiles the interface:

- rewrites descriptions
- merges duplicate families
- emits facade tools
- measures the before/after tradeoff

If your agent only has a few tiny tools, skip it. If the catalog is growing faster than the context window, this is the layer.

## Who this is for

- MCP-heavy agent builders
- framework authors shipping multi-server defaults
- local-model setups where every tool token hurts
- teams that need a publishable raw-vs-compiled report, not vibes

## Layout

```text
src/
  catalog/     collect + normalize
  compile/     select → rewrite → consolidate → facade
  runtime/     MCP server + upstream pool
  benchmark/   raw vs compiled reports
web/           live playground (GitHub Pages)
examples/      mock catalog, live echo, Cursor config
bench/tasks/   example suite
tests/
.github/       CI + Pages
```

## Status

MVP is end-to-end and public:

- collect from mocks or live MCP
- compile with clean selection
- serve three meta-tools over MCP stdio
- forward live `call_tool` to upstream servers
- playground + continuous terminal demo + CI
- publishable numbers: **42 → 3 tools, 11.0x, 8/8**

## License

MIT