Skip to content

Protocol

Category: Mcp_client

Source: protocol.dart

MCP wire-protocol message types (Model Context Protocol).

MCP is layered on JSON-RPC 2.0. We reuse glue_server's [JsonRpcMessage]/[JsonRpcTransport] for framing and add MCP-specific param/result shapes here.

Pure data — no I/O. See client.dart for the dispatch logic and transport/stdio.dart for the subprocess transport.

Classes

McpClientInfo

Constructor

dart
const McpClientInfo({required this.name, required this.version})

Properties

PropertyTypeDescription
nameString
versionString

McpServerInfo

Constructor

dart
const McpServerInfo({required this.name, required this.version})
dart
factory McpServerInfo.fromJson(Map<String, dynamic> json)

Properties

PropertyTypeDescription
nameString
versionString

McpClientCapabilities

Constructor

dart
const McpClientCapabilities({this.roots})

Properties

PropertyTypeDescription
rootsMcpRootsCapability?We advertise roots so servers (e.g. filesystem) can scope access.

McpRootsCapability

Constructor

dart
const McpRootsCapability({this.listChanged = false})

Properties

PropertyTypeDescription
listChangedbool

McpServerCapabilities

Constructor

dart
const McpServerCapabilities({
    this.tools,
    this.prompts,
    this.resources,
    this.sampling,
    this.logging,
    this.experimental,
  })
dart
factory McpServerCapabilities.fromJson(Map<String, dynamic> json)

Properties

PropertyTypeDescription
toolsMcpToolsCapability?
promptsMap&lt;String, dynamic&gt;?
resourcesMap&lt;String, dynamic&gt;?
samplingMap&lt;String, dynamic&gt;?
loggingMap&lt;String, dynamic&gt;?
experimentalMap&lt;String, dynamic&gt;?
supportsSamplingbool get
supportsSamplingbool get

McpToolsCapability

Constructor

dart
const McpToolsCapability({this.listChanged = false})
dart
factory McpToolsCapability.fromJson(Map<String, dynamic> json)
dart
McpToolsCapability(listChanged: json['listChanged'] as bool? ?? false)

Properties

PropertyTypeDescription
listChangedbool

McpInitializeResult

Constructor

dart
const McpInitializeResult({
    required this.protocolVersion,
    required this.serverInfo,
    required this.capabilities,
    this.instructions,
  })
dart
factory McpInitializeResult.fromJson(Map<String, dynamic> json)

Properties

PropertyTypeDescription
protocolVersionString
serverInfoMcpServerInfo
capabilitiesMcpServerCapabilities
instructionsString?

McpToolDescriptor

Constructor

dart
const McpToolDescriptor({
    required this.name,
    required this.description,
    required this.inputSchema,
  })
dart
factory McpToolDescriptor.fromJson(Map<String, dynamic> json)

Properties

PropertyTypeDescription
nameString
descriptionString
inputSchemaMap&lt;String, dynamic&gt;

sealed McpContent

One content item in a tool call result. MCP supports text, image, and embedded resource variants; we model only text directly and pass other kinds through as opaque maps so the agent loop can ignore them.

Constructor

dart
const McpContent()
dart
factory McpContent.fromJson(Map<String, dynamic> json)

McpTextContent

Constructor

dart
const McpTextContent(this.text)

Properties

PropertyTypeDescription
textString

McpOpaqueContent

Constructor

dart
const McpOpaqueContent(this.type, this.raw)

Properties

PropertyTypeDescription
typeString
rawMap&lt;String, dynamic&gt;

McpToolCallResult

Constructor

dart
const McpToolCallResult({required this.content, this.isError = false})
dart
factory McpToolCallResult.fromJson(Map<String, dynamic> json)

Properties

PropertyTypeDescription
contentList&lt;McpContent&gt;
isErrorbool
textPayloadString getConcatenates all text content into a single string. Non-text items are summarised as [&lt;type&gt;]. Used to build the LLM-facing payload.

abstract McpErrorCode

MCP-specific JSON-RPC error codes. The standard JSON-RPC codes (-32700..-32603) come from [JsonRpcErrorCode] in glue_server.

Properties

PropertyTypeDescription
rateLimitedconst intGlue-reserved: the server is rate-limited. Honour Retry-After / data.retry_after_seconds and retry once.

abstract McpMethod

Properties

PropertyTypeDescription
initializeconst
initializedconst
toolsListconst
toolsCallconst
toolsListChangedconst
pingconst

Released under the MIT License.