> ## Documentation Index
> Fetch the complete documentation index at: https://docs.emergence.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Execute Query Endpoint

> Execute a read-only SELECT SQL statement against a configured data connection and return the result rows. Typically called after `generate_sql`; pass the returned `rows` field directly into `generate_plotly_chart` to visualise the result.



## OpenAPI

````yaml /openapi/em-talk2data-v2.yaml post /talk2data/mcp/execute-query
openapi: 3.1.0
info:
  title: Talk to Data Service
  version: 3.2.0-dev1
servers: []
security: []
paths:
  /talk2data/mcp/execute-query:
    post:
      tags:
        - mcp
      summary: Execute Query Endpoint
      description: >-
        Execute a read-only SELECT SQL statement against a configured data
        connection and return the result rows. Typically called after
        `generate_sql`; pass the returned `rows` field directly into
        `generate_plotly_chart` to visualise the result.
      operationId: mcp_execute_query
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExecuteQueryRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExecuteQueryResponse'
        '422':
          description: SQL validation failed
        '501':
          description: Unsupported connection type
        '502':
          description: Database connection resolution or query execution failed
        '503':
          description: execute-query unavailable (EM_RUNTIME_ASSETS_URL not configured)
      security:
        - HTTPBearer: []
components:
  schemas:
    ExecuteQueryRequest:
      properties:
        sql:
          type: string
          minLength: 1
          title: Sql
          description: >-
            SQL query to execute (SELECT only). Identifier-case and quoting
            rules vary by warehouse and by how each schema was defined
            (Snowflake folds unquoted to UPPERCASE; Postgres folds unquoted to
            lowercase; mixed-case-quoted identifiers must be quoted on every
            reference). LLM-authored SQL frequently fails compilation for this
            reason. Prefer calling generate-sql first — it has catalog knowledge
            of the connected schema and emits SQL with correct quoting — then
            pipe its returned SQL into this endpoint verbatim.
        database:
          type: string
          minLength: 1
          title: Database
          description: Resource URI of the data connection (e.g. data:org:project:name)
        max_rows:
          type: integer
          maximum: 5000
          minimum: 1
          title: Max Rows
          description: Maximum rows to return
          default: 500
      type: object
      required:
        - sql
        - database
      title: ExecuteQueryRequest
      description: Request body for synchronous query execution.
    ExecuteQueryResponse:
      properties:
        columns:
          items:
            type: string
          type: array
          title: Columns
        rows:
          items:
            additionalProperties: true
            type: object
          type: array
          title: Rows
        row_count:
          type: integer
          title: Row Count
        truncated:
          type: boolean
          title: Truncated
        sql:
          type: string
          title: Sql
      type: object
      required:
        - columns
        - rows
        - row_count
        - truncated
        - sql
      title: ExecuteQueryResponse
      description: Synchronous query execution result.
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````