1#ifndef SOURCEMETA_CORE_MCP_H_
2#define SOURCEMETA_CORE_MCP_H_
4#ifndef SOURCEMETA_CORE_MCP_EXPORT
5#include <sourcemeta/core/mcp_export.h>
8#include <sourcemeta/core/json.h>
9#include <sourcemeta/core/jsonrpc.h>
25namespace sourcemeta::core {
91 "resources/templates/list"};
96 "notifications/initialized"};
145 -> std::optional<MCPProtocolVersion> {
146 if (header.empty()) {
153 if (header ==
"2025-11-25") {
156 if (header ==
"2025-06-18") {
159 if (header ==
"2025-03-26") {
234SOURCEMETA_CORE_MCP_EXPORT
249SOURCEMETA_CORE_MCP_EXPORT
275SOURCEMETA_CORE_MCP_EXPORT
301SOURCEMETA_CORE_MCP_EXPORT
322SOURCEMETA_CORE_MCP_EXPORT
341SOURCEMETA_CORE_MCP_EXPORT
357SOURCEMETA_CORE_MCP_EXPORT
361 const std::optional<std::size_t> size = std::nullopt,
362 const std::optional<double> priority = std::nullopt)
376SOURCEMETA_CORE_MCP_EXPORT
399SOURCEMETA_CORE_MCP_EXPORT
415SOURCEMETA_CORE_MCP_EXPORT
450SOURCEMETA_CORE_MCP_EXPORT
454 std::optional<sourcemeta::core::JSON> output_schema = std::nullopt,
511SOURCEMETA_CORE_MCP_EXPORT
538SOURCEMETA_CORE_MCP_EXPORT
std::basic_string_view< Char, CharTraits > StringView
The string view type used by the JSON document.
Definition json_value.h:54
JSON::StringView title
Optional human-readable title for the tool.
Definition mcp.h:426
JSON::StringView description
Optional human-readable description.
Definition mcp.h:468
bool logging
Whether the server advertises logging.
Definition mcp.h:484
bool completions
Whether the server advertises completions.
Definition mcp.h:486
bool tools
Whether the server advertises tools.
Definition mcp.h:482
bool destructive
true when the tool may mutate or delete state.
Definition mcp.h:430
bool idempotent
Definition mcp.h:433
JSON::StringView version
Semver-compatible server version.
Definition mcp.h:464
JSON::StringView title
Optional human-readable title.
Definition mcp.h:466
bool open_world
true when the tool interacts with state outside the server's control.
Definition mcp.h:435
JSON::StringView website_url
Optional public website URL.
Definition mcp.h:470
bool resources
Whether the server advertises resources.
Definition mcp.h:480
bool read_only
true when the tool guarantees no side effects.
Definition mcp.h:428
bool prompts
Whether the server advertises prompts.
Definition mcp.h:478
JSON::StringView name
Short machine-readable server name.
Definition mcp.h:462
constexpr auto mcp_supports_implementation_website_url(const MCPProtocolVersion version) noexcept -> bool
Definition mcp.h:209
constexpr JSON::StringView MCP_METHOD_TOOLS_LIST
Definition mcp.h:74
MCPProtocolVersion
Definition mcp.h:29
constexpr auto mcp_supports_jsonrpc_batching(const MCPProtocolVersion version) noexcept -> bool
Definition mcp.h:217
SOURCEMETA_CORE_MCP_EXPORT auto mcp_tool_call_arguments(const sourcemeta::core::JSON &envelope) -> const sourcemeta::core::JSON *
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_resources_read_result(sourcemeta::core::JSON contents) -> sourcemeta::core::JSON
constexpr JSON::StringView MCP_METHOD_TOOLS_CALL
Definition mcp.h:78
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_resource_link(const MCPProtocolVersion version, const JSON::StringView uri, const JSON::StringView mime_type, const JSON::StringView name={}, const JSON::StringView description={}) -> sourcemeta::core::JSON
constexpr JSON::StringView MCP_METHOD_NOTIFICATIONS_INITIALIZED
Definition mcp.h:95
constexpr auto mcp_supports_output_schema(const MCPProtocolVersion version) noexcept -> bool
Definition mcp.h:168
constexpr auto mcp_supports_structured_content(const MCPProtocolVersion version) noexcept -> bool
Definition mcp.h:176
constexpr auto mcp_supports_resource_link_content(const MCPProtocolVersion version) noexcept -> bool
Definition mcp.h:184
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_text_block(const JSON::StringView text) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_tool_error(const sourcemeta::core::JSON &identifier, const JSON::StringView message) -> sourcemeta::core::JSON
constexpr auto mcp_resolve_protocol_version(const JSON::StringView header) noexcept -> std::optional< MCPProtocolVersion >
Definition mcp.h:144
constexpr JSON::StringView MCP_METHOD_PING
Definition mcp.h:70
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
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={}) -> sourcemeta::core::JSON
constexpr JSON::StringView MCP_METHOD_RESOURCES_LIST
Definition mcp.h:82
constexpr auto mcp_is_request_method(const JSON::StringView method) noexcept -> bool
Definition mcp.h:118
constexpr std::int64_t MCP_CODE_RESOURCE_NOT_FOUND
Definition mcp.h:100
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_tool_success(const MCPProtocolVersion version, const sourcemeta::core::JSON &identifier, sourcemeta::core::JSON result) -> sourcemeta::core::JSON
constexpr auto mcp_supports_implementation_description(const MCPProtocolVersion version) noexcept -> bool
Definition mcp.h:201
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_error_resource_not_found(const sourcemeta::core::JSON &identifier) -> sourcemeta::core::JSON
constexpr JSON::StringView MCP_METHOD_INITIALIZE
Definition mcp.h:66
constexpr auto mcp_protocol_version_string(const MCPProtocolVersion version) noexcept -> JSON::StringView
Definition mcp.h:51
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_resource(const JSON::StringView uri, const JSON::StringView name, const JSON::StringView mime_type, const JSON::StringView description={}, const std::optional< std::size_t > size=std::nullopt, const std::optional< double > priority=std::nullopt) -> sourcemeta::core::JSON
constexpr JSON::StringView MCP_METHOD_RESOURCES_TEMPLATES_LIST
Definition mcp.h:90
constexpr std::int64_t MCP_CODE_URL_ELICITATION_REQUIRED
Definition mcp.h:105
constexpr auto mcp_supports_implementation_title(const MCPProtocolVersion version) noexcept -> bool
Definition mcp.h:193
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_initialize_result(const sourcemeta::core::JSON &request, const MCPServerCapabilities &capabilities, const MCPImplementation &server, const JSON::StringView instructions={}) -> sourcemeta::core::JSON
SOURCEMETA_CORE_MCP_EXPORT auto mcp_make_resource_template(const JSON::StringView uri_template, const JSON::StringView name, const JSON::StringView description, const JSON::StringView mime_type) -> sourcemeta::core::JSON
constexpr JSON::StringView MCP_METHOD_RESOURCES_READ
Definition mcp.h:86
@ V_2025_03_26
The MCP 2025-03-26 protocol revision.
Definition mcp.h:31
@ V_2025_11_25
The MCP 2025-11-25 protocol revision.
Definition mcp.h:35
@ V_2025_06_18
The MCP 2025-06-18 protocol revision.
Definition mcp.h:33