Saltar a contenido

Configuration Reference

All server behaviour is controlled through environment variables in the .env file in the project root. Copy .env.example to .env as a starting point.

Variables marked Yes in the Required column have no built-in default and must be supplied. The Mode column indicates which authentication mode the variable applies to: direct, oauth, or both.

Authentication

Variable Mode Required Default Description
AUTHENTICATION_MODE both No direct direct (B1 username/password) or oauth (Keycloak/OIDC token validation)
NODE_ENV both No production Runtime environment: production (minimal error exposure) or development (verbose errors)
AUTH_ALLOW_SELF_SIGNED both No false Bypass SSL certificate verification — dev/testing only. Never enable in production

SAP Business One Connection

Variable Mode Required Default Description
SERVICE_LAYER_ROOT_URL both Yes — B1 Service Layer host only — server appends /b1s/v2/ internally (e.g. https://servicelayer.b1.example.com:50000)
B1_COMPANY_DB direct Yes — Company database name
B1_USERNAME direct Yes — B1 user name
B1_PASSWORD direct Yes — B1 user password
SLD_ROOT_URL oauth Yes — SAP System Landscape Directory URL
B1_OUTBOUND_HEADER_NAME both No — Name of an extra header sent on every Service Layer and SLD request (e.g. clx-filter-key). Set together with B1_OUTBOUND_HEADER_VALUE
B1_OUTBOUND_HEADER_VALUE both No — Secret value of that header. Lets a WAF/CDN rule recognise this server's calls, e.g. to skip Cloudflare bot challenges for a server running on cloud IPs. Ignored unless both variables are set
CF_ACCESS_CLIENT_ID both No — Client ID of a Cloudflare Access service token, sent as CF-Access-Client-Id on every Service Layer and SLD request. Needed when those hostnames sit behind Access applications (a Service Auth policy must include the token)
CF_ACCESS_CLIENT_SECRET both No — Client secret of that service token, sent as CF-Access-Client-Secret. Ignored unless both variables are set

OAuth / Token Validation

Variable Mode Required Default Description
OAUTH_BASE_URL oauth Yes — OAuth provider base URL used to derive token, introspection, and JWKS endpoints (e.g. https://keycloak.b1.example.com/auth/realms/sapb1)
OAUTH_CLIENT_ID oauth Yes — OAuth client ID registered on the provider
OAUTH_CLIENT_SECRET oauth Yes — OAuth client secret (from Keycloak Credentials tab)
OAUTH_REQUIRED_SCOPES oauth No b1_mcp:access Comma-separated OAuth scopes required on incoming bearer tokens; also advertised via OAuth metadata
OAUTH_VERIFY_SCOPES oauth No true Enable/disable OAuth scope enforcement for MCP bearer tokens
VALIDATE_AUDIENCE oauth No true Validate token aud claim against OAUTH_CLIENT_ID. Set to false only if your OAuth provider cannot issue audience-restricted tokens
TOKEN_VALIDATION_MODE oauth No introspection-with-jwt-fallback How incoming access tokens are verified: introspection (remote only, fails closed), jwt (local signature only, no revocation check), or introspection-with-jwt-fallback (remote first, local fallback on AS unavailability)

HTTPS / Transport

Variable Mode Required Default Description
PORT both No 3000 HTTP/HTTPS server port
HTTPS_ENABLED both No true true uses HTTPS (requires key + cert); false uses plain HTTP
HTTPS_KEY_PATH both No ./certs/server.key Path to PEM-encoded TLS private key file
HTTPS_CERT_PATH both No ./certs/server.crt Path to PEM-encoded TLS certificate file (may include the full chain)
HTTPS_CA_PATH both No — Optional CA bundle path for HTTPS chain
HTTPS_PASSPHRASE both No — Optional passphrase for encrypted private keys
MCP_BASE_URL oauth No localhost-derived Public base URL advertised in OAuth/MCP metadata. Leave unset for local development; set when the server is behind a reverse proxy or deployed at a public hostname (e.g. https://mcp.example.com)
TRUST_PROXY both No (unset — no proxy trusted) Express trust proxy setting for deployments behind a reverse proxy, so audit logs and the rate limiter see the real client IP. Use the number of proxy hops (e.g. 1) or the proxy address/CIDR (e.g. 10.0.0.5, loopback). true trusts any X-Forwarded-For header and lets clients spoof their IP
MCP_ALLOWED_HOSTS both No 127.0.0.1,localhost Comma-separated hostnames accepted in the HTTP Host header — DNS rebinding protection
CORS_ALLOWED_ORIGINS both No (empty — CORS disabled) Comma-separated origins allowed for cross-origin requests. Use * to allow all (not recommended for production)

Session & Rate Limiting

Variable Mode Required Default Description
SESSION_TIMEOUT_MINUTES both No 30 MCP HTTP session idle timeout in minutes. Expired sessions are cleaned up and audited
REQUEST_BODY_LIMIT both No 1mb Max request body size (e.g. 2mb, 512kb). Keep small to limit memory use and mitigate DoS risk
MCP_RATE_LIMIT_WINDOW_MINUTES both No 1 Rate limit window size for /mcp in minutes
MCP_RATE_LIMIT_MAX both No 120 Max requests allowed per client per window. Requests on an existing server-issued session are counted per session; all others (including unknown session IDs) per client IP — set TRUST_PROXY behind a reverse proxy

Human Confirmation

Variable Mode Required Default Description
MCP_HUMAN_CONFIRMATION_ENABLED both No true Require human confirmation (MCP elicitation, or b1_confirm_operation) before write operations (POST/PATCH/DELETE) and reads of personal fields. Set to false to bypass in automated pipelines
MCP_CONFIRMATION_MODE both No checkbox How a confirmation counts as approved: checkbox (user must set the confirmed field to true) or accept (no fields; pressing Accept approves — required for clients like Claude Code that show only Accept/Decline). Any other value falls back to checkbox
MCP_CONFIRMATION_CHANNEL both No auto How confirmations are asked: auto (MCP elicitation for clients in MCP_ELICITATION_CLIENTS that declare the capability, b1_confirm_operation for the rest), elicitation or tool for all clients. Any other value falls back to auto
MCP_ELICITATION_CLIENTS both No claude-code Comma-separated MCP client names (clientInfo.name, case-insensitive) known to show elicitation prompts. Other clients confirm through b1_confirm_operation
MCP_CONFIRMATION_TTL_MINUTES both No 10 Validity of a b1_confirm_operation token
MCP_ELICITATION_LANGUAGE both No es Language of the confirmation prompts: es (Spanish, SAP B1 Spanish document names, Paraguayan number format) or en (English, Service Layer entity names). Any other value falls back to es. Errors and tool output returned to the AI stay in English

Personal Data

Variable Mode Required Default Description
PERSONAL_FIELDS_SOURCE both No service Where personal-field classification comes from: service (Service Layer, FP2608+), static (JSON map in PERSONAL_FIELDS_FILE, for earlier releases), or none (no classification — disables redaction and personal-field confirmation). Invalid values fall back to service
PERSONAL_FIELDS_FILE both No ./personal-fields.json Path to the static map used when PERSONAL_FIELDS_SOURCE=static: { "TABLE": ["Column", ...] }. The server refuses to start if the file is missing or malformed. See personal-fields.example.json

E-Invoice Import

Variable Mode Required Default Description
EINVOICE_ENDPOINT_SCOPES both No b1_einvoice:import Scopes the token must carry to call POST /integrations/einvoice; always checked
EINVOICE_ENDPOINT_RATE_LIMIT_MAX both No 60 Requests per minute and client IP to POST /integrations/einvoice
EINVOICE_ENDPOINT_BODY_LIMIT both No 20mb Body limit of POST /integrations/einvoice
EINVOICE_UNATTENDED_SUPPLIER_CREATION both No false Whether POST /integrations/einvoice may create suppliers. Off, an invoice from a supplier not in B1 returns supplier_missing; anyone can email the invoices mailbox. b1_import_einvoice in chat always may, after the user's confirmation
EINVOICE_PRICE_TOLERANCE_PERCENT both No 0 Difference between the invoice's net price and the GRPO/PO price above which a note is added; differences under one currency unit (rounding of the gross price) never are. B1 keeps the base price and shows the difference as a line discount, so the user who adds the draft needs discount authorization on A/P invoices
EINVOICE_SERVICE_HISTORY_DAYS both No 90 How far back to look for the supplier's latest service A/P invoice, whose G/L account service lines use

Everything else comes from the selected company in B1, read on the first import and kept for an hour per company, so any company works without setup:

  • RUC and local currency: company details (CompanyService_GetAdminInfo). Invoices addressed to another RUC are refused.
  • Currency: the B1 currency whose documents code is the invoice's ISO code (PYG → GS).
  • Tax code per VAT rate: the active purchase tax code with that rate (SalesTaxCodes). Of several 0% codes, a draft takes the one used on most 0% lines of the supplier's last five A/P invoices of the same kind (goods or services). A supplier without earlier 0% lines gets the tourism regime code (IVA_RT) for goods and the exempt one (IVA_EXE) for services, with a note to check it.
  • Payment terms: -1 (cash) for cash invoices; for credit, the payment term with exactly the invoice's days (PaymentTermsTypes, days + 30 × months), preferring names with "crédito". The due date always comes from the invoice.
  • Barcodes: BarCode, the BarCodes table and the Items UDFs U_EAN/U_UPC where they exist.
  • New suppliers: group and series of the supplier created last, preferring suppliers identified by a RUC.

Paraguayan localization values B1 does not hold are fixed in services/b1-einvoice-settings.ts: drafts get U_CENT_COMPROBANTE 999, U_CENT_TIPO_DOC 1 and U_CENT_FVTIM 2100-12-31 (U_CENT_DECLARABLE keeps its B1 default); new suppliers get U_CENT_SITUACION CONTRIBUYENTE, U_CENT_TIPO_OPE 2 and U_CENT_TIPO_IDENT 11 (RUC).

Caching

Variable Mode Required Default Description
COMPANY_LIST_CACHE_TTL_MINUTES oauth No 5 Minutes to cache the SLD company list per access token. Increase to reduce SLD load
METADATA_CACHE_TTL_MINUTES both No 30 Minutes to cache SAP B1 OData metadata (entity list and per-entity schemas). Increase to reduce Service Layer load; decrease to pick up schema changes (UDFs, UDOs) faster

Application Logging

Variable Mode Required Default Description
APP_LOG_LEVEL both No info Log verbosity: error, warn, info, debug
APP_LOG_FILE_ENABLED both No true Write application logs to a rotating file
APP_LOG_CONSOLE_ENABLED both No false Write application logs to stdout
APP_LOG_MAX_SIZE_BYTES both No 10485760 Maximum log file size before rotation (default 10 MB)
APP_LOG_RETENTION_DAYS both No 90 Days to retain rotated application log files

Audit Logging

Variable Mode Required Default Description
AUDIT_LOG_FILE_ENABLED both No true Write audit events to a rotating file. Keep enabled in production
AUDIT_LOG_CONSOLE_ENABLED both No false Write audit events to stdout
AUDIT_LOG_MAX_SIZE_BYTES both No 10485760 Maximum audit log file size before rotation (default 10 MB)
AUDIT_LOG_RETENTION_DAYS both No 365 Days to retain rotated audit log files. Tune to meet compliance requirements

Integration Tests

These variables are only used when running npm run test:integration. They are not read by the server at runtime.

Variable Required Default Description
TEST_MCP_CLIENT_ID Yes — OAuth client ID used by integration tests. Must have Authorization Code + PKCE enabled and http://127.0.0.1:*/callback as an allowed redirect URI in Keycloak
TEST_OAUTH_SCOPES No email b1_mcp:access profile Space-separated OAuth scopes requested during integration tests
TEST_OAUTH_INTERACTIVE No true Set to true to trigger a browser-based OAuth PKCE login flow when running integration tests