1#ifndef SOURCEMETA_CORE_MCP_HEADERS_H_
2#define SOURCEMETA_CORE_MCP_HEADERS_H_
4#ifndef SOURCEMETA_CORE_MCP_EXPORT
5#include <sourcemeta/core/mcp_export.h>
8#include <sourcemeta/core/json.h>
9#include <sourcemeta/core/mcp_capabilities.h>
10#include <sourcemeta/core/mcp_error.h>
11#include <sourcemeta/core/mcp_protocol.h>
20namespace sourcemeta::core {
144[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT
auto
146 -> std::pair<MCPRequestMetaStatus, std::optional<MCPRequestMeta>>;
169[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT
auto
171 -> std::pair<MCPRequestMetaStatus, std::optional<MCPRequestMeta>>;
222 const std::span<const JSON::StringView> supported)
244[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT
auto
246 -> std::optional<JSON::StringView>;
289 const std::optional<JSON::StringView> &protocol_version_header,
290 const std::optional<JSON::StringView> &method_header,
291 const std::optional<JSON::StringView> &name_header,
293 const std::span<const JSON::StringView> supported_versions)
294 -> std::optional<sourcemeta::core::JSON>;
317[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT
auto
366 std::span<
const std::pair<JSON::StringView, JSON::StringView>> headers,
367 const JSON &envelope, std::span<const JSON::StringView> supported_versions)
368 -> std::optional<JSON>;
398 std::vector<JSON::StringView>
path;
442[[nodiscard]] SOURCEMETA_CORE_MCP_EXPORT
auto
444 const JSON &arguments)
445 -> std::vector<std::pair<std::string, std::string>>;
480 std::span<const MCPHeaderParameter> parameters,
const JSON &arguments,
481 std::span<
const std::pair<JSON::StringView, JSON::StringView>> headers)
482 -> std::optional<JSON>;
Type
The different types of a JSON instance.
Definition json_value.h:69
std::basic_string_view< Char, CharTraits > StringView
The string view type used by the JSON document.
Definition json_value.h:54
std::vector< JSON::StringView > path
Instance property path, with no array or reference traversal.
Definition mcp_headers.h:398
std::optional< MCPImplementation > client_info
Optional borrowed implementation description.
Definition mcp_headers.h:103
const JSON & meta_object
Borrowed metadata. Never null after successful validation.
Definition mcp_headers.h:107
MCPProtocolVersion protocol_version
The declared protocol revision.
Definition mcp_headers.h:99
const JSON * progress_token
Optional borrowed progress token.
Definition mcp_headers.h:109
std::optional< JSON::StringView > log_level
Optional requested log level.
Definition mcp_headers.h:105
JSON::Type type
One of String, Integer or Boolean.
Definition mcp_headers.h:400
const JSON & client_capabilities
Borrowed capabilities. The source request must outlive this view.
Definition mcp_headers.h:101
JSON::StringView name
The suffix of Mcp-Param-{name}.
Definition mcp_headers.h:396
MCPProtocolVersion
Definition mcp_protocol.h:30
SOURCEMETA_CORE_MCP_EXPORT auto mcp_validate_request_meta(const sourcemeta::core::JSON &envelope) -> std::pair< MCPRequestMetaStatus, std::optional< MCPRequestMeta > >
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 >
constexpr JSON::StringView MCP_HEADER_PROTOCOL_VERSION
Definition mcp_headers.h:24
SOURCEMETA_CORE_MCP_EXPORT auto mcp_request_name_from_body(const sourcemeta::core::JSON &envelope) -> std::optional< JSON::StringView >
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 > >
SOURCEMETA_CORE_MCP_EXPORT auto mcp_validate_request_parameters(const JSON ¶meters) -> std::pair< MCPRequestMetaStatus, std::optional< MCPRequestMeta > >
MCPRequestMetaStatus
Definition mcp_headers.h:36
constexpr JSON::StringView MCP_HEADER_METHOD
Definition mcp_headers.h:28
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
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 >
SOURCEMETA_CORE_MCP_EXPORT auto mcp_encode_header_value(JSON::StringView value) -> std::string
constexpr JSON::StringView MCP_HEADER_NAME
Definition mcp_headers.h:32
@ InvalidEnvelope
The input is not a valid MCP request envelope.
Definition mcp_headers.h:40
@ InvalidMetaKey
Metadata contains an invalid key name or malformed tracing value.
Definition mcp_headers.h:42
@ MetaNotObject
The _meta property is not a JSON object.
Definition mcp_headers.h:60
@ ProtocolVersionNotString
io.modelcontextprotocol/protocolVersion is not a string.
Definition mcp_headers.h:64
@ MissingMeta
The params object lacks a _meta property.
Definition mcp_headers.h:58
@ ClientInfoTitleNotString
title property in io.modelcontextprotocol/clientInfo is not a string.
Definition mcp_headers.h:83
@ ParamsNotObject
The params property is not a JSON object.
Definition mcp_headers.h:56
@ InvalidProgressToken
progressToken must be a string or integer.
Definition mcp_headers.h:52
@ InvalidClientInfo
Implementation icons have invalid shapes.
Definition mcp_headers.h:48
@ Valid
The request metadata is fully valid.
Definition mcp_headers.h:38
@ MissingParams
Request envelope lacks a params property.
Definition mcp_headers.h:54
@ MissingClientCapabilities
_meta lacks io.modelcontextprotocol/clientCapabilities.
Definition mcp_headers.h:68
@ ClientInfoVersionNotString
Definition mcp_headers.h:81
@ InvalidLogLevel
logLevel must be one of the eight specified logging levels.
Definition mcp_headers.h:50
@ MissingClientInfoVersion
io.modelcontextprotocol/clientInfo lacks required version property.
Definition mcp_headers.h:78
@ ClientInfoNameNotString
name property in io.modelcontextprotocol/clientInfo is not a string.
Definition mcp_headers.h:76
@ InvalidClientCapabilities
Known client capability fields have invalid shapes.
Definition mcp_headers.h:44
@ ClientInfoNotObject
io.modelcontextprotocol/clientInfo is not a JSON object.
Definition mcp_headers.h:72
@ ClientCapabilitiesNotObject
io.modelcontextprotocol/clientCapabilities is not a JSON object.
Definition mcp_headers.h:70
@ MissingClientInfoName
io.modelcontextprotocol/clientInfo lacks required name property.
Definition mcp_headers.h:74
@ MissingProtocolVersion
_meta lacks io.modelcontextprotocol/protocolVersion.
Definition mcp_headers.h:62
@ ClientInfoWebsiteUrlNotString
Client websiteUrl must be a string.
Definition mcp_headers.h:46
@ ClientInfoDescriptionNotString
Definition mcp_headers.h:86
@ UnsupportedProtocolVersion
io.modelcontextprotocol/protocolVersion is not a recognized version.
Definition mcp_headers.h:66