AI assistants (MCP)

Introduction

AI coding assistants know a lot of languages, but they may not know KScript, or the version you have. kscript mcp gives them these docs, so they write KScript from the reference of the version you have installed instead of guessing.

kscript mcp is a Model Context Protocol server. Claude Code, Claude Desktop, Cursor, VS Code, Windsurf, Codex, Gemini CLI and most other assistants can use it. It runs on your computer and works offline. It is built from the same guides and language catalog as kscript docs and the editor, so all three always agree.

The KScript extension for VS Code finds the server for you. For other assistants, add it once, and the assistant starts it when it needs it:

claude mcp add kscript -- kscript mcp   # Claude Code

For docs an assistant reads without a server, made from your own code, see Coding agents (kscript agents).

Running the server

Assistants start kscript mcp themselves, talking to it on stdin and stdout. You may also choose the syntax its examples use, or serve it over HTTP:

kscript mcp                 # the server on stdin and stdout: assistants start it themselves
kscript mcp --syntax xml    # show examples as XML instead of .kscript
kscript mcp --http          # serve on http://localhost:4181/mcp instead

What the assistant gets

Tools

The server gives the assistant these tools to call:

  • search_docs searches the guides and the reference: packages, elements, commands, methods, built-in variables and kscript commands.
  • read_doc reads a whole page as Markdown: a guide (language, code-format, web…), a package (KScript.IO), a type’s methods (string methods), variables or cli.
  • lookup gives everything about one name, such as <for>, @read_text, list->map, $args or KScript.Math: its parameters and their types, the return type, retired v1 names and an example.
  • list_make_commands lists the kscript make templates of your project (built in and _templates/) and the project templates.
  • check_code checks code or a file without running it, like kscript check, with your project’s lint rules.
  • format_code formats code or a file like kscript fmt, with your project’s format settings, and returns the result.
  • convert_code converts between XML and .kscript, like kscript convert.
  • run_code runs a short script in the same sandbox as the docs’ Run buttons, and returns what it printed.

Resources

Every page is also a resource, such as kscript://docs/guide/language or kscript://docs/reference/io, for assistants that let you attach resources to a chat.

Syntax and project

Examples come in your project’s syntax: make.syntax in kscript.json, or .kscript outside a project. --syntax picks one for every call, and a tool call can ask for the other. The project is the folder the assistant starts the server in; --dir names another.

What the server may touch

Nothing the server does changes your files. check_code and format_code read a file only when the assistant passes its path, and only a script or page (.kscript, .ks.xml, .html, .md) inside the project folder. run_code runs in an empty temporary folder with no network and without your environment variables.

Setting it up

Install kscript first (Install and editors). Each assistant below starts kscript mcp itself. If one says it can’t find kscript, which happens with desktop apps that don’t read your shell’s PATH, give the full path instead: ~/.kscript/bin/kscript on macOS and Linux (written out, such as /Users/you/.kscript/bin/kscript), or %LOCALAPPDATA%\Programs\kscript\kscript.exe on Windows.

Claude Code

claude mcp add kscript -- kscript mcp

Add --scope project to save it in the project’s .mcp.json, so everyone working on the project gets it:

{
  "mcpServers": {
    "kscript": { "command": "kscript", "args": ["mcp"] }
  }
}

Claude Desktop

Open Settings → Developer → Edit Config and add the server to claude_desktop_config.json, then restart Claude:

{
  "mcpServers": {
    "kscript": { "command": "/Users/you/.kscript/bin/kscript", "args": ["mcp"] }
  }
}

Cursor

Add it to .cursor/mcp.json in your project, or to ~/.cursor/mcp.json for every project:

{
  "mcpServers": {
    "kscript": { "command": "kscript", "args": ["mcp"] }
  }
}

VS Code

In a trusted workspace, the KScript extension automatically provides KScript Docs to agents that use VS Code’s MCP servers. Find it under MCP: List Servers in the command palette and enable its tools in the agent’s tools picker. The extension uses the same KScript installation as the editor, including kscript.server.path if set. In a Remote SSH workspace, install KScript on the remote host. Each workspace folder gets a server that uses that folder’s syntax, lint and format settings.

If you use VS Code without the KScript extension, you can add the server with MCP: Add Server or in .vscode/mcp.json:

{
  "servers": {
    "kscript": { "type": "stdio", "command": "kscript", "args": ["mcp"] }
  }
}

Windsurf

Add it to ~/.codeium/windsurf/mcp_config.json:

{
  "mcpServers": {
    "kscript": { "command": "kscript", "args": ["mcp"] }
  }
}

Codex

codex mcp add kscript -- kscript mcp

Or add it to ~/.codex/config.toml:

[mcp_servers.kscript]
command = "kscript"
args = ["mcp"]

Gemini CLI

Add it to ~/.gemini/settings.json, or .gemini/settings.json in your project:

{
  "mcpServers": {
    "kscript": { "command": "kscript", "args": ["mcp"] }
  }
}

Other assistants

Most assistants take the same thing: a command, kscript, with the argument mcp. For one that connects to a URL instead, run kscript mcp --http and give it http://localhost:4181/mcp. The HTTP server only listens on localhost and turns away requests from web pages. --port picks another port.

Checking that it works

Ask the assistant something only these docs know, such as “Which KScript command reads a JSON file, and what does it return?”. It should call lookup or search_docs and answer with @read_json. Most assistants also list their servers: claude mcp list, MCP in Cursor’s settings, or MCP: List Servers in VS Code.

To see what the server says without an assistant, send it a message yourself:

echo '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | kscript mcp

Edit this page on GitHub