Smart File Organizer MCP Server

Smart File Organizer MCP Server

Lets AI assistants analyze and organize local directories by file type, with dry-run support and safe sorting.

Category
访问服务器

README

Day 3 — Smart File Organizer (MCP Tool Server)

Welcome to Day 3 of your 7-Day Project! Today, you are building a Smart File Organizer and wrapping it as a Model Context Protocol (MCP) Server.

This document explains what MCP is, how your organizer works, and how to test and run it as an AI-callable tool.


💡 What is MCP (Model Context Protocol)?

Traditionally, AI models (like Claude, ChatGPT, or Gemini) are locked inside their chat boxes. They cannot access your local files or run scripts on your computer unless the application hosting them specifically builds a custom feature.

Model Context Protocol (MCP) is an open standard created by Anthropic. It acts like a USB port for AI:

  • MCP Client: The AI chat application (e.g., Claude Desktop, Cursor IDE).
  • MCP Server: A background program (written in Python, Node.js, etc.) that exposes local resources, prompts, or executable Tools.
  • Protocol: The AI can query the server to ask "What tools do you have?" and then "Call tool organize_directory with parameter directory_path."

Today, you are building an MCP Server that exposes your file organizer as a tool, allowing an AI assistant to manage your directories for you!


📁 Project Structure

Here is what we have built in this directory:

  1. organizer.py: The core script that does the file sorting. It can be run by itself from the command line.
  2. server.py: The MCP server code that wraps organizer.py using FastMCP.
  3. test_env_setup.py: A helper script that creates a safe test_downloads/ folder full of dummy files so you can test without touching your real files.
  4. requirements.txt: The dependencies (mcp, fastmcp) needed to run the server.

🚀 How to Run and Test

Follow these steps to learn and run the project:

Step 1: Set up the environment

Make sure you have created your virtual environment and installed the dependencies:

# Create a virtual environment
python -m venv .venv

# Activate it (Windows PowerShell)
.venv\Scripts\Activate.ps1

# Install requirements
pip install -r requirements.txt

Step 2: Generate mock files for testing

Before organizing your actual files, run the generator script. This creates a folder named test_downloads/ with dummy files (.jpg, .pdf, .mp4, etc.):

python test_env_setup.py

Step 3: Run the organizer manually (CLI)

You can run the organizer directly. Let's start with a Dry Run (simulation) so it won't actually move anything:

python organizer.py test_downloads --dry-run

Once you verify that it lists the correct folders and destinations, run it for real:

python organizer.py test_downloads

Check your test_downloads/ folder. You will see that subfolders like Images, Documents, and Videos have been created, and files have been successfully sorted into them!


🔍 Testing the MCP Server (The AI Interface)

MCP servers communicate over standard input/output (stdio) using JSON-RPC, so running python server.py directly in the terminal will look like it's frozen.

To test it visually, we use the MCP Inspector, an official web UI wrapper:

# Run this inside your Day 3 directory
npx @modelcontextprotocol/inspector .venv\Scripts\python.exe server.py
  • What happens: This command starts your server and launches a web browser window (usually at http://localhost:5173 or similar).
  • What to look for:
    1. Click the Tools tab. You should see analyze_directory and organize_directory listed!
    2. Select analyze_directory and enter the path of your test_downloads folder (e.g., C:/Users/user/Desktop/7 day project/Day 3/test_downloads). Click Run.
    3. You will see the AI-friendly textual response summarizing the files.
    4. Now try organize_directory with dry_run = True or False. Watch the directory tidy up!

🤖 Connecting to Your AI Clients

Once your server works, you can add it to your daily AI editors so they can call it.

1. Claude Desktop

Open your Claude Desktop configuration file (typically at %APPDATA%\Claude\claude_desktop_config.json) and add your server:

{
  "mcpServers": {
    "smart-file-organizer": {
      "command": "C:/Users/user/Desktop/7 day project/Day 3/.venv/Scripts/python.exe",
      "args": [
        "C:/Users/user/Desktop/7 day project/Day 3/server.py"
      ]
    }
  }
}

(Make sure to replace the paths above with the actual absolute paths on your computer!)

Restart Claude Desktop, and you will see an organizer tool icon. You can now type: "Organize my downloads folder"!

2. Cursor IDE

  1. Open Cursor Settings -> Features -> MCP.
  2. Click + Add New MCP Server.
  3. Fill in the fields:
    • Name: Smart File Organizer
    • Type: command
    • Command: C:/Users/user/Desktop/7 day project/Day 3/.venv/Scripts/python.exe "C:/Users/user/Desktop/7 day project/Day 3/server.py"
  4. Save and click Refresh. Your Cursor AI agent can now use this tool during chat!

🎯 What You Learned Today

  • Separation of Concerns: Keeping your core logic (organizer.py) separate from your communication logic (server.py).
  • Model Context Protocol (MCP): How to let LLMs access local capabilities via stdio JSON-RPC.
  • Safe CLI Design: Using dry-runs and safe file naming to prevent data loss.
  • Log redirection: Why outputting logs to sys.stderr is critical when standard output (stdout) is used for data transmission.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选