Allows administrators to specify either a whitelist or a blacklist for determining which tools are desired. This work introduces new command-line arguments `--enabled-tools` and `--disabled-tools`, which cannot be used together. Likewise, this work also considers environment variables `BRAVE_MCP_ENABLED_TOOLS` and `BRAVE_MCP_DISABLED_TOOLS` as another means of communicating desired or undesired tools. See https://github.com/brave/brave-search-mcp-server/issues/62 for more on the motivation behind this feature.
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import tools from './tools/index.js';
|
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
import { SetLevelRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
import pkg from '../package.json' with { type: 'json' };
|
|
import { isToolPermittedByUser } from './config.js';
|
|
import { type SmitheryConfig, setOptions } from './config.js';
|
|
export { configSchema } from './config.js';
|
|
|
|
type CreateMcpServerOptions = {
|
|
config: SmitheryConfig;
|
|
};
|
|
|
|
export default function createMcpServer(options?: CreateMcpServerOptions): McpServer {
|
|
if (options?.config) setOptions(options.config);
|
|
|
|
const mcpServer = new McpServer(
|
|
{
|
|
version: pkg.version,
|
|
name: 'brave-search-mcp-server',
|
|
title: 'Brave Search MCP Server',
|
|
},
|
|
{
|
|
capabilities: {
|
|
logging: {},
|
|
tools: { listChanged: false },
|
|
},
|
|
instructions: `Use this server to search the Web for various types of data via the Brave Search API.`,
|
|
}
|
|
);
|
|
|
|
try {
|
|
mcpServer.server.assertCanSetRequestHandler(SetLevelRequestSchema.shape.method.value);
|
|
mcpServer.server.setRequestHandler(SetLevelRequestSchema, () => ({}));
|
|
} catch (error) {
|
|
/**
|
|
* An error here signifies native-handling of the SetLevel request.
|
|
* See https://github.com/modelcontextprotocol/typescript-sdk/issues/871.
|
|
*/
|
|
}
|
|
|
|
for (const tool of Object.values(tools)) {
|
|
// The user may have enabled/disabled this tool at runtime
|
|
if (!isToolPermittedByUser(tool.name)) continue;
|
|
tool.register(mcpServer);
|
|
}
|
|
|
|
return mcpServer;
|
|
}
|