一个自定义的模型上下文协议(MCP)服务器实现,提供文件系统和命令执行工具给Claude桌面和其他大型语言模型(LLM)客户端。
模型上下文协议(MCP)是一个开放协议,标准化了应用程序如何向大型语言模型(LLM)提供上下文。就像USB-C端口提供了一种标准化的方式连接设备到各种外围设备一样,MCP提供了一种标准化的方式连接AI模型到不同的数据源和工具。
这个项目实现了一个FastMCP服务器,包含几个有用的工具,使Claude和其他LLM能够与本地文件系统交互并执行命令。它通过明确定义的工具接口以受控方式扩展了LLM的本地系统访问能力。
MCP服务器提供了以下文件系统和命令执行工具:
MCP遵循客户端-服务器架构:
uv run mcp install来安装MCP服务器which uv以获取uv可执行文件的绝对路径uv可执行文件的绝对路径我的MCP服务器配置如下:
{
"globalShortcut": "",
"mcpServers": {
"zbigniew-mcp": {
"command": "/Users/zbigniewtomanek/.local/bin/uv",
"args": [
"run",
"--with",
"mcp[cli]",
"--with",
"marker-pdf",
"mcp",
"run",
"/Users/zbigniewtomanek/PycharmProjects/my-mcp-tools/server.py"
]
}
}
}
注意:虽然此实现侧重于Claude桌面,但MCP设计为与任何兼容MCP的工具或LLM客户端兼容,提供实施和集成的灵活性。
安全地使用参数列表执行shell命令:
execute_shell_command(["ls", "-la"])
execute_shell_command(["grep", "-r", "TODO", "./src"])
execute_shell_command(["python", "analysis.py", "--input", "data.csv"])
execute_shell_command(["uname", "-a"])
查看文件内容,可选指定行范围:
show_file("/path/to/file.txt")
show_file("/path/to/file.txt", num_lines=10)
show_file("/path/to/file.txt", start_line= 5, num_lines=10)
使用正则表达式在文件中搜索模式:
search_in_file("/path/to/script.py", r"def\s+\w+\s*\(")
search_in_file("/path/to/code.py", r"#\s*TODO", case_sensitive=False)
精确修改文件:
# 替换文本
edit_file("config.json", replacements={"\"debug\": false": "\"debug\": true"})
# 在第5行插入
edit_file("script.py", line_operations=[{"operation": "insert", "line": 5, "content": "# 新注释"}])
# 删除第10-15行
edit_file("file.txt", line_operations=[{"operation": "delete", "start_line": 10, "end_line": 15}])
# 替换第20行
edit_file("file.txt", line_operations=[{"operation": "replace", "line": 20, "content": "更新的内容"}])
写入或追加内容到文件:
# 覆盖文件
write_file("/path/to/file.txt", "新内容")
# 追加到文件
write_file("/path/to/log.txt", "日志条目", mode="a")
抓取网页内容到PDF(需要安装chromium),然后使用本地LLM解析为markdown:
fetch_page("https://example.com")
MCP支持多种通信传输方法:
此实现使用一个本地MCP服务器,通过文本输入/输出进行通信。
您可以轻松地通过添加带有@mcp.tool装饰器的新工具来扩展此MCP服务器。按照server.py中的模式创建新工具,以向您的LLM客户端暴露额外的功能。
MCP服务器为Claude提供了对您本地系统的访问权限。请注意以下事项: