Skip to content

Commit e39c90e

Browse files
feat(mcp): add option for including docs tools
1 parent 86b23ff commit e39c90e

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

packages/mcp-server/src/options.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type McpOptions = {
1717
includeDynamicTools?: boolean | undefined;
1818
includeAllTools?: boolean | undefined;
1919
includeCodeTools?: boolean | undefined;
20+
includeDocsTools?: boolean | undefined;
2021
filters?: Filter[] | undefined;
2122
capabilities?: Partial<ClientCapabilities> | undefined;
2223
};
@@ -55,13 +56,13 @@ export function parseCLIOptions(): CLIOptions {
5556
.option('tools', {
5657
type: 'string',
5758
array: true,
58-
choices: ['dynamic', 'all', 'code'],
59+
choices: ['dynamic', 'all', 'code', 'docs'],
5960
description: 'Use dynamic tools or all tools',
6061
})
6162
.option('no-tools', {
6263
type: 'string',
6364
array: true,
64-
choices: ['dynamic', 'all', 'code'],
65+
choices: ['dynamic', 'all', 'code', 'docs'],
6566
description: 'Do not use any dynamic or all tools',
6667
})
6768
.option('tool', {
@@ -245,13 +246,14 @@ export function parseCLIOptions(): CLIOptions {
245246
}
246247
}
247248

248-
const shouldIncludeToolType = (toolType: 'dynamic' | 'all' | 'code') =>
249+
const shouldIncludeToolType = (toolType: 'dynamic' | 'all' | 'code' | 'docs') =>
249250
explicitTools ? argv.tools?.includes(toolType) && !argv.noTools?.includes(toolType) : undefined;
250251

251252
const explicitTools = Boolean(argv.tools || argv.noTools);
252253
const includeDynamicTools = shouldIncludeToolType('dynamic');
253254
const includeAllTools = shouldIncludeToolType('all');
254255
const includeCodeTools = shouldIncludeToolType('code');
256+
const includeDocsTools = shouldIncludeToolType('docs');
255257

256258
const transport = argv.transport as 'stdio' | 'http';
257259

@@ -261,6 +263,7 @@ export function parseCLIOptions(): CLIOptions {
261263
includeDynamicTools,
262264
includeAllTools,
263265
includeCodeTools,
266+
includeDocsTools,
264267
filters,
265268
capabilities: clientCapabilities,
266269
list: argv.list || false,
@@ -280,8 +283,8 @@ const coerceArray = <T extends z.ZodTypeAny>(zodType: T) =>
280283
);
281284

282285
const QueryOptions = z.object({
283-
tools: coerceArray(z.enum(['dynamic', 'all'])).describe('Use dynamic tools or all tools'),
284-
no_tools: coerceArray(z.enum(['dynamic', 'all'])).describe('Do not use dynamic tools or all tools'),
286+
tools: coerceArray(z.enum(['dynamic', 'all', 'docs'])).describe('Use dynamic tools or all tools'),
287+
no_tools: coerceArray(z.enum(['dynamic', 'all', 'docs'])).describe('Do not use dynamic tools or all tools'),
285288
tool: coerceArray(z.string()).describe('Include tools matching the specified names'),
286289
resource: coerceArray(z.string()).describe('Include tools matching the specified resources'),
287290
operation: coerceArray(z.enum(['read', 'write'])).describe(
@@ -376,11 +379,17 @@ export function parseQueryOptions(defaultOptions: McpOptions, query: unknown): M
376379
: queryOptions.tools?.includes('all') ? true
377380
: defaultOptions.includeAllTools;
378381

382+
let docsTools: boolean | undefined =
383+
queryOptions.no_tools && queryOptions.no_tools?.includes('docs') ? false
384+
: queryOptions.tools?.includes('docs') ? true
385+
: defaultOptions.includeDocsTools;
386+
379387
return {
380388
client: queryOptions.client ?? defaultOptions.client,
381389
includeDynamicTools: dynamicTools,
382390
includeAllTools: allTools,
383391
includeCodeTools: undefined,
392+
includeDocsTools: docsTools,
384393
filters,
385394
capabilities: clientCapabilities,
386395
};

packages/mcp-server/src/server.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,24 +148,26 @@ export function initMcpServer(params: {
148148
export async function selectTools(endpoints: Endpoint[], options?: McpOptions): Promise<Endpoint[]> {
149149
const filteredEndpoints = query(options?.filters ?? [], endpoints);
150150

151-
let includedTools = filteredEndpoints;
151+
let includedTools = filteredEndpoints.slice();
152152

153153
if (includedTools.length > 0) {
154154
if (options?.includeDynamicTools) {
155155
includedTools = dynamicTools(includedTools);
156156
}
157157
} else {
158158
if (options?.includeAllTools) {
159-
includedTools = endpoints;
159+
includedTools = endpoints.slice();
160160
} else if (options?.includeDynamicTools) {
161161
includedTools = dynamicTools(endpoints);
162162
} else if (options?.includeCodeTools) {
163-
includedTools = [await codeTool(), docsSearchTool];
163+
includedTools = [await codeTool()];
164164
} else {
165-
includedTools = endpoints;
165+
includedTools = endpoints.slice();
166166
}
167167
}
168-
168+
if (options?.includeDocsTools ?? true) {
169+
includedTools.push(docsSearchTool);
170+
}
169171
const capabilities = { ...defaultClientCapabilities, ...options?.capabilities };
170172
return applyCompatibilityTransformations(includedTools, capabilities);
171173
}

0 commit comments

Comments
 (0)