Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

refactor(mcp): name the two protocol revisions explicitly

Rach Pradhan3f53656f1fe7
diff --git a/src/mcp.zig b/src/mcp.zig
index 52c325da..b017434b 100644
--- a/src/mcp.zig
+++ b/src/mcp.zig
@@ -367,7 +367,7 @@ pub const Registry = struct {
errdefer tools.shrinkRetainingCapacity(tools_before);
// Handshake. The server's reply tells us which revision it picked;
- // record it (we proceed regardless — see `latest_protocol`).
+ // record it (we proceed regardless — see `legacy_protocol`).
try initializeServer(server, a, a);
const listed = try request(server, a, "{}", "tools/list");
diff --git a/src/mcp_oauth_discovery.zig b/src/mcp_oauth_discovery.zig
index ef2a5ab7..7c5906b3 100644
--- a/src/mcp_oauth_discovery.zig
+++ b/src/mcp_oauth_discovery.zig
@@ -156,14 +156,18 @@ pub fn probe(io: Io, gpa: Allocator, arena: Allocator, resource_url: []const u8)
try requireHttps(resource_url);
var client: std.http.Client = .{ .allocator = gpa, .io = io };
defer client.deinit();
+ // Pinned to the legacy revision on purpose: this probe exists only to
+ // elicit a 401 WWW-Authenticate challenge for `graff mcp login`, and a
+ // modern (2026-07-28) request against a legacy auth server would turn
+ // that 401 into a 400 (see mcp_protocol.zig's era-detection doc).
const body =
\\{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"
- ++ mcp_protocol.latest_protocol ++
+ ++ mcp_protocol.legacy_protocol ++
\\","capabilities":{},"clientInfo":{"name":"codegraff-mcp-login","version":"1"}}}
;
const extra_headers = [_]std.http.Header{
.{ .name = "accept", .value = "application/json, text/event-stream" },
- .{ .name = "mcp-protocol-version", .value = mcp_protocol.latest_protocol },
+ .{ .name = "mcp-protocol-version", .value = mcp_protocol.legacy_protocol },
};
var request = try client.request(.POST, try std.Uri.parse(resource_url), .{
.redirect_behavior = .unhandled,
diff --git a/src/mcp_protocol.zig b/src/mcp_protocol.zig
index 2ca6c697..1ce141be 100644
--- a/src/mcp_protocol.zig
+++ b/src/mcp_protocol.zig
@@ -27,13 +27,20 @@ pub fn rewriteOneOf(a: Allocator, v: *Value) Allocator.Error!void {
}
}
-/// Latest MCP revision advertised during initialization.
-pub const latest_protocol = "2025-11-25";
+/// The one modern (stateless, per-request `_meta`) revision graff speaks.
+/// Never sent in a legacy `initialize` handshake — see `supported_protocols`.
+pub const modern_protocol = "2026-07-28";
+
+/// What graff offers in a legacy `initialize` handshake, and the newest
+/// revision `negotiatedProtocol` will accept back from a server.
+pub const legacy_protocol = "2025-11-25";
/// Revisions whose initialize, tools, and content schemas are compatible with
-/// the subset implemented by this client.
+/// the legacy subset implemented by this client. Deliberately excludes
+/// `modern_protocol`: a server that echoes it back inside an `initialize`
+/// result is not speaking the stateless 2026-07-28 wire format at all.
pub const supported_protocols = [_][]const u8{
- latest_protocol,
+ legacy_protocol,
"2025-06-18",
"2025-03-26",
"2024-11-05",
@@ -129,6 +136,11 @@ test "initialize negotiation rejects missing, non-string, and unsupported versio
.{ .json = "{\"result\":{}}", .expected = error.MissingMcpProtocolVersion },
.{ .json = "{\"result\":{\"protocolVersion\":20251125}}", .expected = error.InvalidMcpProtocolVersion },
.{ .json = "{\"result\":{\"protocolVersion\":\"2099-01-01\"}}", .expected = error.UnsupportedMcpProtocolVersion },
+ // A server echoing the modern, handshake-free revision back inside a
+ // legacy `initialize` result is nonsense — the legacy negotiator must
+ // never accept it (mcp_rpc's stdio/HTTP probe path is the only place
+ // `modern_protocol` is ever legitimate).
+ .{ .json = "{\"result\":{\"protocolVersion\":\"2026-07-28\"}}", .expected = error.UnsupportedMcpProtocolVersion },
};
for (cases) |case| {
var parsed = try std.json.parseFromSlice(Value, std.testing.allocator, case.json, .{});
diff --git a/src/mcp_rpc.zig b/src/mcp_rpc.zig
index c1220feb..afd248b9 100644
--- a/src/mcp_rpc.zig
+++ b/src/mcp_rpc.zig
@@ -14,7 +14,7 @@ const mcp_protocol = @import("mcp_protocol.zig");
const mcp_stdio = @import("mcp_stdio.zig");
const mcp_teardown = @import("mcp_teardown.zig");
-const latest_protocol = mcp_protocol.latest_protocol;
+const legacy_protocol = mcp_protocol.legacy_protocol;
pub const StdioTransport = struct {
child: std.process.Child,
@@ -51,7 +51,7 @@ pub fn deinitServer(server: *Server, io: Io, budget: mcp_teardown.Budget) void {
pub fn initializeServer(server: *Server, response_alloc: Allocator, session_alloc: Allocator) !void {
const init_resp = try request(server, response_alloc,
\\{"protocolVersion":"
- ++ latest_protocol ++
+ ++ legacy_protocol ++
\\","capabilities":{},"clientInfo":{"name":"simple-harness","version":"0.1"}}
, "initialize");
const protocol_transport: mcp_protocol.Transport = switch (server.transport) {
@@ -88,7 +88,7 @@ pub fn request(server: *Server, response_alloc: Allocator, params: []const u8, m
const body = try std.fmt.allocPrint(response_alloc,
\\{{"jsonrpc":"2.0","id":{d},"method":"{s}","params":{s}}}
, .{ id, method, params });
- const protocol_version = if (std.mem.eql(u8, method, "initialize")) latest_protocol else server.protocol_version;
+ const protocol_version = if (std.mem.eql(u8, method, "initialize")) legacy_protocol else server.protocol_version;
const response_body = (try mcp_http.post(http, body, protocol_version, id)) orelse return error.BadMcpResponse;
defer http.client.allocator.free(response_body);
return mcp_http.parseHttpResponse(response_alloc, response_body, id) orelse error.BadMcpResponse;
diff --git a/src/smolify_manifest.zig b/src/smolify_manifest.zig
index d153414d..29c89251 100644
--- a/src/smolify_manifest.zig
+++ b/src/smolify_manifest.zig
@@ -9,7 +9,7 @@ const Allocator = std.mem.Allocator;
const Value = std.json.Value;
const manifest_json = @embedFile("smolify-tools.json");
-pub const bundled_protocol = mcp_protocol.latest_protocol;
+pub const bundled_protocol = mcp_protocol.legacy_protocol;
const public_read_tools = [_][]const u8{
"discover_public_projects",