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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BdUJSmjqGoksdc45ZZJiVY
This commit is contained in:
Kevin Messiaen 2026-07-06 16:40:06 +07:00
parent 5cfd64f151
commit bba645852f
No known key found for this signature in database
GPG key ID: 19FF750A17315202

View file

@ -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<KtxMongoQueryMcpPort['execute']>().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 = {