Skip to main content

Invoice Copilot

The smallest complete agent application: an agent with its own identity reads invoices through an MCP server, and asks a person before it refunds one.

ApplicationDraft
This page is a draft. The code exists, and not all of it has been run for this page yet. The page says what was checked. The code is in server/examples today.
Works with
JavaScript / TypeScriptPythonMCP TypeScript SDK
Stack
Node.js agent, Node.js MCP server, no framework

Scenario​

Northwind Labs, a fictional company, gives its finance team an agent. The agent may read every invoice. A refund is different: it moves money, so a person must approve each one. This is the real version of the simulated demo at app.lumoauth.dev/demo/agents, and the application to read first.

People and agents​

WhoRole in the applicationIdentity in LumoAuth
Invoice CopilotReads invoices and proposes refunds.A registered agent with the capability invoices:read.
Finance leadApproves or denies refunds.A user with access to the approvals inbox.
Invoices MCP serverHolds the invoices and the two tools.A registered MCP server with the scopes mcp:read and mcp:write.

Flows​

FlowWhat happensWhat LumoAuth does
First callThe agent calls the server with no token.The server answers 401 and points at the protected resource metadata.
TokenThe agent asks for a token for this server.Issues a token whose audience is the server.
ReadThe agent calls list_invoices.The server verifies the token. The tool runs.
Refund refusedThe agent calls refund_invoice.The Ask API says no: the capability is missing.
ApprovalThe agent asks for the permission, with the invoice and the amount.Puts the request in the inbox. After approval, issues a token for this refund only.
RefundThe agent calls refund_invoice again.The server accepts the approved token. The audit log links every step.

Parts​

PartBuilt withJob
Agent@lumoauth/agent, or the Python SDKRuns the six flows and prints each request.
MCP server@lumoauth/mcp on the MCP TypeScript SDKTwo tools, and the token checks.
Seed scriptAdmin APICreates the agent and the server registration.

What the seed script creates​

  • The agent "Invoice Copilot" with invoices:read.
  • The MCP server "Invoices" with its resource URI.
  • A role for the approver.

Walkthrough​

  1. Run the seed script and copy its output into .env.
  2. Start the MCP server.
  3. Start the agent, and read the 401 and the token.
  4. Watch the refund wait.
  5. Approve it in the portal, and watch the agent continue.
  6. Open the audit log and filter by the agent.

Before you run it​

  • Check that your plan includes just-in-time permissions in the plans matrix.

Where the code is today​

mcp-server.mjs, agent.mjs and agent.py in the examples folder of the server repository run this scenario with the standard library only. The catalog version replaces the hand-written token code with the SDKs.