Describe a database function. Define how it should be tested. Codoken's peer-to-peer network generates and verifies the SQL in a real sandboxed database process.
Rather than prompting for an entire schema migration or ORM layer, you isolate each piece of database logic into an atom — a pure function or view with a clear contract. The network generates it, a real database runs your tests, and you get back SQL that is provably correct before it touches your schema.
Extract one pure function or view from your design — a discount calculation, an aggregation, a ranking window, a data transform. No application logic, no ORM dependencies.
The test harness creates the minimal schema and inserts fixture rows. Then SELECT assertions check exact outputs using got, expected, and ok columns.
A distributed worker generates the SQL. Independent validators run it in isolated database processes. You receive a function that passed real execution — not just a plausible snippet.
Paste the verified CREATE FUNCTION or CREATE VIEW into your migration. Because it was written and tested in isolation, it slots in without surprising schema conflicts.
Give your local coding agent a one-time system prompt describing Codoken. From there it can decompose any database feature into atoms, submit each one to the network, collect the verified SQL, and assemble the final migration — all without leaving your IDE.
# Codoken — verified SQL generation (MCP) You have the codoken MCP server available as a set of tools. Use it whenever you need a pure SQL function, view, or query transform. ## Tools submit_atom(task_id, language, prompt, test_code, timeout=120) language: "sqlite" or "postgresql" Submits one atom and blocks until APPROVED or REJECTED. Returns the verified SQL on APPROVED. list_languages() — all supported languages get_balance() — current credit balance ## Rules 1. One function or view per atom — no full schema migrations. 2. prompt: state the exact name, input types, return type, and edge cases. 3. test_code must contain: a. Schema setup: CREATE TABLE + INSERT statements (if the function queries data). b. SELECT assertions, one per line: SELECT expr AS got, literal AS expected, expr = literal AS ok; 4. generated_code is ONLY the CREATE FUNCTION / CREATE VIEW definition. 5. On APPROVED, copy only the returned SQL into your migration. 6. On REJECTED, revise the prompt and retry. ## Example (PostgreSQL) submit_atom( task_id = "clamp_fn", language = "postgresql", prompt = """Write a PostgreSQL function named clamp(val NUMERIC, lo NUMERIC, hi NUMERIC) RETURNS NUMERIC that returns val clamped to [lo, hi]. IMMUTABLE LANGUAGE sql. Return only the CREATE OR REPLACE FUNCTION statement.""", test_code = """SELECT clamp(5,1,10) AS got, 5 AS expected, clamp(5,1,10)=5 AS ok; SELECT clamp(-1,0,10) AS got, 0 AS expected, clamp(-1,0,10)=0 AS ok; SELECT clamp(15,0,10) AS got, 10 AS expected, clamp(15,0,10)=10 AS ok""" )
Ask your agent to list every pure SQL function or view a new feature needs — discount logic, ranking queries, aggregation helpers, data transforms. Each becomes its own atom.
The agent writes the function signature, the minimal schema fixture, and concrete SELECT assertions before any SQL exists. The test harness is the spec.
The agent posts each atom, polls until resolved, and retries rejected ones with a revised description. No human in the loop unless it fails twice.
With all functions verified, the agent writes only the migration glue — the small part that wires the verified functions into your application schema.