mcp-saphana
MCP server for SAP HANA enabling querying, schema exploration, and bulk data export via the hdbcli driver.
README
mcp-saphana
MCP (Model Context Protocol) server for SAP HANA. Enables Claude and other MCP clients to query, explore, and bulk-export data from SAP HANA instances using the native hdbcli driver.
Features
- Schema & table discovery — list schemas, list tables/views, search across schemas
- Table introspection — column definitions, data types, nullability
- Data sampling — fetch sample rows for profiling
- Table statistics — row count, disk size, memory footprint (with privilege-aware fallback)
- Column profiling — min/max/null count/distinct count for any column
- Large volume export — chunked pagination via
LIMIT/OFFSETfor multi-million row exports - Dual output formats —
markdown(human-readable) andjson(machine-readable) - Privilege-safe — gracefully falls back when
MONITORINGprivilege is absent
Architecture
server.py # FastMCP server (single file)
├── Lifespan connection # One persistent hdbcli connection per server lifetime
├── 9 MCP tools # Schema/table/column/query/export operations
└── Shared helpers # _get_conn, _cursor_to_rows, _handle_hana_error, _safe_json
Connection strategy
- Uses SAP HANA's native
hdbclidriver (not JDBC/ODBC) - Single persistent connection via FastMCP lifespan context
- Supports single-container, multi-tenant (system DB), and SAP HANA Cloud
- TLS/SSL configurable via env vars
Large volume strategy
saphana_chunked_export wraps the user's SQL in a subquery with LIMIT/OFFSET and returns one chunk at a time. The caller increments chunk_index until has_more is false.
chunk 0: SELECT * FROM (user_sql) AS __q__ LIMIT 1000 OFFSET 0
chunk 1: SELECT * FROM (user_sql) AS __q__ LIMIT 1000 OFFSET 1000
...
Setup
1. Install dependencies
pip install -e .
# or manually:
pip install mcp hdbcli pydantic python-dotenv
2. Configure credentials
cp .env.example .env
# Edit .env with your HANA connection details
HANA_HOST=your-hana-host.example.com
HANA_PORT=39015
HANA_USER=your_username
HANA_PASSWORD=your_password
# Optional — for HANA Cloud / multi-tenant:
HANA_DATABASE=
HANA_ENCRYPT=false
HANA_SSL_VALIDATE_CERTIFICATE=true
Port reference:
| Scenario | Port |
|---|---|
| On-premise, single container | 39015 |
| On-premise, multi-tenant (System DB) | 30013 |
| SAP HANA Cloud | 443 (with HANA_ENCRYPT=true) |
3. Run
python server.py
Tools
| Tool | Description |
|---|---|
saphana_execute_query |
Run any SELECT; auto-applies LIMIT via safe subquery wrap |
saphana_list_schemas |
List all accessible schemas |
saphana_list_tables |
List tables/views in a schema; optional type/name filter |
saphana_describe_table |
Column names, types, nullability, defaults |
saphana_get_table_sample |
Sample N rows from a table |
saphana_get_table_stats |
Row count + disk/memory size (falls back to COUNT(*) without MONITORING) |
saphana_chunked_export |
Paginated bulk export for large result sets |
saphana_search_tables |
Search tables by partial name across all schemas |
saphana_get_column_stats |
Min/max/null count/distinct for a single column |
Claude Desktop / MCP Client Configuration
Add to your MCP client config (e.g., ~/.claude/claude_desktop_config.json):
{
"mcpServers": {
"saphana": {
"command": "python",
"args": ["/path/to/mcp_saphana/server.py"],
"env": {
"HANA_HOST": "your-host",
"HANA_PORT": "39015",
"HANA_USER": "your_user",
"HANA_PASSWORD": "your_password"
}
}
}
}
Or use a .env file and omit the env block (the server loads .env automatically).
Evaluations
evaluation.xml contains 10 read-only questions targeting stable SAP HANA system catalog objects. Run them with the MCP evaluation harness:
pip install anthropic
export ANTHROPIC_API_KEY=your_key
python scripts/evaluation.py \
-t stdio \
-c python \
-a server.py \
-e HANA_HOST=your-host \
-e HANA_USER=your_user \
-e HANA_PASSWORD=your_password \
evaluation.xml
Note: Question 8 in
evaluation.xmlhas a placeholder answer (FILL_IN_FROM_YOUR_INSTANCE). Fill it in by running:SELECT COUNT(*) FROM SYS.TABLES WHERE SCHEMA_NAME = 'SYS'
Known Limitations / Future Work
saphana_chunked_exportusesOFFSET-based pagination — performance degrades at very high offsets on large tables. For extreme volumes, consider SAP HANA's nativeEXPORTstatement or partition-key-based pagination.- No write tools (
INSERT/UPDATE/DELETE) — read-only by design. Add asaphana_execute_dmltool with explicit destructive annotations if needed. - No connection pooling — single persistent connection per server instance. For high-concurrency deployments, switch transport to
streamable_httpand manage a pool in the lifespan context. - Evaluation question answers tied to standard HANA 2.0 SPS06+ catalog structure. Verify on your specific version.
Project Status
| Area | Status |
|---|---|
| Core server | ✅ Complete |
| All 9 tools | ✅ Complete |
| Privilege fallbacks | ✅ Complete |
.env auto-load |
✅ Complete |
| Large volume export | ✅ Complete |
| Evaluation file | ✅ Complete (Q8 needs instance-specific answer) |
| Write tools (DML) | ❌ Not implemented |
| Connection pooling | ❌ Not implemented |
| Streaming HTTP transport | ❌ Not implemented (stdio only) |
| Tests | ❌ Not implemented |
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。