MCP Server - SAP BW Modeling API
An MCP (Model Context Protocol) server that exposes SAP BW4/HANA modeling objects as tools via FastMCP. Allows AI assistants to explore and query your BW system's metadata: InfoAreas, InfoObjects, ADSOs, CompositeProviders, Queries, and more.
Compatibility
This server has only been tested against SAP BW/4HANA, and it relies on theBW Modeling API (the /sap/bw/modeling/ ADT-based endpoints).
It does not work on classic BW 7.5 on AnyDB (non-HANA). Testing on aBW 7.5 AnyDB system showed the /sap/bw/modeling/ endpoints are not availablethere, so the tools fail to retrieve anything. The BW Modeling API is aBW/4HANA (and BW-on-HANA modeling) capability and is not exposed on classicAnyDB installations. Use this server only against BW/4HANA.
Prerequisites
- Python 3.10+
- A SAP BW/4HANA system with the BW Modeling API enabled (
/sap/bw/modeling/).Classic BW 7.5 on AnyDB is not supported (see Compatibility). - A SAP user with appropriate authorizations for the Modeling API
Installation
Using a virtual environment is strongly recommended. It isolates thisserver's dependencies (notably fastmcp and its pinned pydantic) from yoursystem-wide Python, so a later global package upgrade can't silently break theserver. Mismatched fastmcp/pydantic versions are a common cause of theserver failing to start.
Create and activate a venv, then install the dependencies into it:
# Create the virtual environment (once)
python -m venv .venv
# Activate it
# Windows (PowerShell):
.\.venv\Scripts\Activate.ps1
# macOS/Linux:
source .venv/bin/activate
# Install dependencies into the venv
pip install -r requirements.txt
When configuring the MCP client, point command at the venv's Pythoninterpreter so the server always runs with the isolated dependencies — forexample .venv/Scripts/python.exe on Windows or .venv/bin/python onmacOS/Linux (see MCP Client Configuration).
Without a venv, install globally instead:
pip install -r requirements.txt
Configuration
The server is configured via environment variables:
| Variable | Required | Description | Default |
|---|---|---|---|
BW_BASE_URL |
Yes | Base URL of the BW system (e.g. https://bw4hana.example.com) |
— |
BW_USERNAME |
Yes | SAP username | — |
BW_PASSWORD |
Yes | SAP password | — |
BW_CLIENT |
No | SAP client number | 100 |
BW_VERIFY_SSL |
No | Verify SSL certificates (true/false) |
false |
Running the Server
Standalone (stdio transport)
python server.py
With FastMCP CLI
fastmcp run server.py:mcp
HTTP transport
fastmcp run server.py:mcp --transport http --port 8000
MCP Client Configuration
Add this to your MCP client config (e.g. .kiro/settings/mcp.json). If you setup a virtual environment (recommended), set command to the venv's Pythoninterpreter rather than a bare python, so the server runs with the isolateddependencies:
{
"mcpServers": {
"bw-modeling": {
"command": "path/to/.venv/Scripts/python.exe",
"args": ["path/to/server.py"],
"env": {
"BW_BASE_URL": "https://your-bw-system.example.com",
"BW_USERNAME": "your_user",
"BW_PASSWORD": "your_password",
"BW_CLIENT": "100"
}
}
}
}
Available Tools
| Tool | Description |
|---|---|
check_connection |
Test connectivity to the BW system |
search_bw_objects |
Search for any BW object by name/type |
list_infoareas |
List all InfoAreas (organizational folders) |
list_infoobjects |
List InfoObjects (characteristics, key figures) |
list_adsos |
List Advanced DataStore Objects |
list_composite_providers |
List CompositeProviders (HCPR) |
list_queries |
List BEx/BW Queries |
get_object_details |
Get full metadata for any BW object |
get_infoobject_details |
Get InfoObject properties, incl. navigational vs display attributes and compounding |
get_characteristic_values |
Read the actual master-data values of a characteristic (e.g. list 0CUSTOMER/0MATERIAL values), optionally restricted to an InfoProvider |
get_adso_fields |
Get field list of an ADSO |
get_open_ods_view |
Get an Open ODS View (FBPA): its source (e.g. remote S/4 table via Smart Data Access, local table, calc view, DataSource), keys, fields and source-field mapping. Also reachable via get_object_details with type FBPA |
get_hdi_object_source |
Read the design-time source of HANA calculation views and other HTA-transported HANA objects, with a parsed summary of each calculation view (data sources, nodes, joins, filters, calculated columns, outputs). repository="auto" (default) finds the store: classic HANA repository objects (BW on HANA) in CTS_HOT_OBJECT, read with Open SQL by HANA package; HDI objects (BW/4HANA) in CTS_HDI_OBJECT, by HDI namespace, read through the custom read-only ICF service /sap/bc/zhdi_dump (handler ZCL_HDI_OBJECT_HTTP) because their binary content is truncated by the SQL data preview. Without the service, HDI objects are listed but not read |
get_composite_provider_parts |
Get the source (part) providers and join conditions of a CompositeProvider; optionally the node tree (joins, projection filters, calculated fields), per-provider field assignments (source field -> CompositeProvider field) and output-field lineage |
get_infoarea_contents |
List objects in an InfoArea (flat search) |
get_infoarea_tree |
List objects under an InfoArea via the InfoProvider structure (recursive, reliable) |
get_transformation_details |
Get transformation metadata (source, target, rules) |
get_dtp_details |
Get a Data Transfer Process's source/target, settings, and (uniquely) its filter restrictions |
get_query_structure |
List a query's characteristics, key figures, and measures (restricted + calculated) |
get_query_filters |
Read a query's filters (fixed/default) and restricted key figures |
read_query_data |
Execute a query and return its result data (default view only) - see Reading Query Result Data |
read_query_data_drilldown |
Execute a query with an ad-hoc drilldown, an ad-hoc filter, and/or a mandatory-variable screen submitted automatically - see Reading Query Result Data |
get_data_flow |
Show lineage: inbound/outbound transformations and DTPs (with source/target, status, and process chains) |
search_abap_objects |
Search the ABAP repository (via ADT) for programs, classes, interfaces, function modules, CDS views, tables, packages by name (read-only) |
get_abap_source |
Read the ABAP source of a program, include, class (optionally one method, or its local includes), interface, function module, CDS view or table (read-only; e.g. a transformation's generated AMDP class) |
run_sql_query |
Run a read-only ABAP Open SQL SELECT against any table/view (master data, generated ADSO tables, DDIC) via the ADT data preview |
get_query_usage_stats |
Query usage statistics from RVCOLAPSTATAC: sessions, executions, users, active days, first/last run - filtered by InfoArea/provider/query/user and grouped by infoarea, infoprovider, query, user, day or month - see Query Usage Statistics |
get_provider_last_load |
Last (and first) load date and request count of an ADSO from RSPMREQUEST - shows whether it is still being loaded |
get_process_chain |
Read-only process chain definition from the RSPC* tables: steps in the order they run (resolved from the events each step waits for and raises), what each works on (DTP source -> target from RSBKDTP, the aDSO of an activation, the program of an ABAP step, the description of a sub-chain), predecessors and successors with the condition, error mail; expand_subchains adds each sub-chain of a meta chain |
get_process_chain_runs |
Read-only run history of a chain (RSPCLOGCHAIN, status per run) and the steps of a run (RSPCPROCESSLOG: status, start, end, duration, what each step loads); a sub-chain step's subLogId drills into that sub-chain's run |
Reading Query Result Data
Two tools execute a query and return its actual figures, not just itsdesign. They trade off reliability against capability, so tryread_query_data first and only reach for read_query_data_drilldown whenyou hit one of its limitations:
read_query_dataruns the query via the BW reporting (BICS) runtime -a single, stable API call. It returns exactly the query's saved defaultview: default variable values, default drilldown. If the query has amandatory variable, this call returns no data (just the variable list) -it cannot submit one.read_query_data_drilldownexists to cover that gap and to add anad-hoc characteristic to the drilldown that the query's default viewdoesn't show, restrict the result to specific characteristic valuesbefore execution (e.g. one customer, or a short list of fiscal periods)via itsfiltersparameter, and/or override one of the query's ownvariables viavariable_values(e.g. submit a specific date instead ofa "current date" SAP-exit default). It does so via InA (InformationAccess), the internal HTTP API behind BW/4HANA's own "Data Preview"Fiori app (/sap/bw/ina/GetResponse) - reverse-engineered from thatapp's client-side source, since SAP does not publicly document it. Itperforms a 3-call handshake (fetch metadata, submit variables at theirdefault value or the givenvariable_valuesoverride, request theresult grid) and echoes back the query's design-time filters, plus anyad-hocfilters, so the server doesn't aggregate more than the calleractually needs. Bothfiltersandvariable_valuesare equality/IN-list only (no ranges or exclusions);filterscan only target acharacteristic already part of the query's design, same as thedrilldown. Note that a characteristic can be restricted by both a queryvariable and an ad-hoc filter at once (they combine with AND) - if avariable's default is narrower than the filter you want, usevariable_valuesto change the variable itself instead offilters(seeget_query_filtersfor which characteristics are variable-driven).
Because it rides on an undocumented, unversioned protocol rather than theBW Modeling API, read_query_data_drilldown is inherently lessfuture-proof: SAP could change /sap/bw/ina/* without notice. Use it whenyou need what it uniquely offers, but don't treat it as a drop-inreplacement for read_query_data.
Query Usage Statistics
get_query_usage_stats answers "which queries are actually used, by whom,and how often" from the BW/4HANA OLAP statistics view RVCOLAPSTATAC. Itgoes through the same ADT SQL path as run_sql_query, so only objects withOLAP statistics enabled show up.
All parameters are optional:
| Parameter | Meaning | Default |
|---|---|---|
infoprovider |
INFOPROV, e.g. B091_V11 or B091* |
— |
infoarea |
INFOAREA, e.g. B091 or B091* |
— |
query |
OBJNAME, e.g. B091_V11_Q001 or B091* |
— |
user |
USERNAME |
— |
date_from / date_to |
yyyy-mm-dd, inclusive |
last 6 months up to today |
group_by |
any of infoarea, infoprovider, query, user, day, month |
infoprovider + query |
top_n |
max groups returned (0 = all) |
50 |
queries_only |
keep only OBJNAME LIKE '%_Q%' |
true |
Each group returns sessions (distinct SESSIONUID, one per queryopening), executions (distinct STEPUID, one per navigation step orrefresh), users, active_days, first_run and last_run, sorted bysessions descending. The response also echoes the effective dateRange,filters, groupBy and the generated SQL, so results can be quoted withtheir scope.
Implementation notes (ADT data-preview limitations):
- Sorting and
top_nare done in Python - the wrapper breaks onORDER BY. It also breaks onESCAPEand on long single-line SQL, so thestatement is built one clause per line, from only the parameters given. - Name filters accept letters, digits,
_and a trailing*only (*becomes%). WithoutESCAPE,_stays a LIKE single-characterwildcard, so patterns can over-match slightly. monthgrouping fetches per day and user and rolls up in Python (no SQLstring functions); a session spanning midnight is counted once per day.
get_provider_last_load(adso) reports MAX(SYST_DATE) from RSPMREQUESTfor a target (trailing * allowed) - the quickest check of whether an ADSOis still being loaded. RSBKREQUEST is empty on BW/4HANA and isn't used.
Supported Object Types
| Code | Object Type |
|---|---|
AREA |
InfoArea |
IOBJ |
InfoObject |
ADSO |
DataStore Object (advanced) |
HCPR |
CompositeProvider |
QUERY |
Query |
TRFN |
Transformation |
DTP |
Data Transfer Process |
MPRO |
MultiProvider |
ODSO |
DataStore Object (classic) |