
一个用Python构建的沙盒MCP文件服务器,用于我的CS3A期中考试项目。
概览
- 构建您自己的MCP文件服务器连接器 - BSCS-3A - CS3-WK06-MCP - 期中考试PT. 1 - Python 3.11 - 模型上下文协议(MCP) MCP 文件服务器连接器是一个基于 Python 的应用程序,允许 AI 客户端通过模型上下文协议(MCP)管理文件。 该系统提供创建、读取、写入、编辑、移动、搜索和删除文件的工具。它还支持目录管理、文件信息、基本 Git 操作和项目检查点。 为了保护文件,服务器将文件操作限制在指定的工作区 D:\Midterms。它还支持通过 STDIO 进行本地连接,并通过 NFS 和基础认证通过 HTTPS 的可流式 HTTP 远程连接。 1. 开发一个MCP服务器,允许AI客户端执行文件管理操作。2. 限制文件访问已批准的工作区。3. 验证工具输入以减少无效请求。4. 支持本地和远程MCP连接。5.
概述(AI 翻译)
MCP 文件服务器连接器
1.项目信息
- 项目标题: 构建您自己的MCP文件服务器连接器
- 课程与部分: BSCS-3A
- 文档参考: CS3-WK06-MCP - 期中考试第1部分
- 编程语言: Python 3.11
- 协议: 模型上下文协议(MCP)
2.项目简介
MCP 文件服务器连接器是一个基于 Python 的应用程序,允许 AI 客户端通过模型上下文协议(MCP)管理文件。
该系统提供创建、读取、写入、编辑、移动、搜索和删除文件的工具。它还支持目录管理、文件信息、基本 Git 操作和项目检查点。
为了保护文件,服务器将文件操作限制在指定的工作区[T0]]。它还支持通过STDIO的本地连接,以及通过通过HTTPS通过ngrok和基本认证的可流式HTTP进行远程连接。
3.项目目标
该项目旨在:
- 开发一个MCP服务器,允许AI客户端执行文件管理操作。
- 限制文件访问已批准的工作区。
- 验证工具输入以减少无效请求。
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
MCP File Server Connector
1. Project Information
- Project Title: Build Your Own MCP File Server Connector
- Course and Section: BSCS-3A
- Document Reference: CS3-WK06-MCP - Midterms PT. 1
- Programming Language: Python 3.11
- Protocol: Model Context Protocol (MCP)
2. Project Description
The MCP File Server Connector is a Python-based application that allows AI clients to manage files through the Model Context Protocol (MCP).
The system provides tools for creating, reading, writing, editing, moving, searching, and deleting files. It also supports directory management, file information, basic Git operations, and project checkpoints.
To protect files, the server restricts file operations to the designated workspace, D:\Midterms. It also supports local connections through STDIO and remote connections through Streamable HTTP over HTTPS using ngrok and Basic Authentication.
3. Project Objectives
The project aims to:
- Develop an MCP server that allows AI clients to perform file-management operations.
- Restrict file access to an approved workspace.
- Validate tool inputs to reduce invalid requests.
- Support local and remote MCP connections.
- Test the server’s functionality and security.
4. Technologies Used
| Technology | Purpose |
|---|---|
| Python 3.11 | Main programming language |
| MCP SDK | Connects AI clients to the server’s tools |
| Pydantic | Validates selected tool inputs |
| pytest | Runs automated tests |
| Git | Tracks project changes |
| ngrok | Provides an HTTPS tunnel for remote access |
| Windows Task Scheduler | Starts the server and tunnel at user logon |
5. Main Features
- File Management: Create, read, write, edit, move, and delete files.
- Directory Management: Create directories and list their contents.
- File Search: Search for text within files.
- File Information: Retrieve file details, including size information.
- Git Tools: Check repository status and view changes.
- Workspace Security: Reject paths that point outside the approved directory.
- Input Validation: Check selected tool inputs before processing them.
- Local Connection: Connect through STDIO using an MCP-compatible client.
- Remote Connection: Connect through Streamable HTTP using an HTTPS tunnel.
- Project Tracking: Record checkpoints and read project-state information.
6. Available MCP Tools
The server registers 18 tools.
| No. | Tool Name | Description |
|---|---|---|
| 1 | create_text_file |
Creates a text file with the provided content. |
| 2 | read_text_file |
Reads the contents of a text file. |
| 3 | read_multiple_files |
Reads multiple files. |
| 4 | write_file |
Writes content to a file. |
| 5 | edit_file |
Replaces specified text in a file. |
| 6 | str_replace |
Performs a string replacement in a file. |
| 7 | delete |
Deletes a supported file or filesystem target. |
| 8 | create_directory |
Creates a directory. |
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →