Skip to content

Commit 327a388

Browse files
refactor: remove text from the status code for Network requests (#778)
LLM are trained to know the common status code so we can rely on that when displaying the status code and fall back to text in case of errors or pending reponse.
1 parent 24cd066 commit 327a388

File tree

5 files changed

+69
-73
lines changed

5 files changed

+69
-73
lines changed

src/formatters/NetworkFormatter.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,11 @@ export class NetworkFormatter {
183183
const failure = request.failure();
184184
let status: string;
185185
if (httpResponse) {
186-
const responseStatus = httpResponse.status();
187-
status =
188-
responseStatus >= 200 && responseStatus <= 299
189-
? `[success - ${responseStatus}]`
190-
: `[failed - ${responseStatus}]`;
186+
status = httpResponse.status().toString();
191187
} else if (failure) {
192-
status = `[failed - ${failure.errorText}]`;
188+
status = failure.errorText;
193189
} else {
194-
status = '[pending]';
190+
status = 'pending';
195191
}
196192
return status;
197193
}
@@ -231,7 +227,7 @@ function convertNetworkRequestConciseToString(
231227
data: NetworkRequestConcise,
232228
): string {
233229
// TODO truncate the URL
234-
return `reqid=${data.requestId} ${data.method} ${data.url} ${data.status}${data.selectedInDevToolsUI ? ` [selected in the DevTools Network panel]` : ''}`;
230+
return `reqid=${data.requestId} ${data.method} ${data.url} [${data.status}]${data.selectedInDevToolsUI ? ` [selected in the DevTools Network panel]` : ''}`;
235231
}
236232

237233
function formatHeadlers(headers: Record<string, string>): string[] {

tests/McpContext.test.js.snapshot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ exports[`McpContext > should include detailed network request in structured cont
44
"requestId": 456,
55
"method": "GET",
66
"url": "http://example.com/detail",
7-
"status": "[pending]",
7+
"status": "pending",
88
"requestHeaders": {
99
"content-size": "10"
1010
}
@@ -37,7 +37,7 @@ exports[`McpContext > should include network requests in structured content 1`]
3737
"requestId": 123,
3838
"method": "GET",
3939
"url": "http://example.com/api",
40-
"status": "[pending]",
40+
"status": "pending",
4141
"selectedInDevToolsUI": false
4242
}
4343
]

0 commit comments

Comments
 (0)