mcp.protocol.errors

Undocumented in source.

Members

Classes

McpException
class McpException

An error that maps onto a JSON-RPC error object.

Enums

ErrorCode
enum ErrorCode

Standard JSON-RPC 2.0 + MCP error codes.

Functions

isValidElicitationUrl
bool isValidElicitationUrl(string url)

True if url is a valid absolute URI suitable for a URL-mode elicitation.

missingRequiredClientCapability
McpException missingRequiredClientCapability(ClientCapabilities requiredCapabilities, string message)

Build the -32003 MissingRequiredClientCapabilityError a server returns when processing a request requires a client capability that was not declared in the peer's clientCapabilities (draft basic/lifecycle, draft/schema MissingRequiredClientCapabilityError). HTTP transports MUST map this onto a 400 Bad Request. The error's data.requiredCapabilities carries a ClientCapabilities object describing the capabilities the request needs.

resourceNotFound
McpException resourceNotFound(string uri, Json data)

Build a "resource not found" error using the legacy MCP-specific code (-32002). Kept for backwards compatibility; this form always emits -32002. Draft connections should instead use the version-aware overload below, which selects the version-appropriate code (draft aligns it to invalidParams / -32602).

resourceNotFound
McpException resourceNotFound(string uri, ProtocolVersion v, Json data)

Build a "resource not found" error whose code is selected for the negotiated protocol version: draft aligns it to invalidParams (-32602), while earlier versions use the MCP-specific -32002 (see versions.resourceNotFoundCode).

toErrorJson
Json toErrorJson(McpException e)

Build the JSON-RPC error object {code, message, data?}.

urlElicitationRequired
McpException urlElicitationRequired(UrlElicitation[] elicitations, string message)

Build the -32042 URLElicitationRequiredError a server returns when a request cannot be processed until one or more URL-mode elicitations are completed (2025-11-25 elicitation §"URL Elicitation Required Error"). The error's data.elicitations array carries the URL-mode elicitations the client must complete first; each entry is emitted as {mode:"url", elicitationId, url, message}.

userRejected
McpException userRejected(string message, Json data)

Build the conventional -1 "User rejected sampling request" error a client onSampling delegate SHOULD return when the user declines the request (client/sampling §Error Handling).

Structs

UrlElicitation
struct UrlElicitation

A single URL-mode elicitation entry carried by a -32042 URLElicitationRequiredError (2025-11-25 elicitation §"URL Elicitation Required Error"). Each entry directs the user to complete an out-of-band interaction at url; elicitationId correlates the request with the outcome the client later reports back.