Cover image
Try Now
2025-03-31

这是一个文件系统MCP服务器,可以允许LLM从本地计算机上指定的安全目录中读取和列出文件。

3 years

Works with Finder

1

Github Watches

0

Github Forks

1

Github Stars

File system MCP

Overview

filesys is a lightweight mcp server built with Python and the mcp library that securely exposes file contents and metadata from a preconfigured directory. The project leverages FastMCP to provide a set of endpoints that allow:

  • Listing all files in a specified directory.
  • Reading the contents and metadata of a specified file.

New: It now includes an integration with Anthropic's Claude AI, allowing users to interact with the file system through natural language conversation, using Claude Tools to securely access the defined MCP resources.

The project ensures safe file access by validating paths and preventing directory traversal attacks.

Preview

  • Interacting with Claude to list and read files from the safe_folder:
My Image

How It Works

The core functionality is divided into several components:

  • Resources:
    In src/resources.py, two functions are responsible for file operations:

    • list_files(): Scans the base directory (configured in config/config.json) to return a list of visible files.
    • read_file(filename): Reads the content of the specified file and returns it along with metadata (size and last modified timestamp), while ensuring that the file access is safe.
  • Server:
    In src/server.py, a FastMCP server is initialized and registers two resource endpoints:

    • files://list: Invokes list_files().
    • files://read/{filename}: Invokes read_file(filename).

The server is started via run.py, and it utilizes the mcp library to handle resource requests.

  • Claude Tool Client: In claude_tool_client.py, functions (list_files_in_safe_folder, read_file_from_safe_folder) are defined to interact with the running Filesys MCP server. These functions act as a bridge, translating simple function calls into MCP requests and parsing the responses. They are designed to be easily consumable by Claude Tools.

  • Claude Interaction Script: The interact_with_claude.py script sets up an Anthropic client, defines Claude Tools based on the functions in claude_tool_client.py, and runs a command-line conversation loop. Users can ask Claude questions like "What files are available?" or "Read test.txt", and Claude will use the provided tools (which securely call the MCP server) to fulfill the requests.

  • Testing:
    Unit tests in tests/test_resources.py ensure that the file listing and reading functionalities work as expected.

Installation

  1. Clone the Repository:
    git clone https://github.com/iBz-04/Filesys.git
    
  2. Navigate to the Project Directory:
    cd Filesys
    
  3. Create a Virtual Environment (Optional but Recommended):
    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    
  4. Install Dependencies: Make sure you have Python installed. Then install the required libraries:
    pip install -r requirements.txt
    
  5. Configure API Key:
    • Create a file named .env.local in the project's root directory.
    • Add your Anthropic API key to this file:
      ANTHROPIC_API_KEY=your_api_key_here
      
    • Note: The .gitignore file is configured to prevent this file from being committed to Git.

Configuration

The file server reads its configuration from config/config.json. By default, the server operates on the directory specified below:

{
  "directory": "./safe_folder"
}

You can modify this file to point to a different directory if needed.

  • Anthropic API Key: The Claude interaction script reads the ANTHROPIC_API_KEY from the .env.local file (see Installation step 5).

Usage

  1. Start the MCP Server: First, ensure the Filesys MCP server is running in a terminal:

    python run.py
    

    This command initializes the FastMCP server and makes the files://list and files://read/{filename} endpoints available.

  2. Interact with Claude: In a separate terminal (while the server from step 1 is still running), run the Claude interaction script:

    python interact_with_claude.py
    

    You can then ask Claude to interact with the files in the configured safe_folder. Examples:

    • "What files can you see?"
    • "List the available files."
    • "Can you read test.txt for me?"
    • "Tell me the contents of the file named test.txt"
  3. Direct MCP Requests (Optional): You can also interact with the server directly using any MCP-compatible client:

    • List Files: Request files://list.
    • Read a File: Request files://read/{filename} (replace {filename} with the actual file name).

Testing

  • MCP Client Functions: You can test the functions that communicate with the MCP server by running:
    python claude_tool_client.py
    
    This executes the test_tool_functions defined at the end of the script. Ensure the MCP server (python run.py) is running beforehand.
  • Core Resources (if tests exist): If unit tests are created in the tests/ directory (e.g., tests/test_resources.py), you can run them using:
    python -m unittest discover tests
    

Contributing

Contributions are welcome! To contribute:

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. Commit your changes with detailed messages.
  4. Push your branch and open a pull request.

Additional Notes

  • Customize the configuration (config/config.json, .env.local) as needed.
  • Important: The Claude interaction script (interact_with_claude.py) requires the Filesys MCP server (run.py) to be running in a separate process.
  • This project implements basic security measures to restrict file access to the configured directory and prevent directory traversal.
  • Update this documentation as new features are added or changes are made.

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Callycode Limited
  • A geek-themed horoscope generator blending Bitcoin prices, tech jargon, and astrological whimsy.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Beniyam Berhanu
  • Therapist adept at identifying core issues and offering practical advice with images.

  • Khalid kalib
  • Write professional emails

  • INFOLAB OPERATIONS 2
  • A medical specialist offering assistance grounded in clinical guidelines. Disclaimer: This is intended for research and is NOT safe for clinical use!

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • OffchainLabs
  • 进行以太坊的实施

  • huahuayu
  • 统一的API网关,用于将多个Etherscan样区块链Explorer API与对AI助手的模型上下文协议(MCP)支持。

  • deemkeen
  • 用电源组合控制您的MBOT2:MQTT+MCP+LLM

  • jae-jae
  • MCP服务器使用剧作《无头浏览器》获取网页内容。

  • HiveNexus
  • 一个适用于中小型团队的AI聊天机器人,支持DeepSeek,Open AI,Claude和Gemini等车型。 专为中小团队设计的ai聊天应用,支持deepSeek,打开ai,claude,双子座等模型。

    Reviews

    1 (1)
    Avatar
    user_YKTQVltM
    2025-04-17

    Filesys is a powerful and intuitive file management tool developed by iBz-04. Its seamless integration and user-friendly interface make it an essential asset for any workflow. The open-source nature allows for customization according to user needs, ensuring flexibility. Highly recommend for efficient file management!