Skip to main content
Glama
sap-b1-hana-mcp

sap-b1-hana-mcp

by leonardows1

sap-b1-hana-mcp

MCP (Model Context Protocol) server for querying SAP B1 HANA using direct SQL through SAP's official driver (@aps/ana-driver).

No installation required: it runs with npx directly from this GitHub repository. You only need to define environment variables.

Usage

1. Requirements

  • Node.js 20+ (only on the machine running the agent; nothing from the MCP is installed).

2. Register in opencode (or another MCP client)

Add this block to your opencode configuration (for example ~/ .config/opencode/opencode.json):

{
  "mcp": {
    "sap-b1-hana": {
      "type": "local",
      "command": ["npx", "-y", "github:leonardows1/sap-b1-hana-mcp"],
"environment": {
        "HANA_HOST": "192.168.1.100",
        "HANA_PORT": "30015",
        "HANA_USER": "USUARIO_HANA",
        "HANA_PASSWORD": "TU_CONTRASEÑA",
        "HANA_DATABASE": "MI_TENANT",
        "HANA_SCHEMA": "MI_EMPRESA",
        "HANA_READONLY": "true"
      },
      "enabled": true
    }
  }
}

Note: the first time npx runs, it downloads and installs the package and may take more than 5 seconds. If the MCP client reports a timeout at startup, increase "timeout": 60000 in the block.

3. Environment variables

Variable

Required

Description

Example

HANA_HOST

Yes

HANA server host

192.168.1.100

HANA_PORT

No (default 30015)

HANA port (tenant)

30013

HANA_USER

Yes

HANA user

USUARIO_HANA

HANA_PASSWORD

Yes

Password

...

HANA_DATABASE

No

HANA tenant (MDC)

Mi_TENANT`

HANA_SCHEMA

No

Schema (SAP B1 company database)

MI_EMPRESA

HANA_READONLY

No (default true)

true = only read‑only queries; false = allows INSERT/UPDATE/DELETE/DDL

true

HANA_SSL

No (default false)

true = encrypted connection (without certificate validation)

false

Related MCP server: soft1-mcp

MCP tools

Tool

Description

execute_query

Executes SQL and returns rows in JSON (columns, rows, rowCount, truncated).

check_connection

Checks the connection: database, version, and current schema.

list_schemas

Lists schemas on the instance (optional pattern filter).

list_tables

Lists tables of a schema (optional pattern filter).

get_table_schema

Table structure: columns, types, length, scale, nullability.

Important note about SQL and SAP B1

SAP B1 tables and columns use mixed capitalization and are case‑sensitive: column names must be written between double quotes:

SELECT "ItemCode", "ItemName", "OnHand" FROM OITM WHERE "OnHand" > 0 ORDER BY "OnHand" DESC

Without quotes, HANA converts to uppercase and the query fail with invalid column name.

Read‑only mode

With HANA_READONLY=true (default), the server will not accept any statement that is not SELECT, WITH, EXPLAIN, SHOW or DESCRIBE. To enable writes, use HANA_READONLY=false — at your own risk.

Development

npm install
npm run build      # compila TypeScript a dist/
npm test           # tests unitarios (vitest)

The dist/ folder is compiled and versioned: that is what runs when using npx github… without requiring a build on the user’s machine.

Architecture

Layers with manual dependency injection and SOLID principles:

src/
├── index.ts              Composition root: DI, host MCP (stdio)
├── configuration/        HanaOptions + validación de variables de entorno
├── domain/               Modelos: QueryResult, SchemaInfo, TableInfo, ColumnInfo, StatementKind
├── application/          Abstracciones de servicios + ISqlGuard (Strategy) + clasificador SQL
├── infrastructure/       Única capa que toca @sap/hana-client: factory de conexión,
│                         servicios de consulta/esquema, mapeo de datos (Buffer→base64, Date→ISO)
└── mcp/                  Adaptadores delgados: registro de tools MCP

Licenses

  • This project: MIT.

  • Driver @sap/hana-client: SAP Developer License Agreement (distributed through npm dependency, not versioned in this repository). See node_modules/@sap/hana-client/developer-license-3_2.txt.

Available Tools

5 tools
check_connectionA

Verifica la conexión a SAP B1 HANA y devuelve base de datos, versión y esquema actual. Útil para diagnosticar la configuración de variables de entorno.

Inputs: no named parameters.

execute_queryA

Ejecuta una consulta SQL contra SAP B1 HANA y devuelve las filas en JSON. En modo solo lectura (HANA_READONLY=true, por defecto) solo se permiten SELECT/WITH/EXPLAIN. IMPORTANTE: las tablas de SAP B1 usan nombres de columna con mayúsculas y minúsculas mezcladas; deben escribirse entre comillas dobles, ej: SELECT "ItemCode", "ItemName" FROM OITM. El resultado incluye: columns, rows, rowCount y truncated (true si hay más filas de las devueltas).

Inputs: sql (required), limit.

get_table_schemaA

Devuelve la estructura (columnas, tipos, longitud, escala, nulabilidad) de una tabla de SAP B1. Útil antes de escribir consultas.

Inputs: table (required), schema (required).

list_schemasA

Lista los esquemas (company databases de SAP B1) de la instancia HANA, con filtro opcional por patrón de nombre.

Inputs: pattern.

list_tablesA

Lista las tablas de un esquema de SAP B1 (ej. OITM, OCRD, OINV), con filtro opcional por patrón de nombre de tabla.

Inputs: schema (required), pattern.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.3/5.0

    Scored across 5 tools

    Disambiguation5/5

    Each tool addresses a distinct capability: connection readiness, schema discovery, table listing, table-structure inspection, and arbitrary read-only SQL execution. There is no meaningful overlap between query execution and schema-discovery tools.

    Naming Consistency5/5

    All tool names follow a consistent verb_noun pattern in lowercase snake_case: execute_query, check_connection, list_schemas, list_tables, get_table_schema. The naming is predictable and easy to reason about.

    Tool Count5/5

    The five tools form a compact, well-scoped set for a read-only SAP B1 HANA query and exploration server. Each tool adds a necessary capability without redundancy.

    Completeness5/5

    The set covers the full read-only workflow: environment/connection checks, schema and table enumeration, schema detail retrieval, and query execution. There are no obvious missing operations for the server's stated purpose.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI clients to query live data from SAP HANA and SQL databases through read-only SELECT queries with CSV-formatted results.
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables read-only analysis of Soft1 ERP databases through guarded T-SQL queries, schema discovery, knowledge search, and CSV/XLSX exports.
      -
    • A
      license
      A
      quality
      C
      maintenance
      Enables MCP clients to securely query databases, list tables, inspect table schemas, and test connections across Oracle, SQL Server, MySQL, PostgreSQL, and SQLite using read-only SQL tools.
      4
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Gives AI clients guarded access to SAP Business One over SAP HANA / MS SQL and the Service Layer OData API. SQL is read-only, enforced on the server; Service Layer is GET-only by default, with opt-in writes that require user approval unless a profile explicitly turns it off.
      7
      132 npm
      4
      MIT