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
| Name | Required | Description | Default |
|---|---|---|---|
| sql | No | SQL CREATE TABLE statement(s) to convert | |
| sample_json | No | Example JSON record to infer schema from |
Implementation Reference
- packages/mcp/src/tools.ts:247-274 (handler)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."); } - packages/mcp/src/tools.ts:364-365 (registration)The tool execution registration where the 'detect_schema' tool is mapped to the 'handleDetectSchema' function.
case "detect_schema": return handleDetectSchema(args);