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
This commit is contained in:
Sampson authored and GitHub committed 2025-08-18 10:37:19 -05:00
1 parent 9b6e458c66
commit b64b2fea18
11 files changed
+65 -164

No files matched your search

+30 -19
View File
@@ -1,26 +1,37 @@
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import tools from './tools/index.js';
import ClientLogger, { maybeRegisterCustomSetLevelRequestHandler } from './ClientLogger.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 const mcpServer = new McpServer(
{
version: '0.1.0',
name: 'brave-search-mcp-server',
title: 'Brave Search MCP Server',
},
{
capabilities: {
logging: {},
tools: { listChanged: false },
export default function createMcpServer(): McpServer {
const mcpServer = new McpServer(
{
version: pkg.version,
name: 'brave-search-mcp-server',
title: 'Brave Search MCP Server',
},
instructions: `Use this server to search the Web for various types of data via the Brave Search API.`,
{
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.
*/
}
);
ClientLogger.setServer(mcpServer);
// https://github.com/modelcontextprotocol/typescript-sdk/issues/871
maybeRegisterCustomSetLevelRequestHandler(mcpServer.server);
for (const tool of Object.values(tools)) {
mcpServer.tool(tool.name, tool.description, tool.inputSchema, tool.annotations, tool.execute);
}
for (const tool of Object.values(tools)) {
mcpServer.tool(tool.name, tool.description, tool.inputSchema, tool.annotations, tool.execute);
return mcpServer;
}