SAP Datasphere MCP Server

SAP Datasphere MCP Server

Model Context Protocol server that lets AI assistants explore and query SAP Datasphere β€” metadata discovery, catalog search, OData and SQL queries, ETL extraction, data lineage and column profiling β€” with built-in config-driven PII masking.

Category
Visit Server

README

πŸš€ SAP Datasphere MCP Server

PyPI version npm version Python 3.10+ MCP Protocol License: MIT

Model Context Protocol server that lets AI assistants explore and query SAP Datasphere β€” metadata discovery, catalog search, OData and SQL queries, ETL extraction, data lineage and column profiling β€” with built-in config-driven PII masking so sensitive fields never reach the LLM.

Version 1.4.0 Β· 42 tools advertised by default (51 with DATASPHERE_TOOL_PROFILE=full)


🀝 Relationship to the SAP Datasphere CLI

This server and the @sap/datasphere-cli split the work along one line:

Owns Because
MCP server (this repo) Reading data and metadata, catalog search, profiling Consumption and Catalog APIs
CLI Creating and changing objects, tenant administration Design-time and admin APIs

The CLI cannot read data rows β€” that is this server's reason to exist. This server does not create objects, apart from local tables (create_table), because the payload there is derived from data it has already read. Views, analytic models, flows, spaces, users and roles belong to the CLI.

Neither writes data rows. Rows arrive through a data/replication flow, a database user with a SQL client, or a CSV upload in the Data Builder UI.

Guide Content
docs/MCP_VS_CLI.md Authoritative capability split and routing rules
docs/TENANT_CONFIG.md The three config files and the two identities
docs/CLI_LINEAGE_LOOKUP.md Finding objects the Consumption API cannot see

A few tools shell out to the CLI (create_table, the *_database_user* tools, list_repository_objects). The CLI keeps its own session, separate from this server's OAuth credentials β€” check it with the datasphere_cli_status tool.


πŸš€ Quick Start

# npm
npm install -g @mariodefe/sap-datasphere-mcp && npx @mariodefe/sap-datasphere-mcp

# PyPI
pip install sap-datasphere-mcp && sap-datasphere-mcp

# From source
git clone https://github.com/MarioDeFelipe/sap-datasphere-mcp.git
cd sap-datasphere-mcp
pip install -r requirements.txt && pip install -e .
cp .env.example .env      # fill in your credentials
sap-datasphere-mcp

Full walkthrough: docs/GETTING_STARTED.md Β· OAuth setup: docs/OAUTH_SETUP.md

Configuration

DATASPHERE_BASE_URL=https://your-tenant.eu10.hcs.cloud.sap
DATASPHERE_TENANT_ID=your-tenant-id
DATASPHERE_CLIENT_ID=your-client-id
DATASPHERE_CLIENT_SECRET=your-client-secret
DATASPHERE_TOKEN_URL=https://your-tenant.authentication.eu10.hana.ondemand.com/oauth/token
USE_MOCK_DATA=false

Optional settings for the CLI-backed tools (DATASPHERE_CLI_PATH, _HOST, _SECRETS_FILE) are documented in .env.example and docs/TENANT_CONFIG.md.

Never commit .env.

Claude Desktop

{
  "mcpServers": {
    "sap-datasphere": {
      "command": "npx",
      "args": ["@mariodefe/sap-datasphere-mcp"],
      "env": {
        "DATASPHERE_BASE_URL": "https://your-tenant.eu20.hcs.cloud.sap",
        "DATASPHERE_CLIENT_ID": "your-client-id",
        "DATASPHERE_CLIENT_SECRET": "your-client-secret",
        "DATASPHERE_TOKEN_URL": "https://your-tenant.authentication.eu20.hana.ondemand.com/oauth/token"
      }
    }
  }
}

Config location β€” Windows: %APPDATA%\Claude\claude_desktop_config.json Β· macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Β· Linux: ~/.config/Claude/claude_desktop_config.json


πŸ› οΈ Tool Catalog

42 tools in the default lean profile. Set DATASPHERE_TOOL_PROFILE=full to also advertise overlapping metadata tools, and DATASPHERE_EXPOSE_DIAGNOSTICS=true for the endpoint probes β€” 51 in total. Hiding them by default improves the model's tool selection; every handler stays reachable.

Foundation (5)

test_connection Β· get_current_user Β· get_tenant_info Β· get_available_scopes Β· list_spaces

Space discovery (3)

get_space_info Β· get_table_schema Β· search_tables

Catalog and search (5)

list_catalog_assets Β· get_asset_details Β· get_asset_by_compound_key Β· get_space_assets Β· search_catalog

Catalog search runs client-side: /catalog/search returns 404 on the tenants tested, so these tools fetch assets and filter locally across name, label, businessName and description.

Data discovery and quality (2)

Tool Purpose
find_assets_by_column Which assets contain a given column β€” lineage and impact analysis across spaces
analyze_column_distribution Null rate, distinct values, percentiles, IQR outlier detection

Querying data (4)

Tool Purpose
smart_query SQL router: picks analytical vs relational, falls back to client-side aggregation when the asset cannot aggregate
execute_query SELECT with SQL→OData conversion, max 1000 rows
query_relational_entity Relational OData, up to 50,000 records per batch for ETL
query_analytical_data Analytical OData with $apply, $filter, $orderby

Supported SQL: SELECT */column lists, WHERE, LIMIT, GROUP BY, aggregations with and without grouping, ORDER BY. No JOINs β€” OData is single-entity. Names are case-sensitive.

Metadata (7)

get_relational_metadata Β· list_relational_entities Β· get_relational_entity_metadata Β· get_analytical_metadata Β· get_analytical_model Β· list_analytical_datasets Β· get_asset_variables

get_relational_entity_metadata maps OData types to SQL (Edm.String β†’ NVARCHAR(MAX), Edm.Int64 β†’ BIGINT, Edm.Decimal β†’ DECIMAL(18,2), …) for data-warehouse loading. get_asset_variables surfaces input parameters a parameterised view or analytic model expects.

Repository (3)

Tool Purpose
list_repository_objects Lists design-time objects via the CLI, so it also sees objects not exposed for consumption
get_deployed_objects Deployed objects in a space
get_object_definition Object definition (deprecated β€” prefer get_asset_details)

Database users (5) β€” CLI-backed

list_database_users Β· create_database_user Β· update_database_user Β· delete_database_user Β· reset_database_user_password

High-risk operations require consent, cached for 60 minutes.

Tasks (4)

get_task_status Β· run_task_chain Β· get_task_log Β· get_task_history

Object provisioning (1) β€” CLI-backed

create_table β€” builds a CSN definition from your column list and runs datasphere objects local-tables create. Local tables only; see the CLI split above.

Operations (4)

list_connections Β· browse_marketplace Β· datasphere_cli_status Β· get_relational_odata_service (full profile)

datasphere_cli_status reports whether the CLI is installed, which version, which host, and whether a session exists. Run it first when a CLI-backed tool fails.


πŸ” PII / Sensitive-Field Masking

A config-driven, fail-closed masking layer runs inside the response pipeline. Every data-returning tool (smart_query, query_relational_entity, query_analytical_data, get_space_assets, analyze_column_distribution) funnels results through apply_masking() before they reach the LLM. No prompt bypasses it.

Defense in depth. The authoritative access control stays upstream β€” SAP Datasphere Data Access Controls, and not granting the technical user access to PII tables. This layer is the enforced, auditable net on top.

Environment variable Values Default Purpose
DATASPHERE_PII_POLICY path to YAML or JSON (unset) Policy file. Unset = masking fully disabled.
DATASPHERE_PII_MODE enforce | audit_only | off enforce when a policy is present audit_only logs what would be masked without changing data
DATASPHERE_PII_SALT secret string (empty) Salt for deterministic hash/tokenize. Treat as a secret.

If the policy file is configured but missing or unparseable, the server raises at startup and refuses to run. It never silently serves raw data with a broken policy.

mode: enforce
default_action: redact

rules:
  # Most specific wins: asset > space > global; exact > glob
  - space: ZDCS_08
    asset: ZR_SAP_CUSTOMER
    columns:
      EMAIL:  redact       # β†’ "***"
      PHONE:  partial:4    # keep last 4 β†’ "******1234"
      TAXID:  hash         # sha256(salt:value) β€” deterministic, safe for GROUP BY
      SSN:    drop         # column removed from every row
  - space: "*"
    columns:
      "*IBAN*": tokenize   # glob on column name β†’ "TKN_<8hex>"

allowlist:
  enabled: true
  assets:
    ZDCS_08.ZR_OTC_CUST_MONTH: [CUSTOMER, MONTH, REVENUE]   # ONLY these returned

patterns:
  email: '[A-Za-z0-9._%+\-]+@[A-Za-z0-9.\-]+\.[A-Za-z]{2,}'
  iban:  '\b[A-Z]{2}\d{2}[A-Z0-9]{10,30}\b'

Precedence: allowlist (drops everything unlisted) β†’ column rules β†’ value-pattern scan on remaining strings.

Audit log β€” one structured line per call, values never logged:

[pii_masking] space=ZDCS_08 asset=ZR_SAP_CUSTOMER rows=42
              masked_fields=['EMAIL', 'PHONE', 'SSN'] mode=enforce

The response also carries masked_fields, so the client can see what was withheld. Annotated example: pii_policy.yaml.


πŸ”’ Security

Authentication β€” OAuth 2.0 client credentials, tokens refreshed 60s before expiry and encrypted in memory (Fernet). No credentials in code.

Authorization β€” four permission levels (READ, WRITE, ADMIN, SENSITIVE), interactive consent for high-risk operations, full audit logging.

Query safety β€” the SQL sanitizer is fail-closed on SELECT: INSERT/UPDATE/DELETE/DROP and SQL comments are blocked, along with 15+ injection patterns. Write paths do not exist.


🌐 Transports

stdio by default; Streamable HTTP (spec 2025-03-26) at /mcp for long-lived service deployments.

Flag Env var Default Purpose
--transport MCP_TRANSPORT stdio stdio or http
--host MCP_HTTP_HOST 127.0.0.1 Bind address
--port MCP_HTTP_PORT 8080 Bind port
--path MCP_HTTP_PATH /mcp Endpoint path
--auth-token MCP_HTTP_AUTH_TOKEN (none) Require Authorization: Bearer <token>
pip install 'sap-datasphere-mcp[http]'
sap-datasphere-mcp --transport http --port 8080

The server warns when bound to a non-loopback interface without a token. /health serves a plain JSON liveness probe.


πŸ“Š Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   AI Assistant  │◄──►│   MCP Server     │◄──►│  SAP Datasphere β”‚
β”‚ (Claude, Cursor)β”‚    β”‚  Authorization   β”‚    β”‚   (OAuth 2.0)   β”‚
β”‚                 β”‚    β”‚  PII masking     β”‚    β”‚                 β”‚
β”‚                 β”‚    β”‚  Caching         β”‚    β”‚  datasphere CLI β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
src/sap_datasphere_mcp/
β”œβ”€β”€ server.py              # MCP server and all tool handlers
β”œβ”€β”€ cli_runner.py          # Single entry point for `datasphere` CLI calls
β”œβ”€β”€ pii_masking.py         # Config-driven, fail-closed masking
β”œβ”€β”€ cache_manager.py       # TTL cache
β”œβ”€β”€ telemetry.py           # Request metrics
β”œβ”€β”€ tool_descriptions.py   # Tool metadata
β”œβ”€β”€ error_helpers.py       # Error formatting
β”œβ”€β”€ auth/
β”‚   β”œβ”€β”€ oauth_handler.py             # Token management and refresh
β”‚   β”œβ”€β”€ datasphere_auth_connector.py # Authenticated API connector
β”‚   β”œβ”€β”€ authorization.py             # Permission levels
β”‚   β”œβ”€β”€ consent_manager.py           # Consent tracking
β”‚   β”œβ”€β”€ input_validator.py           # Input validation
β”‚   β”œβ”€β”€ sql_sanitizer.py             # SELECT-only enforcement
β”‚   └── data_filter.py               # Credential redaction
└── config/settings.py     # Environment-based settings

Caching TTLs β€” spaces 1h Β· assets 30min Β· metadata 15min Β· users 5min, LRU eviction.

Response times β€” cached metadata under 100ms Β· catalog 100–500ms Β· OData queries 500–2000ms depending on volume.


πŸ§ͺ Testing

pytest                                              # full suite
pytest tests/test_cli_runner.py                     # CLI integration layer
npx @modelcontextprotocol/inspector sap-datasphere-mcp

tests/test_cli_runner.py verifies every CLI command the server hardcodes against the --help dumps in the DataphereCLI repo. Point DATASPHERE_CLI_HELP_DIR at tools/cli-help to enable it; it skips otherwise.

Known failure: tests/test_mcp_server.py uses await server.list_resources()(), an idiom the current MCP SDK no longer supports. Pre-existing, unrelated to the server itself.


πŸš€ Deployment

docker build -t sap-datasphere-mcp:latest .
docker run -d --name sap-mcp --env-file .env sap-datasphere-mcp:latest
# or
docker-compose up -d

Full guide incl. Kubernetes: docs/DEPLOYMENT.md


πŸ“š Documentation

Guide Content
Getting Started Setup walkthrough with examples
API Reference Technical API docs, Python and cURL
OAuth Setup App Integration and OAuth client
Tenant Config Config files, the two identities
MCP vs CLI Which tool owns which task
CLI Lineage Lookup Objects invisible to Consumption
Deployment Docker, Kubernetes, PyPI
Developer Guide Contributing to the codebase
Changelog Version history

πŸ™ Acknowledgments

Built with Amazon Kiro (specifications and architectural steering) and Claude Code (security and authentication, tool descriptions and error handling, caching and telemetry, repository and analytics tools, CLI integration layer).


πŸ“„ License

MIT β€” see LICENSE.

πŸ“ž Support

Issues Β· Discussions Β· SAP Datasphere docs Β· Model Context Protocol

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured