Tutorial: a read-only MCP server so an agent can query your ERP

Step by step in TypeScript: a read-only database user, views without personal data, one validated MCP tool and how to connect it to Claude Code.

JZ Jorge Zamarrón 15 Nov 2026 4 min read
Tutorial: a read-only MCP server so an agent can query your ERP

When someone asks me how to connect an AI agent to their ERP, my first answer is: start with reading. Let the agent look up balances, orders or stock before it can change anything. This tutorial builds that with a small MCP server in TypeScript.

MCP (Model Context Protocol) is the open standard that Claude, Claude Code and a growing number of tools use to let a model call functions in an external system. You define which tools exist and which parameters they accept; the model can only use those.

The rule everything depends on

Read-only access does not belong in the prompt. It belongs in the database. If the agent connects with a user that can only run SELECT on a few views, it does not matter what anyone asks it to do: it cannot write.

The example uses PostgreSQL because the pattern is easy to read. If your ERP is SAP Business One on HANA or SQL Server, the idea is the same with its driver: a dedicated user, permissions on views and nothing else. You can also read through SAP’s Service Layer with a query-only user; what matters is that the user has no write permissions.

-- A view with only the columns the agent needs
create view v_open_invoices as
select customer, folio, issued_on, due_on, balance
from invoices
where balance > 0;

-- A user that can only read that view
create role agent_readonly login password 'change-me';
grant select on v_open_invoices to agent_readonly;

Notice the view leaves out the customer’s tax ID, phone and email. If the agent does not need them to answer, they have no reason to pass through the model.

The server

Create a project and install the official SDK, zod to validate parameters and the Postgres driver:

npm init -y
npm install @modelcontextprotocol/sdk zod pg
npm install -D typescript @types/node @types/pg

The SDK ships as an ES module, so add "type": "module" to your package.json and, in tsconfig.json, use "module": "NodeNext", "moduleResolution": "NodeNext", "rootDir": "src" and "outDir": "dist". Then the server, with a single tool, in src/server.ts:

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
import pg from "pg";

const pool = new pg.Pool({ connectionString: process.env.ERP_READONLY_URL });

const server = new McpServer({ name: "erp-readonly", version: "1.0.0" });

server.tool(
  "open_invoices",
  "Invoices with an outstanding balance for a customer, ordered by due date.",
  { customer: z.string().regex(/^[A-Z0-9-]{3,20}$/) },
  async ({ customer }) => {
    const { rows } = await pool.query(
      "select folio, issued_on, due_on, balance from v_open_invoices where customer = $1 order by due_on limit 50",
      [customer]
    );
    return { content: [{ type: "text", text: JSON.stringify(rows) }] };
  }
);

await server.connect(new StdioServerTransport());

Three details that matter more than the code:

  • The query uses a parameter ($1), never concatenated text. The model builds the value of customer and must not be able to inject SQL.
  • The customer code is checked against a regular expression before touching the database. If something odd arrives, the tool fails and the model sees the failure.
  • The limit 50 keeps a badly framed query from sending ten thousand rows to the model.

Connecting it to Claude Code

Compile with npx tsc and register the server. The connection string goes in an environment variable, not in the code:

claude mcp add erp-readonly -e ERP_READONLY_URL=postgres://agent_readonly:...@host/erp -- node dist/server.js

From there you can ask Claude to review a customer’s open invoices and you will see the tool call. It is a good way to test before connecting the same server to an agent that talks to customers.

What comes after reading

Once reading works and the team trusts the answers, the question of writing comes up: recording a promise to pay, creating an order. That is where I change the approach. Each write is a separate tool with server-side validation, and it almost always leaves the record in a pending state that a person approves. I also keep a log of who asked for what and what the tool returned.

I learned to distrust zero amounts in these integrations. In a project with SAP Business One, a document was not created when a line was worth $0.00, and the error was lost without anyone seeing it. If your tool writes, make it fail loudly.

If you want to connect your ERP and are not sure which table to start with, our SAP Business One integration page explains how we work. Which lookup would you hand an agent first at your company?

JZ

Written by

Jorge Zamarrón · Founder & CEO

Jorge Zamarrón founded Zygnus and has fifteen years of software and process consulting for companies. Jorge sits on the board of Alcis Corp, a holding of more than ten companies with combined sales above 12 billion pesos a year, and leads Innovation and Development at J. García López.

Newsletter

One email when we publish something new

No promotions. Just the articles.