---
title: "execute_sql"
method: POST
path: "/tools/execute_sql"
tags: ["Tools"]
---

# execute_sql

`POST /tools/execute_sql`

## Request

- Base URL: `https://compabase.com/api/mcp`
- URL: `https://compabase.com/api/mcp/tools/execute_sql`
- Auth: one of:
  - HTTP bearer
  - API key in header `X-API-Key`

Run a **read-only** SQL `SELECT` (or `WITH … SELECT`) against the Compabase database.
Use this for custom joins and multi-step aggregations the other tools cannot express.
Prefer dedicated tools (`search_companies`, `get_financials`, and similar) when they
cover the question — they return smaller, more predictable payloads.
CRBR names for KRS companies: `company_crbr_*_public` (all companies; birth_year only).
Raw `company_crbr_beneficiaries` is rejected. JDG people live in `ceidg_chat` (email required).

**Example prompts:** “Write SQL that groups companies by region and sums revenue for PKD 62.”

## Request body

- object
  - `query` string, required: A read-only SQL SELECT or WITH…SELECT statement.

## Response `200`

Query rows

- object

---

[API](https://skmtc.dev/compabase/apis/compabase-mcp.md) · [All operations](https://skmtc.dev/compabase/apis/compabase-mcp/llms.txt) · [OpenAPI document](https://skmtc.dev/compabase/apis/compabase-mcp/revisions/43169ccbb0f7?raw)
