last-mile-mcp
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@last-mile-mcp Prepare invoice for customer Acme and leave it as a draft for my approval"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
last-mile-mcp
A reference MCP server for the part of an AI deployment that actually decides whether it survives: who is calling, what they may touch, and what must never happen without a human.
It is deliberately small and deliberately opinionated. The interesting content is not the tools — it is the four constraints they are built under, each of which was paid for in production.
1. An identified actor per call actor.py
2. A named grant per tool grants.py
3. A hard gate on irreversible actions gate.py
4. Connectors separated from business connectors/ + domain/Why this exists
Most AI pilots do not fail on the model. They fail on the last mile: the model has nothing real to act on, or it is given everything at once and the security review stops it. This repository is the smallest honest example of the middle ground — a model reaching live business objects, under constraints a reviewer can read in one sitting.
Related MCP server: varco_mcp
The four constraints
1. An identified actor per call
A shared MCP server has no single user. Every call runs on behalf of someone,
and the identity lives in a ContextVar, not a module global — the server handles
concurrent requests on one event loop, and a global leaks one caller's identity
into another's tool call under load.
There is no anonymous fallback. current_actor() raises rather than
returning a default. A server that answers without knowing who asked is a server
whose audit trail is fiction.
In production, the actor is resolved from a signed assertion issued by the
identity-aware proxy in front of the server, revalidated here rather than
trusted — so a misconfigured route cannot silently become an open one. The
bundled StaticHeaderResolver is for development only and fails closed on an
unknown principal exactly like the real one.
2. A named grant per tool
One grant, declared at the tool, checked on every call:
@mcp.tool()
def customer_invoices(customer_id: str) -> list[dict[str, Any]]:
require("billing.read")
...Two rules make it work.
Fail closed. A missing grant is a refusal, never a degraded answer.
Refuse loudly. This is the one most implementations get wrong. A tool that
quietly returns [] when the caller lacks permission teaches everyone
downstream that the data does not exist — and a model reading that empty list
will confidently tell a user their customer has no invoices. The refusal has to
be legible:
Support desk service token does not hold the grant 'billing.read'. This is a permission refusal, not an empty result: the data may well exist.
A grant name that is not in the catalogue raises immediately, so a typo fails on the first call rather than silently authorising in production six weeks later.
3. A hard gate on irreversible actions
An agent may draft. Only a human sends.
Every action whose effect leaves the building stops at gate.py and becomes a
draft in the requester's own queue. The tool result says so in words, so the
model reports "I prepared it for you" rather than "I sent it".
This is a product decision, not a safety disclaimer. It is the reason non-technical staff trust a system like this enough to use it daily: nothing it does can embarrass them in front of a customer without their signature.
The line is not "writes are dangerous". open_ticket writes and executes
directly, because a ticket nobody has sent anywhere can be closed again.
prepare_invoice drafts, because an issued invoice reaches the customer and
cannot be recalled. Draw that line explicitly, per action, and write down why.
4. Connectors separated from business logic
connectors/ knows how each external system authenticates, paginates and fails.
Nothing above it does. When a vendor changes an API, the change lands in one
file instead of in every tool that touched that system.
Connectors return domain objects, never raw vendor payloads. A vendor field name that leaks upward becomes a field name in a tool schema, then in the model's vocabulary, and then it is load bearing.
domain/service.py holds the joins and the rules. Tools stay thin: a rule that
lives in a tool body is a rule the next tool will not know about.
Running it
python -m venv .venv && .venv/bin/pip install -e ".[dev]"
.venv/bin/python -m pytest # 14 tests: the constraints, as tests
.venv/bin/lastmile-mcp # stdio MCP server, 8 toolsPoint any MCP client at it. whoami is the first tool to call — when someone
reports that a tool "does not work", the first question is always which token
they are on.
Three demo identities are wired in server.py, with deliberately different
grant sets so refusals are easy to observe:
Principal | Grants |
|
|
|
|
|
|
One gotcha, written down so you don't rediscover it
server.py has no from __future__ import annotations. The server builds
each tool's schema by introspecting real annotation objects; under PEP 563 they
arrive as strings and the introspection fails on issubclass. It surfaces as an
unrelated-looking type error at import time.
A second one, if you are porting code: this targets the MCP Python SDK 2.x,
where FastMCP was renamed to MCPServer and Tool.inputSchema became
Tool.input_schema. 1.x code imports mcp.server.fastmcp and fails here.
Scope
Fixtures instead of real systems, an in-memory draft queue, and a development actor resolver. Everything that would differ in a real deployment is behind an interface, and the constraints above are the part meant to be copied.
MIT. Written by Cédric Laurent.
Available Tools
8 toolsaccount_healthA
One joined view of a customer: contract, open tickets, overdue balance.
Needs both read grants. A caller holding only one gets a refusal rather than a half-answer, because a health summary missing its billing half reads as good news.
Inputs: customer_id (required). Returns: object
customer_invoicesC
Invoices for a customer with their payment state, newest first.
Inputs: customer_id (required). Returns: result
customer_ticketsB
Service tickets for a customer, newest first.
Inputs: customer_id (required), open_only. Returns: result
find_customerB
Find customers by name or id. Returns id, name, sector, sites, contract.
Inputs: query (required). Returns: result
my_draftsC
Everything this caller has prepared and not yet confirmed.
Inputs: no named parameters. Returns: result
open_ticketB
Open a service ticket. Internal and reversible, so it executes directly.
Inputs: title (required), customer_id (required), site. Returns: object
prepare_invoiceA
Prepare an invoice. It is held as a draft and is NEVER issued by this server.
An issued invoice reaches the customer and cannot be recalled, so it is the canonical irreversible action: the tool prepares, a human issues.
Inputs: amount_eur (required), customer_id (required), description (required). Returns: object
whoamiA
The identity and grants this call runs as.
Present in every deployment. When someone reports that a tool "does not work", the first question is which token they are on, and the answer should not require reading a database.
Inputs: no named parameters. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 8 tools
Each tool serves a distinct purpose: customer lookup, ticket listing, invoice listing, combined health view, ticket creation, invoice draft creation, draft listing, and identity/grants. No two tools overlap in intent, and the descriptions clarify any potential ambiguity (e.g., account_health explicitly combines data from other tools).
Naming mixes verb-first (find_customer, open_ticket, prepare_invoice) with noun-first (customer_tickets, customer_invoices, account_health) and possessive (my_drafts, whoami). The pattern is readable but not consistent, lacking a uniform verb_noun or resource_noun structure.
8 tools is well-scoped for a customer service and billing domain. Each tool covers a core operation without unnecessary bloat, and the count feels neither thin nor overwhelming.
The surface covers customer lookup, ticket listing/creation, invoice listing/drafting, health summaries, and identity. Missing update/close actions for tickets or invoices, but these are intentionally excluded (e.g., invoice issuance is human-only), so the gaps are not fatal and agents can work within the design.
Related MCP Connectors
Authorize AI agent tool calls before they run: policy-as-code, human approval, signed receipts.
Governed AI agents for the software your company already runs. 400+ connectors, one endpoint.
Runtime permission, approval, and audit layer for AI agent tool execution.
Governed access to sensitive data, secrets and APIs for AI agents. A signed proof for each decision.
Related MCP Servers
- FlicenseNot gradedqualityCmaintenanceEnables controlled AI-agent access to enterprise-shaped tools with a deny-by-default gated write path, human approval, dry-run execution, and append-only audit logging.1-
- AlicenseNot gradedqualityDmaintenanceEnables MCP-compatible AI agents to safely act on business backends by enforcing per-agent permissions, autonomy thresholds, human approval with review-and-edit, and full audit trails.MIT
- FlicenseNot gradedqualityCmaintenanceEnables AI agents to securely call enterprise MCP tools with tenant-scoped RBAC, human approvals, audit logging, and multi-tool workflows across customer, order, document, and ticket data.-
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to call backend tools under per-agent policy, deciding which tools each agent can see, what arguments it may pass, how often it may call, and which writes wait for human approval. It also redacts secrets and PII from tool results, fences untrusted output against injection, and records every call in a hash-chained audit log.MIT