API reference / @jsprismarine/management-protocol
@jsprismarine/management-protocol
The server side of Java Edition's Server Management Protocol: JSON-RPC 2.0 over a WebSocket, answered the way Java's own management server answers it. It knows nothing about a game server. You hand it a function per method, and it handles the connection, the secret, the parameters and the notifications.
Modules
| Import | What it has |
|---|---|
@jsprismarine/management-protocol/ManagementServer | ManagementServer.listen, which starts the listener, and the Handlers type a server implements |
@jsprismarine/management-protocol/mojangApi | Mojang's OpenRPC document for the pinned Java release, with a type per schema and the Methods and Notifications maps |
@jsprismarine/management-protocol/jsonRpc | answerFrame, the dispatcher, and the JSON-RPC error codes |
@jsprismarine/management-protocol/schemaCheck | schemaMismatch, which checks a value against one of the document's schemas |
@jsprismarine/management-protocol/secret | generateSecret and isValidSecret, for the 40-character secret |
Example
import { ManagementServer } from '@jsprismarine/management-protocol/ManagementServer';
import { generateSecret } from '@jsprismarine/management-protocol/secret';
const server = await ManagementServer.listen({
host: 'localhost',
port: 25585,
secret: generateSecret(),
allowedOrigins: [],
started: () => true,
handlers: {
'minecraft:players': () => [{ id: '853c80ef-3c37-49fd-aa49-938b674adae6', name: 'jeb_' }]
},
notifications: ['minecraft:notification/players/joined']
});
server.notify('minecraft:notification/players/joined', { player: { name: 'jeb_' } });A client authenticates with Authorization: Bearer <secret>, or from a browser with the subprotocol minecraft-v1,<secret> from one of allowedOrigins. rpc.discover answers with the methods in handlers and the listed notifications, so a client sees what the server implements.
mojangApi.json is generated: pnpm --filter @jsprismarine/bedrock-data run dump:java-management copies it from the pinned Java release's data generator report and writes mojangApi.ts from it.