Skip to content

ai support_us

Tki_sor edited this page Nov 12, 2026 · 1 revision

English · 中文

AI-assisted authoring

NekoJS helps AI coding tools such as Claude, Copilot or Cursor write your scripts more accurately. It does two things:

  • Exports documentation: the NekoJS handbook, examples and AI instruction files are written into your game directory for the AI to read. On by default.
  • Provides a query service (MCP): the AI can look up the events, methods and parameters that really exist in your instance instead of guessing from memory. Off by default.

NekoJS is not an AI model, and it never changes your AI tool's settings on its own.

The recommended workflow:

  1. Point the AI at the exported documentation.
  2. Run /nekojs probe in game to generate an API snapshot.
  3. Connect your AI tool to the query service in one of the two ways below.
  4. After the AI writes a script, reload it in game and check the result yourself.

Exported files

Documentation is exported to .github/neko_ai/ in the game directory by default. The files you will use:

Path Contents
nekojs/config/ai.toml Settings for the AI features
.github/neko_ai/current.json Points to the current documentation bundle; its paths are relative to .github/neko_ai/
.github/neko_ai/bundled/<bundleId>/ The bundle itself: handbook, examples, Skills. Do not edit it
.github/neko_ai/AGENTS.md Entry instructions for the AI
.github/neko_ai/environment.json Information about this instance
.github/neko_ai/connection.json Query service address and status (no secret)
.github/neko_ai/snapshots/ API snapshots generated by /nekojs probe
nekojs/config/ai.token The query service access key; created only once a service is enabled

A few notes:

  • AI tools do not read AGENTS.md automatically. Point your tool at it, or merge what you need into your own instruction file.
  • VS Code does not discover the agents/ folder either. To also write to the standard .github/agents/, set [output].editor_agents = true.
  • To change the export folder, set [output].directory. It must be a relative path inside the game directory. Changing it does not move or delete old files.
  • If a bundle was edited, NekoJS refuses to overwrite it and reports an error. Delete the old bundle to let it export again.

Generate an API snapshot

The documentation is only a manual. For the AI to look up the methods in your instance, first run this in game:

/nekojs probe

It generates the type declarations used for code completion, and the snapshot used by AI queries. Run it again after adding mods or changing registered content. A normal /nekojs reload does not refresh the snapshot. See Probe type generation.

Option 1: connect while the game runs

While the game is running, connect straight to its built-in query service. Nothing else needs installing.

  1. Open nekojs/config/ai.toml and set enabled = true under [mcp].
  2. Restart the game and keep it running. Open .github/neko_ai/connection.json and check that listening is true. mcp is usually http://127.0.0.1:8767/mcp.
  3. In your AI tool, add an MCP server of type Streamable HTTP with that URL and the header Authorization: Bearer <key>. The key is the contents of nekojs/config/ai.token.

If your AI tool uses an mcpServers settings file, it looks like this:

{
  "mcpServers": {
    "nekojs": {
      "url": "http://127.0.0.1:8767/mcp",
      "headers": {"Authorization": "Bearer <token>"}
    }
  }
}

Each AI tool configures this differently; some use a settings dialog. Once connected, tools such as nekojs_context should appear in the tool list. The service stops when the game closes.

Option 2: use it with the game closed

A standalone stdio helper reads the documentation and snapshot from the game's last export, so it works while the game is closed. Your AI tool starts it itself, so no port or key is involved.

You need:

  • Java 21 or newer.
  • The nekojs-1.1.0-preview3-authoring-stdio.jar matching your NekoJS version. It is not a mod; do not put it in mods/. In a source build, :common:authoringStdioJar produces it in common/build/libs/.
  • To have started the game at least once and run /nekojs probe successfully.

The launch command:

java -jar /absolute/path/nekojs-1.1.0-preview3-authoring-stdio.jar --game-dir /absolute/game/directory

In your AI tool's mcpServers settings:

{
  "mcpServers": {
    "nekojs": {
      "command": "java",
      "args": ["-jar", "/absolute/path/nekojs-1.1.0-preview3-authoring-stdio.jar", "--game-dir", "/absolute/game/directory"]
    }
  }
}

Replace both paths:

  • --game-dir is the game directory that contains the nekojs/ folder — not nekojs/ itself and not a world save.
  • Absolute paths are recommended. On Windows you can write D:/Games/Instance to avoid escaping backslashes in JSON.
  • If your AI tool cannot find java, set command to the full path of a Java 21 executable.

The helper sees the state as of the last export. After changing mods or scripts, run /nekojs probe in game again. If you change the export folder in ai.toml or the game environment changes, also restart the helper.

If it will not connect

  • --help prints usage. Bad arguments or missing exports make it exit with code 2, with the reason on stderr.
  • By default it finds the export folder from [output].directory in ai.toml. To set it by hand, add --ai-dir <path relative to the game directory>.
  • Queries report not-ready: /nekojs probe has not run successfully yet.
  • They report disabled: [api].enabled is false in ai.toml. Set it back to true and restart the game to export again.
  • They report unavailable: the snapshot files are broken or the game environment changed. Probe again, then restart the helper.
  • The helper's standard output is reserved for the protocol. Do not print anything to stdout from a wrapper script.

Configuration reference

The default nekojs/config/ai.toml:

[output]
directory = ".github/neko_ai"
editor_agents = false

[documentation]
enabled = true
agents = "create-if-missing"

[api]
enabled = true

[http]
enabled = false

[mcp]
enabled = false
host = "127.0.0.1"
port = 8767

[control]
commands = false
reload = false
command_allowlist = []
  • Restart the game after a change; reload does not apply these settings.
  • [mcp].enabled turns on in-game MCP and [http].enabled turns on the plain JSON routes. Both share [mcp].port. Neither affects the standalone stdio helper.
  • host must be 127.0.0.1; only this computer can connect. The port is an integer from 1 to 65535.
  • documentation.agents accepts only create-if-missing or off.
  • [api].enabled = false turns off API queries; the documentation stays readable.
  • [control] switches live actions; see Live actions below.
  • If a setting is invalid or the port is taken, the AI features do not start and the log shows NEKO-1019. The game itself runs normally.

What the AI can look up

Once connected, the AI usually calls nekojs_context, nekojs_capabilities and nekojs_schema first to learn the environment, then uses these four tools to look up APIs:

Tool Use
nekojs_resolve Find a symbol by name, such as Item
nekojs_members List a symbol's methods and properties
nekojs_query Filter by conditions, such as "the of overload whose first parameter is a string"
nekojs_batch Send up to 10 queries at once

These seven tools are available in both options. Queries are read-only: they never run scripts, change files or reload.

The request examples below are for readers who want the details or write their own client. Normal AI tools build these requests themselves.

resolve and members

First use resolve to find a symbol by name:

{
  "scope":{"environmentId":"<environmentId>","snapshotId":"<snapshotId>","scriptType":"SERVER","language":"typescript","memberView":"declared"},
  "name":"Item","kind":"binding","match":"exact",
  "select":["symbolId","name","kind","coverage","source"],"page":{"size":20}
}

Take environmentId and snapshotId from the nekojs_context result. scriptType is uppercase, and language can currently only be typescript. A binding and a class can share a name, so check which result you pick.

Then put the chosen result's symbolId (not its name) in ownerSymbolId and list its members:

{
  "scope":{"environmentId":"<environmentId>","snapshotId":"<snapshotId>","scriptType":"SERVER","language":"typescript","memberView":"declared","ownerSymbolId":"<ownerSymbolId>"},
  "name":"of","kind":"method","arity":{"min":1,"max":1},
  "select":["symbolId","name","parameters","returnType","callArity","coverage"],"page":{"size":20}
}

arity matches by how many arguments a call can take, including optional and variadic parameters. Each overload comes back as its own record.

query

Find the overloads named of whose first parameter has type string:

{
  "scope":{"environmentId":"<environmentId>","snapshotId":"<snapshotId>","scriptType":"SERVER","language":"typescript","memberView":"declared","ownerSymbolId":"<ownerSymbolId>"},
  "from":"members",
  "where":{"all":[
    {"field":"name","op":"eq","value":"of"},
    {"some":{"path":"parameters","where":{"all":[
      {"field":"position","op":"eq","value":0},
      {"field":"type.display","op":"eq","value":"string"}
    ]}}}
  ]},
  "select":["symbolId","name","parameters","returnType","coverage"],"page":{"size":20}
}

from can be symbols, members, events, inputAdapters or declarations. Combine conditions with all/any/not; use some to require that the same parameter meets several conditions. The available fields and operators are whatever nekojs_schema returns.

batch

Send several queries at once, sharing the outer scope:

{
  "scope":{"environmentId":"<environmentId>","snapshotId":"<snapshotId>","scriptType":"SERVER","language":"typescript","memberView":"declared"},
  "queries":[
    {"from":"symbols","where":{"field":"name","op":"eq","value":"Item"},"select":["symbolId","name","coverage"]},
    {"from":"events","where":{"field":"group","op":"eq","value":"ServerEvents"},"select":["symbolId","name","group","coverage"]}
  ]
}

Each sub-query has its own status; check every one.

Reading the results

  • Not found does not mean it does not exist. When the result's coverage is incomplete, an empty result does not prove an API is missing. Some hand-written declarations, inheritance and event signatures are not fully indexed; read the generated declaration files instead.
  • Paging: copy the returned page.nextCursor into page.cursor of the next request and keep everything else the same. Cursors expire after 15 minutes.
  • Limits: 20 results per page by default, at most 100; at most 32 select fields; 1–10 queries per batch; 64 KiB per request and response. If you hit a limit, select fewer fields or use smaller pages.
  • Misspelled fields or operators cause an error; they are never silently ignored.
  • Python members, running scripts, writing files and arbitrary Java reflection are not supported.
Query error What to do
INDEX_NOT_READY Run /nekojs probe successfully in game
INDEX_DISABLED Set [api].enabled to true and restart the game
INDEX_UNAVAILABLE Check the snapshot files, settings and logs
SCOPE_CONFLICT Call nekojs_context again and use this instance's IDs
SNAPSHOT_EXPIRED Call nekojs_context again and start the query over
RESPONSE_TOO_LARGE Select fewer fields or a smaller page, or read the local files

Example scripts

handbook/scripting-examples.md in the bundle has 15 complete scenarios. Each gives the full code, where to put it, how to trigger it, what you should see and how to clean up. The files are in the bundle's examples/ folder.

Try them in a test world, one scenario at a time. Put server examples in nekojs/server_scripts/authoring-examples/, and other types in a folder of the same name inside their script folder.

Scenario File in bundle How to trigger What you should see
Login welcome server/player-login.js Reload, then log in again A welcome message on login
Recipes server/recipes.js /nekojs reload The stick recipe is replaced; flint and glass recipes are added
Item tags server/item-tags.js NeoForge: /nekojs reload, then vanilla /reload The stones item tag contains stone but not granite
Block tags server/block-tags.js NeoForge: /nekojs reload, then vanilla /reload The stones block tag contains stone
Registering content startup/registry.js Restart the game A ruby item and block
Item components server/item-components.js /nekojs reload, check the log An in-memory item is changed; nothing is given to players
Shared state and timers startup/shared-config.js + server/state-and-timer.js Restart once, then /nekojs reload A shared greeting, a rising counter and a delayed log line
Client UI client/counter.tsx NeoForge 26.x only, /nekojs reload client A counter screen whose number rises when you click
Controls client/controls.tsx NeoForge 26.x only, /nekojs reload client A toggle, slider, selector and text field
Forms and dialogs client/forms-and-dialogs.tsx NeoForge 26.x only, /nekojs reload client Input validation, a confirm dialog and a read-only preview
Multiple windows client/workspace.tsx NeoForge 26.x only, /nekojs reload client Notes/Tools/Preview windows that can be minimized
CommonJS modules/hello.cjs + modules/lib/message.cjs /nekojs reload, keeping relative paths Hello, NekoJS! in the log
Assertion tests test/assertions.js /nekojs test Three assertions pass
Logging greeting.js /nekojs reload One load message in the log
Event subscription event-subscription.js /nekojs reload The recipe event is observed; no recipes change

First example: login welcome

Put this code in nekojs/server_scripts/authoring-examples/player-login.js, run /nekojs reload, then leave and log in again:

// Place in server_scripts. The callback runs for future logins, not existing players.
PlayerEvents.loggedIn(event => {
    event.entity.sendMessage("Welcome to NekoJS!");
});

You receive Welcome to NekoJS! when you log in; players already online do not. On Fabric, change event.entity to event.player.

Recipe example

This example replaces the vanilla stick recipe, so use a test world. Put it in nekojs/server_scripts/authoring-examples/recipes.js:

// Use a disposable world: this replaces the vanilla stick recipe.
ServerEvents.recipes(event => {
    event.remove({ id: "minecraft:stick" });
    event.shaped(Item.of("minecraft:stick", 4), ["P", "P"], {
        P: Ingredient.of("minecraft:oak_planks")
    }).id("nekojs_example:sticks");
    event.shapeless(Item.of("minecraft:flint"), [
        Ingredient.of("minecraft:gravel"),
        Ingredient.of("minecraft:gravel")
    ]).id("nekojs_example:flint");
    event.smelting(Item.of("minecraft:glass"), Ingredient.of("minecraft:sand"), 0.1, 200)
        .id("nekojs_example:glass");
});

After /nekojs reload: two oak planks stacked vertically make 4 sticks; two gravel make 1 flint in any arrangement; a furnace smelts sand into glass. Delete the file and reload to get the vanilla stick recipe back.

Checking live results

With in-game MCP, two more read-only tools are available besides the seven above. They need neither an API snapshot nor live actions. The standalone stdio helper does not have them.

Tool Example arguments What it returns
nekojs_errors {"scriptType":"SERVER","limit":25} The current script errors: error ID, script type, file, line and column, and a short message. Both arguments are optional; at most 100 rows
nekojs_operation_status {"operationId":"<full UUID>"} The later status of one live action. It only reads; it never runs the action again

With [http] enabled, you can also POST to the errors and operation_status HTTP routes.

Also, testRunReport in the nekojs_context result is the outcome of the latest /nekojs test run, including passed, failed and overallPassed. If no assertion ran at all, overallPassed is null, which is not a pass.

Live actions (off by default)

When enabled, the AI can use in-game MCP to run server commands you allow, or to reload scripts. Only in-game MCP has this; the standalone stdio helper and the plain HTTP routes do not.

Commands and reloads run by the AI really change your world. Back up your scripts and saves first, preferably use a test world, and always know what the AI is about to do.

To enable it:

  1. Turn on [mcp].enabled in ai.toml.
  2. Under [control], turn on only what you need:
    • To allow commands: commands = true, and list the allowed commands in command_allowlist, for example ["list"].
    • To allow reloads: reload = true.
  3. Restart the game and connect as in Option 1. These tools then appear in your AI tool.
Tool Example arguments What it does
nekojs_execute_game_command {"command":"list","timeoutMs":5000} Runs one server command from the allowlist
nekojs_reload_scripts {"type":"server","timeoutMs":5000} Fully reloads one script type: server, client or test

Commands:

  • The allowlist matches the first word of the command exactly. list and minecraft:list count as different commands.
  • Commands run at permission level 2, not as a player. Commands that need a player or a higher permission level fail.
  • The allowlist is not a sandbox. Allowing a command such as execute allows everything it can do. List only the commands you really need.
  • A server must be running (a single-player world counts).

Reloads:

  • server and test need a running server; client needs a game client. A dedicated server cannot reload client.
  • startup is not supported (restart the game instead), and neither is reloading a single file.
  • A server reload re-applies recipes. Tags still need a vanilla /reload afterwards.
  • In the result, check committed (did the scripts take effect?) and postprocessingSucceeded (did follow-up work such as recipes succeed?) separately.

Timeouts: timeoutMs is an integer from 1 to 8000; the default is 5000. A timeout does not mean the action did not run — it may still be running or may have finished. Do not just retry. Check with nekojs_operation_status or look at the game first. Only one action can run at a time.

Common rejection codes:

Code Reason
CONTROL_DISABLED This action is not turned on under [control]
COMMAND_NOT_ALLOWED The command is not in the allowlist
CONTROL_BUSY Another action is already running
LIVE_RUNTIME_REQUIRED No server is running; the standalone stdio helper always returns this
RELOAD_UNAVAILABLE No game client is available to reload client
RESTART_REQUIRED A startup reload was requested; restart the game
UNSUPPORTED_RELOAD The reload type is not supported
STALE_RUNTIME The world closed or changed, so the old action no longer runs
RELOAD_POSTPROCESSING_FAILED The scripts took effect, but follow-up work such as recipes failed. This is not a rollback
TEST_ASSERTIONS_FAILED The test scripts ran, but some assertions failed

When you are done, turn off the switches you no longer need and restart the game. handbook/live-controls.md in the bundle has the full details.

Advanced: plain HTTP routes

After enabling [http].enabled and restarting, you can send requests directly with a tool such as curl. Every route is under /api/v1/authoring/ and needs Authorization: Bearer <key>. Run this example in a POSIX shell from the game directory:

TOKEN="$(tr -d '\r\n' < nekojs/config/ai.token)"
BASE='http://127.0.0.1:8767/api/v1/authoring'
curl --fail-with-body -H "Authorization: Bearer $TOKEN" "$BASE/context"
curl --fail-with-body -H "Authorization: Bearer $TOKEN" "$BASE/capabilities"
curl --fail-with-body -H "Authorization: Bearer $TOKEN" "$BASE/schema"
# Save the resolve request above as request.json and replace the discovered IDs.
curl --fail-with-body -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' --data-binary @request.json "$BASE/resolve"
unset TOKEN
Method Routes
GET context, capabilities, schema
POST JSON resolve, members, query, batch, errors, operation_status

URL query parameters are not accepted; put every condition in the JSON body. A successful HTTP status does not mean the result is complete; still check coverage.

Advanced: raw MCP requests

You only need this to write your own client or to debug. The service uses Streamable HTTP with JSON responses, protocol version 2025-11-25.

  1. POST an initialize request to the mcp URL with Authorization: Bearer <key>, Content-Type: application/json and Accept: application/json, text/event-stream:
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"local-authoring-client","version":"1"}}}
  1. Note the Mcp-Session-Id response header. Send it, plus MCP-Protocol-Version: 2025-11-25, with every later request.
  2. POST {"jsonrpc":"2.0","method":"notifications/initialized"}; success is HTTP 202. Then you can call tools:
{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"nekojs_context","arguments":{}}}
  1. Read structuredContent and isError in the result, not just the HTTP status. resources/read can only read documents listed by resources/list.
  2. Send DELETE to the mcp URL when finished. Sessions expire after 30 idle minutes; at most 32 can exist at once.

Legacy SSE, GET event streams (GET /mcp returns 405), prompts and resource subscriptions are not supported.

Security

  • The query service listens only on 127.0.0.1, this computer. Do not forward the port or put it behind a public proxy.
  • Treat ai.token like a password. Do not commit it to Git or paste it into chats, screenshots or logs. Any program on this computer that can read the file can use the service.
  • There is no TLS and no remote authorization; it is meant for local use only.
  • What the AI looks up helps it write code. It does not prove a script works in game; check the result yourself.

Related pages: Script basics, TypeScript and JSX, Commands, Error and log reference.


Previous: Event reference · Contents · Next: Commands

NekoJS Wiki

中文 · English

先看这里 / Start here

  • 首页 / Home · 中文 · EN
  • 平台与兼容性 / Platforms and compatibility · 中文 · EN
  • 快速开始 / Quick start · 中文 · EN
  • 配置参考 / Configuration · 中文 · EN
  • 常见问题 / FAQ · 中文 · EN

脚本作者 / Script authors

  • 脚本基础 / Script basics · 中文 · EN
  • 脚本 API 约定 / Script API conventions · 中文 · EN
  • 脚本属性 / Script properties · 中文 · EN
  • 全局绑定 / Global bindings · 中文 · EN
  • 数据、状态与持久化 / Data, state and persistence · 中文 · EN
  • Python 脚本 / Python scripts · 中文 · EN
  • Python 特性清单 / Python feature support · 中文 · EN
  • 事件参考 / Event reference · 中文 · EN
  • AI 辅助脚本编写 / AI-assisted authoring · 中文 · EN
  • 命令 / Commands · 中文 · EN
  • 错误与日志参考 / Error and log reference · 中文 · EN
  • 客户端绘制与后处理 / Client rendering and post effects · 中文 · EN

整合包作者 / Modpack authors

  • 版本化脚本包 / Versioned script packs · 中文 · EN
  • 配方系统 / Recipe system · 中文 · EN
  • 注册新内容 / Registering new content · 中文 · EN
  • 模块系统 / Module system · 中文 · EN
  • TypeScript 与 JSX / TypeScript and JSX · 中文 · EN
  • JSX 客户端 UI / JSX client UI · 中文 · EN
  • MixinJS(实验性) / MixinJS (experimental) · 中文 · EN
  • Node.js 兼容 / Node.js compatibility · 中文 · EN

插件开发者 / Plugin developers

  • 插件开发 / Plugin development · 中文 · EN
  • 类型适配器 / Type adapters · 中文 · EN
  • 事件扩展 / Event extensions · 中文 · EN
  • 注解体系 / Annotations · 中文 · EN

项目贡献者 / Project contributors

  • 项目架构 / Project architecture · 中文 · EN
  • Probe 类型生成 / Probe type generation · 中文 · EN
  • 构建系统 / Build system · 中文 · EN

Clone this wiki locally