Helpers for building Model Context Protocol (MCP) envelopes. More...
Classes | |
| struct | sourcemeta::core::MCPToolAnnotations |
| struct | sourcemeta::core::MCPImplementation |
| struct | sourcemeta::core::MCPServerCapabilities |
Enumerations | |
| enum class | sourcemeta::core::MCPProtocolVersion : std::uint8_t { MCPProtocolVersion::V_2025_03_26 , MCPProtocolVersion::V_2025_06_18 , MCPProtocolVersion::V_2025_11_25 } |
Variables | |
| constexpr JSON::StringView | sourcemeta::core::MCP_METHOD_INITIALIZE {"initialize"} |
| constexpr JSON::StringView | sourcemeta::core::MCP_METHOD_PING {"ping"} |
| constexpr JSON::StringView | sourcemeta::core::MCP_METHOD_TOOLS_LIST {"tools/list"} |
| constexpr JSON::StringView | sourcemeta::core::MCP_METHOD_TOOLS_CALL {"tools/call"} |
| constexpr JSON::StringView | sourcemeta::core::MCP_METHOD_RESOURCES_LIST {"resources/list"} |
| constexpr JSON::StringView | sourcemeta::core::MCP_METHOD_RESOURCES_READ {"resources/read"} |
| constexpr JSON::StringView | sourcemeta::core::MCP_METHOD_RESOURCES_TEMPLATES_LIST |
| constexpr JSON::StringView | sourcemeta::core::MCP_METHOD_NOTIFICATIONS_INITIALIZED |
| constexpr std::int64_t | sourcemeta::core::MCP_CODE_RESOURCE_NOT_FOUND {-32002} |
| constexpr std::int64_t | sourcemeta::core::MCP_CODE_URL_ELICITATION_REQUIRED {-32042} |
Helpers for building Model Context Protocol (MCP) envelopes.
This functionality is included as follows:
| struct sourcemeta::core::MCPToolAnnotations |
Optional hints attached to an MCP tool descriptor.
Public Attributes | |
| JSON::StringView | title = {} |
| Optional human-readable title for the tool. | |
| bool | read_only = false |
| true when the tool guarantees no side effects. | |
| bool | destructive = true |
| true when the tool may mutate or delete state. | |
| bool | idempotent = false |
| bool | open_world = true |
| true when the tool interacts with state outside the server's control. | |
| bool sourcemeta::core::MCPToolAnnotations::idempotent = false |
true when repeated invocations with the same input yield the same result.
| struct sourcemeta::core::MCPImplementation |
Implementation info advertised by an MCP server during the initialize handshake.
Public Attributes | |
| JSON::StringView | name |
| Short machine-readable server name. | |
| JSON::StringView | version |
| Semver-compatible server version. | |
| JSON::StringView | title = {} |
| Optional human-readable title. | |
| JSON::StringView | description = {} |
| Optional human-readable description. | |
| JSON::StringView | website_url = {} |
| Optional public website URL. | |
| struct sourcemeta::core::MCPServerCapabilities |
Boolean toggles for the MCP capabilities object returned during the initialize handshake.
|
strong |
|
constexprnoexcept |
Check whether the given method name corresponds to an MCP request method (notifications excluded). For example:
| SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_error_resource_not_found | ( | const sourcemeta::core::JSON & | identifier | ) | -> sourcemeta::core::JSON |
Build a JSON-RPC error envelope reporting that an MCP resource URI could not be resolved. For example:
| SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_initialize_result | ( | const sourcemeta::core::JSON & | request, |
| const MCPServerCapabilities & | capabilities, | ||
| const MCPImplementation & | server, | ||
| const JSON::StringView | instructions = {} ) -> sourcemeta::core::JSON |
Build the JSON-RPC envelope returned in response to an MCP initialize request. For example:
| SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_resource | ( | const JSON::StringView | uri, |
| const JSON::StringView | name, | ||
| const JSON::StringView | mime_type, | ||
| const JSON::StringView | description = {}, | ||
| const std::optional< std::size_t > | size = std::nullopt, | ||
| const std::optional< double > | priority = std::nullopt ) -> sourcemeta::core::JSON |
Build an MCP resource descriptor as used in resources/list responses. For example:
| SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_resource_link | ( | const MCPProtocolVersion | version, |
| const JSON::StringView | uri, | ||
| const JSON::StringView | mime_type, | ||
| const JSON::StringView | name = {}, | ||
| const JSON::StringView | description = {} ) -> sourcemeta::core::JSON |
Build an MCP content block referencing a resource by URI. For example:
| SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_resource_template | ( | const JSON::StringView | uri_template, |
| const JSON::StringView | name, | ||
| const JSON::StringView | description, | ||
| const JSON::StringView | mime_type ) -> sourcemeta::core::JSON |
Build a single entry for an MCP resources/templates/list response. For example:
| SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_resource_text_content | ( | const JSON::StringView | uri, |
| const JSON::StringView | mime_type, | ||
| const JSON::StringView | text ) -> sourcemeta::core::JSON |
Build an MCP resources/read content entry of Text flavour. For example:
| SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_resources_read_result | ( | sourcemeta::core::JSON | contents | ) | -> sourcemeta::core::JSON |
Wrap a pre-built array of content entries into the MCP resources/read result envelope. For example:
| SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_text_block | ( | const JSON::StringView | text | ) | -> sourcemeta::core::JSON |
Build an MCP Text content block carrying the given text payload. For example:
| SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_tool_descriptor | ( | const MCPProtocolVersion | version, |
| const JSON::StringView | name, | ||
| const JSON::StringView | description, | ||
| sourcemeta::core::JSON | input_schema, | ||
| std::optional< sourcemeta::core::JSON > | output_schema = std::nullopt, | ||
| const MCPToolAnnotations & | annotations = {} ) -> sourcemeta::core::JSON |
Build a single entry for an MCP tools/list response. For example:
| SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_tool_error | ( | const sourcemeta::core::JSON & | identifier, |
| const JSON::StringView | message ) -> sourcemeta::core::JSON |
Build a JSON-RPC envelope wrapping a failed MCP tool call response with the given error message. For example:
| SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_tool_success | ( | const MCPProtocolVersion | version, |
| const sourcemeta::core::JSON & | identifier, | ||
| sourcemeta::core::JSON | result ) -> sourcemeta::core::JSON |
Build a JSON-RPC envelope wrapping a successful MCP tool call response from the given result payload. For example:
| SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_tool_success | ( | const MCPProtocolVersion | version, |
| const sourcemeta::core::JSON & | identifier, | ||
| sourcemeta::core::JSON | structured, | ||
| sourcemeta::core::JSON | content_blocks ) -> sourcemeta::core::JSON |
Build a JSON-RPC envelope wrapping a successful MCP tool call response from caller-provided content blocks and a structured payload. For example:
|
constexprnoexcept |
Get the canonical wire-format string for an MCP protocol version. For example:
|
constexprnoexcept |
Resolve an MCP-Protocol-Version header value into a known protocol version, or std::nullopt when the value is unrecognised. An absent header resolves to the oldest supported version per the Streamable HTTP transport. For example:
|
constexprnoexcept |
Whether the given protocol version supports the description field on the implementation info object.
|
constexprnoexcept |
Whether the given protocol version supports the title field on the implementation info object.
|
constexprnoexcept |
Whether the given protocol version supports the websiteUrl field on the implementation info object.
|
constexprnoexcept |
Whether the given protocol version supports JSON-RPC 2.0 batching.
|
constexprnoexcept |
Whether the given protocol version supports per-tool outputSchema.
|
constexprnoexcept |
Whether the given protocol version supports resource_link content blocks.
|
constexprnoexcept |
Whether the given protocol version supports structuredContent in tool results.
| SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_tool_call_arguments | ( | const sourcemeta::core::JSON & | envelope | ) | -> const sourcemeta::core::JSON * |
Borrow the arguments object from a JSON-RPC tools/call envelope, or return nullptr if no arguments object is present. The returned pointer is valid for the lifetime of the input envelope. For example:
|
constexpr |
The MCP error code returned when a requested resource cannot be found.
|
constexpr |
The MCP error code indicating that the client must complete a URL elicitation flow before retrying.
|
constexpr |
The MCP method name for the initialize request.
|
constexpr |
The MCP method name for the notifications/initialized notification.
|
constexpr |
The MCP method name for the ping request.
|
constexpr |
The MCP method name for the resources/list request.
|
constexpr |
The MCP method name for the resources/read request.
|
constexpr |
The MCP method name for the resources/templates/list request.
|
constexpr |
The MCP method name for the tools/call request.
|
constexpr |
The MCP method name for the tools/list request.