MCP Server with File Search Tool
A Model Context Protocol server providing file search and question tools for AI models. Enables keyword search in files with line numbers and integration with external chat services.
README
MCP Server with File Search Tool
A Model Context Protocol (MCP) server implementation in Node.js using TypeScript. This server provides tools for AI models to interact with external systems, including a powerful file search capability.
Features
- š MCP Server: Implements the Model Context Protocol for AI model integration
- š File Search Tool: Search for keywords within text files with line number results
- š§ Question Tool: A tool for asking freeform questions to a chatbot service
- š ļø BaseTool Abstraction: A simple abstraction for creating new tools with Zod-based schema validation
- š HTTP & STDIO Transport: Supports both HTTP and STDIO transport modes for the MCP server
- š TypeScript: Full TypeScript support with strict type checking
- šÆ ESLint + Prettier: Code quality and formatting tools
- š¦ Modern Node.js: ES2020+ features and modern JavaScript
Prerequisites
- Node.js 18+
- npm or yarn
Installation
-
Clone and navigate to the project:
cd chatbot-mcp -
Install dependencies:
npm install -
Set up environment variables:
cp env.example .env # Edit .env with your configuration
Usage
Development Mode
Run the server with hot reloading:
npm run dev
Production Build
Build the TypeScript code:
npm run build
Run the compiled JavaScript:
npm start
Testing with MCP Inspector
Test your tools using the MCP Inspector:
npx @modelcontextprotocol/inspector dist/index.js
Code Quality
Lint the code:
npm run lint
Fix linting issues:
npm run lint:fix
Format code:
npm run format
Project Structure
chatbot-mcp/
āāā src/
ā āāā index.ts # Main entry point
ā āāā server.ts # MCP server setup
ā āāā tools/
ā ā āāā FileSearchTool.ts # File search tool implementation
ā ā
ā āāā utils/
ā āāā BaseTool.ts # Base class for creating tools
ā āāā toolRegistry.ts # Utility to register all tools
āāā sample.txt # Sample file for testing file search
āāā package.json # Dependencies and scripts
āāā tsconfig.json # TypeScript configuration
āāā .env.example # Environment variables template
āāā README.md # This file
MCP Tools
1. search_file (File Search Tool)
Searches for a specified keyword within a file and returns matching lines with line numbers.
Input Schema:
{
filepath: string, // Path to the file to search
keyword: string, // Keyword to search for
caseSensitive?: boolean // Whether search is case-sensitive (default: false)
}
Example Usage:
{
"filepath": "sample.txt",
"keyword": "MCP",
"caseSensitive": false
}
Example Output:
Found 4 match(es) for keyword "MCP" in file: sample.txt
Line 1: Welcome to the MCP Server Documentation
Line 3: The Model Context Protocol enables seamless integration...
Line 5: MCP servers provide powerful capabilities...
Line 10: MCP makes it easy to build tool-enhanced AI applications.
Features:
- Case-insensitive search by default
- Returns line numbers with matching content
- Handles file not found errors gracefully
- Supports both absolute and relative file paths
HTTP Endpoints
POST /mcp- The primary endpoint for MCP requests when in HTTP modeGET /- A simple message indicating the server is running
Configuration
Environment variables (set in .env file):
PORT- The port for the MCP server to listen on (default:5001)TRANSPORT_MODE- The transport mode for the server, eitherhttporstdio(default:http)CHAT_SERVER_URL- The URL for the external chat service used by thequestionTool
Development
Adding New Tools
- Create a new tool file in
src/tools/ - Extend the
BaseToolclass - Define the input schema using Zod
- Implement the
executemethod - Register the tool in
src/utils/toolRegistry.ts
Example Tool Structure
// src/tools/myNewTool.ts
import { BaseTool } from '../utils/BaseTool';
import { z } from 'zod';
export class MyNewTool extends BaseTool {
constructor() {
super({
name: 'my_new_tool',
title: 'My New Tool',
description: 'A description for the new tool',
inputSchema: {
parameter1: z.string().describe('Description for parameter 1'),
parameter2: z.number().optional().describe('Optional parameter')
}
});
}
async execute(input: any): Promise<any> {
const { parameter1, parameter2 } = input;
// Your tool's logic here
return { success: true, result: `Received ${parameter1}` };
}
}
File Search Tool Implementation
The File Search Tool demonstrates:
- File system operations using Node.js
fsmodule - Error handling for missing files
- String manipulation and search algorithms
- Case-sensitive and case-insensitive search options
- Formatted output with line numbers
Testing the File Search Tool
-
Create a test file (
sample.txt):Welcome to the MCP Server Documentation This is a sample file for testing. The Model Context Protocol enables seamless integration. You can search for any keyword in this file. MCP servers provide powerful capabilities. -
Run the MCP Inspector:
npx @modelcontextprotocol/inspector dist/index.js -
Test with sample input:
- filepath:
sample.txtor full path to the file - keyword:
MCP - caseSensitive:
false
- filepath:
-
Verify the output shows all matching lines with line numbers
MCP Protocol
This server implements the Model Context Protocol, allowing AI models to:
- Discover available tools
- Call tools with structured inputs
- Receive structured outputs
- Handle errors gracefully
The server can be configured to use either stdio or http transport, making it flexible for different MCP client implementations.
Troubleshooting
Common Issues
- Port already in use: Change the
PORTvariable in your.envfile - TypeScript compilation errors: Run
npm run lintto see detailed errors - File not found: Use absolute paths or ensure relative paths are correct
- MCP connection issues: Ensure the server is running and transport mode is correct
Logs
The server provides detailed logging for debugging:
- MCP server initialization
- Tool execution and results
- File operations
- Error details with stack traces
Use Cases
File Search Tool Applications
- Code Review: Search for specific patterns or keywords in source code
- Log Analysis: Find error messages or specific events in log files
- Documentation: Locate specific information in text documents
- Configuration: Search for settings in configuration files
- Data Processing: Find specific entries in CSV or text data files
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
Resources
Author: Parthik Diyora
Date: November 2, 2025
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.