Files
brave-search-mcp-server/src/server.ts
T
Sampson b64b2fea18 single server per transport (#48)
resolves https://github.com/brave/brave-search-mcp-server/issues/47

- Updates SDK to 1.17.3
- Creates a single server instance per transport
- Removes unnecessary ClientLogger (tool execution methods have access to a sendNotification method if so desired)
- Other small syntactic cleanups
2025-08-18 10:37:19 -05:00

38 lines
1.2 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' };
export default function createMcpServer(): McpServer {
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)) {
mcpServer.tool(tool.name, tool.description, tool.inputSchema, tool.annotations, tool.execute);
}
return mcpServer;
}