Skip to main content
Glama
railsware

Coupler Analytics

by railsware

get-schema

Idempotent

Retrieve column names from a Coupler.io data flow schema by specifying the data flow ID and execution ID.

Instructions

Get data table schema from a Coupler.io data flow. Get column names from columnName properties in column definitions. Example: {"columns":[{"key":"Row Updated At.0","label":"Row Updated At","schema":{"type":"string"},"typeOptions":{},"columnName":"col_0"},{"key":"Dimension: Source.0","label":"Dimension: Source","schema":{"type":"string"},"typeOptions":{},"columnName":"col_1"}]}. Here the columns are col_0 and col_1.

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.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaYes

Implementation Reference

  • Main handler function for the get-schema tool. Validates input params, retrieves the schema file via FileManager, assigns column names (col_0, col_1, ...), and returns the schema as structured content.
    export const handler = async (params?: Record<string, unknown>): Promise<CallToolResult> => {
      const validationResult = zodSchema.safeParse(params)
    
      if (!validationResult.success) {
        const error = fromError(validationResult.error)
        logger.error(`Invalid parameters for get-schema tool: ${error.toString()}`)
    
        return textResponse({
          text: `Invalid parameters for get-schema tool. ${error.toString()}`,
          isError: true,
        })
      }
    
      const fileManager = new FileManager(validationResult.data)
    
      let schemaPath: string
    
      try {
        schemaPath = await fileManager.getFile('schema')
      } catch (e) {
        logger.error(`Failed to get dataflow schema file: ${e}`)
        return textResponse({ text: `Failed to get dataflow ${validationResult.data.dataflowId} schema file. ${e}`, isError: true })
      }
    
      const schema = JSON.parse(readFileSync(schemaPath, 'utf-8'))
      schema.columns.forEach((col: ColumnDefinition, index: number) => {
        col.columnName = `col_${index}`
      })
    
      return textResponse({ text: JSON.stringify(schema, null, 2), structuredContent: { schema } })
    }
  • Input/output Zod schemas for get-schema tool. Input requires dataflowId and executionId (non-empty, no whitespace). Output defines a schema object with columns array including key, label, columnName, schema, and optional typeOptions.
    export const zodSchema = 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.'),
    }).strict()
    
    export const inputSchema = zodToJsonSchema(zodSchema)
    
    const zodOutputSchema = z.object({
      schema: z.object({
        columns: z.array(z.object({
          key: z.string(),
          label: z.string().describe('Human readable column label.'),
          columnName: z.string().describe('The actual column name in the SQLite database.'),
          schema: z.record(z.unknown()),
          typeOptions: z.record(z.unknown()).optional().describe('Additional options for the column type.'),
        }))
      })
    })
    
    export const outputSchema = zodToJsonSchema(zodOutputSchema)
  • Registration/index file for the get-schema tool. Exports the handler, name, description, and a toolListEntry object that ties together name, description, input/output schemas, and annotations.
    import { inputSchema, outputSchema } from './schema.js'
    
    export { handler } from './handler.js'
    export const name = 'get-schema'
    export const description = 'Get data table schema from a Coupler.io data flow. Get column names from `columnName` properties in column definitions. Example: {"columns":[{"key":"Row Updated At.0","label":"Row Updated At","schema":{"type":"string"},"typeOptions":{},"columnName":"col_0"},{"key":"Dimension: Source.0","label":"Dimension: Source","schema":{"type":"string"},"typeOptions":{},"columnName":"col_1"}]}. Here the columns are `col_0` and `col_1`.'
    
    const annotations = {
      title: 'Get data schema from a Coupler.io data flow.',
      idempotentHint: true,
    }
    
    export const toolListEntry = {
      name,
      description,
      inputSchema,
      outputSchema,
      annotations,
    }
  • Server registration of get-schema tool. Imported from tools/get-schema/index.ts, added to TOOL_MAP for dispatch, and listed in ListToolsRequestSchema handler for discovery.
    import * as getSchema from '../tools/get-schema/index.js'
    import * as listDataflows from '../tools/list-dataflows/index.js'
    import * as getDataflow from '../tools/get-dataflow/index.js'
    
    const TOOL_MAP = {
      [getData.name]: getData.handler,
      [getSchema.name]: getSchema.handler,
      [listDataflows.name]: listDataflows.handler,
      [getDataflow.name]: getDataflow.handler,
    }
    
    export const server = new Server({
      name: 'Coupler.io MCP server',
      version: '0.0.5',
    }, {
      capabilities: {
        tools: {},
        logging: {}
      }
    })
    
    // Look up the tool by name in TOOL_MAP and call its handler
    server.setRequestHandler(CallToolRequestSchema, async (request) => {
      const handler = TOOL_MAP[request.params.name as keyof typeof TOOL_MAP]
      if (!handler) {
        throw new Error(`Handler for tool "${request.params.name}" not found`)
      }
    
      return await handler(request.params.arguments)
    })
    
    // List all tools
    server.setRequestHandler(
      ListToolsRequestSchema,
      async () => ({
        tools: [
          getData.toolListEntry,
          getSchema.toolListEntry,
          listDataflows.toolListEntry,
          getDataflow.toolListEntry,
        ]
      })
    )
  • FileManager helper class used by the get-schema handler to retrieve the schema file (schema.json) either from cache or by downloading via a signed URL from the Coupler.io API.
    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
      }
    }
Behavior4/5

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

Annotations set idempotentHint=true, confirming safe reuse. The description adds behavioral context by explaining how to interpret the response (columnName properties) and providing a concrete example. No contradictions with annotations.

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

Conciseness5/5

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

Three sentences, no filler. First sentence defines the action, second explains how to extract column names, third provides an illustrative example. Every sentence adds value, and the structure is front-loaded.

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?

For a tool with 2 required parameters, existing output schema, and idempotent annotation, the description adequately covers purpose and response interpretation. Lacks explicit error scenarios or prerequisites beyond parameter descriptions, but overall complete enough.

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?

Both parameters (dataflowId, executionId) have clear descriptions in the input schema, achieving 100% schema coverage. The description does not add additional meaning to these parameters, focusing instead on the output format. Baseline 3 is appropriate.

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

Purpose5/5

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

The description clearly states 'Get data table schema from a Coupler.io data flow' with a specific verb and resource. It distinguishes from siblings by focusing on schema retrieval, differentiating from get-data (data), get-dataflow (metadata), and list-dataflows (enumeration).

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

Usage Guidelines3/5

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

The description does not explicitly state when to use this tool versus alternatives. It implies usage for obtaining column names before fetching data, but lacks explicit when-to-use or when-not-to-use guidance. The example helps but does not clarify selection criteria.

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