file-search-tool

Abhishek2634/file-search-tool

3.2

If you are the rightful owner of file-search-tool and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

The MCP File Search Server is a tool for searching keywords within text files using the Model Context Protocol.

Tools
1
Resources
0
Prompts
0

MCP File Search Server

A Model Context Protocol (MCP) server that provides a file search tool for searching keywords within text files. Built with TypeScript and Node.js.

Description

This MCP server implements a search_file tool that allows AI applications to search for specific keywords in files and returns matching lines with their line numbers. The server supports both case-sensitive and case-insensitive search options.

Features

  • 🔍 Search for keywords in text files
  • 📍 Returns matching lines with line numbers
  • 🔤 Case-sensitive and case-insensitive search modes
  • ⚡ Built with TypeScript for type safety
  • 🔌 Compatible with MCP protocol

Prerequisites

  • Node.js (v14 or higher)
  • npm or yarn

Installation

  1. Clone the repository:
    git clone <your-repository-url>
    cd mcp-file-search
  1. Install dependencies:
    npm install
  1. Build the project:
    npm run build

Usage

Running the Server

The server uses STDIO transport for communication: node build/index.js

Testing with MCP Inspector

  1. Start the MCP Inspector:
    npx @modelcontextprotocol/inspector node build/index.js
  1. Open the provided URL in your browser

  2. Click "Connect" to connect to the server

  3. Navigate to the "Tools" tab to see the search_file tool

  4. Test the tool with these parameters:

    • keyword: "MCP" (or any search term)
    • filePath: "sample.txt" (or path to any text file)
    • caseSensitive: false (optional, defaults to false)

Tool Parameters

The search_file tool accepts the following parameters:

ParameterTypeRequiredDescription
keywordstringYesThe keyword to search for in the file
filePathstringYesPath to the file to search in (absolute or relative)
caseSensitivebooleanNoWhether the search should be case-sensitive (default: false)

Development

Available Scripts

  • npm run build - Compile TypeScript to JavaScript
  • npm run watch - Watch for changes and recompile
  • npm run inspector - Run MCP Inspector for testing

Building from Source

    npm run build

The compiled output will be in the build/ directory.

Dependencies

  • @modelcontextprotocol/sdk - MCP SDK for building servers
  • zod - Schema validation
  • typescript - TypeScript compiler

Error Handling

The server includes error handling for:

  • File not found errors
  • Invalid file paths
  • Read permission errors
  • Invalid parameter types

Troubleshooting

Troubleshooting

Issue: ENOENT: no such file or directory

Solution: Ensure you're using the correct file path. Try using absolute paths or ensure the file exists in the specified location.

Issue: Connection error in MCP Inspector

Solution: Make sure the server is built (npm run build) and the path in Arguments field is build/index.js.

Issue: Command not found

Solution: Run the inspector from the project directory using npx @modelcontextprotocol/inspector node build/index.js.

Made with ❤️ by Abhishek.