feat: add session-configurable snapshot settings via browser_configure_snapshots

Implements dynamic snapshot configuration that MCP clients can control during
sessions without requiring server restarts or CLI changes.

New tool: browser_configure_snapshots
- Configure includeSnapshots, maxSnapshotTokens, differentialSnapshots at runtime
- Changes take effect immediately for subsequent tool calls
- Shows current settings when called with no parameters
- Provides helpful tips and usage guidance

Key improvements:
1. **Runtime Configuration**: Update snapshot behavior during active sessions
2. **Client Control**: MCP clients can adapt to different workflows dynamically
3. **Immediate Effect**: No server restart required - changes apply instantly
4. **State Tracking**: Context maintains current session configuration
5. **User Friendly**: Clear feedback on current settings and changes

Updated tool descriptions:
- All interactive tools now mention "configurable via browser_configure_snapshots"
- Removed references to CLI-only configuration
- Enhanced browser_snapshot description for explicit snapshots

Benefits for users:
🔄 Dynamic configuration without restarts
🎛️ Client-controlled snapshot behavior
📊 View current settings anytime
 Instant configuration changes
🎯 Adapt settings per workflow/task

Example usage:
```json
{
  "includeSnapshots": false,
  "maxSnapshotTokens": 25000,
  "differentialSnapshots": true
}
```

This transforms snapshot configuration from static CLI options into a flexible
session management system that adapts to client needs in real-time.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Ryan Malloy 2025-08-22 08:28:36 -06:00
parent 574fdc4959
commit 2fe8b9355c
5 changed files with 110 additions and 8 deletions

View file

@ -74,6 +74,12 @@ const installPopularExtensionSchema = z.object({
version: z.string().optional().describe('Specific version to install (defaults to latest)')
});
const configureSnapshotsSchema = z.object({
includeSnapshots: z.boolean().optional().describe('Enable/disable automatic snapshots after interactive operations. When false, use browser_snapshot for explicit snapshots.'),
maxSnapshotTokens: z.number().min(0).optional().describe('Maximum tokens allowed in snapshots before truncation. Use 0 to disable truncation.'),
differentialSnapshots: z.boolean().optional().describe('Enable differential snapshots that show only changes since last snapshot instead of full page snapshots.')
});
export default [
defineTool({
capability: 'core',
@ -524,6 +530,78 @@ export default [
}
},
}),
defineTool({
capability: 'core',
schema: {
name: 'browser_configure_snapshots',
title: 'Configure snapshot behavior',
description: 'Configure how page snapshots are handled during the session. Control automatic snapshots, size limits, and differential modes. Changes take effect immediately for subsequent tool calls.',
inputSchema: configureSnapshotsSchema,
type: 'destructive',
},
handle: async (context: Context, params: z.output<typeof configureSnapshotsSchema>, response: Response) => {
try {
const changes: string[] = [];
// Update snapshot configuration
if (params.includeSnapshots !== undefined)
changes.push(`📸 Auto-snapshots: ${params.includeSnapshots ? 'enabled' : 'disabled'}`);
if (params.maxSnapshotTokens !== undefined) {
if (params.maxSnapshotTokens === 0)
changes.push(`📏 Snapshot truncation: disabled (unlimited size)`);
else
changes.push(`📏 Max snapshot tokens: ${params.maxSnapshotTokens.toLocaleString()}`);
}
if (params.differentialSnapshots !== undefined) {
changes.push(`🔄 Differential snapshots: ${params.differentialSnapshots ? 'enabled' : 'disabled'}`);
if (params.differentialSnapshots)
changes.push(` ↳ Reset differential state for fresh tracking`);
}
// Apply the updated configuration using the context method
context.updateSnapshotConfig(params);
// Provide user feedback
if (changes.length === 0) {
response.addResult('No snapshot configuration changes specified.\n\n**Current settings:**\n' +
`📸 Auto-snapshots: ${context.config.includeSnapshots ? 'enabled' : 'disabled'}\n` +
`📏 Max snapshot tokens: ${context.config.maxSnapshotTokens === 0 ? 'unlimited' : context.config.maxSnapshotTokens.toLocaleString()}\n` +
`🔄 Differential snapshots: ${context.config.differentialSnapshots ? 'enabled' : 'disabled'}`);
return;
}
let result = '✅ **Snapshot configuration updated:**\n\n';
result += changes.map(change => `- ${change}`).join('\n');
result += '\n\n**💡 Tips:**\n';
if (!context.config.includeSnapshots)
result += '- Use `browser_snapshot` tool when you need explicit page snapshots\n';
if (context.config.differentialSnapshots) {
result += '- Differential mode shows only changes between operations\n';
result += '- First snapshot after enabling will establish baseline\n';
}
if (context.config.maxSnapshotTokens > 0 && context.config.maxSnapshotTokens < 5000)
result += '- Consider increasing token limit if snapshots are frequently truncated\n';
result += '\n**Changes take effect immediately for subsequent tool calls.**';
response.addResult(result);
} catch (error) {
throw new Error(`Failed to configure snapshots: ${error}`);
}
},
}),
];
// Helper functions for extension downloading