Skip to content

Commit b5edb9e

Browse files
committed
diag(mcp): sanitize initialize preview + log at warn for visibility
Review fixes (Cursor): - Run the initialize body preview through sanitizeForLogging (defense-in-depth against a server stuffing token-like values into serverInfo/capabilities). - Log diagnostics at warn, not info, so they surface even if an environment's LOG_LEVEL drops info (staging runs INFO, but this removes the dependency).
1 parent ed55598 commit b5edb9e

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

apps/sim/lib/mcp/http-diagnostics.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { FetchLike } from '@modelcontextprotocol/sdk/shared/transport.js'
22
import { createLogger } from '@sim/logger'
3+
import { sanitizeForLogging } from '@/lib/core/security/redaction'
34
import { getMcpSafeErrorDiagnostics } from '@/lib/mcp/error-diagnostics'
45

56
const logger = createLogger('McpHttpDiag')
@@ -69,7 +70,7 @@ export function withMcpHttpDiagnostics(
6970
const reqHeaders = new Headers((init?.headers as HeadersInit | undefined) ?? undefined)
7071
const startedAt = Date.now()
7172

72-
logger.info('request', {
73+
logger.warn('request', {
7374
phase,
7475
method,
7576
url,
@@ -91,7 +92,7 @@ export function withMcpHttpDiagnostics(
9192
throw error
9293
}
9394

94-
logger.info('response', {
95+
logger.warn('response', {
9596
phase,
9697
method,
9798
url,
@@ -121,7 +122,7 @@ export function withMcpHttpDiagnostics(
121122
for (;;) {
122123
const { done, value } = await reader.read()
123124
if (done) {
124-
logger.info('initialize body complete', {
125+
logger.warn('initialize body complete', {
125126
url,
126127
chunks,
127128
bytes,
@@ -132,12 +133,12 @@ export function withMcpHttpDiagnostics(
132133
chunks += 1
133134
bytes += value.byteLength
134135
if (chunks <= MAX_LOGGED_CHUNKS) {
135-
logger.info('initialize body chunk', {
136+
logger.warn('initialize body chunk', {
136137
url,
137138
chunk: chunks,
138139
size: value.byteLength,
139140
ms: Date.now() - startedAt,
140-
preview: decoder.decode(value, { stream: true }).slice(0, PREVIEW_CHARS),
141+
preview: sanitizeForLogging(decoder.decode(value, { stream: true }), PREVIEW_CHARS),
141142
})
142143
}
143144
}

0 commit comments

Comments
 (0)