Skip to main content
Glama

detect_schema

Convert SQL CREATE TABLE statements or JSON samples into structured schemas for generating test data that matches existing database structures.

Instructions

Convert an existing database schema or JSON sample into MockHero's schema format.

Send a SQL CREATE TABLE statement and get back the structured schema ready to use with generate_test_data. Or send a sample JSON record and MockHero will infer the field types.

This is useful when you have migration files or an existing database and want to generate test data that matches your schema without manually writing the definition.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlNoSQL CREATE TABLE statement(s) to convert
sample_jsonNoExample JSON record to infer schema from

Implementation Reference

  • The handler function that implements the logic for 'detect_schema', processing either SQL or JSON input to generate a schema.
    async function handleDetectSchema(
      args: Record<string, unknown>
    ): Promise<ToolResult> {
      const { sql, sample_json } = args;
    
      if (!sql && !sample_json) {
        return err(
          "Either 'sql' (SQL CREATE TABLE statements) or 'sample_json' (JSON sample data) is required."
        );
      }
    
      if (sql && typeof sql === "string") {
        const schema = detectFromSql(sql);
        if (schema.tables.length === 0) {
          return err(
            "Could not detect any tables from the provided SQL. Make sure it contains valid CREATE TABLE statements."
          );
        }
        return ok(schema);
      }
    
      if (sample_json) {
        const schema = detectFromJson(sample_json);
        return ok(schema);
      }
    
      return err("Invalid input. Provide 'sql' as a string or 'sample_json' as an object.");
    }
  • The tool execution registration where the 'detect_schema' tool is mapped to the 'handleDetectSchema' function.
    case "detect_schema":
      return handleDetectSchema(args);

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/dinosaur24/mockhero'

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