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

-10
View File
@@ -1,7 +1,6 @@
import type { Endpoints } from './types.js';
import config from '../config.js';
import { stringify } from '../utils.js';
import ClientLogger from '../ClientLogger.js';
const typeToPathMap: Record<keyof Endpoints, string> = {
images: '/res/v1/images/search',
@@ -32,8 +31,6 @@ async function issueRequest<T extends keyof Endpoints>(
const url = new URL(`https://api.search.brave.com${typeToPathMap[endpoint]}`);
const queryParams = new URLSearchParams();
await ClientLogger.log('info', `Preparing to issue request to ${url.toString()}`);
// TODO (Sampson): Move param-construction/validation to modules
for (const [key, value] of Object.entries(parameters)) {
// The 'ids' parameter is expected to appear multiple times for multiple IDs
@@ -79,15 +76,11 @@ async function issueRequest<T extends keyof Endpoints>(
}
}
await ClientLogger.log('debug', `Using parameters: ${queryParams.toString()}`);
// Issue Request
const urlWithParams = url.toString() + '?' + queryParams.toString();
const headers = { ...defaultRequestHeaders, ...requestHeaders } as Headers;
const response = await fetch(urlWithParams, { headers });
await ClientLogger.log('debug', `Received response from ${urlWithParams}`);
// Handle Error
if (!response.ok) {
let errorMessage = `${response.status} ${response.statusText}`;
@@ -99,15 +92,12 @@ async function issueRequest<T extends keyof Endpoints>(
errorMessage += `\n${await response.text()}`;
}
await ClientLogger.log('error', errorMessage);
// TODO (Sampson): Setup proper error handling, updating state, etc.
throw new Error(errorMessage);
}
// Return Response
const responseBody = await response.json();
await ClientLogger.log('debug', `Returning response: ${stringify(responseBody, true)}`);
return responseBody as Endpoints[T]['response'];
}