wms-mcp-tenant-guard-demo
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
wms-mcp-tenant-guard-demo
A minimal MCP server for a multi-tenant warehouse system. It lets an AI agent check stock and create warehouse tasks, and it is built so that a token for Tenant A cannot read or change anything that belongs to Tenant B.
This is the companion repo for the blog post "Building an MCP Server for a WMS: Letting AI Agents Query Stock and Create Tasks Without Leaking Tenant B's Data" (read the post).
Fake data only. 2 made-up tenants, a few made-up SKUs and locations, an in-memory store. This is a teaching example, not the code behind any production system.
The 3 rules, and where each one lives
Rule | What it means | Where to look |
1. Tenant comes from the token | The server checks the token's signature, issuer, expiry and audience (it must be issued for this server). Tenant and user are read from the verified claims. No tool has a |
|
2. Safe retries, full audit | Write tools need an |
|
3. No lethal trifecta | The server reads private data and may return untrusted free text, so it has no way to send data out: no email, webhook or URL fetch tools. Free text is off by default and comes back in a labeled field. |
|
Tool hints (readOnlyHint, destructiveHint, idempotentHint, openWorldHint) are set honestly,
but nothing depends on them. Every check is enforced in the server.
Related MCP server: InventoryApplication MCP Server
Quick start
Needs Node.js 22.18 or newer (TypeScript runs directly, no build step).
npm install
npm test # 20 tests, including Tenant A vs Tenant B
npm start # MCP server on http://localhost:3333/mcp
npm run token -- a # prints a 1-hour token for fake Tenant A (use "b" for Tenant B)npm start and npm run token create a throwaway signing key in .dev-keys/ (git-ignored)
so the demo works offline. A real deployment trusts your identity provider instead. See
"Adapting this to your system" below.
Connect any MCP client that supports Streamable HTTP and a bearer token header to
http://localhost:3333/mcp. The server speaks MCP revision 2026-07-28 and also answers
2025-era clients; the tenant checks are the same on both.
Tools
Tool | Type | Scope needed | Idempotency key | Can it... |
| read |
| no | read only the caller's tenant; notes only if |
| read |
| no | return 50 rows per page, never everything |
| write |
| yes | create a task only; it never moves stock or puts away into a dock |
| write |
| yes | count up to 25 locations; never adjusts inventory |
| read |
| no | look up a task ID only inside the caller's tenant |
Every call is limited to 60 per minute per tenant, user and tool.
What the tests prove
Each test runs a real MCP client against the real handler, in memory. The numbers match the test list in the blog post.
# | Test | Expected |
1 | Tenant A asks for a SKU only Tenant B has (both protocol eras) |
|
2 | Tenant A adds | rejected; schemas advertise |
3 | Tenant B uses a task ID created by Tenant A |
|
4 | Token issued for a different server | HTTP 401 before any MCP parsing |
5 | Expired token, no token, token without a tenant | HTTP 401 |
6 | Same idempotency key sent twice | 1 task, same result both times |
7 | Same key, different quantity | error, still 1 task |
8 | Same key used by Tenant A and Tenant B | 2 separate tasks |
9 | A note containing "IGNORE PREVIOUS INSTRUCTIONS..." | returned as labeled data; 0 outbound network calls |
Plus: scope denial is audited, every audit row has the same 10 fields and no raw arguments, a looping agent hits the rate limit, and the tool list contains nothing that can send data out.
Try breaking it. Change stockForSku in src/data/store.ts to search every tenant, then run
npm test. 4 tests fail. That is the point of having them.
Adapting this to your system
In this demo | In production |
Local key in |
|
| Whatever claim your identity provider uses; set |
In-memory | Your database, with a tenant column on every table and row-level security, so a missed filter still cannot cross tenants |
In-memory idempotency map | A table with |
Audit to stdout | An append-only table or log pipeline your support team can query |
Fixed-window rate limit in memory | A shared limiter (for example in your gateway), since the server is stateless and runs as many copies |
Environment variables: MCP_RESOURCE (this server's public URL, used as the token audience),
TOKEN_ISSUER, TENANT_CLAIM, PORT.
What this demo does not do
It is not an authorization server. It does not log users in or issue tokens.
Calls rejected by the MCP layer's own schema check (for example an unknown
tenant_idfield) are refused before our audit step, so they are not audited. Add request logging at the HTTP layer if you need those.It cannot stop the trifecta across servers. If a user connects this server and an email tool from somewhere else to the same assistant, the risk returns. Say so in your customer docs.
Truncating and labeling free text lowers prompt-injection risk. It does not remove it.
Layout
src/
config.ts limits and claim names
auth/verifier.ts token checks: signature, issuer, audience, expiry, tenant claim
auth/principal.ts the verified caller (tenant, user, client, scopes)
data/store.ts fake tenant-partitioned store
data/seed.ts 2 fake tenants, including one injection attempt in a note
guard/ idempotency, audit, rate limit, argument hashing
tools/definitions.ts the 5 tools, their schemas, scopes and hints
tools/runTool.ts the pipeline every call goes through
tools/untrusted.ts labeling and truncating free text
server/mcp.ts registers tools on a per-request MCP server
server/app.ts auth gate + MCP handler (web-standard fetch)
server/http.ts local Node HTTP server
scripts/ local-only token minting
test/ the tests listed aboveLicense
MIT. See LICENSE. Security reports: see SECURITY.md.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Connect AI to store orders, products and inventory with scoped access and human approvals.
Odoo ERP for AI agents: hosted OAuth endpoint, gated writes, one endpoint for every instance.
Verified, pay-per-use API tools for AI agents through one authenticated connection.
Zero-trust gateway for AI agents: score tool calls, verify agent cards, enforce policy, audit.
Related MCP Servers
- 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.-
- FlicenseNot gradedqualityCmaintenanceEnables AI agents to query and modify inventory data through natural language, bridging AI assistants to the inventory management system without requiring SQL knowledge or direct database access.-
- AlicenseNot gradedqualityCmaintenanceEnables an AI agent to query a warehouse management system for orders, stock, stalled orders, and audit logs, and to make narrowly scoped writes by changing order status with a required reason or appending notes, with all writes recorded in a full audit trail.MIT
- AlicenseAqualityBmaintenanceEnables AI agents to manage inventory conversationally: list and look up products, check current stock levels, record inbound and outbound movements idempotently, review movement history, and surface items below their minimum threshold. Every figure is grounded in tool calls rather than model estimation, and invalid operations return explicit error codes the agent can reason about.5MIT