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
6 changes: 3 additions & 3 deletions src/mcp/Server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub fn sendResult(self: *Self, id: std.json.Value, result: anytype) !void {
}

pub fn sendError(self: *Self, id: std.json.Value, code: protocol.ErrorCode, message: []const u8) !void {
try self.sendResponse(.{
try self.sendResponse(protocol.Response{
.id = id,
.@"error" = protocol.Error{
.code = @intFromEnum(code),
Expand All @@ -114,7 +114,7 @@ test "MCP.Server - Integration: synchronous smoke test" {

try router.processRequests(server, &in_reader);

try testing.expectJson(.{ .id = 1 }, out_alloc.writer.buffered());
try testing.expectJson(.{ .jsonrpc = "2.0", .id = 1 }, out_alloc.writer.buffered());
}

test "MCP.Server - Integration: ping request returns an empty result" {
Expand All @@ -135,5 +135,5 @@ test "MCP.Server - Integration: ping request returns an empty result" {

try router.processRequests(server, &in_reader);

try testing.expectJson(.{ .id = "ping-1", .result = .{} }, out_alloc.writer.buffered());
try testing.expectJson(.{ .jsonrpc = "2.0", .id = "ping-1", .result = .{} }, out_alloc.writer.buffered());
}
10 changes: 5 additions & 5 deletions src/mcp/router.zig
Original file line number Diff line number Diff line change
Expand Up @@ -120,30 +120,30 @@ test "MCP.router - handleMessage - synchronous unit tests" {
\\{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test-client","version":"1.0.0"}}}
);
try testing.expectJson(
\\{ "id": 1, "result": { "capabilities": { "tools": {} } } }
\\{ "jsonrpc": "2.0", "id": 1, "result": { "capabilities": { "tools": {} } } }
, out_alloc.writer.buffered());
out_alloc.writer.end = 0;

// 2. Ping
try handleMessage(server, aa,
\\{"jsonrpc":"2.0","id":2,"method":"ping"}
);
try testing.expectJson(.{ .id = 2, .result = .{} }, out_alloc.writer.buffered());
try testing.expectJson(.{ .jsonrpc = "2.0", .id = 2, .result = .{} }, out_alloc.writer.buffered());
out_alloc.writer.end = 0;

// 3. Tools list
try handleMessage(server, aa,
\\{"jsonrpc":"2.0","id":3,"method":"tools/list"}
);
try testing.expectJson(.{ .id = 3 }, out_alloc.writer.buffered());
try testing.expectJson(.{ .jsonrpc = "2.0", .id = 3 }, out_alloc.writer.buffered());
try testing.expect(std.mem.indexOf(u8, out_alloc.writer.buffered(), "\"name\":\"goto\"") != null);
out_alloc.writer.end = 0;

// 4. Method not found
try handleMessage(server, aa,
\\{"jsonrpc":"2.0","id":4,"method":"unknown_method"}
);
try testing.expectJson(.{ .id = 4, .@"error" = .{ .code = -32601 } }, out_alloc.writer.buffered());
try testing.expectJson(.{ .jsonrpc = "2.0", .id = 4, .@"error" = .{ .code = -32601 } }, out_alloc.writer.buffered());
out_alloc.writer.end = 0;

// 5. Parse error
Expand All @@ -152,6 +152,6 @@ test "MCP.router - handleMessage - synchronous unit tests" {
defer filter.deinit();

try handleMessage(server, aa, "invalid json");
try testing.expectJson("{\"id\": null, \"error\": {\"code\": -32700}}", out_alloc.writer.buffered());
try testing.expectJson("{\"jsonrpc\": \"2.0\", \"id\": null, \"error\": {\"code\": -32700}}", out_alloc.writer.buffered());
}
}
Loading