From bba645852f0aacefa22f52d508f8ce60b07f3f08 Mon Sep 17 00:00:00 2001 From: Kevin Messiaen <114553769+kevinmessiaen@users.noreply.github.com> Date: Mon, 6 Jul 2026 16:40:06 +0700 Subject: [PATCH] test(mcp): add mongo_query server registration test Closes a coverage gap for the mongo_query MCP tool and fixes Knip's default-mode unused-export flag on KtxMongoQueryMcpPort, which had no cross-file consumer before this test imported it. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01BdUJSmjqGoksdc45ZZJiVY --- packages/cli/test/context/mcp/server.test.ts | 52 ++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/packages/cli/test/context/mcp/server.test.ts b/packages/cli/test/context/mcp/server.test.ts index 6a7e756a..69091aab 100644 --- a/packages/cli/test/context/mcp/server.test.ts +++ b/packages/cli/test/context/mcp/server.test.ts @@ -21,6 +21,8 @@ import type { KtxKnowledgeMcpPort, KtxMcpContextPorts, KtxMcpToolHandlerContext, + KtxMongoQueryMcpPort, + KtxMongoQueryResponse, KtxSemanticLayerMcpPort, KtxSqlExecutionMcpPort, KtxSqlExecutionResponse, @@ -495,6 +497,56 @@ describe('createKtxMcpServer', () => { ); }); + it('registers mongo_query when the host provides a MongoDB query port', async () => { + const fake = makeFakeServer(); + const response: KtxMongoQueryResponse = { + headers: ['_id', 'city'], + rows: [ + ['a1', 'Indianapolis'], + ['a2', 'Indianapolis'], + ], + rowCount: 2, + }; + const mongoQuery: KtxMongoQueryMcpPort = { + execute: vi.fn().mockResolvedValue(response), + }; + + createKtxMcpServer({ + server: fake.server, + userContext: { userId: 'local-user' }, + contextTools: { + mongoQuery, + }, + }); + + expect(fake.tools.map((tool) => tool.name)).toEqual(['mongo_query']); + await expect( + getTool(fake.tools, 'mongo_query').handler({ + connectionId: 'mongo', + collection: 'business', + pipeline: [{ $match: { city: 'Indianapolis' } }], + limit: 100, + }), + ).resolves.toEqual({ + content: [ + { + type: 'text', + text: JSON.stringify(response), + }, + ], + structuredContent: response, + }); + expect(mongoQuery.execute).toHaveBeenCalledWith( + { + connectionId: 'mongo', + collection: 'business', + pipeline: [{ $match: { city: 'Indianapolis' } }], + limit: 100, + }, + undefined, + ); + }); + it('registers entity_details when the host provides an entity-details port', async () => { const fake = makeFakeServer(); const entityDetails: KtxEntityDetailsMcpPort = {