knotflow Lessons PDF ↓ Deutsch Handbook Modeller ↗ Source

Lesson 4.5 · IV Tools

Tools for an AI

What it's about: No language model has ever seen knotflow. Still, an AI can write models in it if it gets the same tools as a human: evaluate, read errors, look at the result, look things up. kf mcp provides exactly that, over the Model Context Protocol (MCP). On top of that comes a compact language map that is generated from the code and therefore never goes out of date.

What you should know first: an AI assistant that speaks MCP (such as Claude Code, Claude Desktop or Zed's agent panel), and an installed kf. Lesson 4.4 explains the related protocol for editors; you do not need to have read it.

1. Tools instead of knowledge

A language model learns a language from examples in its training, and there are none for knotflow. You could train one further (fine-tuning), but that goes out of date with every change to the language. The better way is the one a human takes too: read a description, write something, try it, correct it. For this the AI needs two things:

2. MCP: a protocol for tools

MCP is to AI assistants what the LSP (Lesson 4.4) is to editors: a shared protocol, so that one server works with many programs, such as Claude Desktop, Claude Code or Zed's agent panel. Here too it is JSON-RPC, just one message per line instead of a length header. A server offers three things:

3. Four tools

Tool gives the AI
evaluate errors with line, column and hint; parameters, values; for each export: closed solid yes/no, parts, size, volume
render pictures as PNG, from diagonally above, from above and from the side
reference signature and description of a function, a group or a library, or the whole language map
examples the example models as templates, a project with its libraries

Here some things that were built for humans pay off:

4. The language map

docs/llms.txt (also kf guide and the resource knotflow://guide) consists of two parts:

It is in English because it is aimed at language models. A test compares the file with the output of kf guide. If a function changes, the test fails until the map has been regenerated.

5. Running it safely

Letting an AI run its own code normally needs an isolated environment (a sandbox). knotflow needs none. The language can neither write files nor reach the network. All it can read is libraries and data files in the model's folder, through relative paths written as literals in the text (Lesson 2.5); a model the AI sends as text reads no data files at all. Every evaluation is limited: at most ten million calls, lists of up to ten million elements, depth 1000 (Lesson 2.3). What was crash safety in Lesson 2.3 is security here. An AI can try out as much as it likes.

6. Setting it up

In Zed, the extension from Lesson 4.4 brings the server along: switch on "knotflow" in the agent panel. For Claude Code, claude mcp add knotflow -- kf mcp is enough; for Claude Desktop, an entry in its configuration. The details are in editors/README.md. If a newer kf is installed later, the running server adds a note to its answers that it should be restarted.

Together with the browser (Lesson 2.4) this makes a workspace for three: the AI writes into the file, the LSP checks while it writes, the browser shows the folder as a 3D model with sliders.

Try it yourself

  1. Set up the server in Zed or Claude Code and ask the AI: "Write a knotflow model for a bowl with eight ribs, with diameter and height as sliders." How often does it call evaluate before the model runs without errors? Does it look at the result with render?
  2. A touchstone: describe the air-pruning pot in words (Lesson 3.5) and let the AI rebuild it. Where does it fail, and which of that could a better language map fix?
  3. Read docs/llms.txt. Is a pitfall missing that you tripped over yourself? Add it to crates/cli/src/guide.rs and regenerate the map.