test: add MCP call tests for each search tool
This commit is contained in:
1 parent
38d703263d
commit
896ac6acd3
8 files changed
+361
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { after, before, describe, it } from 'node:test';
|
||||
import type { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
||||
import { connectTestClient, stubFetch } from '../../testUtils/mcpTestHarness.js';
|
||||
import { name } from './index.js';
|
||||
|
||||
describe(name, () => {
|
||||
let client: Client;
|
||||
let close: () => Promise<void>;
|
||||
let restoreFetch: () => void;
|
||||
|
||||
before(async () => {
|
||||
restoreFetch = stubFetch((url) => {
|
||||
if (url.pathname === '/res/v1/images/search') {
|
||||
return {
|
||||
type: 'images',
|
||||
query: { original: 'brave browser' },
|
||||
results: [
|
||||
{
|
||||
type: 'image_result',
|
||||
title: 'Brave Browser Logo',
|
||||
url: 'https://example.com/logo.png',
|
||||
page_fetched: '2024-01-01T00:00:00Z',
|
||||
confidence: 'high',
|
||||
properties: {
|
||||
url: 'https://example.com/logo-full.png',
|
||||
width: 512,
|
||||
height: 512,
|
||||
},
|
||||
},
|
||||
],
|
||||
extra: { might_be_offensive: false },
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
({ client, close } = await connectTestClient());
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
restoreFetch();
|
||||
await close();
|
||||
});
|
||||
|
||||
it('returns image results for a simple query', async () => {
|
||||
const result = await client.callTool({ name, arguments: { query: 'brave browser' } });
|
||||
|
||||
assert.equal(result.isError ?? false, false, JSON.stringify(result.content));
|
||||
assert.ok(Array.isArray(result.content) && result.content.length > 0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,47 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { after, before, describe, it } from 'node:test';
|
||||
import type { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
||||
import { connectTestClient, stubFetch } from '../../testUtils/mcpTestHarness.js';
|
||||
import { name } from './index.js';
|
||||
|
||||
describe(name, () => {
|
||||
let client: Client;
|
||||
let close: () => Promise<void>;
|
||||
let restoreFetch: () => void;
|
||||
|
||||
before(async () => {
|
||||
restoreFetch = stubFetch((url) => {
|
||||
if (url.pathname === '/res/v1/llm/context') {
|
||||
return {
|
||||
grounding: {
|
||||
generic: [
|
||||
{
|
||||
url: 'https://search.brave.com/',
|
||||
title: 'Brave Search',
|
||||
snippets: ['Brave is a privacy-focused browser and search engine.'],
|
||||
},
|
||||
],
|
||||
map: [],
|
||||
},
|
||||
sources: {
|
||||
'https://search.brave.com/': { title: 'Brave Search' },
|
||||
},
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
({ client, close } = await connectTestClient());
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
restoreFetch();
|
||||
await close();
|
||||
});
|
||||
|
||||
it('returns grounding content for a simple query', async () => {
|
||||
const result = await client.callTool({ name, arguments: { query: 'brave browser' } });
|
||||
|
||||
assert.equal(result.isError ?? false, false, JSON.stringify(result.content));
|
||||
assert.ok(Array.isArray(result.content) && result.content.length > 0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,48 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { after, before, describe, it } from 'node:test';
|
||||
import type { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
||||
import { connectTestClient, stubFetch } from '../../testUtils/mcpTestHarness.js';
|
||||
import { name } from './index.js';
|
||||
|
||||
describe(name, () => {
|
||||
let client: Client;
|
||||
let close: () => Promise<void>;
|
||||
let restoreFetch: () => void;
|
||||
|
||||
before(async () => {
|
||||
restoreFetch = stubFetch((url) => {
|
||||
if (url.pathname === '/res/v1/web/search') {
|
||||
return {
|
||||
type: 'search',
|
||||
locations: {
|
||||
results: [{ id: 'poi-1', title: 'Brave Coffee Shop' }],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (url.pathname === '/res/v1/local/descriptions') {
|
||||
return {
|
||||
type: 'local_descriptions',
|
||||
results: [{ type: 'local_description', id: 'poi-1', description: 'A cozy coffee shop.' }],
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
({ client, close } = await connectTestClient());
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
restoreFetch();
|
||||
await close();
|
||||
});
|
||||
|
||||
it('returns enriched location results for a simple query', async () => {
|
||||
const result = await client.callTool({
|
||||
name,
|
||||
arguments: { query: 'coffee shops in san francisco' },
|
||||
});
|
||||
|
||||
assert.equal(result.isError ?? false, false, JSON.stringify(result.content));
|
||||
assert.ok(Array.isArray(result.content) && result.content.length > 0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,47 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { after, before, describe, it } from 'node:test';
|
||||
import type { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
||||
import { connectTestClient, stubFetch } from '../../testUtils/mcpTestHarness.js';
|
||||
import { name } from './index.js';
|
||||
|
||||
describe(name, () => {
|
||||
let client: Client;
|
||||
let close: () => Promise<void>;
|
||||
let restoreFetch: () => void;
|
||||
|
||||
before(async () => {
|
||||
restoreFetch = stubFetch((url) => {
|
||||
if (url.pathname === '/res/v1/news/search') {
|
||||
return {
|
||||
results: [
|
||||
{
|
||||
url: 'https://example.com/news',
|
||||
title: 'Brave ships a new release',
|
||||
description: 'News about Brave.',
|
||||
age: '1 hour ago',
|
||||
page_age: '2024-01-01T00:00:00Z',
|
||||
breaking: false,
|
||||
is_live: false,
|
||||
extra_snippets: [],
|
||||
thumbnail: { src: 'https://example.com/news-thumb.jpg' },
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
({ client, close } = await connectTestClient());
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
restoreFetch();
|
||||
await close();
|
||||
});
|
||||
|
||||
it('returns news results for a simple query', async () => {
|
||||
const result = await client.callTool({ name, arguments: { query: 'brave browser' } });
|
||||
|
||||
assert.equal(result.isError ?? false, false, JSON.stringify(result.content));
|
||||
assert.ok(Array.isArray(result.content) && result.content.length > 0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { after, before, describe, it } from 'node:test';
|
||||
import type { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
||||
import { connectTestClient, stubFetch } from '../../testUtils/mcpTestHarness.js';
|
||||
import { name } from './index.js';
|
||||
|
||||
describe(name, () => {
|
||||
let client: Client;
|
||||
let close: () => Promise<void>;
|
||||
let restoreFetch: () => void;
|
||||
|
||||
before(async () => {
|
||||
restoreFetch = stubFetch((url) => {
|
||||
if (url.pathname === '/res/v1/local/place_search') {
|
||||
return { type: 'locations' };
|
||||
}
|
||||
});
|
||||
|
||||
({ client, close } = await connectTestClient());
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
restoreFetch();
|
||||
await close();
|
||||
});
|
||||
|
||||
it('returns a locations response for a simple location query', async () => {
|
||||
const result = await client.callTool({
|
||||
name,
|
||||
arguments: { location: 'san francisco ca united states' },
|
||||
});
|
||||
|
||||
assert.equal(result.isError ?? false, false, JSON.stringify(result.content));
|
||||
assert.ok(Array.isArray(result.content) && result.content.length > 0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { after, before, describe, it } from 'node:test';
|
||||
import type { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
||||
import { connectTestClient, stubFetch } from '../../testUtils/mcpTestHarness.js';
|
||||
import { name } from './index.js';
|
||||
|
||||
describe(name, () => {
|
||||
let client: Client;
|
||||
let close: () => Promise<void>;
|
||||
let restoreFetch: () => void;
|
||||
|
||||
before(async () => {
|
||||
restoreFetch = stubFetch((url) => {
|
||||
if (url.pathname === '/res/v1/summarizer/search') {
|
||||
return {
|
||||
type: 'summarizer',
|
||||
status: 'complete',
|
||||
summary: [{ type: 'token', data: 'Brave is a privacy-focused browser.' }],
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
({ client, close } = await connectTestClient());
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
restoreFetch();
|
||||
await close();
|
||||
});
|
||||
|
||||
it('returns a summary for a completed key', async () => {
|
||||
const result = await client.callTool({ name, arguments: { key: 'test-key' } });
|
||||
|
||||
assert.equal(result.isError ?? false, false, JSON.stringify(result.content));
|
||||
assert.ok(Array.isArray(result.content) && result.content.length > 0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,50 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { after, before, describe, it } from 'node:test';
|
||||
import type { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
||||
import { connectTestClient, stubFetch } from '../../testUtils/mcpTestHarness.js';
|
||||
import { name } from './index.js';
|
||||
|
||||
describe(name, () => {
|
||||
let client: Client;
|
||||
let close: () => Promise<void>;
|
||||
let restoreFetch: () => void;
|
||||
|
||||
before(async () => {
|
||||
restoreFetch = stubFetch((url) => {
|
||||
if (url.pathname === '/res/v1/videos/search') {
|
||||
return {
|
||||
results: [
|
||||
{
|
||||
url: 'https://example.com/video',
|
||||
title: 'Introducing Brave',
|
||||
description: 'A video about the Brave browser.',
|
||||
age: '1 day ago',
|
||||
video: {
|
||||
duration: '5:00',
|
||||
views: '1000',
|
||||
creator: 'Brave Software',
|
||||
publisher: 'Brave Software',
|
||||
tags: ['browser'],
|
||||
},
|
||||
thumbnail: { src: 'https://example.com/thumb.jpg' },
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
({ client, close } = await connectTestClient());
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
restoreFetch();
|
||||
await close();
|
||||
});
|
||||
|
||||
it('returns video results for a simple query', async () => {
|
||||
const result = await client.callTool({ name, arguments: { query: 'brave browser' } });
|
||||
|
||||
assert.equal(result.isError ?? false, false, JSON.stringify(result.content));
|
||||
assert.ok(Array.isArray(result.content) && result.content.length > 0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { after, before, describe, it } from 'node:test';
|
||||
import type { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
||||
import { connectTestClient, stubFetch } from '../../testUtils/mcpTestHarness.js';
|
||||
import { name } from './index.js';
|
||||
|
||||
describe(name, () => {
|
||||
let client: Client;
|
||||
let close: () => Promise<void>;
|
||||
let restoreFetch: () => void;
|
||||
|
||||
before(async () => {
|
||||
restoreFetch = stubFetch((url) => {
|
||||
if (url.pathname === '/res/v1/web/search') {
|
||||
return {
|
||||
type: 'search',
|
||||
web: {
|
||||
results: [
|
||||
{
|
||||
url: 'https://search.brave.com/',
|
||||
title: 'Brave Search',
|
||||
description: 'A privacy-focused search engine.',
|
||||
extra_snippets: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
({ client, close } = await connectTestClient());
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
restoreFetch();
|
||||
await close();
|
||||
});
|
||||
|
||||
it('returns web results for a simple query', async () => {
|
||||
const result = await client.callTool({ name, arguments: { query: 'brave browser' } });
|
||||
|
||||
assert.equal(result.isError ?? false, false, JSON.stringify(result.content));
|
||||
assert.ok(Array.isArray(result.content) && result.content.length > 0);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user