uses refined, proper tool list in state (#284)

This commit is contained in:
Sampson authored and GitHub committed 2026-04-22 09:05:00 -05:00
1 parent ba5419076f
commit ae86cdc13f
2 files changed
+36 -14

No files matched your search

+2 -2
View File
@@ -117,8 +117,8 @@ The server supports the following environment variables:
- `BRAVE_MCP_PORT`: HTTP server port (default: 8000) - `BRAVE_MCP_PORT`: HTTP server port (default: 8000)
- `BRAVE_MCP_HOST`: HTTP server host (default: "0.0.0.0") - `BRAVE_MCP_HOST`: HTTP server host (default: "0.0.0.0")
- `BRAVE_MCP_LOG_LEVEL`: Desired logging level("debug", "info", "notice", "warning", "error", "critical", "alert", or "emergency", default: "info") - `BRAVE_MCP_LOG_LEVEL`: Desired logging level("debug", "info", "notice", "warning", "error", "critical", "alert", or "emergency", default: "info")
- `BRAVE_MCP_ENABLED_TOOLS`: When used, specifies a whitelist for supported tools - `BRAVE_MCP_ENABLED_TOOLS`: When used, specifies a space-separated whitelist for supported tools
- `BRAVE_MCP_DISABLED_TOOLS`: When used, specifies a blacklist for supported tools - `BRAVE_MCP_DISABLED_TOOLS`: When used, specifies a space-separated blacklist for supported tools
- `BRAVE_MCP_STATELESS`: HTTP stateless mode (default: "true"). When running on Amazon Bedrock Agentcore, set to "true". - `BRAVE_MCP_STATELESS`: HTTP stateless mode (default: "true"). When running on Amazon Bedrock Agentcore, set to "true".
### Command Line Options ### Command Line Options
+34 -12
View File
@@ -6,8 +6,19 @@ import tools from './tools/index.js';
dotenv.config({ debug: false, quiet: true }); dotenv.config({ debug: false, quiet: true });
function parseToolNameList(value: string | string[] | undefined | null): string[] {
if (value == null) return [];
if (Array.isArray(value))
return value.map((t: string) => t.trim()).filter((t: string) => t.length > 0);
return value
.trim()
.split(/\s+/)
.filter((t: string) => t.length > 0);
}
// Config schema for Smithery.ai // Config schema for Smithery.ai
export const configSchema = z.object({ export const configSchema = z
.object({
braveApiKey: z braveApiKey: z
.string() .string()
.describe('Your API key') .describe('Your API key')
@@ -39,7 +50,18 @@ export const configSchema = z.object({
.default(false) .default(false)
.describe('Whether the server should be stateless') .describe('Whether the server should be stateless')
.optional(), .optional(),
}); })
.refine(
(config) => {
const enabledTools = parseToolNameList(config.enabledTools);
const disabledTools = parseToolNameList(config.disabledTools);
return enabledTools.length === 0 || disabledTools.length === 0;
},
{
message: 'enabledTools and disabledTools cannot be used together',
path: ['enabledTools', 'disabledTools'],
}
);
export type SmitheryConfig = z.infer<typeof configSchema>; export type SmitheryConfig = z.infer<typeof configSchema>;
@@ -113,20 +135,20 @@ export function getOptions(): Configuration | false {
const toolNames = Object.values(tools).map((tool) => tool.name); const toolNames = Object.values(tools).map((tool) => tool.name);
// Validate tool inclusion configuration // Validate tool inclusion configuration
const enabledTools = options.enabledTools.filter((t: string) => t.trim().length > 0); const enabledTools = parseToolNameList(options.enabledTools);
const disabledTools = options.disabledTools.filter((t: string) => t.trim().length > 0); const disabledTools = parseToolNameList(options.disabledTools);
if (enabledTools.length > 0 && disabledTools.length > 0) { if (enabledTools.length > 0 && disabledTools.length > 0) {
console.error('Error: --enabled-tools and --disabled-tools cannot be used together'); console.error('Error: --enabled-tools and --disabled-tools cannot be used together');
return false; return false;
} }
if ( const invalidToolNames = [...enabledTools, ...disabledTools].filter(
[...enabledTools, ...disabledTools].some( (t: string) => !toolNames.includes(t)
(t) => t.trim().length > 0 && !toolNames.includes(t.trim()) );
) if (invalidToolNames.length > 0) {
) { console.error(`Invalid tool name(s) used: ${invalidToolNames.join(', ')}`);
console.error(`Invalid tool name used. Must be one of: ${toolNames.join(', ')}`); console.error(`Valid tool names are: ${toolNames.join(', ')}`);
return false; return false;
} }
@@ -175,8 +197,8 @@ export function getOptions(): Configuration | false {
state.port = options.port; state.port = options.port;
state.host = options.host; state.host = options.host;
state.loggingLevel = options.loggingLevel; state.loggingLevel = options.loggingLevel;
state.enabledTools = options.enabledTools; state.enabledTools = enabledTools;
state.disabledTools = options.disabledTools; state.disabledTools = disabledTools;
state.stateless = options.stateless; state.stateless = options.stateless;
state.ready = true; state.ready = true;