How to script a KCD2 multiplayer server
Write your gamemode as a KCDS resource in TypeScript or JavaScript, with server and client scripts.
1. A resource's files
A resource is a folder in the server's resources\ folder:
hello/ package.json tsconfig.json types/ shared.d.ts and server-api.d.ts from the KCDS-Types zip src/server/index.ts
The KCDS-Types zip comes with every release on the download page; its
shared.d.ts and server-api.d.ts declare the server API for TypeScript (see
TypeScript).
2. The manifest
package.json names the scripts in its own kcds section:
{
"name": "hello",
"version": "1.0.0",
"scripts": { "build": "tsc -p tsconfig.json" },
"devDependencies": {
"typescript": "5.9.3"
},
"kcds": { "serverScripts": ["dist/server/index.js"] }
}serverScripts: compiled server CommonJS files.clientScripts: client CommonJS files the server sends to the players.sharedScripts: files run on both sides, before that side's scripts.resourceDependencies: resources this one needs.
tsconfig.json compiles the server scripts against the KCDS declarations:
{
"compilerOptions": {
"target": "ES2022",
"module": "commonjs",
"lib": ["ES2022"],
"types": [],
"strict": true,
"rootDir": "src/server",
"outDir": "dist/server"
},
"files": ["types/shared.d.ts", "types/server-api.d.ts"],
"include": ["src/server/**/*.ts"]
}3. A command
Put this in src/server/index.ts. The API is the global kcds object and needs no import:
const { Events, Chat } = kcds.core; Events.on("playerCommand", (player, command, args) => { if (command.toLowerCase() !== "hello") return; Chat.sendToPlayer(player, args.length ? args.join(" ") : "Hello!", { author: "Server" }); });
The host passes the command without its slash and splits the arguments at spaces.
4. Build and run
Compile the resource, put it in the server's resources\ folder and start the server. Type /hello in the
chat.
5. Next steps
The docs cover every part of the SDK: areas, markers, the world, props, doors, carts, stashes, custom buffs and more, and the API reference lists every type and member, generated from the SDK definition on every build.