Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
MCP

Helpers for building Model Context Protocol (MCP) envelopes. More...

Classes

struct  sourcemeta::core::MCPImplementation
struct  sourcemeta::core::MCPClientCapabilities
struct  sourcemeta::core::MCPServerCapabilities
class  sourcemeta::core::MCPError
struct  sourcemeta::core::MCPRequestMeta
struct  sourcemeta::core::MCPHeaderParameter
struct  sourcemeta::core::MCPCachePolicy
struct  sourcemeta::core::MCPToolAnnotations
struct  sourcemeta::core::MCPResourceAnnotations
struct  sourcemeta::core::MCPDescriptorPresentation
struct  sourcemeta::core::MCPSubscriptionFilter

Enumerations

enum class  sourcemeta::core::MCPErrorContext : std::uint8_t { MCPErrorContext::Request , MCPErrorContext::Transport }
enum class  sourcemeta::core::MCPRequestMetaStatus : std::uint8_t {
  MCPRequestMetaStatus::Valid , MCPRequestMetaStatus::InvalidEnvelope , MCPRequestMetaStatus::InvalidMetaKey , MCPRequestMetaStatus::InvalidClientCapabilities ,
  MCPRequestMetaStatus::ClientInfoWebsiteUrlNotString , MCPRequestMetaStatus::InvalidClientInfo , MCPRequestMetaStatus::InvalidLogLevel , MCPRequestMetaStatus::InvalidProgressToken ,
  MCPRequestMetaStatus::MissingParams , MCPRequestMetaStatus::ParamsNotObject , MCPRequestMetaStatus::MissingMeta , MCPRequestMetaStatus::MetaNotObject ,
  MCPRequestMetaStatus::MissingProtocolVersion , MCPRequestMetaStatus::ProtocolVersionNotString , MCPRequestMetaStatus::UnsupportedProtocolVersion , MCPRequestMetaStatus::MissingClientCapabilities ,
  MCPRequestMetaStatus::ClientCapabilitiesNotObject , MCPRequestMetaStatus::ClientInfoNotObject , MCPRequestMetaStatus::MissingClientInfoName , MCPRequestMetaStatus::ClientInfoNameNotString ,
  MCPRequestMetaStatus::MissingClientInfoVersion , MCPRequestMetaStatus::ClientInfoVersionNotString , MCPRequestMetaStatus::ClientInfoTitleNotString , MCPRequestMetaStatus::ClientInfoDescriptionNotString
}
enum class  sourcemeta::core::MCPLogLevel : std::uint8_t {
  MCPLogLevel::Debug , MCPLogLevel::Info , MCPLogLevel::Notice , MCPLogLevel::Warning ,
  MCPLogLevel::Error , MCPLogLevel::Critical , MCPLogLevel::Alert , MCPLogLevel::Emergency
}
enum class  sourcemeta::core::MCPProtocolVersion : std::uint8_t { MCPProtocolVersion::V_2025_03_26 , MCPProtocolVersion::V_2025_06_18 , MCPProtocolVersion::V_2025_11_25 , MCPProtocolVersion::V_2026_07_28 }
enum class  sourcemeta::core::MCPCacheScope : std::uint8_t { MCPCacheScope::Public , MCPCacheScope::Private }

Functions

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_parse_client_capabilities (const MCPProtocolVersion version, const sourcemeta::core::JSON &capabilities) -> MCPClientCapabilities
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_serialize_client_capabilities (const MCPProtocolVersion version, const MCPClientCapabilities &capabilities) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_parse_server_capabilities (MCPProtocolVersion version, const JSON &capabilities) -> MCPServerCapabilities
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_serialize_server_capabilities (MCPProtocolVersion version, const MCPServerCapabilities &capabilities) -> JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_error (MCPProtocolVersion version, const JSON *identifier, std::int64_t code, JSON::StringView message, std::optional< JSON > data=std::nullopt, MCPErrorContext context=MCPErrorContext::Request) -> JSON
constexpr auto sourcemeta::core::mcp_error_code_to_http_status (const MCPProtocolVersion version, const std::int64_t code) noexcept -> std::optional< HTTPStatus >
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_error_unsupported_protocol_version (const MCPProtocolVersion version, const sourcemeta::core::JSON *identifier, const JSON::StringView requested, const std::span< const JSON::StringView > supported) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_error_missing_required_capability (const MCPProtocolVersion version, const sourcemeta::core::JSON *identifier, sourcemeta::core::JSON required_capabilities, const JSON::StringView message) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_error_header_mismatch (const MCPProtocolVersion version, const sourcemeta::core::JSON *identifier, const JSON::StringView message) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_error_header_mismatch (const MCPProtocolVersion version, const sourcemeta::core::JSON *identifier, const JSON::StringView header_name, const JSON::StringView header_value, const JSON::StringView body_value) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_error_header_mismatch (const MCPProtocolVersion version, const sourcemeta::core::JSON *identifier, const JSON::StringView header_name, const JSON::StringView header_value) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_error_resource_not_found (const MCPProtocolVersion version, const sourcemeta::core::JSON *identifier) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_validate_request_meta (const sourcemeta::core::JSON &envelope) -> std::pair< MCPRequestMetaStatus, std::optional< MCPRequestMeta > >
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_validate_request_parameters (const JSON &parameters) -> std::pair< MCPRequestMetaStatus, std::optional< MCPRequestMeta > >
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_error_request_meta (const MCPProtocolVersion version, const sourcemeta::core::JSON *identifier, const MCPRequestMetaStatus status, const JSON::StringView requested, const std::span< const JSON::StringView > supported) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_request_name_from_body (const sourcemeta::core::JSON &envelope) -> std::optional< JSON::StringView >
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_validate_request_headers (const MCPProtocolVersion version, const std::optional< JSON::StringView > &protocol_version_header, const std::optional< JSON::StringView > &method_header, const std::optional< JSON::StringView > &name_header, const sourcemeta::core::JSON &envelope, const std::span< const JSON::StringView > supported_versions) -> std::optional< sourcemeta::core::JSON >
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_encode_header_value (JSON::StringView value) -> std::string
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_validate_request_headers (MCPProtocolVersion version, std::span< const std::pair< JSON::StringView, JSON::StringView > > headers, const JSON &envelope, std::span< const JSON::StringView > supported_versions) -> std::optional< JSON >
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_parameter_headers (std::span< const MCPHeaderParameter > parameters, const JSON &arguments) -> std::vector< std::pair< std::string, std::string > >
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_validate_parameter_headers (MCPProtocolVersion version, const JSON &identifier, std::span< const MCPHeaderParameter > parameters, const JSON &arguments, std::span< const std::pair< JSON::StringView, JSON::StringView > > headers) -> std::optional< JSON >
constexpr auto sourcemeta::core::mcp_log_level_string (const MCPLogLevel level) noexcept -> JSON::StringView
constexpr auto sourcemeta::core::mcp_resolve_log_level (const JSON::StringView value) noexcept -> std::optional< MCPLogLevel >
constexpr auto sourcemeta::core::mcp_log_level_enabled (const MCPLogLevel level, const MCPLogLevel threshold) noexcept -> bool
constexpr auto sourcemeta::core::mcp_protocol_version_string (const MCPProtocolVersion version) noexcept -> JSON::StringView
constexpr auto sourcemeta::core::mcp_resolve_protocol_version (const JSON::StringView value) noexcept -> std::optional< MCPProtocolVersion >
constexpr auto sourcemeta::core::mcp_protocol_version_at_least (const MCPProtocolVersion current, const MCPProtocolVersion minimum) noexcept -> bool
constexpr auto sourcemeta::core::mcp_protocol_version_is_valid (const JSON::StringView value) noexcept -> bool
constexpr auto sourcemeta::core::mcp_uses_initialization_handshake (const MCPProtocolVersion version) noexcept -> bool
constexpr auto sourcemeta::core::mcp_supports_ping (const MCPProtocolVersion version) noexcept -> bool
constexpr auto sourcemeta::core::mcp_requires_request_meta (const MCPProtocolVersion version) noexcept -> bool
constexpr auto sourcemeta::core::mcp_requires_result_type (const MCPProtocolVersion version) noexcept -> bool
constexpr auto sourcemeta::core::mcp_requires_cacheable_metadata (const MCPProtocolVersion version) noexcept -> bool
constexpr auto sourcemeta::core::mcp_supports_server_discover (const MCPProtocolVersion version) noexcept -> bool
constexpr auto sourcemeta::core::mcp_supports_subscriptions_listen (const MCPProtocolVersion version) noexcept -> bool
constexpr auto sourcemeta::core::mcp_supports_mrtr (const MCPProtocolVersion version) noexcept -> bool
constexpr auto sourcemeta::core::mcp_supports_protocol_sessions (const MCPProtocolVersion version) noexcept -> bool
constexpr auto sourcemeta::core::mcp_supports_output_schema (const MCPProtocolVersion version) noexcept -> bool
constexpr auto sourcemeta::core::mcp_supports_structured_content (const MCPProtocolVersion version) noexcept -> bool
constexpr auto sourcemeta::core::mcp_supports_resource_link_content (const MCPProtocolVersion version) noexcept -> bool
constexpr auto sourcemeta::core::mcp_supports_implementation_title (const MCPProtocolVersion version) noexcept -> bool
constexpr auto sourcemeta::core::mcp_supports_implementation_description (const MCPProtocolVersion version) noexcept -> bool
constexpr auto sourcemeta::core::mcp_supports_implementation_website_url (const MCPProtocolVersion version) noexcept -> bool
constexpr auto sourcemeta::core::mcp_supports_jsonrpc_batching (const MCPProtocolVersion version) noexcept -> bool
constexpr auto sourcemeta::core::mcp_is_request_method (const MCPProtocolVersion version, const JSON::StringView method) noexcept -> bool
constexpr auto sourcemeta::core::mcp_is_server_request_method (const MCPProtocolVersion version, const JSON::StringView method) noexcept -> bool
constexpr auto sourcemeta::core::mcp_is_notification_method (const MCPProtocolVersion version, const JSON::StringView method) noexcept -> bool
constexpr auto sourcemeta::core::mcp_is_input_request_method (const MCPProtocolVersion version, const JSON::StringView method) noexcept -> bool
constexpr auto sourcemeta::core::mcp_supports_method (const MCPProtocolVersion version, const JSON::StringView method) noexcept -> bool
constexpr auto sourcemeta::core::mcp_is_mrtr_method (const JSON::StringView method) noexcept -> bool
constexpr auto sourcemeta::core::mcp_is_cacheable_method (const JSON::StringView method) noexcept -> bool
constexpr auto sourcemeta::core::mcp_is_client_notification_method (MCPProtocolVersion version, JSON::StringView method) noexcept -> bool
constexpr auto sourcemeta::core::mcp_is_server_notification_method (MCPProtocolVersion version, JSON::StringView method) noexcept -> bool
constexpr auto sourcemeta::core::mcp_cache_scope_string (const MCPCacheScope scope) noexcept -> JSON::StringView
constexpr auto sourcemeta::core::mcp_resolve_cache_scope (const JSON::StringView scope) noexcept -> std::optional< MCPCacheScope >
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_serialize_resource_annotations (MCPProtocolVersion version, const MCPResourceAnnotations &annotations) -> JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_image_block (MCPProtocolVersion version, JSON::StringView data, JSON::StringView mime_type, const MCPResourceAnnotations &annotations={}) -> JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_audio_block (MCPProtocolVersion version, JSON::StringView data, JSON::StringView mime_type, const MCPResourceAnnotations &annotations={}) -> JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_embedded_resource (MCPProtocolVersion version, JSON resource, const MCPResourceAnnotations &annotations={}) -> JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_resource_blob_content (JSON::StringView uri, JSON::StringView mime_type, JSON::StringView blob) -> JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_text_block (const JSON::StringView text) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_resource_link (const MCPProtocolVersion version, const JSON::StringView uri, const JSON::StringView name, const JSON::StringView mime_type={}, const JSON::StringView description={}) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_decorate_result (const MCPProtocolVersion version, sourcemeta::core::JSON result, const std::optional< MCPImplementation > &server_info=std::nullopt) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_decorate_cacheable_result (const MCPProtocolVersion version, sourcemeta::core::JSON result, const MCPCachePolicy &cache_policy, const JSON::StringView method) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_empty_response (const MCPProtocolVersion version, const sourcemeta::core::JSON &identifier, const std::optional< MCPImplementation > &server_info=std::nullopt) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_tool_success (const MCPProtocolVersion version, const sourcemeta::core::JSON &identifier, sourcemeta::core::JSON result, const std::optional< MCPImplementation > &server_info=std::nullopt) -> sourcemeta::core::JSON
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, const std::optional< MCPImplementation > &server_info=std::nullopt) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_tool_error (const MCPProtocolVersion version, const sourcemeta::core::JSON &identifier, const JSON::StringView message, const std::optional< MCPImplementation > &server_info=std::nullopt) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_resource (const MCPProtocolVersion version, 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, const MCPDescriptorPresentation &presentation={}, const MCPResourceAnnotations &annotations={}) -> sourcemeta::core::JSON
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
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_resources_read_result (const MCPProtocolVersion version, sourcemeta::core::JSON contents, const MCPCachePolicy &cache_policy) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_resource_template (const MCPProtocolVersion version, const JSON::StringView uri_template, const JSON::StringView name, const JSON::StringView description, const JSON::StringView mime_type, const MCPDescriptorPresentation &presentation={}, const MCPResourceAnnotations &annotations={}) -> sourcemeta::core::JSON
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={}, const MCPDescriptorPresentation &presentation={}) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_tools_list_result (const MCPProtocolVersion version, sourcemeta::core::JSON tools, const std::optional< JSON::StringView > next_cursor, const MCPCachePolicy &cache_policy) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_resources_list_result (const MCPProtocolVersion version, sourcemeta::core::JSON resources, const std::optional< JSON::StringView > next_cursor, const MCPCachePolicy &cache_policy) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_resource_templates_list_result (const MCPProtocolVersion version, sourcemeta::core::JSON resource_templates, const std::optional< JSON::StringView > next_cursor, const MCPCachePolicy &cache_policy) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_prompts_list_result (const MCPProtocolVersion version, sourcemeta::core::JSON prompts, const std::optional< JSON::StringView > next_cursor, const MCPCachePolicy &cache_policy) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_prompts_get_result (MCPProtocolVersion version, JSON::StringView description, JSON messages) -> JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_completion_result (MCPProtocolVersion version, JSON values, std::optional< std::int64_t > total, std::optional< bool > has_more) -> JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_write_result (std::ostream &stream, MCPProtocolVersion version, JSON::StringView method, const JSON &identifier, const JSON &result, std::optional< MCPCachePolicy > cache_policy, std::optional< MCPImplementation > server_info=std::nullopt) -> void
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_write_result (std::ostream &stream, MCPProtocolVersion version, JSON::StringView method, const JSON &identifier, JSON &&result, std::optional< MCPCachePolicy > cache_policy, std::optional< MCPImplementation > server_info=std::nullopt) -> void
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_initialize_response (const sourcemeta::core::JSON &request, const MCPServerCapabilities &capabilities, const MCPImplementation &server, const std::span< const JSON::StringView > supported_versions, const JSON::StringView instructions={}) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_server_discover_response (const MCPProtocolVersion version, const sourcemeta::core::JSON &identifier, const MCPServerCapabilities &capabilities, const MCPImplementation &server, const std::span< const JSON::StringView > supported_versions, const JSON::StringView instructions, const MCPCachePolicy &cache_policy) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_input_required_response (const MCPProtocolVersion version, const JSON::StringView method, const sourcemeta::core::JSON &identifier, std::optional< sourcemeta::core::JSON > input_requests, std::optional< JSON::StringView > request_state, const MCPClientCapabilities &client_capabilities, const std::optional< MCPImplementation > &server_info=std::nullopt) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_request_input_responses (MCPProtocolVersion version, const sourcemeta::core::JSON &envelope) -> const sourcemeta::core::JSON *
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_request_state (MCPProtocolVersion version, const sourcemeta::core::JSON &envelope) -> std::optional< JSON::StringView >
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_parse_subscription_filter (MCPProtocolVersion version, const JSON &parameters) -> std::optional< MCPSubscriptionFilter >
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_intersect_subscription_filters (const MCPSubscriptionFilter &requested, const MCPSubscriptionFilter &supported) -> MCPSubscriptionFilter
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_result_type (const JSON &result) -> std::optional< JSON::StringView >
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_resolve_result_type (MCPProtocolVersion version, const JSON &result, std::span< const JSON::StringView > supported_extension_types={}) -> std::optional< JSON::StringView >
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_validate_continuation (MCPProtocolVersion version, const JSON &parameters, const JSON &input_requests) -> bool
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_validate_continuation (MCPProtocolVersion version, const JSON &parameters, const JSON &input_requests, std::optional< JSON::StringView > expected_state) -> bool
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_notification (MCPProtocolVersion version, bool from_server, JSON::StringView method, JSON parameters, std::optional< JSON > subscription_id, const MCPSubscriptionFilter *acknowledged=nullptr, const MCPRequestMeta *request_context=nullptr) -> JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_subscription_acknowledged_notification (const MCPProtocolVersion version, const sourcemeta::core::JSON &subscription_id, const MCPSubscriptionFilter &requested, const MCPSubscriptionFilter &supported) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_subscription_acknowledged_notification (const MCPProtocolVersion version, const JSON::StringView subscription_id, const MCPSubscriptionFilter &requested, const MCPSubscriptionFilter &supported) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_subscription_close_response (const MCPProtocolVersion version, const sourcemeta::core::JSON &identifier, const std::optional< MCPImplementation > &server_info=std::nullopt) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_request_subscription_id (MCPProtocolVersion version, const sourcemeta::core::JSON &envelope) -> const sourcemeta::core::JSON *
SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_tool_call_arguments (const sourcemeta::core::JSON &envelope) -> const sourcemeta::core::JSON *

Variables

constexpr std::int64_t sourcemeta::core::MCP_CODE_RESOURCE_NOT_FOUND {-32002}
constexpr std::int64_t sourcemeta::core::MCP_CODE_URL_ELICITATION_REQUIRED {-32042}
constexpr std::int64_t sourcemeta::core::MCP_CODE_HEADER_MISMATCH {-32020}
constexpr std::int64_t sourcemeta::core::MCP_CODE_MISSING_REQUIRED_CLIENT_CAPABILITY {-32021}
constexpr std::int64_t sourcemeta::core::MCP_CODE_UNSUPPORTED_PROTOCOL_VERSION {-32022}
constexpr JSON::StringView sourcemeta::core::MCP_HEADER_PROTOCOL_VERSION {"MCP-Protocol-Version"}
constexpr JSON::StringView sourcemeta::core::MCP_HEADER_METHOD {"Mcp-Method"}
constexpr JSON::StringView sourcemeta::core::MCP_HEADER_NAME {"Mcp-Name"}
constexpr JSON::StringView sourcemeta::core::MCP_PROTOCOL_VERSION_2025_03_26 {"2025-03-26"}
constexpr JSON::StringView sourcemeta::core::MCP_PROTOCOL_VERSION_2025_06_18 {"2025-06-18"}
constexpr JSON::StringView sourcemeta::core::MCP_PROTOCOL_VERSION_2025_11_25 {"2025-11-25"}
constexpr JSON::StringView sourcemeta::core::MCP_PROTOCOL_VERSION_2026_07_28 {"2026-07-28"}
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_INITIALIZE {"initialize"}
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_NOTIFICATIONS_INITIALIZED
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_PING {"ping"}
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_SERVER_DISCOVER {"server/discover"}
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_SUBSCRIPTIONS_LISTEN
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_NOTIFICATIONS_SUBSCRIPTIONS_ACKNOWLEDGED
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_SUBSCRIBE
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_RESOURCES_UNSUBSCRIBE
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_RESOURCES_TEMPLATES_LIST
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_PROMPTS_LIST {"prompts/list"}
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_PROMPTS_GET {"prompts/get"}
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_COMPLETION_COMPLETE
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_LOGGING_SET_LEVEL {"logging/setLevel"}
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_NOTIFICATIONS_CANCELLED
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_NOTIFICATIONS_MESSAGE
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_NOTIFICATIONS_PROGRESS
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_NOTIFICATIONS_PROMPTS_LIST_CHANGED
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_NOTIFICATIONS_RESOURCES_LIST_CHANGED
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_NOTIFICATIONS_RESOURCES_UPDATED
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_NOTIFICATIONS_TOOLS_LIST_CHANGED
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_ROOTS_LIST {"roots/list"}
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_SAMPLING_CREATE_MESSAGE
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_ELICITATION_CREATE {"elicitation/create"}
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_NOTIFICATIONS_ELICITATION_COMPLETE
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_NOTIFICATIONS_ROOTS_LIST_CHANGED
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_NOTIFICATIONS_TASKS_STATUS
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_TASKS_CANCEL {"tasks/cancel"}
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_TASKS_GET {"tasks/get"}
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_TASKS_LIST {"tasks/list"}
constexpr JSON::StringView sourcemeta::core::MCP_METHOD_TASKS_RESULT {"tasks/result"}

Detailed Description

Helpers for building Model Context Protocol (MCP) envelopes.

This functionality is included as follows:

#include <sourcemeta/core/mcp.h>
Deployment boundaries
Enforce transport byte limits, decompression budgets and timeouts in the application. MCP envelope validation does not limit the memory or time already spent receiving and parsing a message. After parsing, sourcemeta::core::mcp_validate_request_meta checks envelope metadata, not the caller's identity or application authorization.

Authenticate the caller and authorize each resource before opening a file or making a network request. URI validation and sourcemeta::core::mcp_make_resource do not grant resource-access permission.

sourcemeta::core::mcp_validate_continuation checks protocol fields and, optionally, an exact state-token echo. The application must protect state integrity, bind it to the caller and operation, and enforce expiry and replay policy. These are application controls, not additional requirements imposed by Core's MCP validators. Multiple workers need shared atomic state consumption.


Class Documentation

◆ sourcemeta::core::MCPImplementation

struct sourcemeta::core::MCPImplementation

Information about an MCP implementation (client or server). Every string is a borrowed view and the icons array is a borrowed pointer, so the referents must outlive any builder this is passed to. For example:

#include <sourcemeta/core/mcp.h>
#include <array>
#include <cassert>
constexpr std::array<sourcemeta::core::JSON::StringView, 1> SUPPORTED{
{"2025-11-25"}};
const auto request{sourcemeta::core::parse_json(R"JSON({
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2025-11-25",
"capabilities": {},
"clientInfo": { "name": "client", "version": "1" }
}
})JSON")};
const sourcemeta::core::MCPImplementation server{.name = "srv",
.version = "1.0.0"};
request, sourcemeta::core::MCPServerCapabilities{}, server,
SUPPORTED) == sourcemeta::core::parse_json(R"JSON({
"jsonrpc": "2.0",
"id": 1,
"result": {
"protocolVersion": "2025-11-25",
"capabilities": {},
"serverInfo": { "name": "srv", "version": "1.0.0" }
}
})JSON"));
SOURCEMETA_CORE_JSON_EXPORT auto parse_json(std::basic_istream< JSON::Char, JSON::CharTraits > &stream, std::uint32_t maximum_input_bytes=JSON_MAXIMUM_INPUT_BYTES) -> JSON
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_initialize_response(const sourcemeta::core::JSON &request, const MCPServerCapabilities &capabilities, const MCPImplementation &server, const std::span< const JSON::StringView > supported_versions, const JSON::StringView instructions={}) -> sourcemeta::core::JSON
Definition mcp_capabilities.h:54
See also
https://modelcontextprotocol.io/specification/2025-11-25/schema#implementation

Public Attributes

JSON::StringView name
 Implementation identifier name.
JSON::StringView version
 Implementation version (not required to be SemVer).
JSON::StringView title = {}
 Optional human-readable title.
JSON::StringView description = {}
 Optional human-readable description.
JSON::StringView website_url = {}
 Optional public website URL.
const JSON * icons = nullptr
 Optional borrowed array of icons (2025-11-25 and later).

◆ sourcemeta::core::MCPClientCapabilities

struct sourcemeta::core::MCPClientCapabilities

Capabilities advertised by an MCP client. The typed flags describe the capabilities this library understands, while the snapshot retains whatever else the peer sent so that a parse followed by a serialize does not discard it.

Roots and sampling are deprecated as of protocol version 2026-07-28, which states that new implementations should not adopt them. They remain representable here because the library still speaks the revisions that define them.

See also
https://modelcontextprotocol.io/specification/2026-07-28/deprecated https://modelcontextprotocol.io/specification/2026-07-28/basic/index#_meta https://modelcontextprotocol.io/specification/2026-07-28/schema#clientcapabilities

Public Attributes

bool roots = false
 Whether the client advertises roots.
bool roots_list_changed = false
 Whether roots advertise listChanged (legacy revisions only).
bool sampling = false
 Whether the client advertises sampling.
bool sampling_context = false
bool sampling_tools = false
 Whether sampling advertises tools support.
bool elicitation = false
 Whether the client advertises elicitation.
bool elicitation_form = false
 Whether elicitation advertises form support.
bool elicitation_url = false
 Whether elicitation advertises url support.
std::optional< sourcemeta::core::JSON > extensions = std::nullopt
 Optional extensions map for client capabilities.
std::optional< sourcemeta::core::JSON > experimental = std::nullopt
 Optional experimental map for client capabilities.
std::optional< JSON > source = std::nullopt

Member Data Documentation

◆ sampling_context

bool sourcemeta::core::MCPClientCapabilities::sampling_context = false

Whether sampling advertises context support. Declaring it is what permits a server to ask for context from the requesting server or from all of them. Those two request values were deprecated in 2025-11-25, which asks a server to avoid them and not to use them at all unless a client declares this capability. The capability itself is not deprecated.

◆ source

std::optional<JSON> sourcemeta::core::MCPClientCapabilities::source = std::nullopt

Optional owned source preserving the parsed capability settings. Keeps extension settings, unknown capabilities and 2025-11-25 task data. Typed flags and optional maps override this snapshot when serializing. The per-request metadata view does not allocate or populate this snapshot.

◆ sourcemeta::core::MCPServerCapabilities

struct sourcemeta::core::MCPServerCapabilities

Public Attributes

bool prompts = false
 Whether the server advertises prompts.
bool resources = false
 Whether the server advertises resources.
bool tools = false
 Whether the server advertises tools.
bool logging = false
 Whether the server advertises logging.
bool completions = false
 Whether the server advertises completions.
bool tools_list_changed = false
 Whether tools advertise listChanged.
bool resources_subscribe = false
 Whether resources advertise subscribe.
bool resources_list_changed = false
 Whether resources advertise listChanged.
bool prompts_list_changed = false
 Whether prompts advertise listChanged.
std::optional< sourcemeta::core::JSON > extensions = std::nullopt
 Optional extensions map for capabilities.
std::optional< sourcemeta::core::JSON > experimental = std::nullopt
 Optional experimental map for capabilities.
std::optional< JSON > source = std::nullopt

Member Data Documentation

◆ source

std::optional<JSON> sourcemeta::core::MCPServerCapabilities::source = std::nullopt

Owned source preserving unknown capabilities, settings and legacy tasks. Typed flags and optional maps override their corresponding source fields.

◆ sourcemeta::core::MCPError

class sourcemeta::core::MCPError

An error that represents a violation of an MCP contract, such as building a result for a revision that does not define it, or supplying a descriptor the specification rejects. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
#include <string>
try {
// Resource links arrived in 2025-06-18
assert(false);
} catch (const sourcemeta::core::MCPError &error) {
assert(error.what() ==
std::string{"Resource links require MCP 2025-06-18 or later"});
}
Definition mcp_error.h:42
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_resource_link(const MCPProtocolVersion version, const JSON::StringView uri, const JSON::StringView name, const JSON::StringView mime_type={}, const JSON::StringView description={}) -> sourcemeta::core::JSON
@ V_2025_03_26
Protocol revision 2025-03-26.
Definition mcp_protocol.h:32
Inheritance diagram for sourcemeta::core::MCPError:
sourcemeta::core::Error

Public Member Functions

 MCPError (const StaticString message) noexcept
 Construct an error with a descriptive message.
Public Member Functions inherited from sourcemeta::core::Error
auto message () const noexcept -> StaticString

Additional Inherited Members

Protected Member Functions inherited from sourcemeta::core::Error
 Error (const StaticString message) noexcept
 Construct the error given its message.

◆ sourcemeta::core::MCPRequestMeta

struct sourcemeta::core::MCPRequestMeta

Parsed representation of 2026-07-28 request metadata. The protocol revision is a value, while the capabilities, implementation, log level, metadata object and progress token all reference the validated request, so the request must outlive this view.

See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/index#_meta

Public Attributes

MCPProtocolVersion protocol_version
 The declared protocol revision.
const JSON & client_capabilities
 Borrowed capabilities. The source request must outlive this view.
std::optional< MCPImplementation > client_info
 Optional borrowed implementation description.
std::optional< JSON::StringView > log_level
 Optional requested log level.
const JSON & meta_object
 Borrowed metadata. Never null after successful validation.
const JSON * progress_token = nullptr
 Optional borrowed progress token.

◆ sourcemeta::core::MCPHeaderParameter

struct sourcemeta::core::MCPHeaderParameter

A caller-provided parameter header descriptor. String views borrow the name and property path supplied by the caller. The path names the chain of properties reaching the mirrored value from the arguments root, and the type is restricted to the three primitives the specification permits.

A server declares these mirrors as annotations inside a tool's input schema, and deriving descriptors from that schema is the caller's job rather than this module's, because it means interpreting a schema. In particular the caller owns the rule that an annotation counts only where the property is reachable from the schema root through a chain of property keys alone, never through an array, composition, conditional or reference keyword, and that a tool whose annotation sits anywhere else is rejected and excluded from the tool listing.

Given descriptors, this module enforces the remaining constraints on them: each name is a non-empty HTTP token, which also rules out control characters, the names are case-insensitively unique, only the three primitive types are mirrored, and an integer value stays within the range a double can represent exactly.

See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http#schema-extension https://modelcontextprotocol.io/specification/2026-07-28/server/tools#x-mcp-header

Public Attributes

JSON::StringView name
 The suffix of Mcp-Param-{name}.
std::vector< JSON::StringView > path
 Instance property path, with no array or reference traversal.
JSON::Type type
 One of String, Integer or Boolean.

◆ sourcemeta::core::MCPCachePolicy

struct sourcemeta::core::MCPCachePolicy

Cache policy specifying TTL in milliseconds and scope for cacheable MCP results. Both fields are required for cacheable operations in MCP 2026-07-28.

See also
https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/caching#cacheable-results

Public Attributes

std::int64_t ttl_ms = 0
MCPCacheScope scope = MCPCacheScope::Private
 Cache scope (public or private).

Member Data Documentation

◆ ttl_ms

std::int64_t sourcemeta::core::MCPCachePolicy::ttl_ms = 0

Time-to-live in milliseconds. The schema bounds this below by zero, so a negative value is refused rather than folded to zero.

See also
https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/caching#cacheable-results

◆ sourcemeta::core::MCPToolAnnotations

struct sourcemeta::core::MCPToolAnnotations

Optional hints attached to an MCP tool descriptor. The defaults are the conservative reading the specification assigns to a hint a server does not state, so a descriptor built without them claims nothing favourable about the tool.

See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#toolannotations

Public Attributes

JSON::StringView title = {}
 Optional human-readable title for the tool.
bool read_only = false
 true as an advisory hint that the tool does not modify its environment.
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.

Member Data Documentation

◆ idempotent

bool sourcemeta::core::MCPToolAnnotations::idempotent = false

true when repeated invocations with the same arguments have no additional effect on the environment.

◆ sourcemeta::core::MCPResourceAnnotations

struct sourcemeta::core::MCPResourceAnnotations

Advisory resource/content annotations. String and audience views are borrowed, so their referents must outlive any builder this is passed to.

See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#annotations

Public Attributes

std::optional< std::span< const JSON::StringView > > audience = std::nullopt
 Optional audience roles ("user" and/or "assistant"). Empty stays explicit.
std::optional< double > priority = std::nullopt
JSON::StringView last_modified = {}
 Optional timestamp string. The caller supplies a valid ISO 8601 timestamp.

Member Data Documentation

◆ priority

std::optional<double> sourcemeta::core::MCPResourceAnnotations::priority = std::nullopt

Optional priority. The schema bounds this between zero and one, so a value outside them is refused rather than folded in.

See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#annotations

◆ sourcemeta::core::MCPDescriptorPresentation

struct sourcemeta::core::MCPDescriptorPresentation

Optional presentation fields shared by descriptors. All views borrow data. A field the target revision does not define is dropped rather than reported.

See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#tool-title https://modelcontextprotocol.io/specification/2026-07-28/schema#tool-icons

Public Attributes

JSON::StringView title = {}
 Human-readable title (2025-06-18 and later).
const JSON * icons = nullptr
 Optional icon array (2025-11-25 and later).

◆ sourcemeta::core::MCPSubscriptionFilter

struct sourcemeta::core::MCPSubscriptionFilter

Opt-in filters for a 2026-07-28 subscription. Explicit false values are preserved. An absent value is not requested. Resource URI views are borrowed, so the parsed parameters must outlive the filter.

See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/subscriptions

Public Attributes

std::optional< bool > tools_list_changed = std::nullopt
 Opt in to notifications that the tool list changed.
std::optional< bool > prompts_list_changed = std::nullopt
 Opt in to notifications that the prompt list changed.
std::optional< bool > resources_list_changed = std::nullopt
 Opt in to notifications that the resource list changed.
std::optional< std::vector< JSON::StringView > > resource_subscriptions

Member Data Documentation

◆ resource_subscriptions

std::optional<std::vector<JSON::StringView> > sourcemeta::core::MCPSubscriptionFilter::resource_subscriptions
Initial value:
=
std::nullopt

Borrowed resource URIs whose updates are requested. An absent list requests no subscriptions, while an explicit empty list stays explicit.

Enumeration Type Documentation

◆ MCPCacheScope

enum class sourcemeta::core::MCPCacheScope : std::uint8_t
strong

Cache scope for 2026-07-28 cacheable MCP results.

See also
https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/caching#cacheable-results
Enumerator
Public 

Public caching is permissible across multiple clients/users.

Private 

Result is private and must only be reused within the same authorization context.

◆ MCPErrorContext

enum class sourcemeta::core::MCPErrorContext : std::uint8_t
strong

Context for errors with no readable MCP request identifier. The two legacy revisions require an error response to echo a readable identifier, which a transport-level rejection cannot always produce, so the context selects whether that requirement is enforced.

See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http
Enumerator
Request 

A normal request response. Older schemas require a readable identifier.

Transport 

An HTTP transport rejection. Notifications use an id-less response; unreadable legacy requests use JSON-RPC's null-ID transport fallback, which cannot satisfy the 2025-03-26/2025-06-18 MCP error schemas.

◆ MCPLogLevel

enum class sourcemeta::core::MCPLogLevel : std::uint8_t
strong

Syslog severity levels, ordered from least to most severe. A request's logging threshold admits its own level and all more severe levels. The enumerator order is the severity order, so the levels compare directly.

This feature is deprecated as of protocol version 2026-07-28, which states that new implementations should not adopt it and that existing implementations should migrate to standard error output for the stdio transport, or to a general-purpose observability framework.

See also
https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/logging https://modelcontextprotocol.io/specification/2026-07-28/deprecated
Enumerator
Debug 

Detailed information useful for debugging.

Info 

General informational messages.

Notice 

Normal but significant conditions.

Warning 

Conditions that may require attention.

Error 

Error conditions.

Critical 

Critical conditions.

Alert 

Conditions requiring immediate action.

Emergency 

Conditions indicating that the system is unusable.

◆ MCPProtocolVersion

enum class sourcemeta::core::MCPProtocolVersion : std::uint8_t
strong

The supported MCP protocol revisions.

MCP 2026-07-28 is a major architectural redesign replacing stateful initialization with stateless, per-request capability negotiation, removing initialize, ping, and logging/setLevel, and introducing server/discover, subscriptions/listen, explicit result types, and caching policies.

Supported legacy revisions (2025-03-26 through 2025-11-25) use connection-scoped initialization handshakes and stateful protocol sessions.

See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/index#_meta
Enumerator
V_2025_03_26 

Protocol revision 2025-03-26.

V_2025_06_18 

Protocol revision 2025-06-18.

V_2025_11_25 

The initialization-handshake revision 2025-11-25.

V_2026_07_28 

The stateless, per-request capability negotiation revision (2026-07-28).

◆ MCPRequestMetaStatus

enum class sourcemeta::core::MCPRequestMetaStatus : std::uint8_t
strong

Validation status returned by mcp_validate_request_meta.

Enumerator
Valid 

The request metadata is fully valid.

InvalidEnvelope 

The input is not a valid MCP request envelope.

InvalidMetaKey 

Metadata contains an invalid key name or malformed tracing value.

InvalidClientCapabilities 

Known client capability fields have invalid shapes.

ClientInfoWebsiteUrlNotString 

Client websiteUrl must be a string.

InvalidClientInfo 

Implementation icons have invalid shapes.

InvalidLogLevel 

logLevel must be one of the eight specified logging levels.

InvalidProgressToken 

progressToken must be a string or integer.

MissingParams 

Request envelope lacks a params property.

ParamsNotObject 

The params property is not a JSON object.

MissingMeta 

The params object lacks a _meta property.

MetaNotObject 

The _meta property is not a JSON object.

MissingProtocolVersion 

_meta lacks io.modelcontextprotocol/protocolVersion.

ProtocolVersionNotString 

io.modelcontextprotocol/protocolVersion is not a string.

UnsupportedProtocolVersion 

io.modelcontextprotocol/protocolVersion is not a recognized version.

MissingClientCapabilities 

_meta lacks io.modelcontextprotocol/clientCapabilities.

ClientCapabilitiesNotObject 

io.modelcontextprotocol/clientCapabilities is not a JSON object.

ClientInfoNotObject 

io.modelcontextprotocol/clientInfo is not a JSON object.

MissingClientInfoName 

io.modelcontextprotocol/clientInfo lacks required name property.

ClientInfoNameNotString 

name property in io.modelcontextprotocol/clientInfo is not a string.

MissingClientInfoVersion 

io.modelcontextprotocol/clientInfo lacks required version property.

ClientInfoVersionNotString 

version property in io.modelcontextprotocol/clientInfo is not a string.

ClientInfoTitleNotString 

title property in io.modelcontextprotocol/clientInfo is not a string.

ClientInfoDescriptionNotString 

description property in io.modelcontextprotocol/clientInfo is not a string.

Function Documentation

◆ mcp_cache_scope_string()

auto sourcemeta::core::mcp_cache_scope_string ( const MCPCacheScope scope) -> JSON::StringView
nodiscardconstexprnoexcept

Canonical string conversion for cache scope. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_cache_scope_string(const MCPCacheScope scope) noexcept -> JSON::StringView
Definition mcp_results.h:49
@ Public
Public caching is permissible across multiple clients/users.
Definition mcp_results.h:30
@ Private
Definition mcp_results.h:33

◆ mcp_decorate_cacheable_result()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_decorate_cacheable_result ( const MCPProtocolVersion version,
sourcemeta::core::JSON result,
const MCPCachePolicy & cache_policy,
const JSON::StringView method ) -> sourcemeta::core::JSON
nodiscard

Decorate an MCP result object with cache metadata (ttlMs and cacheScope) for 2026-07-28. Takes and returns a bare result object. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
{.ttl_ms = 5000,
"resultType": "complete",
"ttlMs": 5000,
"cacheScope": "private"
})JSON"));
static auto make_object() -> JSON
constexpr JSON::StringView MCP_METHOD_TOOLS_LIST
Definition mcp_protocol.h:112
SOURCEMETA_CORE_MCP_EXPORT auto mcp_decorate_cacheable_result(const MCPProtocolVersion version, sourcemeta::core::JSON result, const MCPCachePolicy &cache_policy, const JSON::StringView method) -> sourcemeta::core::JSON
@ V_2026_07_28
The stateless, per-request capability negotiation revision (2026-07-28).
Definition mcp_protocol.h:38
See also
https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/caching#cacheable-results

◆ mcp_decorate_result()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_decorate_result ( const MCPProtocolVersion version,
sourcemeta::core::JSON result,
const std::optional< MCPImplementation > & server_info = std::nullopt ) -> sourcemeta::core::JSON
nodiscard

Decorate a successful MCP result object with version-appropriate envelope fields (resultType: "complete" and optional _meta.io.modelcontextprotocol/serverInfo for 2026-07-28). Takes and returns a bare result object, so an earlier revision leaves it unchanged. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
sourcemeta::core::parse_json(R"JSON({ "status": "ok" })JSON")) ==
sourcemeta::core::parse_json(R"JSON({ "status": "ok" })JSON"));
sourcemeta::core::parse_json(R"JSON({ "status": "ok" })JSON")) ==
"status": "ok",
"resultType": "complete"
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_decorate_result(const MCPProtocolVersion version, sourcemeta::core::JSON result, const std::optional< MCPImplementation > &server_info=std::nullopt) -> sourcemeta::core::JSON
@ V_2025_11_25
The initialization-handshake revision 2025-11-25.
Definition mcp_protocol.h:36
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#result

◆ mcp_encode_header_value()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_encode_header_value ( JSON::StringView value) -> std::string
nodiscard

Encode a Mcp-Name or Mcp-Param value using the MCP 2026-07-28 sentinel encoding when the value cannot be represented literally. A value passes through only when every byte is printable ASCII, it neither begins nor ends with a space, and it would not be mistaken for the sentinel form. Everything else is encoded. Throws MCPError for input that is not UTF-8. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
assert(sourcemeta::core::mcp_encode_header_value("weather") == "weather");
"=?base64?IGNhZsOpIA==?=");
"=?base64?IHBhZGRlZCA=?=");
SOURCEMETA_CORE_MCP_EXPORT auto mcp_encode_header_value(JSON::StringView value) -> std::string
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http#value-encoding

◆ mcp_error_code_to_http_status()

auto sourcemeta::core::mcp_error_code_to_http_status ( const MCPProtocolVersion version,
const std::int64_t code ) -> std::optional< HTTPStatus >
nodiscardconstexprnoexcept

Map an MCP or JSON-RPC error code to the HTTP status the specification mandates for it on the Streamable HTTP transport, or nothing where it mandates none.

Only 2026-07-28 ties a status to an error code on its own, and only for four of them: an unimplemented method answers 404, while a header mismatch, a missing required client capability and an unsupported protocol version each answer 400.

Invalid parameters is deliberately absent despite carrying a mandate of its own, because the mandate is written for one cause of that code, a request that omits a required metadata field, while the same code also answers a resource that cannot be found and an argument that disagrees with its mirrored header. Those have no mandated status, and a missing resource would be poorly served by the one the metadata rule gives. A caller rejecting a request for missing metadata therefore answers 400 on its own authority, which it can do because it chose that rejection and this helper cannot see which cause produced the code.

Every other code in that revision, and every code in the three earlier revisions, has no mandated status: those revisions tie a status to a transport condition such as a terminated session rather than to a JSON-RPC error, which in that era travels on a 200.

So an absent result is not a gap to paper over. It says the choice belongs to the adapter, which is why this returns nothing instead of inventing a status, and in particular why a resource that cannot be found no longer reports the server as being at fault. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
.has_value());
.has_value());
constexpr HTTPStatus HTTP_STATUS_BAD_REQUEST
Definition http_status.h:153
constexpr HTTPStatus HTTP_STATUS_NOT_FOUND
Definition http_status.h:173
constexpr std::int64_t JSONRPC_CODE_INTERNAL
Definition jsonrpc.h:43
constexpr std::int64_t JSONRPC_CODE_METHOD_NOT_FOUND
Definition jsonrpc.h:35
constexpr auto mcp_error_code_to_http_status(const MCPProtocolVersion version, const std::int64_t code) noexcept -> std::optional< HTTPStatus >
Definition mcp_error.h:189
constexpr std::int64_t MCP_CODE_HEADER_MISMATCH
Definition mcp_error.h:121
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http#server-validation https://modelcontextprotocol.io/specification/2026-07-28/basic/index#_meta

◆ mcp_intersect_subscription_filters()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_intersect_subscription_filters ( const MCPSubscriptionFilter & requested,
const MCPSubscriptionFilter & supported ) -> MCPSubscriptionFilter
nodiscard

Restrict requested events and URIs to those the server supports. The result is the subset the server agreed to honor, so an event only carries a value when both sides opted into it and an unsupported event stays absent. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
.tools_list_changed = true, .prompts_list_changed = true};
.tools_list_changed = true};
requested, supported)};
assert(agreed.tools_list_changed == true);
assert(!agreed.prompts_list_changed.has_value());
SOURCEMETA_CORE_MCP_EXPORT auto mcp_intersect_subscription_filters(const MCPSubscriptionFilter &requested, const MCPSubscriptionFilter &supported) -> MCPSubscriptionFilter
Definition mcp_results.h:1174
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/subscriptions

◆ mcp_is_cacheable_method()

auto sourcemeta::core::mcp_is_cacheable_method ( const JSON::StringView method) -> bool
nodiscardconstexprnoexcept

Whether a complete operation result requires caching metadata in 2026-07-28. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_is_cacheable_method(const JSON::StringView method) noexcept -> bool
Definition mcp_protocol.h:1227
See also
https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/caching#cacheable-results

◆ mcp_is_client_notification_method()

auto sourcemeta::core::mcp_is_client_notification_method ( MCPProtocolVersion version,
JSON::StringView method ) -> bool
nodiscardconstexprnoexcept

Check the base client notification direction for an exact revision. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
"notifications/roots/list_changed"));
"notifications/roots/list_changed"));
constexpr auto mcp_is_client_notification_method(MCPProtocolVersion version, JSON::StringView method) noexcept -> bool
Definition mcp_protocol.h:1254
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema

◆ mcp_is_input_request_method()

auto sourcemeta::core::mcp_is_input_request_method ( const MCPProtocolVersion version,
const JSON::StringView method ) -> bool
nodiscardconstexprnoexcept

Whether a nested MRTR request method is defined in this revision. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
"elicitation/create"));
"elicitation/create"));
constexpr auto mcp_is_input_request_method(const MCPProtocolVersion version, const JSON::StringView method) noexcept -> bool
Definition mcp_protocol.h:1044
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/mrtr

◆ mcp_is_mrtr_method()

auto sourcemeta::core::mcp_is_mrtr_method ( const JSON::StringView method) -> bool
nodiscardconstexprnoexcept

Whether an operation may return an input_required result. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
assert(!sourcemeta::core::mcp_is_mrtr_method("tools/list"));
constexpr auto mcp_is_mrtr_method(const JSON::StringView method) noexcept -> bool
Definition mcp_protocol.h:1206
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/mrtr

◆ mcp_is_notification_method()

auto sourcemeta::core::mcp_is_notification_method ( const MCPProtocolVersion version,
const JSON::StringView method ) -> bool
nodiscardconstexprnoexcept

Whether a notification method is defined in this revision. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
"notifications/cancelled"));
"notifications/initialized"));
constexpr auto mcp_is_notification_method(const MCPProtocolVersion version, const JSON::StringView method) noexcept -> bool
Definition mcp_protocol.h:982
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema

◆ mcp_is_request_method()

auto sourcemeta::core::mcp_is_request_method ( const MCPProtocolVersion version,
const JSON::StringView method ) -> bool
nodiscardconstexprnoexcept

Whether a base client-to-server request is defined in this revision. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_is_request_method(const MCPProtocolVersion version, const JSON::StringView method) noexcept -> bool
Definition mcp_protocol.h:867
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema

◆ mcp_is_server_notification_method()

auto sourcemeta::core::mcp_is_server_notification_method ( MCPProtocolVersion version,
JSON::StringView method ) -> bool
nodiscardconstexprnoexcept

Check the base server notification direction for an exact revision. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
"notifications/cancelled"));
"notifications/initialized"));
constexpr auto mcp_is_server_notification_method(MCPProtocolVersion version, JSON::StringView method) noexcept -> bool
Definition mcp_protocol.h:1298
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema

◆ mcp_is_server_request_method()

auto sourcemeta::core::mcp_is_server_request_method ( const MCPProtocolVersion version,
const JSON::StringView method ) -> bool
nodiscardconstexprnoexcept

Whether a standalone server-to-client request is defined in this revision. In 2026-07-28 these are nested MRTR requests, not JSON-RPC requests. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_is_server_request_method(const MCPProtocolVersion version, const JSON::StringView method) noexcept -> bool
Definition mcp_protocol.h:935
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema

◆ mcp_log_level_enabled()

auto sourcemeta::core::mcp_log_level_enabled ( const MCPLogLevel level,
const MCPLogLevel threshold ) -> bool
nodiscardconstexprnoexcept

Whether a notification meets an explicitly selected logging threshold. A threshold admits its own severity and every more severe one. The specification scopes a threshold to the request that carried it and only permits a notification once a request has asked for one, so a caller reaches this predicate having already found a threshold to apply. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_log_level_enabled(const MCPLogLevel level, const MCPLogLevel threshold) noexcept -> bool
Definition mcp_logging.h:140
@ Warning
Conditions that may require attention.
Definition mcp_logging.h:34
@ Error
Error conditions.
Definition mcp_logging.h:36
@ Debug
Detailed information useful for debugging.
Definition mcp_logging.h:28
See also
https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/logging

◆ mcp_log_level_string()

auto sourcemeta::core::mcp_log_level_string ( const MCPLogLevel level) -> JSON::StringView
nodiscardconstexprnoexcept

Convert a logging severity to its canonical wire string. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_log_level_string(const MCPLogLevel level) noexcept -> JSON::StringView
Definition mcp_logging.h:59
See also
https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/logging

◆ mcp_make_audio_block()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_audio_block ( MCPProtocolVersion version,
JSON::StringView data,
JSON::StringView mime_type,
const MCPResourceAnnotations & annotations = {} ) -> JSON
nodiscard

Build a base64 audio block, with the same contracts as the image builder. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
"audio/wav") ==
"type": "audio",
"data": "YWJj",
"mimeType": "audio/wav"
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_audio_block(MCPProtocolVersion version, JSON::StringView data, JSON::StringView mime_type, const MCPResourceAnnotations &annotations={}) -> JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#audiocontent

◆ mcp_make_completion_result()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_completion_result ( MCPProtocolVersion version,
JSON values,
std::optional< std::int64_t > total,
std::optional< bool > has_more ) -> JSON
nodiscard

Build a completion result. Values must be strings and contain at most 100 entries. A supplied total cannot be smaller than the returned entry count. Returns a bare result object. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
"completion": { "values": [], "total": 0, "hasMore": false }
})JSON"));
static auto make_array() -> JSON
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_completion_result(MCPProtocolVersion version, JSON values, std::optional< std::int64_t > total, std::optional< bool > has_more) -> JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#completeresult

◆ mcp_make_embedded_resource()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_embedded_resource ( MCPProtocolVersion version,
JSON resource,
const MCPResourceAnnotations & annotations = {} ) -> JSON
nodiscard

Embed a checked text/blob resource-content entry in a content block. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
"file:///a", "application/octet-stream", "YWJj")) ==
"type": "resource",
"resource": {
"uri": "file:///a",
"mimeType": "application/octet-stream",
"blob": "YWJj"
}
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_resource_blob_content(JSON::StringView uri, JSON::StringView mime_type, JSON::StringView blob) -> JSON
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_embedded_resource(MCPProtocolVersion version, JSON resource, const MCPResourceAnnotations &annotations={}) -> JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#embeddedresource

◆ mcp_make_empty_response()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_empty_response ( const MCPProtocolVersion version,
const sourcemeta::core::JSON & identifier,
const std::optional< MCPImplementation > & server_info = std::nullopt ) -> sourcemeta::core::JSON
nodiscard

Build an empty MCP response with resultType: "complete".

The builders in this header come in two shapes, and the name says which. A function named for a result returns the bare payload that belongs under the result key, while one named for a response returns the whole JSON-RPC envelope around it and therefore takes the identifier to echo. That is the specification's own distinction, which pairs a result such as DiscoverResult with the envelope DiscoverResultResponse, and reserves JSONRPCResultResponse for the generic shape. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
"jsonrpc": "2.0",
"id": 0,
"result": { "resultType": "complete" }
})JSON"));
Definition json_value.h:39
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_empty_response(const MCPProtocolVersion version, const sourcemeta::core::JSON &identifier, const std::optional< MCPImplementation > &server_info=std::nullopt) -> sourcemeta::core::JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#emptyresult
https://modelcontextprotocol.io/specification/2026-07-28/schema#jsonrpcresultresponse

◆ mcp_make_error()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_error ( MCPProtocolVersion version,
const JSON * identifier,
std::int64_t code,
JSON::StringView message,
std::optional< JSON > data = std::nullopt,
MCPErrorContext context = MCPErrorContext::Request ) -> JSON
nodiscard

Construct a checked MCP error. Null, fractional and container identifiers are treated as unreadable. For 2026-07-28, rejects retired and undefined reserved codes and checks the required data for version/capability errors. Every revision the version error advertises must be one this library models. The caller remains responsible for choosing an error that describes the actual failure. Header mismatch data is optional. Returns a complete JSON-RPC error envelope rather than a bare error object. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
const sourcemeta::core::JSON identifier{1};
"Unsupported protocol version",
"requested": "1999-01-01",
"supported": []
})JSON")) == sourcemeta::core::parse_json(R"JSON({
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32022,
"message": "Unsupported protocol version",
"data": { "requested": "1999-01-01", "supported": [] }
}
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_error(MCPProtocolVersion version, const JSON *identifier, std::int64_t code, JSON::StringView message, std::optional< JSON > data=std::nullopt, MCPErrorContext context=MCPErrorContext::Request) -> JSON
constexpr std::int64_t MCP_CODE_UNSUPPORTED_PROTOCOL_VERSION
Definition mcp_error.h:131
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/index#responses

◆ mcp_make_error_header_mismatch() [1/3]

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_error_header_mismatch ( const MCPProtocolVersion version,
const sourcemeta::core::JSON * identifier,
const JSON::StringView header_name,
const JSON::StringView header_value ) -> sourcemeta::core::JSON
nodiscard

Build a JSON-RPC error response for header mismatch (-32020) reporting an unexpected header supplied without a corresponding body value. Defined for 2026-07-28 only. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
const sourcemeta::core::JSON identifier{1};
"Mcp-Name", "foo") == sourcemeta::core::parse_json(R"JSON({
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32020,
"message": "Header mismatch: unexpected header provided",
"data": { "header": "Mcp-Name", "headerValue": "foo" }
}
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_error_header_mismatch(const MCPProtocolVersion version, const sourcemeta::core::JSON *identifier, const JSON::StringView message) -> sourcemeta::core::JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http#schema-extension

◆ mcp_make_error_header_mismatch() [2/3]

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_error_header_mismatch ( const MCPProtocolVersion version,
const sourcemeta::core::JSON * identifier,
const JSON::StringView header_name,
const JSON::StringView header_value,
const JSON::StringView body_value ) -> sourcemeta::core::JSON
nodiscard

Build a JSON-RPC error response for header mismatch (-32020) with detailed header mismatch payload, naming the header along with the conflicting transport and body values. Defined for 2026-07-28 only. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
const sourcemeta::core::JSON identifier{1};
"Mcp-Name", "foo",
"bar") == sourcemeta::core::parse_json(R"JSON({
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32020,
"message": "Header mismatch",
"data": {
"header": "Mcp-Name",
"headerValue": "foo",
"bodyValue": "bar"
}
}
})JSON"));
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http#schema-extension

◆ mcp_make_error_header_mismatch() [3/3]

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_error_header_mismatch ( const MCPProtocolVersion version,
const sourcemeta::core::JSON * identifier,
const JSON::StringView message ) -> sourcemeta::core::JSON
nodiscard

Build a JSON-RPC error response for header mismatch (-32020). This overload carries a caller-supplied message and no data, for a mismatch that names no single header. Defined for 2026-07-28 only. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
const sourcemeta::core::JSON identifier{1};
"Duplicate routing header") ==
"jsonrpc": "2.0",
"id": 1,
"error": { "code": -32020, "message": "Duplicate routing header" }
})JSON"));
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http#schema-extension

◆ mcp_make_error_missing_required_capability()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_error_missing_required_capability ( const MCPProtocolVersion version,
const sourcemeta::core::JSON * identifier,
sourcemeta::core::JSON required_capabilities,
const JSON::StringView message ) -> sourcemeta::core::JSON
nodiscard

Build a JSON-RPC error response for missing required client capability (-32021). This error is defined for 2026-07-28 only, and the required capabilities must themselves be a valid client capability object. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
const sourcemeta::core::JSON identifier{"x"};
sourcemeta::core::parse_json(R"JSON({ "elicitation": {} })JSON"),
"Elicitation is required") ==
"jsonrpc": "2.0",
"id": "x",
"error": {
"code": -32021,
"message": "Elicitation is required",
"data": { "requiredCapabilities": { "elicitation": {} } }
}
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_error_missing_required_capability(const MCPProtocolVersion version, const sourcemeta::core::JSON *identifier, sourcemeta::core::JSON required_capabilities, const JSON::StringView message) -> sourcemeta::core::JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/index#error-codes

◆ mcp_make_error_request_meta()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_error_request_meta ( const MCPProtocolVersion version,
const sourcemeta::core::JSON * identifier,
const MCPRequestMetaStatus status,
const JSON::StringView requested,
const std::span< const JSON::StringView > supported ) -> sourcemeta::core::JSON
nodiscard

Construct an appropriate JSON-RPC error response from an invalid MCPRequestMetaStatus. An unrecognized revision becomes the dedicated unsupported-version error carrying the supported list, an envelope that is not a readable request becomes an invalid-request error, and every remaining failure becomes an invalid-params error naming the offending field. Passing the status for valid metadata throws MCPError, and so does a supported list naming a revision this library does not model, since that is a condition on the caller rather than on the peer. For example:

#include <sourcemeta/core/mcp.h>
#include <array>
#include <cassert>
const sourcemeta::core::JSON identifier{1};
constexpr std::array<sourcemeta::core::JSON::StringView, 1> SUPPORTED{
{"2026-07-28"}};
SUPPORTED)
.at("error")
.at("code")
SUPPORTED)
.at("error")
.at("code")
constexpr auto UNSUPPORTED{
UNSUPPORTED, "1999-01-01", SUPPORTED)
.at("error")
.at("code")
.to_integer() ==
constexpr std::int64_t JSONRPC_CODE_INVALID_PARAMS
Definition jsonrpc.h:39
constexpr std::int64_t JSONRPC_CODE_INVALID_REQUEST
Definition jsonrpc.h:31
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_error_request_meta(const MCPProtocolVersion version, const sourcemeta::core::JSON *identifier, const MCPRequestMetaStatus status, const JSON::StringView requested, const std::span< const JSON::StringView > supported) -> sourcemeta::core::JSON
@ InvalidEnvelope
The input is not a valid MCP request envelope.
Definition mcp_headers.h:40
@ MissingMeta
The params object lacks a _meta property.
Definition mcp_headers.h:58
@ UnsupportedProtocolVersion
io.modelcontextprotocol/protocolVersion is not a recognized version.
Definition mcp_headers.h:66
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/index#error-codes

◆ mcp_make_error_resource_not_found()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_error_resource_not_found ( const MCPProtocolVersion version,
const sourcemeta::core::JSON * identifier ) -> sourcemeta::core::JSON
nodiscard

Build a version-aware JSON-RPC error response reporting that a resource was not found. Emits -32002 for legacy revisions, and -32602 (Invalid Params) for 2026-07-28, which retired the dedicated code. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
const sourcemeta::core::JSON identifier{1};
&identifier) == sourcemeta::core::parse_json(R"JSON({
"jsonrpc": "2.0",
"id": 1,
"error": { "code": -32602, "message": "Resource not found" }
})JSON"));
&identifier) == sourcemeta::core::parse_json(R"JSON({
"jsonrpc": "2.0",
"id": 1,
"error": { "code": -32002, "message": "Resource not found" }
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_error_resource_not_found(const MCPProtocolVersion version, const sourcemeta::core::JSON *identifier) -> sourcemeta::core::JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/server/resources#error-handling

◆ mcp_make_error_unsupported_protocol_version()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_error_unsupported_protocol_version ( const MCPProtocolVersion version,
const sourcemeta::core::JSON * identifier,
const JSON::StringView requested,
const std::span< const JSON::StringView > supported ) -> sourcemeta::core::JSON
nodiscard

Build a JSON-RPC error response for unsupported protocol version (-32022). This error is defined for 2026-07-28 only, and the list of supported revisions must not be empty. Every revision in it must be one this library models, which is a condition on the caller rather than on the peer, so a violation throws instead of becoming an error envelope. An absent identifier omits the member rather than sending a null one. For example:

#include <sourcemeta/core/mcp.h>
#include <array>
#include <cassert>
const sourcemeta::core::JSON identifier{7};
constexpr std::array<sourcemeta::core::JSON::StringView, 2> SUPPORTED{
{"2025-11-25", "2026-07-28"}};
"1999-01-01", SUPPORTED) == sourcemeta::core::parse_json(R"JSON({
"jsonrpc": "2.0",
"id": 7,
"error": {
"code": -32022,
"message": "Unsupported protocol version",
"data": {
"supported": [ "2025-11-25", "2026-07-28" ],
"requested": "1999-01-01"
}
}
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_error_unsupported_protocol_version(const MCPProtocolVersion version, const sourcemeta::core::JSON *identifier, const JSON::StringView requested, const std::span< const JSON::StringView > supported) -> sourcemeta::core::JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/index#error-codes

◆ mcp_make_image_block()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_image_block ( MCPProtocolVersion version,
JSON::StringView data,
JSON::StringView mime_type,
const MCPResourceAnnotations & annotations = {} ) -> JSON
nodiscard

Build a base64 image or audio content block for an explicit revision. Core checks the block shape, not the media bytes or MIME semantics. Returns a bare content block for the caller to place in a result.

The encoding of the data is a schema format annotation rather than a stated requirement, so it is not checked here, and a caller that cares about it decodes the data itself. Contrast the address of a URL mode elicitation, which the specification states as a requirement in prose and which is therefore checked. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
"image/png") ==
"type": "image",
"data": "YWJj",
"mimeType": "image/png"
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_image_block(MCPProtocolVersion version, JSON::StringView data, JSON::StringView mime_type, const MCPResourceAnnotations &annotations={}) -> JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#imagecontent

◆ mcp_make_initialize_response()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_initialize_response ( const sourcemeta::core::JSON & request,
const MCPServerCapabilities & capabilities,
const MCPImplementation & server,
const std::span< const JSON::StringView > supported_versions,
const JSON::StringView instructions = {} ) -> sourcemeta::core::JSON
nodiscard

Build the JSON-RPC envelope returned in response to an MCP initialize request. The revision is the one the client asked for when the server supports it and it uses the handshake, and otherwise the highest supported handshake revision, so an unrecognized request negotiates down rather than failing. The advertised list must be non-empty, every revision in it must be one this library models, and at least one must use the handshake. A request that is not readable, or whose parameters are missing or malformed, does yield an error envelope. For example:

#include <sourcemeta/core/mcp.h>
#include <array>
#include <cassert>
constexpr std::array<sourcemeta::core::JSON::StringView, 4> SUPPORTED{
{"2025-03-26", "2025-06-18", "2025-11-25", "2026-07-28"}};
const auto request{sourcemeta::core::parse_json(R"JSON({
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2025-11-25",
"capabilities": {},
"clientInfo": { "name": "client", "version": "1" }
}
})JSON")};
const sourcemeta::core::MCPImplementation server{.name = "srv",
.version = "1.0.0"};
request, sourcemeta::core::MCPServerCapabilities{}, server,
SUPPORTED) ==
"jsonrpc": "2.0",
"id": 1,
"result": {
"protocolVersion": "2025-11-25",
"capabilities": {},
"serverInfo": { "name": "srv", "version": "1.0.0" }
}
})JSON"));
const auto unknown{sourcemeta::core::parse_json(R"JSON({
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "9999-01-01",
"capabilities": {},
"clientInfo": { "name": "client", "version": "1" }
}
})JSON")};
unknown, sourcemeta::core::MCPServerCapabilities{}, server,
SUPPORTED)
.at("result")
.at("protocolVersion") == sourcemeta::core::JSON{"2025-11-25"});
See also
https://modelcontextprotocol.io/specification/2025-11-25/basic/lifecycle#initialization

◆ mcp_make_input_required_response()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_input_required_response ( const MCPProtocolVersion version,
const JSON::StringView method,
const sourcemeta::core::JSON & identifier,
std::optional< sourcemeta::core::JSON > input_requests,
std::optional< JSON::StringView > request_state,
const MCPClientCapabilities & client_capabilities,
const std::optional< MCPImplementation > & server_info = std::nullopt ) -> sourcemeta::core::JSON
nodiscard

Build an MCP Multi Round-Trip Result (input_required). At least one of input_requests or request_state must be provided. Only tools/call, resources/read, and prompts/get may carry this result. The client capabilities are checked so a server does not ask for input the client never advertised.

A nested request that sends the user to an address has that address checked for being a URI with a scheme, which is the format the specification annotates the field with and the reading its prose requirement supports. What makes an address usable within a particular scheme is left alone: the specification restricts the scheme not at all, and each scheme states its own rules in its own document, so enforcing one scheme's rules and not the others would be a policy this builder has no grounds to choose. A caller that needs an address it can actually open checks that where it opens it. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
#include <utility>
auto input_requests{sourcemeta::core::parse_json(R"JSON({
"confirm": {
"method": "elicitation/create",
"params": {
"message": "Confirm delete?",
"requestedSchema": { "type": "object", "properties": {} }
}
}
})JSON")};
sourcemeta::core::JSON{50}, std::move(input_requests),
"opaque-state-token-123",
.elicitation_form = true})};
assert(envelope.at("result").at("resultType") ==
sourcemeta::core::JSON{"input_required"});
assert(envelope.at("result").at("requestState") ==
sourcemeta::core::JSON{"opaque-state-token-123"});
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_input_required_response(const MCPProtocolVersion version, const JSON::StringView method, const sourcemeta::core::JSON &identifier, std::optional< sourcemeta::core::JSON > input_requests, std::optional< JSON::StringView > request_state, const MCPClientCapabilities &client_capabilities, const std::optional< MCPImplementation > &server_info=std::nullopt) -> sourcemeta::core::JSON
Definition mcp_capabilities.h:84
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/mrtr#supported-requests

◆ mcp_make_notification()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_notification ( MCPProtocolVersion version,
bool from_server,
JSON::StringView method,
JSON parameters,
std::optional< JSON > subscription_id,
const MCPSubscriptionFilter * acknowledged = nullptr,
const MCPRequestMeta * request_context = nullptr ) -> JSON
nodiscard

Construct a checked notification. The direction and parameters are explicit. 2026-07-28 logging/progress require the current validated request context. Logging must meet the requested severity and cannot use a subscription ID. The caller must route it on the response stream of that same request. For 2026-07-28 server list/resource updates, subscription_id and the already acknowledged filter are mandatory. A server cancellation must name that subscription. Runtime code owns acknowledgment ordering, token activity, increasing progress, authorization and stream lifetime. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
#include <optional>
"notifications/cancelled",
R"JSON({ "requestId": 0, "reason": "done" })JSON"),
std::nullopt) ==
"jsonrpc": "2.0",
"method": "notifications/cancelled",
"params": { "requestId": 0, "reason": "done" }
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_notification(MCPProtocolVersion version, bool from_server, JSON::StringView method, JSON parameters, std::optional< JSON > subscription_id, const MCPSubscriptionFilter *acknowledged=nullptr, const MCPRequestMeta *request_context=nullptr) -> JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/subscriptions

◆ mcp_make_parameter_headers()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_parameter_headers ( std::span< const MCPHeaderParameter > parameters,
const JSON & arguments ) -> std::vector< std::pair< std::string, std::string > >
nodiscard

Produce mirrored parameter headers. Missing/null values are omitted. Throws MCPError on a type mismatch or an unsafe integer. A value that cannot be represented literally is sentinel encoded. For example:

#include <sourcemeta/core/mcp.h>
#include <array>
#include <cassert>
#include <string>
#include <utility>
#include <vector>
const std::array<sourcemeta::core::MCPHeaderParameter, 3> descriptors{
{{.name = "Label",
.path = {"nested", "text"},
{.name = "Count",
.path = {"number"},
{.name = "Enabled",
.path = {"enabled"},
const auto arguments{sourcemeta::core::parse_json(R"JSON({
"nested": { "text": " café " },
"number": 42,
"enabled": false
})JSON")};
const std::vector<std::pair<std::string, std::string>> expected{
{"Mcp-Param-Label", "=?base64?IGNhZsOpIA==?="},
{"Mcp-Param-Count", "42"},
{"Mcp-Param-Enabled", "false"}};
arguments) == expected);
@ String
The JSON string type.
Definition json_value.h:79
@ Boolean
The JSON boolean type.
Definition json_value.h:73
@ Integer
The JSON integer type.
Definition json_value.h:75
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_parameter_headers(std::span< const MCPHeaderParameter > parameters, const JSON &arguments) -> std::vector< std::pair< std::string, std::string > >
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http#schema-extension

◆ mcp_make_prompts_get_result()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_prompts_get_result ( MCPProtocolVersion version,
JSON::StringView description,
JSON messages ) -> JSON
nodiscard

Build a prompt result from checked role/content messages. Returns a bare result object. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
"description",
{
"role": "user",
"content": { "type": "text", "text": "hello" }
}
])JSON")) ==
"description": "description",
"messages": [
{
"role": "user",
"content": { "type": "text", "text": "hello" }
}
]
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_prompts_get_result(MCPProtocolVersion version, JSON::StringView description, JSON messages) -> JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/server/prompts

◆ mcp_make_prompts_list_result()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_prompts_list_result ( const MCPProtocolVersion version,
sourcemeta::core::JSON prompts,
const std::optional< JSON::StringView > next_cursor,
const MCPCachePolicy & cache_policy ) -> sourcemeta::core::JSON
nodiscard

Build an MCP prompts/list result object for 2026-07-28 with required cache metadata. Returns a bare result object. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
const auto entries{sourcemeta::core::parse_json(
R"JSON([ { "name": "review", "description": "Review" } ])JSON")};
sourcemeta::core::JSON{entries}, "cursor-abc",
{.ttl_ms = 120000,
"resultType": "complete",
"prompts": [ { "name": "review", "description": "Review" } ],
"nextCursor": "cursor-abc",
"ttlMs": 120000,
"cacheScope": "public"
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_prompts_list_result(const MCPProtocolVersion version, sourcemeta::core::JSON prompts, const std::optional< JSON::StringView > next_cursor, const MCPCachePolicy &cache_policy) -> sourcemeta::core::JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/caching#cacheable-results

◆ mcp_make_resource()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_resource ( const MCPProtocolVersion version,
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,
const MCPDescriptorPresentation & presentation = {},
const MCPResourceAnnotations & annotations = {} ) -> sourcemeta::core::JSON
nodiscard

Build an MCP resource descriptor as used in resources/list responses. Returns a bare descriptor for the caller to collect into a list result. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
"a", "text/plain") ==
"uri": "file:///a",
"name": "a",
"mimeType": "text/plain"
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_resource(const MCPProtocolVersion version, 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, const MCPDescriptorPresentation &presentation={}, const MCPResourceAnnotations &annotations={}) -> sourcemeta::core::JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#resource

◆ mcp_make_resource_blob_content()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_resource_blob_content ( JSON::StringView uri,
JSON::StringView mime_type,
JSON::StringView blob ) -> JSON
nodiscard

Build a blob resource-content entry. The caller supplies base64-encoded data. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
"file:///a", "application/octet-stream", "YWJj") ==
"uri": "file:///a",
"mimeType": "application/octet-stream",
"blob": "YWJj"
})JSON"));
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#blobresourcecontents

◆ mcp_make_resource_link()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_resource_link ( const MCPProtocolVersion version,
const JSON::StringView uri,
const JSON::StringView name,
const JSON::StringView mime_type = {},
const JSON::StringView description = {} ) -> sourcemeta::core::JSON
nodiscard

Build an MCP content block referencing a resource by URI. This block type was introduced in 2025-06-18, so an earlier revision is rejected. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
"file:///foo", "My File", "text/plain", "A description") ==
"type": "resource_link",
"uri": "file:///foo",
"name": "My File",
"description": "A description",
"mimeType": "text/plain"
})JSON"));
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#resourcelink

◆ mcp_make_resource_template()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_resource_template ( const MCPProtocolVersion version,
const JSON::StringView uri_template,
const JSON::StringView name,
const JSON::StringView description,
const JSON::StringView mime_type,
const MCPDescriptorPresentation & presentation = {},
const MCPResourceAnnotations & annotations = {} ) -> sourcemeta::core::JSON
nodiscard

Build a single entry for an MCP resources/templates/list response. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
"file:///{path}", "Files", "Resolves a file path",
"text/plain") ==
"uriTemplate": "file:///{path}",
"name": "Files",
"description": "Resolves a file path",
"mimeType": "text/plain"
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_resource_template(const MCPProtocolVersion version, const JSON::StringView uri_template, const JSON::StringView name, const JSON::StringView description, const JSON::StringView mime_type, const MCPDescriptorPresentation &presentation={}, const MCPResourceAnnotations &annotations={}) -> sourcemeta::core::JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#resourcetemplate

◆ mcp_make_resource_templates_list_result()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_resource_templates_list_result ( const MCPProtocolVersion version,
sourcemeta::core::JSON resource_templates,
const std::optional< JSON::StringView > next_cursor,
const MCPCachePolicy & cache_policy ) -> sourcemeta::core::JSON
nodiscard

Build an MCP resources/templates/list result object for 2026-07-28 with required cache metadata. Returns a bare result object. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
const auto entries{sourcemeta::core::parse_json(
R"JSON([ { "uriTemplate": "file:///{path}", "name": "Files" } ])JSON")};
sourcemeta::core::JSON{entries}, std::nullopt,
{.ttl_ms = 0,
"resourceTemplates": [
{ "uriTemplate": "file:///{path}", "name": "Files" }
]
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_resource_templates_list_result(const MCPProtocolVersion version, sourcemeta::core::JSON resource_templates, const std::optional< JSON::StringView > next_cursor, const MCPCachePolicy &cache_policy) -> sourcemeta::core::JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/caching#cacheable-results

◆ mcp_make_resource_text_content()

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
nodiscard

Build an MCP resources/read content entry of Text flavour. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
"file:///a", "text/plain", "Hello") ==
"uri": "file:///a",
"mimeType": "text/plain",
"text": "Hello"
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_resource_text_content(const JSON::StringView uri, const JSON::StringView mime_type, const JSON::StringView text) -> sourcemeta::core::JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#textresourcecontents

◆ mcp_make_resources_list_result()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_resources_list_result ( const MCPProtocolVersion version,
sourcemeta::core::JSON resources,
const std::optional< JSON::StringView > next_cursor,
const MCPCachePolicy & cache_policy ) -> sourcemeta::core::JSON
nodiscard

Build an MCP resources/list result object for 2026-07-28 with required cache metadata. Returns a bare result object. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
"text/plain"));
sourcemeta::core::JSON{entries}, "cursor-abc",
{.ttl_ms = 120000,
"resultType": "complete",
"resources": [
{ "uri": "file:///a", "name": "a", "mimeType": "text/plain" }
],
"nextCursor": "cursor-abc",
"ttlMs": 120000,
"cacheScope": "public"
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_resources_list_result(const MCPProtocolVersion version, sourcemeta::core::JSON resources, const std::optional< JSON::StringView > next_cursor, const MCPCachePolicy &cache_policy) -> sourcemeta::core::JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/caching#cacheable-results

◆ mcp_make_resources_read_result()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_resources_read_result ( const MCPProtocolVersion version,
sourcemeta::core::JSON contents,
const MCPCachePolicy & cache_policy ) -> sourcemeta::core::JSON
nodiscard

Wrap a pre-built array of content entries into the MCP resources/read result envelope with a required cache policy for 2026-07-28. Returns a bare result object, so the caller still wraps it in a JSON-RPC envelope. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
#include <utility>
"file:///a", "text/plain", "Hello"));
std::move(contents),
{.ttl_ms = 30000,
"contents": [
{ "uri": "file:///a", "mimeType": "text/plain", "text": "Hello" }
]
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_resources_read_result(const MCPProtocolVersion version, sourcemeta::core::JSON contents, const MCPCachePolicy &cache_policy) -> sourcemeta::core::JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/server/resources

◆ mcp_make_server_discover_response()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_server_discover_response ( const MCPProtocolVersion version,
const sourcemeta::core::JSON & identifier,
const MCPServerCapabilities & capabilities,
const MCPImplementation & server,
const std::span< const JSON::StringView > supported_versions,
const JSON::StringView instructions,
const MCPCachePolicy & cache_policy ) -> sourcemeta::core::JSON
nodiscard

Build the JSON-RPC response envelope for an MCP 2026-07-28 server/discover request. This is the stateless replacement for the initialization handshake, so it carries the supported revisions, the capabilities and the cache metadata in one response. The advertised list must be non-empty, must include the revision being served, and every revision in it must be one this library models. For example:

#include <sourcemeta/core/mcp.h>
#include <array>
#include <cassert>
constexpr std::array<sourcemeta::core::JSON::StringView, 1> SUPPORTED{
{"2026-07-28"}};
const sourcemeta::core::MCPImplementation server{.name = "srv",
.version = "2.0.0"};
sourcemeta::core::JSON{1}, sourcemeta::core::MCPServerCapabilities{},
server, SUPPORTED, "Instructions here",
{.ttl_ms = 3600000,
assert(envelope.at("result").at("resultType") ==
sourcemeta::core::JSON{"complete"});
assert(envelope.at("result").at("supportedVersions") ==
sourcemeta::core::parse_json(R"JSON([ "2026-07-28" ])JSON"));
assert(envelope.at("result").at("cacheScope") ==
sourcemeta::core::JSON{"public"});
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_server_discover_response(const MCPProtocolVersion version, const sourcemeta::core::JSON &identifier, const MCPServerCapabilities &capabilities, const MCPImplementation &server, const std::span< const JSON::StringView > supported_versions, const JSON::StringView instructions, const MCPCachePolicy &cache_policy) -> sourcemeta::core::JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#discoverresult

◆ mcp_make_subscription_acknowledged_notification() [1/2]

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_subscription_acknowledged_notification ( const MCPProtocolVersion version,
const JSON::StringView subscription_id,
const MCPSubscriptionFilter & requested,
const MCPSubscriptionFilter & supported ) -> sourcemeta::core::JSON
nodiscard

Build an acknowledgement notification for subscriptions/listen with a string subscription ID. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
filter.tools_list_changed = true;
filter, filter) ==
"jsonrpc": "2.0",
"method": "notifications/subscriptions/acknowledged",
"params": {
"_meta": { "io.modelcontextprotocol/subscriptionId": "sub-42" },
"notifications": { "toolsListChanged": true }
}
})JSON"));
std::optional< bool > tools_list_changed
Opt in to notifications that the tool list changed.
Definition mcp_results.h:1176
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_subscription_acknowledged_notification(const MCPProtocolVersion version, const sourcemeta::core::JSON &subscription_id, const MCPSubscriptionFilter &requested, const MCPSubscriptionFilter &supported) -> sourcemeta::core::JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/subscriptions

◆ mcp_make_subscription_acknowledged_notification() [2/2]

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_subscription_acknowledged_notification ( const MCPProtocolVersion version,
const sourcemeta::core::JSON & subscription_id,
const MCPSubscriptionFilter & requested,
const MCPSubscriptionFilter & supported ) -> sourcemeta::core::JSON
nodiscard

Build an acknowledgement notification for subscriptions/listen with a string or integer subscription ID. The filter is restricted to the intersection of requested and server-supported events and URIs. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
filter.prompts_list_changed = true;
sourcemeta::core::JSON{123}, filter, filter) ==
"jsonrpc": "2.0",
"method": "notifications/subscriptions/acknowledged",
"params": {
"_meta": { "io.modelcontextprotocol/subscriptionId": 123 },
"notifications": { "promptsListChanged": true }
}
})JSON"));
std::optional< bool > prompts_list_changed
Opt in to notifications that the prompt list changed.
Definition mcp_results.h:1178
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/subscriptions

◆ mcp_make_subscription_close_response()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_subscription_close_response ( const MCPProtocolVersion version,
const sourcemeta::core::JSON & identifier,
const std::optional< MCPImplementation > & server_info = std::nullopt ) -> sourcemeta::core::JSON
nodiscard

Build a graceful close response for subscriptions/listen. Returns a complete JSON-RPC envelope. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
.at("id") == sourcemeta::core::JSON{9});
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_subscription_close_response(const MCPProtocolVersion version, const sourcemeta::core::JSON &identifier, const std::optional< MCPImplementation > &server_info=std::nullopt) -> sourcemeta::core::JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/subscriptions

◆ mcp_make_text_block()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_text_block ( const JSON::StringView text) -> sourcemeta::core::JSON
nodiscard

Build an MCP Text content block carrying the given text payload. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
"type": "text",
"text": "hello"
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_text_block(const JSON::StringView text) -> sourcemeta::core::JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#textcontent

◆ mcp_make_tool_descriptor()

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 = {},
const MCPDescriptorPresentation & presentation = {} ) -> sourcemeta::core::JSON
nodiscard

Build a single entry for an MCP tools/list response. Schemas must declare type: object at the root. The caller validates the remaining schema content. The behavioural hints are always emitted, with the conservative defaults the specification assigns to an absent hint. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
"Says hello",
R"JSON({ "type": "object" })JSON")) ==
"name": "say",
"description": "Says hello",
"inputSchema": { "type": "object" },
"annotations": {
"readOnlyHint": false,
"destructiveHint": true,
"idempotentHint": false,
"openWorldHint": true
}
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto 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={}, const MCPDescriptorPresentation &presentation={}) -> sourcemeta::core::JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#tool

◆ mcp_make_tool_error()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_tool_error ( const MCPProtocolVersion version,
const sourcemeta::core::JSON & identifier,
const JSON::StringView message,
const std::optional< MCPImplementation > & server_info = std::nullopt ) -> sourcemeta::core::JSON
nodiscard

Build a version-aware JSON-RPC envelope wrapping a failed MCP tool call response with the given error message. For 2026-07-28, adds resultType: "complete". A tool failure is reported inside a successful response rather than as a JSON-RPC error. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
sourcemeta::core::JSON{7}, "Schema not found") ==
"jsonrpc": "2.0",
"id": 7,
"result": {
"content": [ { "type": "text", "text": "Schema not found" } ],
"isError": true
}
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_tool_error(const MCPProtocolVersion version, const sourcemeta::core::JSON &identifier, const JSON::StringView message, const std::optional< MCPImplementation > &server_info=std::nullopt) -> sourcemeta::core::JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/server/tools#error-handling

◆ mcp_make_tool_success() [1/2]

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_tool_success ( const MCPProtocolVersion version,
const sourcemeta::core::JSON & identifier,
sourcemeta::core::JSON result,
const std::optional< MCPImplementation > & server_info = std::nullopt ) -> sourcemeta::core::JSON
nodiscard

Build a JSON-RPC envelope wrapping a successful MCP tool call response from the given result payload. The payload is rendered as a text content block and, from 2025-06-18 onward, also carried as structured content. This checks the MCP result shape, not the payload against a tool's outputSchema. Evaluate declared output schemas before publishing a successful result; rejecting a result cannot undo side effects of a tool that already ran. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
#include <utility>
result.assign("foo", sourcemeta::core::JSON{42});
sourcemeta::core::JSON{1}, std::move(result)) ==
"jsonrpc": "2.0",
"id": 1,
"result": {
"content": [ { "type": "text", "text": "{\n \"foo\": 42\n}" } ],
"structuredContent": { "foo": 42 },
"isError": false
}
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_tool_success(const MCPProtocolVersion version, const sourcemeta::core::JSON &identifier, sourcemeta::core::JSON result, const std::optional< MCPImplementation > &server_info=std::nullopt) -> sourcemeta::core::JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/server/tools

◆ mcp_make_tool_success() [2/2]

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,
const std::optional< MCPImplementation > & server_info = std::nullopt ) -> sourcemeta::core::JSON
nodiscard

Build a JSON-RPC envelope wrapping a successful MCP tool call response from caller-provided content blocks and a structured payload. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
#include <utility>
structured.assign("ok", sourcemeta::core::JSON{true});
blocks.push_back(sourcemeta::core::mcp_make_text_block("done"));
sourcemeta::core::JSON{1}, std::move(structured),
std::move(blocks)) ==
"jsonrpc": "2.0",
"id": 1,
"result": {
"content": [ { "type": "text", "text": "done" } ],
"structuredContent": { "ok": true },
"isError": false
}
})JSON"));
See also
https://modelcontextprotocol.io/specification/2026-07-28/server/tools

◆ mcp_make_tools_list_result()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_make_tools_list_result ( const MCPProtocolVersion version,
sourcemeta::core::JSON tools,
const std::optional< JSON::StringView > next_cursor,
const MCPCachePolicy & cache_policy ) -> sourcemeta::core::JSON
nodiscard

Build an MCP tools/list result object for 2026-07-28 with required cache metadata. Returns a bare result object. An absent cursor omits the member, while an explicit empty one is preserved. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
"Calculator",
sourcemeta::core::parse_json(R"JSON({ "type": "object" })JSON")));
sourcemeta::core::JSON{entries}, "cursor-abc",
{.ttl_ms = 120000,
.at("nextCursor") == sourcemeta::core::JSON{"cursor-abc"});
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_tools_list_result(const MCPProtocolVersion version, sourcemeta::core::JSON tools, const std::optional< JSON::StringView > next_cursor, const MCPCachePolicy &cache_policy) -> sourcemeta::core::JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/caching#cacheable-results

◆ mcp_parse_client_capabilities()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_parse_client_capabilities ( const MCPProtocolVersion version,
const sourcemeta::core::JSON & capabilities ) -> MCPClientCapabilities
nodiscard

Parse client capabilities from a JSON object. A capability the given revision does not define is ignored rather than reported, while a known capability of the wrong type is rejected with MCPError. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
"roots": { "listChanged": true }
})JSON"))};
assert(capabilities.roots);
assert(capabilities.roots_list_changed);
assert(!capabilities.sampling);
SOURCEMETA_CORE_MCP_EXPORT auto mcp_parse_client_capabilities(const MCPProtocolVersion version, const sourcemeta::core::JSON &capabilities) -> MCPClientCapabilities
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#clientcapabilities

◆ mcp_parse_server_capabilities()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_parse_server_capabilities ( MCPProtocolVersion version,
const JSON & capabilities ) -> MCPServerCapabilities
nodiscard

Parse validated server capabilities, owning the snapshot and opaque settings. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
"tools": { "listChanged": true },
"resources": { "subscribe": true }
})JSON"))};
assert(capabilities.tools);
assert(capabilities.tools_list_changed);
assert(capabilities.resources_subscribe);
assert(!capabilities.prompts);
SOURCEMETA_CORE_MCP_EXPORT auto mcp_parse_server_capabilities(MCPProtocolVersion version, const JSON &capabilities) -> MCPServerCapabilities
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#servercapabilities

◆ mcp_parse_subscription_filter()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_parse_subscription_filter ( MCPProtocolVersion version,
const JSON & parameters ) -> std::optional< MCPSubscriptionFilter >
nodiscard

Parse the filter in checked 2026-07-28 listen parameters. String views borrow the parameters, while the optional URI vector owns only those views, so the parameters must outlive the filter. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
const auto parameters{sourcemeta::core::parse_json(R"JSON({
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": {}
},
"notifications": {
"toolsListChanged": true,
"promptsListChanged": false
}
})JSON")};
assert(filter->tools_list_changed == true);
assert(filter->prompts_list_changed == false);
assert(!filter->resources_list_changed.has_value());
SOURCEMETA_CORE_MCP_EXPORT auto mcp_parse_subscription_filter(MCPProtocolVersion version, const JSON &parameters) -> std::optional< MCPSubscriptionFilter >
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/subscriptions

◆ mcp_protocol_version_at_least()

auto sourcemeta::core::mcp_protocol_version_at_least ( const MCPProtocolVersion current,
const MCPProtocolVersion minimum ) -> bool
nodiscardconstexprnoexcept

Check whether an MCP protocol revision is at least the given minimum version. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_protocol_version_at_least(const MCPProtocolVersion current, const MCPProtocolVersion minimum) noexcept -> bool
Definition mcp_protocol.h:462
@ V_2025_06_18
Protocol revision 2025-06-18.
Definition mcp_protocol.h:34
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/versioning

◆ mcp_protocol_version_is_valid()

auto sourcemeta::core::mcp_protocol_version_is_valid ( const JSON::StringView value) -> bool
nodiscardconstexprnoexcept

Check whether the given wire string is a valid, recognized MCP protocol version. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_protocol_version_is_valid(const JSON::StringView value) noexcept -> bool
Definition mcp_protocol.h:484
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/versioning

◆ mcp_protocol_version_string()

auto sourcemeta::core::mcp_protocol_version_string ( const MCPProtocolVersion version) -> JSON::StringView
nodiscardconstexprnoexcept

Convert an MCPProtocolVersion enum value to its canonical string representation. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
"2026-07-28");
constexpr auto mcp_protocol_version_string(const MCPProtocolVersion version) noexcept -> JSON::StringView
Definition mcp_protocol.h:388
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/versioning

◆ mcp_request_input_responses()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_request_input_responses ( MCPProtocolVersion version,
const sourcemeta::core::JSON & envelope ) -> const sourcemeta::core::JSON *
nodiscard

Access inputResponses from an MRTR continuation request envelope. Returns a borrowed pointer into the envelope, or null when the member is absent or malformed. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
const auto continuation{sourcemeta::core::parse_json(R"JSON({
"jsonrpc": "2.0",
"id": 51,
"method": "tools/call",
"params": {
"name": "my-tool",
"requestState": "token-xyz",
"inputResponses": { "confirm": { "value": true } }
}
})JSON")};
continuation) ==
R"JSON({ "confirm": { "value": true } })JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_request_input_responses(MCPProtocolVersion version, const sourcemeta::core::JSON &envelope) -> const sourcemeta::core::JSON *
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/mrtr

◆ mcp_request_name_from_body()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_request_name_from_body ( const sourcemeta::core::JSON & envelope) -> std::optional< JSON::StringView >
nodiscard

Borrow the target tool name or resource URI from a JSON-RPC request body. The returned view is valid only while the source string remains alive and unchanged. A resource read is named by its URI rather than by a name, and a request that names no target yields nothing. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
const auto envelope{sourcemeta::core::parse_json(R"JSON({
"method": "tools/call",
"params": { "name": "weather" }
})JSON")};
assert(sourcemeta::core::mcp_request_name_from_body(envelope) == "weather");
SOURCEMETA_CORE_MCP_EXPORT auto mcp_request_name_from_body(const sourcemeta::core::JSON &envelope) -> std::optional< JSON::StringView >
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http#standard-request-headers

◆ mcp_request_state()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_request_state ( MCPProtocolVersion version,
const sourcemeta::core::JSON & envelope ) -> std::optional< JSON::StringView >
nodiscard

Access requestState token from an MRTR continuation request envelope. The returned view borrows the envelope. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
const auto continuation{sourcemeta::core::parse_json(R"JSON({
"jsonrpc": "2.0",
"id": 51,
"method": "tools/call",
"params": { "name": "my-tool", "requestState": "token-xyz" }
})JSON")};
continuation) == "token-xyz");
SOURCEMETA_CORE_MCP_EXPORT auto mcp_request_state(MCPProtocolVersion version, const sourcemeta::core::JSON &envelope) -> std::optional< JSON::StringView >
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/mrtr

◆ mcp_request_subscription_id()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_request_subscription_id ( MCPProtocolVersion version,
const sourcemeta::core::JSON & envelope ) -> const sourcemeta::core::JSON *
nodiscard

Access io.modelcontextprotocol/subscriptionId from request or result metadata. Returns a borrowed pointer into the envelope, or null when absent. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
const auto envelope{sourcemeta::core::parse_json(R"JSON({
"jsonrpc": "2.0",
"method": "notifications/tools/list_changed",
"params": {
"_meta": { "io.modelcontextprotocol/subscriptionId": "sub-1" }
}
})JSON")};
SOURCEMETA_CORE_MCP_EXPORT auto mcp_request_subscription_id(MCPProtocolVersion version, const sourcemeta::core::JSON &envelope) -> const sourcemeta::core::JSON *
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/subscriptions

◆ mcp_requires_cacheable_metadata()

auto sourcemeta::core::mcp_requires_cacheable_metadata ( const MCPProtocolVersion version) -> bool
nodiscardconstexprnoexcept

Whether cacheable responses in the specified protocol version must include ttlMs and cacheScope. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_requires_cacheable_metadata(const MCPProtocolVersion version) noexcept -> bool
Definition mcp_protocol.h:594
See also
https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/caching#cacheable-results

◆ mcp_requires_request_meta()

auto sourcemeta::core::mcp_requires_request_meta ( const MCPProtocolVersion version) -> bool
nodiscardconstexprnoexcept

Whether requests in the specified protocol version must carry metadata inside params._meta. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_requires_request_meta(const MCPProtocolVersion version) noexcept -> bool
Definition mcp_protocol.h:550
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/index#_meta

◆ mcp_requires_result_type()

auto sourcemeta::core::mcp_requires_result_type ( const MCPProtocolVersion version) -> bool
nodiscardconstexprnoexcept

Whether result responses in the specified protocol version must carry an explicit resultType field. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_requires_result_type(const MCPProtocolVersion version) noexcept -> bool
Definition mcp_protocol.h:572
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema

◆ mcp_resolve_cache_scope()

auto sourcemeta::core::mcp_resolve_cache_scope ( const JSON::StringView scope) -> std::optional< MCPCacheScope >
nodiscardconstexprnoexcept

Parse a canonical cache scope string. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
assert(!sourcemeta::core::mcp_resolve_cache_scope("shared").has_value());
constexpr auto mcp_resolve_cache_scope(const JSON::StringView scope) noexcept -> std::optional< MCPCacheScope >
Definition mcp_results.h:77

◆ mcp_resolve_log_level()

auto sourcemeta::core::mcp_resolve_log_level ( const JSON::StringView value) -> std::optional< MCPLogLevel >
nodiscardconstexprnoexcept

Parse an exact, case-sensitive logging severity without allocating. An unrecognized value yields no level, which the specification asks a server to report as an invalid parameter. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
assert(!sourcemeta::core::mcp_resolve_log_level("NOTICE").has_value());
assert(!sourcemeta::core::mcp_resolve_log_level("verbose").has_value());
constexpr auto mcp_resolve_log_level(const JSON::StringView value) noexcept -> std::optional< MCPLogLevel >
Definition mcp_logging.h:103
@ Notice
Normal but significant conditions.
Definition mcp_logging.h:32
See also
https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/logging

◆ mcp_resolve_protocol_version()

auto sourcemeta::core::mcp_resolve_protocol_version ( const JSON::StringView value) -> std::optional< MCPProtocolVersion >
nodiscardconstexprnoexcept

Resolve an MCP protocol version wire string to its corresponding enum value, or std::nullopt when the string does not match any recognized version. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
.has_value());
constexpr auto mcp_resolve_protocol_version(const JSON::StringView value) noexcept -> std::optional< MCPProtocolVersion >
Definition mcp_protocol.h:425
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/versioning

◆ mcp_resolve_result_type()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_resolve_result_type ( MCPProtocolVersion version,
const JSON & result,
std::span< const JSON::StringView > supported_extension_types = {} ) -> std::optional< JSON::StringView >
nodiscard

Recognize base and explicitly negotiated extension result types. The extension span is the caller's negotiated allowlist, not arbitrary input. Missing discriminators mean complete. Input_required and extensions require 2026-07-28. The returned view borrows the result (or a static base name). For example:

#include <sourcemeta/core/mcp.h>
#include <array>
#include <cassert>
const std::array<sourcemeta::core::JSON::StringView, 1> EXTENSIONS{
{"org.example/custom"}};
const auto custom{sourcemeta::core::parse_json(
R"JSON({ "resultType": "org.example/custom" })JSON")};
EXTENSIONS) == "org.example/custom");
EXTENSIONS)
.has_value());
SOURCEMETA_CORE_MCP_EXPORT auto mcp_resolve_result_type(MCPProtocolVersion version, const JSON &result, std::span< const JSON::StringView > supported_extension_types={}) -> std::optional< JSON::StringView >
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/index#result-responses

◆ mcp_result_type()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_result_type ( const JSON & result) -> std::optional< JSON::StringView >
nodiscard

Extract a raw result discriminator without validating support. Absent resultType means complete on incoming legacy results. Unknown string discriminators remain available to extensions. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
R"JSON({ "resultType": "example/extension" })JSON")) ==
"example/extension");
sourcemeta::core::parse_json(R"JSON({})JSON")) == "complete");
R"JSON({ "resultType": 1 })JSON"))
.has_value());
SOURCEMETA_CORE_MCP_EXPORT auto mcp_result_type(const JSON &result) -> std::optional< JSON::StringView >
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/index#result-responses

◆ mcp_serialize_client_capabilities()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_serialize_client_capabilities ( const MCPProtocolVersion version,
const MCPClientCapabilities & capabilities ) -> sourcemeta::core::JSON
nodiscard

Serialize client capabilities into a JSON object for the specified protocol version. A capability the target revision does not define is dropped, so serializing for an older revision than the one parsed is how a caller downgrades an advertisement. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
capabilities.roots = true;
capabilities.roots_list_changed = true;
capabilities) == sourcemeta::core::parse_json(R"JSON({
"roots": { "listChanged": true }
})JSON"));
capabilities) ==
sourcemeta::core::parse_json(R"JSON({ "roots": {} })JSON"));
bool roots
Whether the client advertises roots.
Definition mcp_capabilities.h:86
bool roots_list_changed
Whether roots advertise listChanged (legacy revisions only).
Definition mcp_capabilities.h:88
SOURCEMETA_CORE_MCP_EXPORT auto mcp_serialize_client_capabilities(const MCPProtocolVersion version, const MCPClientCapabilities &capabilities) -> sourcemeta::core::JSON
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#clientcapabilities

◆ mcp_serialize_resource_annotations()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_serialize_resource_annotations ( MCPProtocolVersion version,
const MCPResourceAnnotations & annotations ) -> JSON
nodiscard

Serialize advisory annotations, checking audience roles and gating lastModified to 2025-06-18 and later. Empty annotations remain an object. For example:

#include <sourcemeta/core/mcp.h>
#include <array>
#include <cassert>
constexpr std::array<sourcemeta::core::JSON::StringView, 2> ROLES{
{"user", "assistant"}};
.audience = ROLES, .priority = 0.5};
annotations) ==
"audience": [ "user", "assistant" ],
"priority": 0.5
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_serialize_resource_annotations(MCPProtocolVersion version, const MCPResourceAnnotations &annotations) -> JSON
Definition mcp_results.h:134
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#annotations

◆ mcp_serialize_server_capabilities()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_serialize_server_capabilities ( MCPProtocolVersion version,
const MCPServerCapabilities & capabilities ) -> JSON
nodiscard

Serialize server capabilities for an explicit revision. Typed flags override the source snapshot. Opaque settings survive only in retained capabilities. Throws MCPError for malformed known fields. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
capabilities.tools = true;
capabilities.tools_list_changed = true;
capabilities) == sourcemeta::core::parse_json(R"JSON({
"tools": { "listChanged": true }
})JSON"));
bool tools
Whether the server advertises tools.
Definition mcp_capabilities.h:127
bool tools_list_changed
Whether tools advertise listChanged.
Definition mcp_capabilities.h:133
SOURCEMETA_CORE_MCP_EXPORT auto mcp_serialize_server_capabilities(MCPProtocolVersion version, const MCPServerCapabilities &capabilities) -> JSON
Definition mcp_capabilities.h:121
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#servercapabilities

◆ mcp_supports_implementation_description()

auto sourcemeta::core::mcp_supports_implementation_description ( const MCPProtocolVersion version) -> bool
nodiscardconstexprnoexcept

Whether the specified MCP protocol version supports implementation description. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_supports_implementation_description(const MCPProtocolVersion version) noexcept -> bool
Definition mcp_protocol.h:799
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema

◆ mcp_supports_implementation_title()

auto sourcemeta::core::mcp_supports_implementation_title ( const MCPProtocolVersion version) -> bool
nodiscardconstexprnoexcept

Whether the specified MCP protocol version supports implementation title. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_supports_implementation_title(const MCPProtocolVersion version) noexcept -> bool
Definition mcp_protocol.h:776
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema

◆ mcp_supports_implementation_website_url()

auto sourcemeta::core::mcp_supports_implementation_website_url ( const MCPProtocolVersion version) -> bool
nodiscardconstexprnoexcept

Whether the specified MCP protocol version supports implementation website URL. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_supports_implementation_website_url(const MCPProtocolVersion version) noexcept -> bool
Definition mcp_protocol.h:822
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema

◆ mcp_supports_jsonrpc_batching()

auto sourcemeta::core::mcp_supports_jsonrpc_batching ( const MCPProtocolVersion version) -> bool
nodiscardconstexprnoexcept

Whether the specified MCP protocol version supports JSON-RPC batching. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_supports_jsonrpc_batching(const MCPProtocolVersion version) noexcept -> bool
Definition mcp_protocol.h:845
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http

◆ mcp_supports_method()

auto sourcemeta::core::mcp_supports_method ( const MCPProtocolVersion version,
const JSON::StringView method ) -> bool
nodiscardconstexprnoexcept

Whether a method is defined by the base protocol, including nested requests. This does not establish server implementation or negotiated extension support. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_supports_method(const MCPProtocolVersion version, const JSON::StringView method) noexcept -> bool
Definition mcp_protocol.h:1082
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema

◆ mcp_supports_mrtr()

auto sourcemeta::core::mcp_supports_mrtr ( const MCPProtocolVersion version) -> bool
nodiscardconstexprnoexcept

Whether the specified MCP protocol version supports Multi Round-Trip Results (input_required). For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_supports_mrtr(const MCPProtocolVersion version) noexcept -> bool
Definition mcp_protocol.h:663
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/mrtr

◆ mcp_supports_output_schema()

auto sourcemeta::core::mcp_supports_output_schema ( const MCPProtocolVersion version) -> bool
nodiscardconstexprnoexcept

Whether the specified MCP protocol version supports output schema on tool definitions. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_supports_output_schema(const MCPProtocolVersion version) noexcept -> bool
Definition mcp_protocol.h:708
See also
https://modelcontextprotocol.io/specification/2026-07-28/server/tools

◆ mcp_supports_ping()

auto sourcemeta::core::mcp_supports_ping ( const MCPProtocolVersion version) -> bool
nodiscardconstexprnoexcept

Whether the specified MCP protocol version supports the ping method. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_supports_ping(const MCPProtocolVersion version) noexcept -> bool
Definition mcp_protocol.h:528
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/lifecycle

◆ mcp_supports_protocol_sessions()

auto sourcemeta::core::mcp_supports_protocol_sessions ( const MCPProtocolVersion version) -> bool
nodiscardconstexprnoexcept

Whether the specified MCP protocol version supports stateful protocol sessions. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_supports_protocol_sessions(const MCPProtocolVersion version) noexcept -> bool
Definition mcp_protocol.h:685
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http

◆ mcp_supports_resource_link_content()

auto sourcemeta::core::mcp_supports_resource_link_content ( const MCPProtocolVersion version) -> bool
nodiscardconstexprnoexcept

Whether the specified MCP protocol version supports resource link content. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_supports_resource_link_content(const MCPProtocolVersion version) noexcept -> bool
Definition mcp_protocol.h:753
See also
https://modelcontextprotocol.io/specification/2026-07-28/schema

◆ mcp_supports_server_discover()

auto sourcemeta::core::mcp_supports_server_discover ( const MCPProtocolVersion version) -> bool
nodiscardconstexprnoexcept

Whether the specified MCP protocol version supports the 2026-07-28 server/discover method. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_supports_server_discover(const MCPProtocolVersion version) noexcept -> bool
Definition mcp_protocol.h:617
See also
https://modelcontextprotocol.io/specification/2026-07-28/server/discover

◆ mcp_supports_structured_content()

auto sourcemeta::core::mcp_supports_structured_content ( const MCPProtocolVersion version) -> bool
nodiscardconstexprnoexcept

Whether the specified MCP protocol version supports structured content. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_supports_structured_content(const MCPProtocolVersion version) noexcept -> bool
Definition mcp_protocol.h:730
See also
https://modelcontextprotocol.io/specification/2026-07-28/server/tools

◆ mcp_supports_subscriptions_listen()

auto sourcemeta::core::mcp_supports_subscriptions_listen ( const MCPProtocolVersion version) -> bool
nodiscardconstexprnoexcept

Whether the specified MCP protocol version supports 2026-07-28 server-side subscriptions via subscriptions/listen. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_supports_subscriptions_listen(const MCPProtocolVersion version) noexcept -> bool
Definition mcp_protocol.h:640
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/subscriptions

◆ mcp_tool_call_arguments()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_tool_call_arguments ( const sourcemeta::core::JSON & envelope) -> const sourcemeta::core::JSON *
nodiscard

Borrow the arguments object from a JSON-RPC tools/call envelope. Returns null when the member is absent or is not an object, so a tool that takes no arguments is indistinguishable from a malformed one here. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
const auto envelope{sourcemeta::core::parse_json(R"JSON({
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": { "name": "foo", "arguments": { "x": 1 } }
})JSON")};
sourcemeta::core::parse_json(R"JSON({ "x": 1 })JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_tool_call_arguments(const sourcemeta::core::JSON &envelope) -> const sourcemeta::core::JSON *
See also
https://modelcontextprotocol.io/specification/2026-07-28/server/tools

◆ mcp_uses_initialization_handshake()

auto sourcemeta::core::mcp_uses_initialization_handshake ( const MCPProtocolVersion version) -> bool
nodiscardconstexprnoexcept

Whether the specified MCP protocol version uses an initialization handshake (initialize / notifications/initialized). For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
constexpr auto mcp_uses_initialization_handshake(const MCPProtocolVersion version) noexcept -> bool
Definition mcp_protocol.h:506
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/lifecycle

◆ mcp_validate_continuation() [1/2]

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_validate_continuation ( MCPProtocolVersion version,
const JSON & parameters,
const JSON & input_requests ) -> bool
nodiscard

Check continuation field shapes, exact state echo when expected, and known response kinds against the prior input requests. Unknown response keys are ignored. Core does not validate the user's form values against arbitrary JSON Schema, protect state integrity, or enforce new request IDs/history. This overload checks field shapes without matching a state token. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
const auto parameters{sourcemeta::core::parse_json(R"JSON({
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": {}
},
"requestState": "state",
"inputResponses": {
"form": { "action": "accept", "content": { "value": 1.25 } }
}
})JSON")};
const auto prior{sourcemeta::core::parse_json(R"JSON({
"form": {
"method": "elicitation/create",
"params": {
"mode": "form",
"message": "value",
"requestedSchema": { "type": "object", "properties": {} }
}
}
})JSON")};
prior));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_validate_continuation(MCPProtocolVersion version, const JSON &parameters, const JSON &input_requests) -> bool
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/mrtr#client-requirements-basic-workflow

◆ mcp_validate_continuation() [2/2]

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_validate_continuation ( MCPProtocolVersion version,
const JSON & parameters,
const JSON & input_requests,
std::optional< JSON::StringView > expected_state ) -> bool
nodiscard

Check continuation fields and the state token, where the expected state selects one of three outcomes. Passing std::nullopt requires the token to be absent, which is how a server that issued no state enforces that the retry carries none. Passing an empty string requires a token that is present and empty. Passing any other string requires the token to equal it exactly. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
const auto parameters{sourcemeta::core::parse_json(R"JSON({
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": {}
},
"requestState": "state"
})JSON")};
"state"));
"other"));
std::nullopt));
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/mrtr

◆ mcp_validate_parameter_headers()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_validate_parameter_headers ( MCPProtocolVersion version,
const JSON & identifier,
std::span< const MCPHeaderParameter > parameters,
const JSON & arguments,
std::span< const std::pair< JSON::StringView, JSON::StringView > > headers ) -> std::optional< JSON >
nodiscard

Compare annotated parameters with raw HTTP headers case-insensitively. Validates required mirrors, encoding, duplicates and numeric equivalence. Protocol version must be 2026-07-28. The caller supplies the descriptors. Returns nothing when every mirror agrees, and a JSON-RPC error envelope otherwise. For example:

#include <sourcemeta/core/mcp.h>
#include <array>
#include <cassert>
#include <utility>
const std::array<sourcemeta::core::MCPHeaderParameter, 1> descriptors{
{{.name = "Count",
.path = {"number"},
const auto arguments{
sourcemeta::core::parse_json(R"JSON({ "number": 42 })JSON")};
const std::array<std::pair<sourcemeta::core::JSON::StringView,
1>
headers{{{"Mcp-Param-Count", "42"}}};
sourcemeta::core::JSON{0}, descriptors, arguments, headers)
.has_value());
std::basic_string_view< Char, CharTraits > StringView
The string view type used by the JSON document.
Definition json_value.h:54
SOURCEMETA_CORE_MCP_EXPORT auto mcp_validate_parameter_headers(MCPProtocolVersion version, const JSON &identifier, std::span< const MCPHeaderParameter > parameters, const JSON &arguments, std::span< const std::pair< JSON::StringView, JSON::StringView > > headers) -> std::optional< JSON >
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http#server-validation

◆ mcp_validate_request_headers() [1/2]

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_validate_request_headers ( const MCPProtocolVersion version,
const std::optional< JSON::StringView > & protocol_version_header,
const std::optional< JSON::StringView > & method_header,
const std::optional< JSON::StringView > & name_header,
const sourcemeta::core::JSON & envelope,
const std::span< const JSON::StringView > supported_versions ) -> std::optional< sourcemeta::core::JSON >
nodiscard

Validate Streamable HTTP transport header values against the parsed JSON-RPC request body for the specified protocol version. Returns nothing when the headers agree with the body, and a ready-to-send JSON-RPC error envelope otherwise. Every revision in the supported list must be one this library models, which is a condition on the caller rather than on the peer, so a violation throws rather than producing an envelope. For example:

#include <sourcemeta/core/mcp.h>
#include <array>
#include <cassert>
constexpr std::array<sourcemeta::core::JSON::StringView, 1> SUPPORTED{
{"2026-07-28"}};
const auto envelope{sourcemeta::core::parse_json(R"JSON({
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "weather",
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": {}
}
}
})JSON")};
"2026-07-28", "tools/call", "weather", envelope, SUPPORTED)
.has_value());
"tools/call", "other", envelope, SUPPORTED)
.has_value());
SOURCEMETA_CORE_MCP_EXPORT auto mcp_validate_request_headers(const MCPProtocolVersion version, const std::optional< JSON::StringView > &protocol_version_header, const std::optional< JSON::StringView > &method_header, const std::optional< JSON::StringView > &name_header, const sourcemeta::core::JSON &envelope, const std::span< const JSON::StringView > supported_versions) -> std::optional< sourcemeta::core::JSON >
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http#server-validation

◆ mcp_validate_request_headers() [2/2]

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_validate_request_headers ( MCPProtocolVersion version,
std::span< const std::pair< JSON::StringView, JSON::StringView > > headers,
const JSON & envelope,
std::span< const JSON::StringView > supported_versions ) -> std::optional< JSON >
nodiscard

Validate a borrowed HTTP header collection. Names are case insensitive. Duplicate recognized singleton fields are rejected. Unknown fields stay opaque. HTTP framing, Origin and session validation belong to the adapter. Returns nothing on success and a JSON-RPC error envelope otherwise. Every revision in the supported list must be one this library models, which is a condition on the caller rather than on the peer, so a violation throws rather than producing an envelope. For example:

#include <sourcemeta/core/mcp.h>
#include <array>
#include <cassert>
#include <utility>
constexpr std::array<sourcemeta::core::JSON::StringView, 1> SUPPORTED{
{"2026-07-28"}};
const auto envelope{sourcemeta::core::parse_json(R"JSON({
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "weather",
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": {}
}
}
})JSON")};
const std::array<std::pair<sourcemeta::core::JSON::StringView,
3>
headers{{{"MCP-Protocol-Version", "2026-07-28"},
{"Mcp-Method", "tools/call"},
{"Mcp-Name", "weather"}}};
envelope, SUPPORTED)
.has_value());
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http#server-validation

◆ mcp_validate_request_meta()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_validate_request_meta ( const sourcemeta::core::JSON & envelope) -> std::pair< MCPRequestMetaStatus, std::optional< MCPRequestMeta > >
nodiscard

Validate and extract MCP 2026-07-28 request metadata from a request envelope. Use mcp_validate_request_parameters for parameters. The metadata is only present when the status is MCPRequestMetaStatus::Valid, and it borrows from the envelope. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
const auto envelope{sourcemeta::core::parse_json(R"JSON({
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": {}
}
}
})JSON")};
const auto [status,
assert(meta->protocol_version ==
assert(!meta->client_info.has_value());
SOURCEMETA_CORE_MCP_EXPORT auto mcp_validate_request_meta(const sourcemeta::core::JSON &envelope) -> std::pair< MCPRequestMetaStatus, std::optional< MCPRequestMeta > >
@ Valid
The request metadata is fully valid.
Definition mcp_headers.h:38
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/index#_meta

◆ mcp_validate_request_parameters()

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_validate_request_parameters ( const JSON & parameters) -> std::pair< MCPRequestMetaStatus, std::optional< MCPRequestMeta > >
nodiscard

Validate metadata in a parameters object, without guessing envelope shape. This is the entry point for a caller that has already located the parameters, such as one dispatching a batch member. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
const auto parameters{sourcemeta::core::parse_json(R"JSON({
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": {}
}
})JSON")};
SOURCEMETA_CORE_MCP_EXPORT auto mcp_validate_request_parameters(const JSON &parameters) -> std::pair< MCPRequestMetaStatus, std::optional< MCPRequestMeta > >
See also
https://modelcontextprotocol.io/specification/2026-07-28/basic/index#_meta

◆ mcp_write_result() [1/2]

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_write_result ( std::ostream & stream,
MCPProtocolVersion version,
JSON::StringView method,
const JSON & identifier,
const JSON & result,
std::optional< MCPCachePolicy > cache_policy,
std::optional< MCPImplementation > server_info = std::nullopt ) -> void

Serialize a complete MCP response for one of the six cacheable operations. The result is copied before decoration. The source remains unchanged. A cache policy is mandatory for 2026-07-28. Pass std::nullopt for legacy responses. A precomputed discovery result is held to the same rules as the builder that produces one, so its advertised revisions must be non-empty, must include the revision being served, and must each be one this library models. This writes JSON only. Stdio callers must append a newline themselves. For example:

#include <sourcemeta/core/mcp.h>
#include <cassert>
#include <sstream>
result.assign("resources", sourcemeta::core::JSON::make_array());
std::ostringstream stream;
"resources/list", sourcemeta::core::JSON{1}, result,
assert(sourcemeta::core::parse_json(stream.str()) ==
"jsonrpc": "2.0",
"id": 1,
"result": {
"resources": [],
"resultType": "complete",
"ttlMs": 0,
"cacheScope": "private"
}
})JSON"));
SOURCEMETA_CORE_MCP_EXPORT auto mcp_write_result(std::ostream &stream, MCPProtocolVersion version, JSON::StringView method, const JSON &identifier, const JSON &result, std::optional< MCPCachePolicy > cache_policy, std::optional< MCPImplementation > server_info=std::nullopt) -> void
Definition mcp_results.h:95
See also
https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/caching#cacheable-results

◆ mcp_write_result() [2/2]

SOURCEMETA_CORE_MCP_EXPORT auto sourcemeta::core::mcp_write_result ( std::ostream & stream,
MCPProtocolVersion version,
JSON::StringView method,
const JSON & identifier,
JSON && result,
std::optional< MCPCachePolicy > cache_policy,
std::optional< MCPImplementation > server_info = std::nullopt ) -> void

Serialize a complete MCP response for one of the six cacheable operations using move semantics, decorating the provided result in-place. A cache policy is mandatory for 2026-07-28. Pass std::nullopt for legacy responses. A precomputed discovery result is held to the same rules as the builder that produces one, so its advertised revisions must be non-empty, must include the revision being served, and must each be one this library models. This writes JSON only. Stdio callers must append a newline themselves.

See also
https://modelcontextprotocol.io/specification/2026-07-28/server/utilities/caching#cacheable-results

Variable Documentation

◆ MCP_CODE_HEADER_MISMATCH

std::int64_t sourcemeta::core::MCP_CODE_HEADER_MISMATCH {-32020}
constexpr

The MCP error code indicating that a transport header disagreed with the request body.

◆ MCP_CODE_MISSING_REQUIRED_CLIENT_CAPABILITY

std::int64_t sourcemeta::core::MCP_CODE_MISSING_REQUIRED_CLIENT_CAPABILITY {-32021}
constexpr

The MCP error code indicating that a required capability was not declared in request metadata.

◆ MCP_CODE_RESOURCE_NOT_FOUND

std::int64_t sourcemeta::core::MCP_CODE_RESOURCE_NOT_FOUND {-32002}
constexpr

The legacy MCP error code returned when a requested resource cannot be found.

◆ MCP_CODE_UNSUPPORTED_PROTOCOL_VERSION

std::int64_t sourcemeta::core::MCP_CODE_UNSUPPORTED_PROTOCOL_VERSION {-32022}
constexpr

The MCP error code indicating that the requested protocol version is not supported by the receiver.

◆ MCP_CODE_URL_ELICITATION_REQUIRED

std::int64_t sourcemeta::core::MCP_CODE_URL_ELICITATION_REQUIRED {-32042}
constexpr

The MCP error code indicating that the client must complete a URL elicitation flow before retrying. Defined in 2025-11-25 and retired in 2026-07-28.

◆ MCP_HEADER_METHOD

JSON::StringView sourcemeta::core::MCP_HEADER_METHOD {"Mcp-Method"}
constexpr

Header name for the MCP method in Streamable HTTP transport.

◆ MCP_HEADER_NAME

JSON::StringView sourcemeta::core::MCP_HEADER_NAME {"Mcp-Name"}
constexpr

Header name for the target name/URI in Streamable HTTP transport.

◆ MCP_HEADER_PROTOCOL_VERSION

JSON::StringView sourcemeta::core::MCP_HEADER_PROTOCOL_VERSION {"MCP-Protocol-Version"}
constexpr

Header name for the protocol version in Streamable HTTP transport.

◆ MCP_METHOD_COMPLETION_COMPLETE

◆ MCP_METHOD_ELICITATION_CREATE

◆ MCP_METHOD_INITIALIZE

JSON::StringView sourcemeta::core::MCP_METHOD_INITIALIZE {"initialize"}
constexpr

◆ MCP_METHOD_LOGGING_SET_LEVEL

JSON::StringView sourcemeta::core::MCP_METHOD_LOGGING_SET_LEVEL {"logging/setLevel"}
constexpr

◆ MCP_METHOD_NOTIFICATIONS_CANCELLED

◆ MCP_METHOD_NOTIFICATIONS_ELICITATION_COMPLETE

JSON::StringView sourcemeta::core::MCP_METHOD_NOTIFICATIONS_ELICITATION_COMPLETE
constexpr
Initial value:
{
"notifications/elicitation/complete"}

Wire method name for notifications/elicitation/complete.

See also
https://modelcontextprotocol.io/specification/2025-11-25/schema#elicitationcompletenotification

◆ MCP_METHOD_NOTIFICATIONS_INITIALIZED

JSON::StringView sourcemeta::core::MCP_METHOD_NOTIFICATIONS_INITIALIZED
constexpr
Initial value:
{
"notifications/initialized"}

Wire string for the initialization confirmation notification.

See also
https://modelcontextprotocol.io/specification/2025-06-18/schema#initializednotification https://modelcontextprotocol.io/specification/2025-11-25/schema#initializednotification

◆ MCP_METHOD_NOTIFICATIONS_MESSAGE

◆ MCP_METHOD_NOTIFICATIONS_PROGRESS

◆ MCP_METHOD_NOTIFICATIONS_PROMPTS_LIST_CHANGED

JSON::StringView sourcemeta::core::MCP_METHOD_NOTIFICATIONS_PROMPTS_LIST_CHANGED
constexpr

◆ MCP_METHOD_NOTIFICATIONS_RESOURCES_LIST_CHANGED

JSON::StringView sourcemeta::core::MCP_METHOD_NOTIFICATIONS_RESOURCES_LIST_CHANGED
constexpr

◆ MCP_METHOD_NOTIFICATIONS_RESOURCES_UPDATED

JSON::StringView sourcemeta::core::MCP_METHOD_NOTIFICATIONS_RESOURCES_UPDATED
constexpr

◆ MCP_METHOD_NOTIFICATIONS_ROOTS_LIST_CHANGED

JSON::StringView sourcemeta::core::MCP_METHOD_NOTIFICATIONS_ROOTS_LIST_CHANGED
constexpr
Initial value:
{
"notifications/roots/list_changed"}

Wire method name for notifications/roots/list_changed.

This feature is deprecated as of protocol version 2026-07-28, which states that new implementations should not adopt it. The method remains here because the library still speaks the revisions that define it.

See also
https://modelcontextprotocol.io/specification/2026-07-28/deprecated https://modelcontextprotocol.io/specification/2025-06-18/schema#rootslistchangednotification https://modelcontextprotocol.io/specification/2025-11-25/schema#rootslistchangednotification

◆ MCP_METHOD_NOTIFICATIONS_SUBSCRIPTIONS_ACKNOWLEDGED

JSON::StringView sourcemeta::core::MCP_METHOD_NOTIFICATIONS_SUBSCRIPTIONS_ACKNOWLEDGED
constexpr
Initial value:
{
"notifications/subscriptions/acknowledged"}

Wire string for the 2026-07-28 subscriptions acknowledged notification.

See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#subscriptionsacknowledgednotification

◆ MCP_METHOD_NOTIFICATIONS_TASKS_STATUS

JSON::StringView sourcemeta::core::MCP_METHOD_NOTIFICATIONS_TASKS_STATUS
constexpr
Initial value:
{
"notifications/tasks/status"}

Wire method name for notifications/tasks/status.

See also
https://modelcontextprotocol.io/specification/2025-11-25/schema#taskstatusnotification

◆ MCP_METHOD_NOTIFICATIONS_TOOLS_LIST_CHANGED

JSON::StringView sourcemeta::core::MCP_METHOD_NOTIFICATIONS_TOOLS_LIST_CHANGED
constexpr

◆ MCP_METHOD_PING

JSON::StringView sourcemeta::core::MCP_METHOD_PING {"ping"}
constexpr

◆ MCP_METHOD_PROMPTS_GET

◆ MCP_METHOD_PROMPTS_LIST

◆ MCP_METHOD_RESOURCES_LIST

◆ MCP_METHOD_RESOURCES_READ

◆ MCP_METHOD_RESOURCES_SUBSCRIBE

JSON::StringView sourcemeta::core::MCP_METHOD_RESOURCES_SUBSCRIBE
constexpr

◆ MCP_METHOD_RESOURCES_TEMPLATES_LIST

◆ MCP_METHOD_RESOURCES_UNSUBSCRIBE

JSON::StringView sourcemeta::core::MCP_METHOD_RESOURCES_UNSUBSCRIBE
constexpr

◆ MCP_METHOD_ROOTS_LIST

JSON::StringView sourcemeta::core::MCP_METHOD_ROOTS_LIST {"roots/list"}
constexpr

Wire string for the roots list request method.

This feature is deprecated as of protocol version 2026-07-28, which states that new implementations should not adopt it. The method remains here because the library still speaks the revisions that define it.

See also
https://modelcontextprotocol.io/specification/2026-07-28/deprecated https://modelcontextprotocol.io/specification/2025-06-18/schema#listrootsrequest https://modelcontextprotocol.io/specification/2025-11-25/schema#listrootsrequest https://modelcontextprotocol.io/specification/2026-07-28/schema#listrootsrequest

◆ MCP_METHOD_SAMPLING_CREATE_MESSAGE

JSON::StringView sourcemeta::core::MCP_METHOD_SAMPLING_CREATE_MESSAGE
constexpr
Initial value:
{
"sampling/createMessage"}

Wire string for the sampling create-message request method.

This feature is deprecated as of protocol version 2026-07-28, which states that new implementations should not adopt it. The method remains here because the library still speaks the revisions that define it.

See also
https://modelcontextprotocol.io/specification/2026-07-28/deprecated https://modelcontextprotocol.io/specification/2025-06-18/schema#createmessagerequest https://modelcontextprotocol.io/specification/2025-11-25/schema#createmessagerequest https://modelcontextprotocol.io/specification/2026-07-28/schema#createmessagerequest

◆ MCP_METHOD_SERVER_DISCOVER

JSON::StringView sourcemeta::core::MCP_METHOD_SERVER_DISCOVER {"server/discover"}
constexpr

Wire string for the 2026-07-28 server discovery request method.

See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#discoverrequest

◆ MCP_METHOD_SUBSCRIPTIONS_LISTEN

JSON::StringView sourcemeta::core::MCP_METHOD_SUBSCRIPTIONS_LISTEN
constexpr
Initial value:
{
"subscriptions/listen"}

Wire string for the 2026-07-28 subscriptions listen request method.

See also
https://modelcontextprotocol.io/specification/2026-07-28/schema#subscriptionslistenrequest

◆ MCP_METHOD_TASKS_CANCEL

JSON::StringView sourcemeta::core::MCP_METHOD_TASKS_CANCEL {"tasks/cancel"}
constexpr

◆ MCP_METHOD_TASKS_GET

JSON::StringView sourcemeta::core::MCP_METHOD_TASKS_GET {"tasks/get"}
constexpr

◆ MCP_METHOD_TASKS_LIST

JSON::StringView sourcemeta::core::MCP_METHOD_TASKS_LIST {"tasks/list"}
constexpr

◆ MCP_METHOD_TASKS_RESULT

JSON::StringView sourcemeta::core::MCP_METHOD_TASKS_RESULT {"tasks/result"}
constexpr

◆ MCP_METHOD_TOOLS_CALL

◆ MCP_METHOD_TOOLS_LIST

◆ MCP_PROTOCOL_VERSION_2025_03_26

JSON::StringView sourcemeta::core::MCP_PROTOCOL_VERSION_2025_03_26 {"2025-03-26"}
constexpr

Wire string constant for MCP protocol version 2025-03-26.

◆ MCP_PROTOCOL_VERSION_2025_06_18

JSON::StringView sourcemeta::core::MCP_PROTOCOL_VERSION_2025_06_18 {"2025-06-18"}
constexpr

Wire string constant for MCP protocol version 2025-06-18.

◆ MCP_PROTOCOL_VERSION_2025_11_25

JSON::StringView sourcemeta::core::MCP_PROTOCOL_VERSION_2025_11_25 {"2025-11-25"}
constexpr

Wire string constant for MCP protocol version 2025-11-25.

◆ MCP_PROTOCOL_VERSION_2026_07_28

JSON::StringView sourcemeta::core::MCP_PROTOCOL_VERSION_2026_07_28 {"2026-07-28"}
constexpr

Wire string constant for MCP protocol version 2026-07-28.