[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/management-protocol](https://jsprismarine.dev/api/@jsprismarine/management-protocol/index.md) / jsonRpc

# jsonRpc

## Interfaces

### RpcError

Defined in: [jsonRpc.ts:24](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L24)

The error member of a response.

#### Properties

##### code

> `readonly` **code**: `number`

Defined in: [jsonRpc.ts:25](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L25)

##### data?

> `readonly` `optional` **data?**: `string`

Defined in: [jsonRpc.ts:27](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L27)

##### message

> `readonly` **message**: `string`

Defined in: [jsonRpc.ts:26](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L26)

***

### RpcMethod

Defined in: [jsonRpc.ts:58](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L58)

A method the dispatcher can call.

#### Properties

##### beforeStart?

> `readonly` `optional` **beforeStart?**: `boolean`

Defined in: [jsonRpc.ts:62](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L62)

Whether a client may call it before the server has started, as only `rpc.discover` may.

##### call

> `readonly` **call**: (`params`) => `unknown`

Defined in: [jsonRpc.ts:70](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L70)

Runs the method.

###### Parameters

###### params

`Readonly`\<`Record`\<`string`, `unknown`\>\>

The parameter by name, checked against its schema, or nothing.

###### Returns

`unknown`

The result, sent as the response's `result`.

###### Throws

When the parameter is well-formed but names
  something the method cannot act on. Any other error becomes an internal error.

##### param?

> `readonly` `optional` **param?**: [`RpcParam`](#rpcparam)

Defined in: [jsonRpc.ts:60](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L60)

The parameter, when the method takes one. No method of the protocol takes more.

***

### RpcNotification

Defined in: [jsonRpc.ts:36](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L36)

A notification the server sends: a method name and its parameters, and no id.

#### Properties

##### jsonrpc

> `readonly` **jsonrpc**: `"2.0"`

Defined in: [jsonRpc.ts:37](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L37)

##### method

> `readonly` **method**: `string`

Defined in: [jsonRpc.ts:38](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L38)

##### params?

> `readonly` `optional` **params?**: readonly `unknown`[]

Defined in: [jsonRpc.ts:39](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L39)

***

### RpcParam

Defined in: [jsonRpc.ts:52](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L52)

One parameter a method declares, as Mojang's document lists it.

#### Properties

##### name

> `readonly` **name**: `string`

Defined in: [jsonRpc.ts:53](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L53)

##### schema

> `readonly` **schema**: `unknown`

Defined in: [jsonRpc.ts:54](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L54)

***

### RpcTable

Defined in: [jsonRpc.ts:74](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L74)

The methods one connection can call, by name, and the components their schemas refer to.

#### Properties

##### components

> `readonly` **components**: [`Components`](https://jsprismarine.dev/api/@jsprismarine/management-protocol/schemaCheck/index.md#components)

Defined in: [jsonRpc.ts:76](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L76)

##### methods

> `readonly` **methods**: `ReadonlyMap`\<`string`, [`RpcMethod`](#rpcmethod)\>

Defined in: [jsonRpc.ts:75](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L75)

##### onInternalError?

> `readonly` `optional` **onInternalError?**: (`method`, `error`) => `void`

Defined in: [jsonRpc.ts:80](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L80)

Told about an error a method threw that is not an `InvalidParams`, which the client sees no detail of.

###### Parameters

###### method

`string`

###### error

`unknown`

###### Returns

`void`

##### started

> `readonly` **started**: () => `boolean`

Defined in: [jsonRpc.ts:78](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L78)

Whether the server has started; before it has, only `beforeStart` methods are dispatched.

###### Returns

`boolean`

## Type Aliases

### FrameAnswer

> **FrameAnswer** = \{ `kind`: `"reply"`; `text`: `string`; \} \| \{ `kind`: `"none"`; \} \| \{ `kind`: `"close"`; \}

Defined in: [jsonRpc.ts:179](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L179)

What a frame needs in reply.

#### Union Members

##### Type Literal

\{ `kind`: `"reply"`; `text`: `string`; \}

A frame to send back.

***

##### Type Literal

\{ `kind`: `"none"`; \}

Nothing: the frame was a notification, or a stray response.

***

##### Type Literal

\{ `kind`: `"close"`; \}

A batch held something that is not a request, which Java answers by closing the connection.

***

### RpcId

> **RpcId** = `string` \| `number` \| `null`

Defined in: [jsonRpc.ts:21](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L21)

A request id: what the client sent, echoed back on the response.

***

### RpcResponse

> **RpcResponse** = \{ `id`: [`RpcId`](#rpcid); `jsonrpc`: `"2.0"`; `result`: `unknown`; \} \| \{ `error`: [`RpcError`](#rpcerror); `id`: [`RpcId`](#rpcid); `jsonrpc`: `"2.0"`; \}

Defined in: [jsonRpc.ts:31](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L31)

A response: a result or an error, for the request with the same id.

## Variables

### RPC\_ERRORS

> `const` **RPC\_ERRORS**: `object`

Defined in: [jsonRpc.ts:43](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L43)

The five errors JSON-RPC 2.0 defines, by the name its specification gives them.

#### Type Declaration

##### internalError

> `readonly` **internalError**: `object`

###### internalError.code

> `readonly` **code**: `-32603` = `-32603`

###### internalError.message

> `readonly` **message**: `"Internal error"` = `'Internal error'`

##### invalidParams

> `readonly` **invalidParams**: `object`

###### invalidParams.code

> `readonly` **code**: `-32602` = `-32602`

###### invalidParams.message

> `readonly` **message**: `"Invalid params"` = `'Invalid params'`

##### invalidRequest

> `readonly` **invalidRequest**: `object`

###### invalidRequest.code

> `readonly` **code**: `-32600` = `-32600`

###### invalidRequest.message

> `readonly` **message**: `"Invalid Request"` = `'Invalid Request'`

##### methodNotFound

> `readonly` **methodNotFound**: `object`

###### methodNotFound.code

> `readonly` **code**: `-32601` = `-32601`

###### methodNotFound.message

> `readonly` **message**: `"Method not found"` = `'Method not found'`

##### parseError

> `readonly` **parseError**: `object`

###### parseError.code

> `readonly` **code**: `-32700` = `-32700`

###### parseError.message

> `readonly` **message**: `"Parse error"` = `'Parse error'`

## Functions

### answerFrame()

> **answerFrame**(`text`, `table`): `Promise`\<[`FrameAnswer`](#frameanswer)\>

Defined in: [jsonRpc.ts:194](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L194)

Answers one frame: a request, a notification, or a batch of them.

#### Parameters

##### text

`string`

The frame, as the client sent it.

##### table

[`RpcTable`](#rpctable)

The methods the connection can call.

#### Returns

`Promise`\<[`FrameAnswer`](#frameanswer)\>

What to send back, if anything.

***

### notificationFrame()

> **notificationFrame**(`method`, `param?`): `string`

Defined in: [jsonRpc.ts:218](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/management-protocol/src/jsonRpc.ts#L218)

A notification frame. MSMP sends a notification's parameter as an array of one value, and no
`params` at all for a notification that has none.

#### Parameters

##### method

`string`

##### param?

`unknown`

#### Returns

`string`
