Skip to main content
Glama
railsware

Coupler Analytics

by railsware

get-data

Idempotent

Run SQL queries on a Coupler.io data flow execution to retrieve specific data.

Instructions

Get data from a Coupler.io data flow run. Make sure to first query a sample of 5 rows from data table, e.g. SELECT * from data LIMIT 5, and then run the get-schema tool, to better understand the structure. The get-schema tool will return the JSON-encoded schema of the data table. When visualizing the data, do not try to read any files or fetch any URLs, just generate a static page and use the data you get from the tools.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataflowIdYesThe ID of the data flow with a successful run
executionIdYesThe ID of the last successful run (execution) of the data flow.
queryYesThe SQL query to run on the data flow sqlite file.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataYesThe data returned from the query.

Implementation Reference

  • The main handler function for the 'get-data' tool. It validates input params with Zod schema, downloads/gets the sqlite file via FileManager, executes the user-provided SQL query on it using node:sqlite, and returns the result as JSON.
    import { DatabaseSync as Database } from 'node:sqlite'
    import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js'
    import { fromError } from 'zod-validation-error'
    
    import { textResponse } from '../../util/tool-response.js'
    import { FileManager } from '../shared/file-manager.js'
    import { logger } from '../../logger/index.js'
    
    import { zodInputSchema } from './schema.js'
    
    export const handler = async (params?: Record<string, unknown>): Promise<CallToolResult> => {
      const validationResult = zodInputSchema.safeParse(params)
    
      if (!validationResult.success) {
        const error = fromError(validationResult.error)
        logger.error(`Invalid parameters for get-data tool: ${error.toString()}`)
    
        return textResponse({
          text: `Invalid parameters for get-data tool. ${error.toString()}`,
          isError: true,
        })
      }
    
      const fileManager = new FileManager(validationResult.data)
    
      let sqlitePath: string
      try {
        sqlitePath = await fileManager.getFile('sqlite')
      } catch (e) {
        return textResponse({ text: `Failed to get data flow ${validationResult.data.dataflowId} sqlite file. ${e}`, isError: true })
      }
    
      const db = new Database(sqlitePath, { readOnly: true })
      let statement, queryResult
      try {
        statement = db.prepare(validationResult.data.query)
        queryResult = statement.all()
      } catch (e) {
        return textResponse({ text: `Failed to execute query: ${e}`, isError: true })
      } finally {
        db.close()
      }
    
      return textResponse({
        text: JSON.stringify(queryResult, null, 2),
        structuredContent: { data: queryResult }
      })
    }
  • Defines the Zod input schema (dataflowId, executionId, query) and output schema for the get-data tool. Input enforces query must start with SELECT. Output expects an array of records.
    import { z } from 'zod'
    import { zodToJsonSchema } from 'zod-to-json-schema'
    
    export const zodInputSchema = z.object({
      dataflowId: z.string()
        .min(1, 'dataflowId is required')
        .regex(/^\S+$/, 'dataflowId must not contain whitespace')
        .describe('The ID of the data flow with a successful run'),
      executionId: z.string()
        .min(1, 'executionId is required')
        .regex(/^\S+$/, 'executionId must be a non-empty string')
        .describe('The ID of the last successful run (execution) of the data flow.'),
      query: z.string()
        .min(1, 'query is required')
        .regex(/^SELECT.*?/, 'must start with "SELECT"')
        .describe('The SQL query to run on the data flow sqlite file.'),
    }).strict()
    
    export const inputSchema = zodToJsonSchema(zodInputSchema)
    
    const zodOutputSchema = z.object({
      data: z.array(
        z.record(z.unknown())
      ).describe('The data returned from the query.'),
    })
    
    export const outputSchema = zodToJsonSchema(zodOutputSchema)
  • Exports the tool name ('get-data'), description, input/output schemas, and re-exports the handler. This is the tool registration entry point.
    import { inputSchema, outputSchema } from './schema.js'
    
    export { handler } from './handler.js'
    
    export const name = 'get-data'
    export const description = 'Get data from a Coupler.io data flow run. Make sure to first query a sample of 5 rows from `data` table, e.g. `SELECT * from data LIMIT 5`, and then run the `get-schema` tool, to better understand the structure. The `get-schema` tool will return the JSON-encoded schema of the `data` table. When visualizing the data, do not try to read any files or fetch any URLs, just generate a static page and use the data you get from the tools.'
    
    const annotations = {
      title: 'Get and query data from a Coupler.io data flow.',
      idempotentHint: true,
    }
    
    export const toolListEntry = {
      name,
      description,
      inputSchema,
      outputSchema,
      annotations,
    }
  • Imports the get-data tool module into the server. Also line 11 maps getData.name ('get-data') to getData.handler in TOOL_MAP, and line 42 adds getData.toolListEntry to the tool listing.
    import * as getData from '../tools/get-data/index.js'
  • FileManager helper class used by the handler to download and cache the sqlite file for a dataflow execution before querying it.
    export class FileManager {
      readonly dataflowId: string
      readonly executionId: string
      readonly coupler: CouplerioClient
    
      constructor({
        dataflowId,
        executionId,
        Client = CouplerioClient
      }: {
        dataflowId: string,
        executionId: string,
        Client?: typeof CouplerioClient
      }) {
        this.dataflowId = dataflowId
        this.executionId = executionId
        this.coupler = new Client({ auth: COUPLER_ACCESS_TOKEN })
      }
    
      initStorage() {
        mkdirSync(path.join(DOWNLOAD_DIR, this.dataflowId, this.executionId), { recursive: true })
      }
    
      /**
       *
       * @throws {Error} If the file does not exist yet and can't be downloaded
       */
      async getFile(fileType: keyof typeof DataflowFile): Promise<string> {
        const filePath = this.buildFilePath(fileType)
    
        if (existsSync(filePath)) {
          return filePath
        }
    
        const fileUrl = await this.getFileUrl(fileType)
    
        return await this.downloadFile(fileUrl, fileType)
      }
    
      /**
       *
       * @throws {Error} If the file can't be downloaded or written
       */
      async downloadFile(url: string, fileType: keyof typeof DataflowFile): Promise<string> {
        await this.initStorage()
        const fileResponse = await fetch(url)
        const filePath = this.buildFilePath(fileType)
    
        if (!fileResponse.ok) {
          throw new Error(`Failed to download file. Response status: ${fileResponse.status}`)
        }
    
        const data = Buffer.from(await fileResponse.arrayBuffer())
    
        writeFileSync(filePath, data)
    
        return filePath
      }
    
      buildFilePath(fileType: keyof typeof DataflowFile): string {
        const fileName = fileType === 'sqlite' ? DataflowFile.sqlite.name : DataflowFile.schema.name
    
        return path.join(DOWNLOAD_DIR, this.dataflowId, this.executionId, fileName)
      }
    
      /**
       *
       * @throws {Error} If the request fails
       */
      async getFileUrl(fileType: keyof typeof DataflowFile): Promise<string> {
        const query = new URLSearchParams({
          execution_id: this.executionId,
        })
    
        const response = await this.coupler.request(
          `/dataflows/{dataflowId}/signed_url?${query}`,
          {
            expand: { dataflowId: this.dataflowId },
            request: {
              method: 'POST',
              body: JSON.stringify({
                file: fileType
              })
            },
          }
        )
    
        if (!response.ok) {
          throw new Error(`Failed to get ${fileType} file signed URL for dataflow ID ${this.dataflowId}. Response status: ${response.status}`)
        }
    
        const { signed_url: signedUrl } = await response.json() as SignedUrlDto
    
        return signedUrl
      }
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The annotations include idempotentHint: true, which already indicates that the tool is safe to repeat. The description adds no behavioral details beyond that, such as side effects, authentication needs, or rate limits. It does not contradict the annotations, but it also does not provide extra disclosure beyond the purpose (getting data). Given the annotations cover the main behavioral trait, a score of 3 is appropriate.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the main purpose in the first sentence. It includes necessary workflow instructions but could be more concise by separating usage guidelines from the core purpose. The length is reasonable and does not contain fluff, though the sample query and get-schema instructions could be part of a separate section.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool has an output schema (per context signals), so the description does not need to explain return values. The description gives enough context to use the tool in combination with the sibling tools (get-schema, list-dataflows). It covers the prerequisite steps and important caveats (no file/URL fetching). Overall, combined with the structured information, the description is sufficiently complete for an agent to use the tool effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with each parameter (dataflowId, executionId, query) having a clear description in the input schema. The tool description does not add any semantic information beyond what the schema already provides. The example query in the description ('SELECT * from data LIMIT 5') is a usage hint, not parameter semantics. Therefore, no added value beyond the schema baseline.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The tool name 'get-data' and title 'Get and query data from a Coupler.io data flow' clearly indicate that the tool retrieves data. The description starts with 'Get data from a Coupler.io data flow run', which aligns with the purpose. However, it does not explicitly distinguish itself from sibling tools like get-schema or list-dataflows, though the name and context imply the distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit workflow guidance: first query a sample of 5 rows using a SELECT statement, then run get-schema to understand the structure. It also instructs on visualization behavior ('do not try to read any files or fetch any URLs'). While it gives clear context on when to use this tool, it does not mention when not to use it or explicitly name alternatives, though get-schema is referenced as a prerequisite.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/railsware/coupler-io-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server