Developer ToolsFree generatorPDF, Excel, Word export

ERP MCP Server Python Skeleton (FastMCP Generator)

The quickest way to let an AI assistant look up ERP data is a small MCP server with a few narrow tools. This generator writes a Python skeleton with one read-only lookup that validates its input, hides internals in error text and returns only the fields the model needs.

Fill in

Generated code
Download:

server.py

import os
import re

import requests
from mcp.server.fastmcp import FastMCP

mcp = FastMCP("erp-readonly")

BASE_URL = "https://erp.example.com/api/v1"
ID_PATTERN = re.compile(r"^[A-Z0-9-]{4,20}$")


@mcp.tool()
def get_sales_order(order_number: str) -> str:
    """Look up one record by its identifier. Read only, never changes ERP data."""
    if not ID_PATTERN.match(order_number):
        return "Rejected: order_number must match the pattern [A-Z0-9-]{4,20}."

    token = os.environ.get("ERP_API_TOKEN")
    if not token:
        return "Server is not configured: credentials are missing."

    try:
        response = requests.get(
            BASE_URL + "/salesorders/" + order_number,
            headers={"Authorization": "Bearer " + token, "Accept": "application/json"},
            timeout=15,
        )
    except requests.RequestException:
        return "The ERP could not be reached. Try again later."

    if response.status_code == 404:
        return "No record found for that identifier."
    if response.status_code in (401, 403):
        return "The service account is not permitted to read this record."
    if response.status_code != 200:
        return "The ERP returned an error (HTTP " + str(response.status_code) + ")."

    data = response.json()
    # Return only the fields the model needs, never the whole record
    keep = ["id", "customer", "status", "total", "currency"]
    slim = {key: data.get(key) for key in keep}
    return str(slim)


if __name__ == "__main__":
    mcp.run(transport="stdio")

Setup commands

pip install "mcp[cli]" requests
export ERP_API_TOKEN=your-token
python server.py

Uses the official MCP Python SDK FastMCP helper. Package layout and the exact transport names can change between SDK releases, so check the documentation of the version you install. Replace the response field names with your ERP schema. Keep the service account read only. Add write tools only behind human approval.

Move your MCP prototype toward production

Optional: an engineer reviews your tools, roles and logging.

Optional. The tool and every export work without this. No spam.

How to use it

Name the server and the tool, set the identifier and its allowed pattern, and enter your ERP API URL and resource. Copy the code into server.py, install the SDK, set the token and run it. In a desktop MCP client, register the command in the client configuration, then ask a question that needs the lookup. Start with stdio for local testing and move to HTTP transport only when you need a shared service with authentication.

Design choices in the skeleton

The tool does one thing, with one typed argument. The regex stops injection style input before it reaches the ERP URL. Errors return short sentences rather than stack traces so the model can explain them. The response is trimmed to a short list of fields, which keeps conversations small and avoids exposing data the user did not ask about.

  • One narrow tool per business question
  • Validate every argument before calling the ERP
  • Credentials only from the environment
  • Return a small set of fields
  • Read-only service account behind the tool

Going further

Add pagination limits to list tools, log each call with the user and arguments, and put rate limiting in front of the ERP. For on-premises ERPs, run the server inside the network so data never leaves it. A write tool should create a proposal that a person approves in the ERP or a workflow, not post directly. Review the tool descriptions, since the model reads them to decide when to call.

Common mistakes

Common errors include exposing one generic query tool with free SQL, returning entire records, embedding tokens in the code, and using vague tool descriptions so the model picks the wrong tool. Another is running the server with an administrator account because it is convenient during a demo and never changing it.

Frequently Asked Questions

What is FastMCP?

FastMCP is a high-level helper in the official MCP Python SDK. You write ordinary Python functions, decorate them as tools, and it builds the schema from type hints and docstrings and handles the protocol and transport.

Should an ERP MCP server allow SQL queries?

Avoid it for a first version. Narrow tools such as get order or list open lines are easier to secure and describe. If you must offer SQL, enforce a read-only database role, a single statement check, a row limit and an allow list of views.

stdio or HTTP transport?

stdio runs the server as a local process for one user and is simplest for testing. Streamable HTTP suits a shared server but needs authentication, TLS and session handling. Choose based on who needs access and where the ERP network is.

Can the model change ERP data through this?

Not with this skeleton, which performs only GET requests. The ERP role should also be read only. If you add write tools, require a human approval step and log every call.

Netray builds and operates MCP servers over ERP data, including on-premises deployments. We can help you move a prototype to something your security team will accept.