Skip to main content
Glama
mcp-server-chile
by crisvd
README.md
# mcp-server-chile — A Least-Privilege MCP Server for Chilean Business Tasks

![CI](https://github.com/crisvd/mcp-server-chile/actions/workflows/ci.yml/badge.svg)
![Python](https://img.shields.io/badge/python-3.10%2B-blue)
![Dependencies](https://img.shields.io/badge/dependencies-0-green)
![MCP](https://img.shields.io/badge/MCP-2026--07--28%20%2B%202025%20compat-purple)

🇪🇸 Resumen en español: [README.es.md](README.es.md)

> An [MCP](https://modelcontextprotocol.io) server that gives AI agents **exact, auditable tools** (RUT validation, IVA maths, economic indicators, order lookup, refund *requests*) instead of letting models guess. Built from scratch on the wire protocol (no SDK, zero dependencies) so every security decision is visible, and designed around **least privilege**: read-only by default, writes only on request, and even then the agent *proposes* while a person *decides*.

## Why this project

Agents become dangerous when they get tools. This repo shows how to expose tools responsibly: validated inputs, honest annotations, scoped capabilities, rate limits, masked audit logs and no existence leaks, plus a protocol implementation that is current (spec **2026-07-28**) **and** compatible with the 2025 clients still in the wild.

## Tools

| Tool | Scope | What it does |
|------|-------|--------------|
| `validate_rut` | read | Modulo-11 check digit; normalises/format RUTs. Invalid RUT = normal result, not an error |
| `calculate_iva` | read | Net/IVA/total from a net or gross amount, exact integer arithmetic |
| `check_invoice_totals` | read | IVA = 19% of net (±1 peso) and net + exempt + IVA = total |
| `get_economic_indicator` | read | UF, dólar, euro, UTM, IPC. **Offline = synthetic sample** (`is_sample: true`); `--online` uses mindicador.cl |
| `convert_uf_to_clp` | read | UF → CLP at a date's UF value, `Decimal` half-up |
| `get_order_status` | read | Status of an order **only if it belongs to the given customer**; missing and foreign look identical |
| `request_refund` | **write** (needs `--allow-write`) | Creates a refund **request** pending human approval. `confirm=true` + idempotency key. Never moves money |

## Try it (no keys, no cost)

```bash
python examples/client_demo.py --allow-write       # spawns the server and talks to it over stdio
python -m unittest discover -s tests -t .          # 55 tests, incl. a real subprocess over stdio
```

```text
connected: modern (2026-07-28), server=mcp-server-chile
tools: ['calculate_iva', 'check_invoice_totals', ..., 'request_refund', 'validate_rut']

check_invoice_totals(100000, 19000, 120000)
  -> {"consistent": false, "expected_iva": 19000, "expected_total": 119000, "problems": ["net + exempt + IVA = 119000, but total says 120000"]}

get_order_status(20001, someone else's order)
  -> ERROR "order not found for that customer"

request_refund(...)  -> {"status": "pending_human_approval", "replayed": false, ...}
same call again      -> {"status": "pending_human_approval", "replayed": true, ...}
```

## Connect it to an AI host

```bash
pip install -e .                                   # makes `python -m mcp_chile` work from anywhere
claude mcp add chile -- python -m mcp_chile        # Claude Code (verify syntax for your version)
```

Claude Desktop / other hosts: see [`examples/claude_desktop_config.json`](examples/claude_desktop_config.json) and [docs/CONFIGURATION.md](docs/CONFIGURATION.md).

## Protocol: dual era

| | Modern (**2026-07-28**) | Legacy (2025-06-18 / 2025-11-25) |
|--|-------------------------|-----------------------------------|
| Opening | None. Every request carries `_meta` (version + capabilities) | `initialize` → `notifications/initialized` |
| Discovery | `server/discover` (required by the spec) | `initialize` result |
| Methods | `server/discover`, `tools/list`, `tools/call` | + `ping` |
| Results | include `resultType: "complete"`, list results carry `ttlMs`/`cacheScope` | classic shape |
| Version error | `-32022` with `{supported, requested}` | negotiated down in `initialize` |

Stdio rules honoured: newline-delimited JSON, **nothing but protocol on stdout** (logs → stderr), UTF-8, exit on stdin EOF, LF line endings even on Windows (tested end-to-end). Details and what I verified against the spec: [docs/PROTOCOL.md](docs/PROTOCOL.md).

## Security model (summary: [docs/SECURITY.md](docs/SECURITY.md))

| Threat | Control (each has tests) |
|--------|--------------------------|
| Excessive agency | Read-only by default; write tool absent (not merely "denied") unless `--allow-write`; it only creates a request |
| Hallucinated/unsafe arguments | Strict JSON-Schema validation (`additionalProperties: false`, patterns, ranges) before any handler runs; errors are **tool errors** with actionable text so the model self-corrects |
| Runaway agent loops / abuse | Sliding-window rate limits (all calls, and a tighter one for writes) |
| Double actions on retry | Idempotency keys; same key + different params is rejected |
| Confused deputy / data leak | Ownership check on every order; missing and foreign orders return the same error |
| Prompt injection in arguments | Free text is stored and never interpreted; nothing in the server executes it |
| SSRF via the model | Online provider builds URLs from a whitelist of codes and a strict date; no model-controlled host or path |
| Leaky errors | Crashes return a generic message; details go to stderr only |
| PII in logs | Audit JSONL masks e-mails/RUTs and reduces free text to its length |
| Mislabelled tools | Annotations are honest (`readOnlyHint`, `destructiveHint`, `idempotentHint`, `openWorldHint`) and the description of the write tool says it does *not* refund |
| Output flooding | Result size cap |

## Docs

[PRD](docs/PRD.md) · [Architecture](docs/architecture.md) · [Protocol](docs/PROTOCOL.md) · [Security & threat model](docs/SECURITY.md) · [Configuration](docs/CONFIGURATION.md) · [Enterprise Q&A](docs/enterprise-qa.md) · [Risk matrix](docs/risk-matrix.md)

## Limitations (honest list)

- **Only tools.** No resources, prompts, sampling, tasks or notifications; no HTTP transport or OAuth (stdio only, so authentication is the host/OS user's, not the server's).
- The MCP spec moves fast. Verified against 2026-07-28 on the date in [docs/PROTOCOL.md](docs/PROTOCOL.md); legacy-era details (2025-11-25 tools page) are only partially verified. Re-check before relying on it.
- Offline indicators are **synthetic**. `--online` uses a third-party free API (mindicador.cl) whose terms and format you should verify; it is tested only with a fake transport.
- Orders are a fixture; a real deployment would use the company's order API with a service credential of minimal scope.
- Rate limiting is per process, not per user; the stdio server serves exactly one host session.
- Free-text `reason` is stored as submitted; a downstream human UI must escape it.

## License

MIT

TDQS

A4.1/5.0

Scored across 6 tools

Disambiguation4/5

Each tool has a clearly distinct verb+resource target: IVA math, invoice consistency verification, UF→CLP conversion, indicator lookup, RUT validation, and order lookup. The only mild friction is that convert_uf_to_clp implicitly depends on the same UF data as get_economic_indicator, and get_order_status is an outlier from the finance/tax theme, but the descriptions make the boundaries clear enough.

Naming Consistency5/5

All six tools follow a strict verb_noun snake_case pattern (calculate_iva, check_invoice_totals, convert_uf_to_clp, get_economic_indicator, get_order_status, validate_rut). Verbs are specific and predictable, and noun objects are unambiguous.

Tool Count5/5

Six tools is well within a comfortable scope and each one performs a concrete, non-redundant operation. There are no filler or wrapper tools; every entry earns its slot.

Completeness4/5

The surface covers the core Chilean finance helpers: IVA calculation, invoice verification, UF conversion, economic indicators, and RUT validation. The notable gaps are the reverse CLP→UF conversion and any batch/multi-indicator retrieval, but agents can work around these.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues