Skip to main content
Glama
seek-your-way-out

Cloudflare D1 Database MCP Server

d1_query

Execute SQL queries on Cloudflare D1 databases using the MCP server's REST API to perform database operations through natural language commands.

Instructions

Run a SQL query against the configured Cloudflare D1 database.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYesThe SQL statement to execute.
bindingsNoOptional positional bindings for the SQL statement.

Implementation Reference

  • Core handler function in D1Client that executes the SQL query by making a POST request to the Cloudflare D1 API endpoint.
    async executeQuery(sql: string, bindings?: unknown[]): Promise<D1QueryResult> {
      const url = `${CLOUDFLARE_API_BASE}/accounts/${this.config.accountId}/d1/database/${this.config.databaseId}/raw`;
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Authorization": `Bearer ${this.config.apiToken}`,
          "Content-Type": "application/json",
        },
        body: JSON.stringify({
          sql,
          bindings,
        }),
      });
    
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`Cloudflare D1 request failed with status ${response.status}: ${text}`);
      }
    
      const data = (await response.json()) as D1QueryResult;
      return data;
    }
  • MCP tool dispatch handler in server that parses arguments and delegates to D1Client.executeQuery, then formats the result as MCP content.
    if (name === "d1_query") {
      const { sql, bindings } = args as {
        sql: string;
        bindings?: unknown[];
      };
      
      const result = await client.executeQuery(sql, bindings);
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(result, null, 2)
          }
        ]
      };
  • src/server.ts:29-50 (registration)
    Tool registration in the listTools response, including name, description, and input schema.
    {
      name: "d1_query",
      description: "Run a SQL query against the configured Cloudflare D1 database.",
      inputSchema: {
        type: "object",
        properties: {
          sql: {
            type: "string",
            description: "The SQL statement to execute."
          },
          bindings: {
            type: "array",
            description: "Optional positional bindings for the SQL statement.",
            items: {
              type: ["string", "number", "boolean", "null"]
            }
          }
        },
        required: ["sql"]
      }
    },
    {
  • Type definition for the result returned by Cloudflare D1 API queries.
    export interface D1QueryResult {
      success: boolean;
      result?: unknown;
      errors?: Array<{ code: number; message: string }>;
      messages?: Array<{ code: number; message: string }>;
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool runs SQL queries but doesn't cover critical aspects like whether it's read-only or can perform mutations, authentication requirements, rate limits, error handling, or output format. For a database query tool with zero annotation coverage, this is a significant gap.

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?

The description is a single, efficient sentence with zero waste. It's front-loaded with the core purpose and avoids unnecessary elaboration, making it easy for an agent to parse quickly.

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

Completeness2/5

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

Given the complexity of a database query tool with no annotations and no output schema, the description is incomplete. It lacks information on behavioral traits (e.g., read/write permissions, safety), output structure, or error conditions. This leaves the agent under-informed for effective tool invocation.

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%, so the schema already documents both parameters ('sql' and 'bindings') adequately. The description doesn't add any parameter-specific details beyond what the schema provides, such as SQL dialect constraints or binding usage examples. Baseline 3 is appropriate when the schema does the heavy lifting.

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 description clearly states the action ('Run a SQL query') and target resource ('configured Cloudflare D1 database'), making the purpose unambiguous. It distinguishes from the sibling tool 'd1_list_tables' by focusing on query execution rather than metadata listing. However, it doesn't explicitly contrast with the sibling, so it's not a perfect 5.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention the sibling tool 'd1_list_tables' or any other potential tools, nor does it specify use cases, prerequisites, or exclusions. This leaves the agent with minimal context for tool selection.

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/seek-your-way-out/cloudflare-sywo-mcp-server'

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