Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/core/mcp/headers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <sourcemeta/core/unicode.h>

#include <algorithm> // std::find
#include <cassert> // assert
#include <optional> // std::optional, std::nullopt
#include <span> // std::span
#include <string> // std::string
Expand Down Expand Up @@ -460,11 +461,11 @@ auto mcp_validate_request_headers(
version, identifier, MCP_HEADER_PROTOCOL_VERSION,
*protocol_version_header, mcp_protocol_version_string(version));
}
if (meta_status && *meta_status != MCPRequestMetaStatus::Valid) {
return mcp_make_error_request_meta(version, identifier, *meta_status,
*protocol_version_header,
supported_versions);
}
// Every other outcome was reported above, and the one left is only reached
// by a body version that names no revision carrying metadata, which the two
// checks above have already turned down by holding the body to the header
// and the header to the revision this session speaks
assert(!meta_status || *meta_status == MCPRequestMetaStatus::Valid);
if (!method_header ||
!sourcemeta::core::mcp_is_plain_header_value(*method_header)) {
return mcp_make_error_header_mismatch(version, identifier,
Expand Down
8 changes: 1 addition & 7 deletions src/core/mcp/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <sourcemeta/core/uri.h>

#include <algorithm> // std::all_of
#include <cmath> // std::isfinite
#include <initializer_list> // std::initializer_list
#include <set> // std::set
#include <utility> // std::move, std::pair
Expand Down Expand Up @@ -189,9 +188,7 @@ inline auto annotations(const JSON &value, const bool received = false)
if (const auto *priority{
field(*item, "priority", sourcemeta::core::MCP_HASH_PRIORITY)};
priority != nullptr &&
(!priority->is_number() ||
(priority->is_real() && !std::isfinite(priority->to_real())) ||
*priority < JSON{0} || *priority > JSON{1})) {
(!priority->is_number() || *priority < JSON{0} || *priority > JSON{1})) {
return false;
}
if (const auto *audience{
Expand Down Expand Up @@ -1149,9 +1146,6 @@ inline auto valid_input_response(const JSON::StringView method,
return false;
}
for (const auto &entry : content->as_object()) {
if (entry.second.is_real() && !std::isfinite(entry.second.to_real())) {
return false;
}
if (!entry.second.is_string() && !entry.second.is_number() &&
!entry.second.is_boolean() && !validation::strings(entry.second)) {
return false;
Expand Down
11 changes: 8 additions & 3 deletions test/mcp/mcp_error_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1034,9 +1034,13 @@ TEST(error_code_to_http_status_method_not_found_2026_07_28) {
// travels on a 200, so there is no status to report for any code
// https://modelcontextprotocol.io/specification/2025-11-25/basic/transports
TEST(error_code_to_http_status_method_not_found_2025_11_25) {
// The revision is held in a variable that is not itself constant, as a
// mapping handed nothing but constants is answered where it is written
// rather than where it is defined
sourcemeta::core::MCPProtocolVersion version{
sourcemeta::core::MCPProtocolVersion::V_2025_11_25};
EXPECT_FALSE(sourcemeta::core::mcp_error_code_to_http_status(
sourcemeta::core::MCPProtocolVersion::V_2025_11_25,
sourcemeta::core::JSONRPC_CODE_METHOD_NOT_FOUND)
version, sourcemeta::core::JSONRPC_CODE_METHOD_NOT_FOUND)
.has_value());
}

Expand Down Expand Up @@ -1132,8 +1136,9 @@ TEST(error_code_to_http_status_resource_not_found) {
}

TEST(error_code_to_http_status_unmapped_code) {
std::int64_t code{-99999};
EXPECT_FALSE(sourcemeta::core::mcp_error_code_to_http_status(
sourcemeta::core::MCPProtocolVersion::V_2026_07_28, -99999)
sourcemeta::core::MCPProtocolVersion::V_2026_07_28, code)
.has_value());
}

Expand Down
Loading
Loading