copy_paste
Copy or move content between files using text patterns. Find content by search patterns and insert at marker locations to edit files efficiently.
Instructions
Copy/paste content between files using text patterns. Find content by search pattern, insert at marker location.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| source | Yes | ||
| target | Yes | ||
| cut | No | Optional: true to cut (move) instead of copy. Default: false |
Implementation Reference
- src/handlers/copyPasteHandler.ts:10-72 (handler)The main execute method implementing the copy/paste logic: extracts content from source by pattern, inserts into target at marker, optionally removes from source if cut=true.async execute(params: CopyPasteParams): Promise<CopyPasteResult> { try { await this.validateParams(params); // Extract content by pattern const contentToMove = await this.storageService.extractContentByPattern( params.source.file, params.source.start_pattern, params.source.end_pattern, params.source.line_count ); let sourceModified = false; let targetModified = false; try { // Insert content by marker await this.storageService.insertContentByMarker( params.target.file, params.target.marker, contentToMove, params.target.position, params.target.replace_pattern ); targetModified = true; // Remove from source if cut=true if (params.cut) { await this.storageService.removeContentByPattern( params.source.file, params.source.start_pattern, params.source.end_pattern, params.source.line_count ); sourceModified = true; } return { success: true, message: `Successfully ${params.cut ? 'moved' : 'copied'} content`, contentMoved: contentToMove, sourceModified, targetModified }; } catch (error) { return { success: false, message: `Operation failed: ${error instanceof Error ? error.message : 'Unknown error'}`, sourceModified, targetModified }; } } catch (error) { return { success: false, message: `Validation failed: ${error instanceof Error ? error.message : 'Unknown error'}`, sourceModified: false, targetModified: false }; } }
- src/types/index.ts:17-29 (schema)TypeScript interfaces defining the input parameters (CopyPasteParams) and output result (CopyPasteResult) for the copy_paste tool.export interface CopyPasteParams { source: SourceParams; target: TargetParams; cut?: boolean; } export interface CopyPasteResult { success: boolean; message: string; contentMoved?: string; sourceModified?: boolean; targetModified?: boolean; }
- src/server.ts:46-104 (registration)Tool registration in ListToolsRequestHandler, defining name, description, and inputSchema for 'copy_paste'.{ name: 'copy_paste', description: 'Copy/paste content between files using text patterns. Find content by search pattern, insert at marker location.', inputSchema: { type: 'object', properties: { source: { type: 'object', properties: { file: { type: 'string', description: 'Path to source file' }, start_pattern: { type: 'string', description: 'Text pattern to find start of content to copy (e.g., "function processData", "// Section start")' }, end_pattern: { type: 'string', description: 'Optional: text pattern for end of content. If not provided, uses line_count' }, line_count: { type: 'number', description: 'Optional: number of lines to copy from start_pattern. Default: 1' } }, required: ['file', 'start_pattern'] }, target: { type: 'object', properties: { file: { type: 'string', description: 'Path to target file' }, marker: { type: 'string', description: 'Text pattern to find insertion point (e.g., "// Insert here", "class MyClass")' }, position: { type: 'string', enum: ['before', 'after', 'replace'], description: 'Where to insert relative to marker: before, after, or replace the marker' }, replace_pattern: { type: 'string', description: 'Optional: specific text pattern to replace (when position=replace)' } }, required: ['file', 'marker', 'position'] }, cut: { type: 'boolean', description: 'Optional: true to cut (move) instead of copy. Default: false' } }, required: ['source', 'target'] } }
- src/server.ts:112-144 (registration)Dispatch logic in CallToolRequestHandler that casts arguments to CopyPasteParams and calls the handler's execute method.if (name === 'copy_paste') { try { // Валидация и типизация входных аргументов if (!args || typeof args !== 'object') { throw new Error('Invalid arguments provided'); } const params = args as unknown as CopyPasteParams; const result = await this.copyPasteHandler.execute(params); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2) } ] }; } catch (error) { return { content: [ { type: 'text', text: JSON.stringify({ success: false, message: `Tool execution error: ${error instanceof Error ? error.message : 'Unknown error'}` }, null, 2) } ], isError: true }; } }
- src/server.ts:37-37 (registration)Instantiation of the CopyPasteHandler with storage service dependency.this.copyPasteHandler = new CopyPasteHandler(storageService);