Skip to content
Merged
Changes from 1 commit
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
148 changes: 58 additions & 90 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import {Client} from '@modelcontextprotocol/sdk/client/index.js';
import {StdioClientTransport} from '@modelcontextprotocol/sdk/client/stdio.js';
import {executablePath} from 'puppeteer';

import {
OFF_BY_DEFAULT_CATEGORIES,
ToolCategory,
} from '../src/tools/categories.js';
import {OFF_BY_DEFAULT_CATEGORIES} from '../src/tools/categories.js';
import type {ToolDefinition} from '../src/tools/ToolDefinition.js';

describe('e2e', () => {
Expand Down Expand Up @@ -80,44 +77,7 @@ describe('e2e', () => {
async client => {
const {tools} = await client.listTools();
const exposedNames = tools.map(t => t.name).sort();
const files = fs.readdirSync('build/src/tools');
const definedNames = [];
for (const file of files) {
if (
file === 'ToolDefinition.js' ||
file === 'tools.js' ||
file === 'slim'
) {
continue;
}
const fileTools = await import(`../src/tools/${file}`);
for (const maybeTool of Object.values<unknown>(fileTools)) {
if (typeof maybeTool === 'function') {
const tool = (maybeTool as (val: boolean) => ToolDefinition)(
false,
);
if (tool && typeof tool === 'object' && 'name' in tool) {
if (tool.annotations?.conditions) {
continue;
}
definedNames.push(tool.name);
}
continue;
}
if (
typeof maybeTool === 'object' &&
maybeTool !== null &&
'name' in maybeTool
) {
const tool = maybeTool as ToolDefinition;
if (tool.annotations?.conditions) {
continue;
}
definedNames.push(tool.name);
}
}
}

const definedNames = await getToolsWithFilteredCategories();
definedNames.sort();
assert.deepStrictEqual(exposedNames, definedNames);
},
Expand All @@ -129,54 +89,9 @@ describe('e2e', () => {
await withClient(async client => {
const {tools} = await client.listTools();
const exposedNames = tools.map(t => t.name).sort();
const files = fs.readdirSync('build/src/tools');
const definedNames = [];
for (const file of files) {
if (
file === 'ToolDefinition.js' ||
file === 'tools.js' ||
file === 'slim'
) {
continue;
}
const fileTools = await import(`../src/tools/${file}`);
for (const maybeTool of Object.values<unknown>(fileTools)) {
if (typeof maybeTool === 'function') {
const tool = (maybeTool as (val: boolean) => ToolDefinition)(false);
if (tool && typeof tool === 'object' && 'name' in tool) {
if (tool.annotations?.conditions) {
continue;
}
if (
tool.annotations?.category &&
tool.annotations?.category === ToolCategory.EXTENSIONS
) {
continue;
}
definedNames.push(tool.name);
}
continue;
}
if (
typeof maybeTool === 'object' &&
maybeTool !== null &&
'name' in maybeTool
) {
const tool = maybeTool as ToolDefinition;
if (tool.annotations?.conditions) {
continue;
}
if (
tool.annotations?.category &&
tool.annotations?.category === ToolCategory.EXTENSIONS
) {
continue;
}
definedNames.push(tool.name);
}
}
}

const definedNames = await getToolsWithFilteredCategories(
OFF_BY_DEFAULT_CATEGORIES,
);
definedNames.sort();
assert.deepStrictEqual(exposedNames, definedNames);
});
Expand Down Expand Up @@ -245,3 +160,56 @@ describe('e2e', () => {
);
});
});

async function getToolsWithFilteredCategories(
filterOutCategories: string[] = [],
): Promise<string[]> {
const files = fs.readdirSync('build/src/tools');
const definedNames = [];
for (const file of files) {
if (
file === 'ToolDefinition.js' ||
file === 'tools.js' ||
file === 'slim'
) {
continue;
}
const fileTools = await import(`../src/tools/${file}`);
for (const maybeTool of Object.values<unknown>(fileTools)) {
if (typeof maybeTool === 'function') {
const tool = (maybeTool as (val: boolean) => ToolDefinition)(false);
if (tool && typeof tool === 'object' && 'name' in tool) {
if (tool.annotations?.conditions) {
continue;
}
if (
tool.annotations?.category &&
filterOutCategories.includes(tool.annotations?.category)
) {
continue;
}
definedNames.push(tool.name);
}
continue;
}
if (
typeof maybeTool === 'object' &&
maybeTool !== null &&
'name' in maybeTool
) {
const tool = maybeTool as ToolDefinition;
if (tool.annotations?.conditions) {
continue;
}
if (
tool.annotations?.category &&
filterOutCategories.includes(tool.annotations?.category)
) {
continue;
}
definedNames.push(tool.name);
Comment thread
nroscino marked this conversation as resolved.
Outdated
}
}
}
return definedNames;
}
Loading