Skip to content

AnandhaSivam-00/Custom-Local-MCP-Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MCP Local Files CLI (Wizard-Bot)

A custom Model Context Protocol (MCP) implementation that allows Gemini AI to interact directly with your local file system. This project consists of both an MCP Server that exposes file system tools and an MCP Client that integrates with Google's Gemini AI.

Features

  • Local File Interaction: Search, read, and write files directly in your local environment.
  • AI-Powered Assistance: Integrated with Gemini AI (Wizard-Bot) for intelligent file analysis and code generation.
  • Secure Workspace: Operations are restricted to a specific workspace directory (mcp_workspace by default) to ensure security.
  • Standardized Protocol: Built using the Model Context Protocol (MCP) SDK.

Available Tools

  • search_files: Recursively search for files in the workspace matching a pattern.
  • read_file: Read the content of a specific file.
  • write_file: Create or overwrite a file with specified content.

Available Prompts

  • analyse_code: Analyse the code file by taking the filePath as a argument
  • generate_file: Generate the file from a description by taking the file-name, description and language as a argument.
  • summarize_workspace: Summarize the entire workspace

Prerequisites

  • Node.js (v18 or higher recommended)
  • NPM
  • A Google Gemini API Key

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd Custom-Local-MCP-Server
  2. Install dependencies:

    npm install

Configuration (.env Setup)

The application requires an API key from Google Gemini to function. Create a .env file in the root directory and add the following variables:

# Required: Your Google Gemini API Key
GEMINI_API_KEY=your_api_key_here

# Optional: The Gemini model to use (Defaults to gemini-1.5-flash-lite)
# Note: Ensure the model name is correct as per Google's latest releases.
GEMINI_MODEL=gemini-1.5-flash-lite

# Optional: Custom workspace path for file operations
# Defaults to a folder named 'mcp_workspace' in the project root if not set.
MCP_WORKSPACE_PATH=./mcp_workspace

#Required: For displaying the suggestion while typing
MAX_VISIBLE_SUGGESTION=5

Usage

To start the interactive CLI client:

npm run dev

Once started, you can chat with Wizard-Bot and ask it to perform file operations. For example:

  • "Search for all .ts files in my workspace."
  • "Read the content of src/server.ts and explain it."
  • "Create a new file called hello.txt with the text 'Hello from MCP!'"

Type exit or quit to end the session.

Testing

To test the MCP server functionality, you can use the MCP Inspector:

npm run test

Project Structure

  • src/server.ts: The MCP Server implementation that defines and registers tools.
  • src/client.ts: The MCP Client that connects to the server and handles the AI chat loop.
  • src/tools/: Contains the individual tool implementations (search, read, write).
  • src/utils/: Utility functions for directory walking and path validation.
  • mcp_workspace/: The default directory where all file operations occur.

Security Note

This tool has write access to your local files within the ALLOWED_DIR (specified by MCP_WORKSPACE_PATH). Always review the actions the AI is proposing before allowing it to proceed if used in a production environment.

Snapshots

image image image image image

About

Building the Custom MCP server that list, read, and write directly in our Local environment using the Gemini's flash-lite-preview

Topics

Resources

Stars

Watchers

Forks

Contributors