Skip to content

Commit 41b93bf

Browse files
feat(mcp): add an option to disable code tool
You can now disable the code tool via a flag, in case your server only needs access to the search_docs capability (useful for coding agents).
1 parent 06e8759 commit 41b93bf

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

packages/mcp-server/src/options.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type CLIOptions = McpOptions & {
1414
};
1515

1616
export type McpOptions = {
17+
includeCodeTool?: boolean | undefined;
1718
includeDocsTools?: boolean | undefined;
1819
stainlessApiKey?: string | undefined;
1920
codeAllowHttpGets?: boolean | undefined;
@@ -92,11 +93,13 @@ export function parseCLIOptions(): CLIOptions {
9293
: argv.tools?.includes(toolType) ? true
9394
: undefined;
9495

96+
const includeCodeTool = shouldIncludeToolType('code');
9597
const includeDocsTools = shouldIncludeToolType('docs');
9698

9799
const transport = argv.transport as 'stdio' | 'http';
98100

99101
return {
102+
...(includeCodeTool !== undefined && { includeCodeTool }),
100103
...(includeDocsTools !== undefined && { includeDocsTools }),
101104
debug: !!argv.debug,
102105
stainlessApiKey: argv.stainlessApiKey,
@@ -129,13 +132,19 @@ export function parseQueryOptions(defaultOptions: McpOptions, query: unknown): M
129132
const queryObject = typeof query === 'string' ? qs.parse(query) : query;
130133
const queryOptions = QueryOptions.parse(queryObject);
131134

135+
let codeTool: boolean | undefined =
136+
queryOptions.no_tools && queryOptions.no_tools?.includes('code') ? false
137+
: queryOptions.tools?.includes('code') ? true
138+
: defaultOptions.includeCodeTool;
139+
132140
let docsTools: boolean | undefined =
133141
queryOptions.no_tools && queryOptions.no_tools?.includes('docs') ? false
134142
: queryOptions.tools?.includes('docs') ? true
135143
: defaultOptions.includeDocsTools;
136144

137145
return {
138-
codeExecutionMode: defaultOptions.codeExecutionMode,
146+
...(codeTool !== undefined && { includeCodeTool: codeTool }),
139147
...(docsTools !== undefined && { includeDocsTools: docsTools }),
148+
codeExecutionMode: defaultOptions.codeExecutionMode,
140149
};
141150
}

packages/mcp-server/src/server.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,16 @@ export async function initMcpServer(params: {
158158
* Selects the tools to include in the MCP Server based on the provided options.
159159
*/
160160
export function selectTools(options?: McpOptions): McpTool[] {
161-
const includedTools = [
162-
codeTool({
163-
blockedMethods: blockedMethodsForCodeTool(options),
164-
codeExecutionMode: options?.codeExecutionMode ?? 'stainless-sandbox',
165-
}),
166-
];
161+
const includedTools = [];
162+
163+
if (options?.includeCodeTool ?? true) {
164+
includedTools.push(
165+
codeTool({
166+
blockedMethods: blockedMethodsForCodeTool(options),
167+
codeExecutionMode: options?.codeExecutionMode ?? 'stainless-sandbox',
168+
}),
169+
);
170+
}
167171
if (options?.includeDocsTools ?? true) {
168172
includedTools.push(docsSearchTool);
169173
}

0 commit comments

Comments
 (0)