Skip to content

Spec Editor Demo: Gosling 🔬 ​

The Gosling demo is a Gosling spec editor next to the rendered chart. You can write the spec yourself, or have AI generate or edit it through MCP. Both work on the same spec: when you type valid JSON, the chart re-renders, and when AI changes the spec, the editor shows it.

Live Version: https://gosling.demo.mcp-web.dev

Code: https://github.com/flekschas/mcp-web/tree/main/demos/gosling

Key Components ​

  • src/spec/tools.ts: Exposes the spec as state with addStateTools(), plus a get_render_status tool that reports errors from the renderer.

  • src/spec/schema.ts: The Zod schema of the spec. It describes the top level of the spec for AI and validates the whole spec against the official Gosling JSON Schema.

  • src/editor/spec-editor.tsx: A CodeMirror JSON editor bound to the same state. Invalid JSON shows an error and leaves the last valid spec in place.

  • src/mcp/code-mode.ts: The Code mode switch. With code mode on, AI changes the spec with a short program instead of sending the whole spec back (see the code tool). The browser remembers the mode. Switching reloads the page and keeps the spec, and the connector URL stays the same.

From JSON Schema to Zod ​

Gosling defines its grammar as a large JSON Schema, while state tools need a Zod schema. The demo doesn't convert one into the other. Instead, it combines a small hand-written Zod object for the top level of the spec with a synchronous refinement that checks the whole spec against the JSON Schema with Ajv. AI sees a compact description of the spec, while validation covers the full grammar, and its errors point to the exact place in the spec.

The demo passes no error hints: in our experiments, learned hints lowered the quality of Gosling specs.