Skip to content

Commit 782e9fa

Browse files
feat(mcp): add logging when environment variable is set
1 parent 850f0f6 commit 782e9fa

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

packages/mcp-server/src/server.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const server = new McpServer(
2828
name: 'isaacus_api',
2929
version: '0.11.0',
3030
},
31-
{ capabilities: { tools: {} } },
31+
{ capabilities: { tools: {}, logging: {} } },
3232
);
3333

3434
/**
@@ -61,7 +61,24 @@ export function init(params: {
6161

6262
const endpointMap = Object.fromEntries(providedEndpoints.map((endpoint) => [endpoint.tool.name, endpoint]));
6363

64-
const client = params.client || new Isaacus({ defaultHeaders: { 'X-Stainless-MCP': 'true' } });
64+
const logAtLevel =
65+
(level: 'debug' | 'info' | 'warning' | 'error') =>
66+
(message: string, ...rest: unknown[]) => {
67+
console.error(message, ...rest);
68+
void server.sendLoggingMessage({
69+
level,
70+
data: { message, rest },
71+
});
72+
};
73+
const logger = {
74+
debug: logAtLevel('debug'),
75+
info: logAtLevel('info'),
76+
warn: logAtLevel('warning'),
77+
error: logAtLevel('error'),
78+
};
79+
80+
const client =
81+
params.client || new Isaacus({ defaultHeaders: { 'X-Stainless-MCP': 'true' }, logger: logger });
6582

6683
server.setRequestHandler(ListToolsRequestSchema, async () => {
6784
return {

0 commit comments

Comments
 (0)