@@ -250,6 +250,61 @@ pub export fn mongodb_mcp_reset() void {
250250}
251251
252252// ---------------------------------------------------------------------------
253+ // ═══════════════════════════════════════════════════════════════════════
254+ // Standard ABI (ADR-0005 four symbols + ADR-0006 invoke)
255+ // ═══════════════════════════════════════════════════════════════════════
256+
257+ const shim = @import ("cartridge_shim" );
258+
259+ const CARTRIDGE_NAME_PTR : [* :0 ]const u8 = "mongodb-mcp" ;
260+ const CARTRIDGE_VERSION_PTR : [* :0 ]const u8 = "0.1.0" ;
261+
262+ export fn boj_cartridge_init () callconv (.c ) c_int {
263+ return 0 ;
264+ }
265+
266+ export fn boj_cartridge_deinit () callconv (.c ) void {}
267+
268+ export fn boj_cartridge_name () callconv (.c ) [* :0 ]const u8 {
269+ return CARTRIDGE_NAME_PTR ;
270+ }
271+
272+ export fn boj_cartridge_version () callconv (.c ) [* :0 ]const u8 {
273+ return CARTRIDGE_VERSION_PTR ;
274+ }
275+
276+ /// Dispatch the cartridge.json MCP tools. Grade D Alpha stubs.
277+ export fn boj_cartridge_invoke (
278+ tool_name : [* c ]const u8 ,
279+ json_args : [* c ]const u8 ,
280+ out_buf : [* c ]u8 ,
281+ in_out_len : [* c ]usize ,
282+ ) callconv (.c ) i32 {
283+ _ = json_args ;
284+ if (shim .invokeArgsNull (tool_name , out_buf , in_out_len )) return shim .RC_BAD_ARGS ;
285+
286+ const body : []const u8 = if (shim .toolIs (tool_name , "mongo_connect" ))
287+ "{\" result\" :{\" status\" :\" stub\" }}"
288+ else if (shim .toolIs (tool_name , "mongo_find" ))
289+ "{\" result\" :{\" status\" :\" stub\" }}"
290+ else if (shim .toolIs (tool_name , "mongo_insert" ))
291+ "{\" result\" :{\" status\" :\" stub\" }}"
292+ else if (shim .toolIs (tool_name , "mongo_update" ))
293+ "{\" result\" :{\" status\" :\" stub\" }}"
294+ else if (shim .toolIs (tool_name , "mongo_delete" ))
295+ "{\" result\" :{\" status\" :\" stub\" }}"
296+ else if (shim .toolIs (tool_name , "mongo_aggregate" ))
297+ "{\" result\" :{\" status\" :\" stub\" }}"
298+ else if (shim .toolIs (tool_name , "mongo_list_collections" ))
299+ "{\" result\" :{\" items\" :[],\" count\" :0,\" status\" :\" stub\" }}"
300+ else if (shim .toolIs (tool_name , "mongo_disconnect" ))
301+ "{\" result\" :{\" status\" :\" stub\" }}"
302+ else
303+ return shim .RC_UNKNOWN_TOOL ;
304+
305+ return shim .writeResult (out_buf , in_out_len , body );
306+ }
307+
253308// Tests
254309// ---------------------------------------------------------------------------
255310
@@ -351,3 +406,51 @@ test "operation counting" {
351406
352407 try std .testing .expectEqual (@as (c_int , 0 ), mongodb_mcp_disconnect (slot ));
353408}
409+
410+ // ═══════════════════════════════════════════════════════════════════════
411+ // ADR-0006 invoke dispatch tests
412+ // ═══════════════════════════════════════════════════════════════════════
413+
414+ test "boj_cartridge_name returns mongodb-mcp" {
415+ const n = std .mem .span (boj_cartridge_name ());
416+ try std .testing .expectEqualStrings ("mongodb-mcp" , n );
417+ }
418+
419+ test "boj_cartridge_init returns 0" {
420+ try std .testing .expectEqual (@as (c_int , 0 ), boj_cartridge_init ());
421+ }
422+
423+ test "invoke: each declared tool succeeds" {
424+ var buf : [256 ]u8 = undefined ;
425+ const tools = [_ ][]const u8 {
426+ "mongo_connect" ,
427+ "mongo_find" ,
428+ "mongo_insert" ,
429+ "mongo_update" ,
430+ "mongo_delete" ,
431+ "mongo_aggregate" ,
432+ "mongo_list_collections" ,
433+ "mongo_disconnect" ,
434+ };
435+ for (tools ) | t | {
436+ var len : usize = buf .len ;
437+ const rc = boj_cartridge_invoke (t .ptr , "{}" , & buf , & len );
438+ try std .testing .expectEqual (@as (i32 , 0 ), rc );
439+ try std .testing .expect (std .mem .indexOf (u8 , buf [0.. len ], "result" ) != null );
440+ }
441+ }
442+
443+ test "invoke: unknown tool returns -1" {
444+ var buf : [64 ]u8 = undefined ;
445+ var len : usize = buf .len ;
446+ const rc = boj_cartridge_invoke ("nope" , "{}" , & buf , & len );
447+ try std .testing .expectEqual (@as (i32 , -1 ), rc );
448+ }
449+
450+ test "invoke: buffer too small returns -3" {
451+ var buf : [4 ]u8 = undefined ;
452+ var len : usize = buf .len ;
453+ const rc = boj_cartridge_invoke ("mongo_connect" , "{}" , & buf , & len );
454+ try std .testing .expectEqual (@as (i32 , -3 ), rc );
455+ try std .testing .expect (len > 4 );
456+ }
0 commit comments