Skip to main content
Glama
leonardows1

sap-b1-hana-mcp

by leonardows1

sap-b1-hana-mcp

MCP(Model Context Protocol)服务器,用于通过 SAP 官方驱动(@sap/hana-client)直接使用 SQL 查询 SAP B1 HANA。

无需安装:直接从 GitHub 仓库使用 npx 运行。只需定义环境变量。

使用方法

1. 要求

  • Node.js 20+(仅在运行代理的机器上需要;无需安装任何 MCP 相关组件)。

2. 注册到 opencode(或其他 MCP 客户端)

将以下配置块添加到你的 opencode 配置中(例如 ~/.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
    }
  }
}

注意:npx 首次运行时会下载并安装包,可能需要超过 5 秒。如果 MCP 客户端在启动时报超时,请增大该配置块中的 "timeout": 60000。

3. 环境变量

变量

是否必填

描述

示例

HANA_HOST

是

HANA 服务器主机

192.168.1.100

HANA_PORT

否(默认 30015)

HANA(租户)端口

30013

HANA_USER

是

HANA 用户

USUARIO_HANA

HANA_PASSWORD

是

密码

...

HANA_DATABASE

否

HANA 租户(MDC)

MI_TENANT

HANA_SCHEMA

否

架构(SAP B1 公司数据库)

MI_EMPRESA

HANA_READONLY

否(默认 true)

true = 仅执行只读查询;false = 允许 INSERT/UPDATE/DELETE/DDL

true

HANA_SSL

否(默认 false)

true = 加密连接(不验证证书)

false

Related MCP server: SQL Server MCP Server (Diamond Inventory)

MCP 工具

Tool

Descripción

execute_query

执行 SQL 并将行以 JSON 格式返回(columns、rows、rowCount、truncated)。

check_connection

验证连接:数据库、版本和当前架构。

list_schemas

列出实例中的架构(可选按模式过滤)。

list_tables

列出某个架构中的表(可选按模式过滤)。

get_table_schema

表的结构:列、类型、长度、小数位数、可空性。

关于 SQL 和 SAP B1 的重要说明

SAP B1 的表和列使用混合大小写并区分大小写:列名必须写在双引号中:

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

不加引号时,HANA 会转换为大写,查询将失败并提示 invalid column name。

只读模式

在 HANA_READONLY=true(默认值)的情况下,服务器会拒绝除 SELECT、WITH、EXPLAIN、SHOW 或 DESCRIBE 之外的任何语句。若要启用写入,请使用 HANA_READONLY=false——风险自负。

开发

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

dist/ 目录会被编译并纳入版本管理:npx github:... 执行的就是该目录,用户机器上无需构建。

架构

使用手动依赖注入和 SOLID 原则的分层结构:

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

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.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

TDQS

A4.3/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description takes on the full burden. It discloses that the tool verifies connectivity and returns database/version/schema, which is helpful. However, it does not state whether the operation is read-only, whether special credentials are required, or how failures are surfaced.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, focused sentence. It leads with the action and resource, then lists the return values and the diagnostic use case with no filler or redundant text.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a zero-parameter connectivity check with no output schema, this description gives sufficient context: what will happen, what will be returned, and why you'd call it. Nothing essential is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has zero parameters, so the input schema is fully described by itself. There is no parameter semantics to add; the baseline of 4 applies, and the description appropriately does not invent irrelevant parameter guidance.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb ('Verifica') and resource ('la conexión a SAP B1 HANA'), and clarifies what it returns: database, version, and current schema. This clearly differentiates it from siblings like execute_query or list_tables, which operate on queries and table listings.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It gives a clear context for use: diagnosing the configuration of environment variables. It doesn't explicitly list exclusions or alternatives, but the diagnostic purpose is enough to distinguish it from the querying and listing siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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).

ParametersJSON Schema
NameRequiredDescriptionDefault
sqlYesSentencia SQL a ejecutar (SELECT, WITH o EXPLAIN).
limitNoMáximo de filas a devolver (por defecto 100).

TDQS

A4.7/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full behavioral disclosure. It reveals the read-only mode, the crucial SAP B1 mixed-case column naming rule with a double quote example, and the exact response shape including 'columns', 'rows', 'rowCount', and 'truncated' semantics.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured, starting with purpose, then constraints, a critical usage warning, and finally the response contract. Each sentence earns its place without redundancy, making it easy to consume despite the rich content.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the simple schema, no output schema, and two intuitive parameters, this description is self-contained. It defines what the tool does, the read-only constraints, the important casing/quote behavior, and what the result contains, leaving nothing essential unspecified.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is already 100%, so the schema documents both sql and limit. The description adds extra parameter-related guidance through the SQL quoting warning and example, which helps the agent construct valid queries beyond the schema's basic description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description begins with 'Ejecuta una consulta SQL contra SAP B1 HANA y devuelve las filas en JSON', naming a specific verb, target system, and return format. This clearly differentiates the tool from metadata-only siblings like list_tables and get_table_schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly states the default read-only mode and the restricted allowed SQL statements ('SELECT/WITH/EXPLAIN'), giving an obvious usage boundary. It does not explicitly name sibling tools or when-not-to-use cases, but the read-only restriction is a clear contextual guideline.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get_table_schemaA

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

ParametersJSON Schema
NameRequiredDescriptionDefault
tableYesNombre de la tabla (ej. OITM).
schemaYesNombre del esquema (ej. MI_EMPRESA).

TDQS

A3.8/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are present, so the description carries the responsibility of indicating behavior. It communicates that the tool is read-only and returns metadata rather than data, which is the core behavioral trait. However, it does not mention edge-case behavior such as errors when the table or schema does not exist.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two short sentences, front-loads what the tool returns, and adds a practical timing guideline with no filler. Every sentence contributes to selecting the tool correctly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple metadata retrieval tool with two fully documented parameters, the description is largely complete: it names the output fields and gives a usage context. The only minor omission is the absence of a remark about what happens when the schema or table is invalid, but this is not critical for the intended use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema describes both parameters (table and schema) with examples and 100% coverage. The description adds no parameter-specific meaning beyond what the schema already provides, so the baseline of 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states a specific verb and resource: it returns the structure (columns, types, length, scale, nullability) of an SAP B1 table. This intrinsically separates it from execute_query and list_tables, though it does not explicitly name a sibling as the differentiator.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The phrase 'Útil antes de escribir consultas' gives clear context for when to invoke the tool: before forming SQL queries against a table. It does not state exclusions or explicitly discuss alternatives such as list_tables or execute_query.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

list_schemasA

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

ParametersJSON Schema
NameRequiredDescriptionDefault
patternNoPatrón parcial del nombre del esquema (ej. PRUEBAS).

TDQS

A4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description bears the responsibility. It correctly conveys that the tool lists schemas and that filtering is optional, which is adequate for a simple read-only tool, but it does not disclose return format, pagination, or failure behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

A single sentence that front-loads the action and resource within the instance, adds the meaningful 'company databases' clarification, and closes with the optional filter. No wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with one optional parameter and no output schema, the description plus the schema provide most of what an agent needs to invoke correctly. A short note on the expected return type would be slight improvement, but the intent is clear.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema already documents 'pattern' with a clear description and says schema coverage every parameter, so the description Lisa does not need to add. It only repeats the idea of an optional pattern filter without adding new semantics.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb ('Lista') and resource ('esquemas (company databases de SAP B1) de la instancia HANA'), making the tool's purpose unambiguous. The parenthetical clarification of what the schemas represent adds useful context without confusing the reader.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description clearly implies when to use the tool: to list schemas with an optional name-pattern filter. It does not explicitly name alternatives like list_tables, but the resource difference (schemas vs tables) makes the usage evident.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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.

ParametersJSON Schema
NameRequiredDescriptionDefault
schemaYesNombre del esquema (ej. MI_EMPRESA).
patternNoPatrón parcial del nombre de tabla (ej. OITM u OIT%).

TDQS

A3.8/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden of behavioral disclosure. It transparently communicates that the call is read-only ('Lista') and that the pattern supports wildcards via the 'OIT%' example. What is missing is how results are returned (a list of table names?), whether errors are thrown for nonexistent schemas, or any pagination/limit behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

A single front-loaded sentence: verb and object first, optional filter and examples second, nothing that could be removed. It is compact, readable, and the example table codes earn their place by tying the tool to a SAP B1 context.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple 2-parameter tool with full schema coverage, this is mostly complete: the description covers what the tool does and the optional filter behavior. The remaining gaps, the lack of mention of the return format and of clear guidance among the sibling list tools, are real but do not prevent an agent from calling it correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters. The description adds reinforcement with concrete SAP B1 table examples but largely repeats the pattern concept already present in the pattern property ('OITM u OIT%'), providing no additional format, validation, or usage detail.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses a specific verb ('Lista') and a concrete resource ('las tablas de un esquema de SAP B1'), with real SAP B1 table identifiers (OITM, OCRD, OINV) as examples. This clearly differentiates it from siblings like list_schemas (schemas) and get_table_schema (structure of one table), because the scope is explicitly 'tables within a schema'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The intended use is clear but implied: the agent calls this to enumerate tables of a schema, and the optional pattern filter is stated. However, there is no explicit guidance about when not to use it or which sibling to prefer, e.g., 'use list_schemas for schemas' or 'use get_table_schema for a single table'.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

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

  1. 5 tool updatesv1.0.0
    • First observedcheck_connection
    • First observedexecute_query
    • First observedget_table_schema
    • First observedlist_schemas
    • First observedlist_tables

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

ActivitySlowing
ResponsivenessNo 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
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables safe, read-only querying and schema exploration for Microsoft SQL Server databases with preconfigured Diamond Inventory support, multiple database management, and optional HTTP API.
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    Provides read-only analytics and metadata exploration for Dynamics NAV 2015 databases, enabling user details, permissions, table schemas, and autonomous SQL queries.
    -
  • F
    license
    Not graded
    quality
    C
    maintenance
    Enables read-only analysis of Soft1 ERP databases through guarded T-SQL queries, schema discovery, knowledge search, and CSV/XLSX exports.
    -