search
Find cells containing specific values in Excel or CSV files to locate data quickly. Use exact or partial matching across sheets for efficient data analysis.
Instructions
Search for cells containing a specific value
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Path to the CSV or Excel file | |
| searchValue | Yes | Value to search for | |
| exact | No | Whether to match exactly or contains (default: false) | |
| sheet | No | Sheet name for Excel files (optional) |
Implementation Reference
- src/handlers/data-operations.ts:267-318 (handler)The handler function that implements the core logic of the 'search' tool. It reads the file content, iterates through all cells, checks for exact or partial matches against the searchValue, and returns a list of matching cells with their positions.async search(args: ToolArgs): Promise<ToolResponse> { try { const { filePath, searchValue, exact = false, sheet } = args; const data = await readFileContent(filePath, sheet); const matches = []; for (let row = 0; row < data.length; row++) { for (let col = 0; col < (data[row]?.length || 0); col++) { const cellValue = String(data[row][col]); const isMatch = exact ? cellValue === searchValue : cellValue.toLowerCase().includes(searchValue.toLowerCase()); if (isMatch) { const colLetter = String.fromCharCode(65 + (col % 26)); matches.push({ cell: `${colLetter}${row + 1}`, value: data[row][col], row: row + 1, column: col + 1, }); } } } return { content: [ { type: 'text', text: JSON.stringify({ success: true, searchValue, found: matches.length, matches, }, null, 2), }, ], }; } catch (error) { return { content: [ { type: 'text', text: JSON.stringify({ success: false, error: error instanceof Error ? error.message : 'Unknown error occurred', }, null, 2), }, ], }; } }
- src/index.ts:164-188 (schema)The input schema definition for the 'search' tool in the ListTools response, specifying the parameters, types, descriptions, and required fields.name: 'search', description: 'Search for cells containing a specific value', inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'Path to the CSV or Excel file', }, searchValue: { type: 'string', description: 'Value to search for', }, exact: { type: 'boolean', description: 'Whether to match exactly or contains (default: false)', }, sheet: { type: 'string', description: 'Sheet name for Excel files (optional)', }, }, required: ['filePath', 'searchValue'], }, },
- src/index.ts:1207-1208 (registration)The dispatch registration in the CallToolRequestSchema handler's switch statement, mapping the tool name 'search' to the DataOperationsHandler.search method.case 'search': return await this.dataOpsHandler.search(toolArgs);