Skip to content

Commit 65c1635

Browse files
committed
feat: Enhance network log preservation features with improved messaging and descriptions for AI Agents
1 parent 911f36c commit 65c1635

File tree

2 files changed

+59
-14
lines changed

2 files changed

+59
-14
lines changed

src/McpResponse.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ Call ${handleDialog.name} to handle it before continuing.`);
223223
if (this.#networkRequestsOptions?.include) {
224224
let requests = context.getNetworkRequests();
225225

226-
// Apply resource type filtering if specified
227226
if (this.#networkRequestsOptions.resourceTypes?.length) {
228227
const normalizedTypes = new Set(
229228
this.#networkRequestsOptions.resourceTypes,
@@ -234,7 +233,15 @@ Call ${handleDialog.name} to handle it before continuing.`);
234233
});
235234
}
236235

236+
const preservationEnabled = context.isNetworkLogPreservationEnabled();
237+
237238
response.push('## Network requests');
239+
if (preservationEnabled) {
240+
response.push('🔒 **Preservation Mode: ACTIVE** (requests persist across navigations)');
241+
} else {
242+
response.push('📋 Normal mode (logs cleared on navigation). Enable preservation to keep history.');
243+
}
244+
238245
if (requests.length) {
239246
const data = this.#dataWithPagination(
240247
requests,

src/tools/network.ts

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const FILTERABLE_RESOURCE_TYPES: readonly [ResourceType, ...ResourceType[]] = [
3434

3535
export const listNetworkRequests = defineTool({
3636
name: 'list_network_requests',
37-
description: `List all requests for the currently selected page`,
37+
description: `List all requests for the currently selected page. By default, only shows requests since the last navigation. To preserve requests across navigations, first call enable_network_log_preservation before navigating.`,
3838
annotations: {
3939
category: ToolCategories.NETWORK,
4040
readOnlyHint: true,
@@ -89,7 +89,7 @@ export const getNetworkRequest = defineTool({
8989

9090
export const enableNetworkLogPreservation = defineTool({
9191
name: 'enable_network_log_preservation',
92-
description: `Enable network log preservation mode. When enabled, all network requests are preserved across page navigations and response bodies are automatically captured. By default, logs are cleaned on navigation for performance.`,
92+
description: `Enable network log preservation mode to keep ALL network requests across navigations. IMPORTANT: Call this BEFORE navigating or interacting with the page if you want to analyze request patterns across multiple actions. When enabled, all request/response bodies are automatically captured and cached for later analysis. Use this when you need to compare requests before/after certain actions or track API calls across page transitions.`,
9393
annotations: {
9494
category: ToolCategories.NETWORK,
9595
readOnlyHint: false,
@@ -115,31 +115,44 @@ export const enableNetworkLogPreservation = defineTool({
115115
),
116116
},
117117
handler: async (request, response, context) => {
118+
const wasAlreadyEnabled = context.isNetworkLogPreservationEnabled();
119+
118120
context.enableNetworkLogPreservation({
119121
includeRequestBodies: request.params.includeRequestBodies,
120122
includeResponseBodies: request.params.includeResponseBodies,
121123
maxRequests: request.params.maxRequests,
122124
});
123-
response.appendResponseLine(
124-
'Network log preservation enabled. All network requests will be preserved across navigations.',
125-
);
125+
126+
if (wasAlreadyEnabled) {
127+
response.appendResponseLine(
128+
'⚠️ Network log preservation was already enabled. Settings updated.',
129+
);
130+
} else {
131+
response.appendResponseLine(
132+
'✅ Network log preservation enabled. All network requests will be preserved across navigations.',
133+
);
134+
}
135+
126136
if (request.params.includeRequestBodies) {
127-
response.appendResponseLine('Request bodies will be captured.');
137+
response.appendResponseLine('📤 Request bodies will be captured.');
128138
}
129139
if (request.params.includeResponseBodies) {
130-
response.appendResponseLine('Response bodies will be captured.');
140+
response.appendResponseLine('📥 Response bodies will be captured.');
131141
}
132142
if (request.params.maxRequests) {
133143
response.appendResponseLine(
134-
`Maximum ${request.params.maxRequests} requests will be preserved.`,
144+
`🔢 Maximum ${request.params.maxRequests} requests will be preserved.`,
135145
);
136146
}
147+
response.appendResponseLine(
148+
'\n💡 TIP: Preservation is now active. Navigate, click buttons, or interact with the page - all network activity will be recorded.',
149+
);
137150
},
138151
});
139152

140153
export const disableNetworkLogPreservation = defineTool({
141154
name: 'disable_network_log_preservation',
142-
description: `Disable network log preservation mode and optionally clear existing preserved logs. After disabling, network logs will be cleaned on navigation (default behavior).`,
155+
description: `Disable network log preservation mode and optionally clear existing preserved logs. After disabling, network logs will be cleaned on navigation (default behavior). Call this when you're done analyzing preserved requests to restore normal performance.`,
143156
annotations: {
144157
category: ToolCategories.NETWORK,
145158
readOnlyHint: false,
@@ -154,33 +167,58 @@ export const disableNetworkLogPreservation = defineTool({
154167
),
155168
},
156169
handler: async (request, response, context) => {
170+
const wasEnabled = context.isNetworkLogPreservationEnabled();
171+
172+
if (!wasEnabled) {
173+
response.appendResponseLine(
174+
'⚠️ Network log preservation was not enabled. No action taken.',
175+
);
176+
return;
177+
}
178+
157179
context.disableNetworkLogPreservation();
158180
if (request.params.clearExisting) {
159181
context.clearPreservedNetworkLogs();
160182
response.appendResponseLine(
161-
'Network log preservation disabled and existing logs cleared.',
183+
'Network log preservation disabled and existing logs cleared.',
162184
);
163185
} else {
164186
response.appendResponseLine(
165-
'Network log preservation disabled. Existing logs retained.',
187+
'Network log preservation disabled. Existing logs retained.',
166188
);
167189
}
190+
response.appendResponseLine(
191+
'💡 Normal behavior restored: network logs will be cleared on navigation.',
192+
);
168193
},
169194
});
170195

171196
export const clearPreservedNetworkLogs = defineTool({
172197
name: 'clear_preserved_network_logs',
173-
description: `Clear all preserved network logs for the currently selected page. This does not disable preservation mode.`,
198+
description: `Clear all preserved network logs for the currently selected page without disabling preservation mode. Use this to reset the preserved request history while keeping preservation active for future requests.`,
174199
annotations: {
175200
category: ToolCategories.NETWORK,
176201
readOnlyHint: false,
177202
},
178203
schema: {},
179204
handler: async (_request, response, context) => {
205+
if (!context.isNetworkLogPreservationEnabled()) {
206+
response.appendResponseLine(
207+
'⚠️ Network log preservation is not enabled. No preserved logs to clear.',
208+
);
209+
response.appendResponseLine(
210+
'💡 TIP: Call enable_network_log_preservation first to start preserving logs.',
211+
);
212+
return;
213+
}
214+
180215
const preservedCount = context.getPreservedNetworkRequests().length;
181216
context.clearPreservedNetworkLogs();
182217
response.appendResponseLine(
183-
`Cleared ${preservedCount} preserved network request(s).`,
218+
`✅ Cleared ${preservedCount} preserved network request(s).`,
219+
);
220+
response.appendResponseLine(
221+
'💡 Preservation mode is still active. New requests will continue to be preserved.',
184222
);
185223
},
186224
});

0 commit comments

Comments
 (0)