MCP实用工具服务器

MCP实用工具服务器是一组本地运行的小型、专注的工具,包括文件管理、Python代码执行、URL抓取和Shell命令执行等功能。

  • by adityaanilraut
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 adityaanilraut/mcp-servers

使用说明

MCP实用服务器

小而专注 模型上下文协议(MCP) 您可以在本地运行的服务器:

  • 文件管理器(Python) --安全的文件和目录操作
  • Python运行程序(Python/FastMCP) --在沙盒子进程中执行简短的Python代码段
  • URL抓取器(Python/FastMCP) --获取网页并返回结构化文本+链接
  • Shell Exec(Node.js) --使用护栏执行shell命令

传输:所有服务器都通过stdio进行通信,因此它们可以直接由MCP主机/工具启动。


存储库布局

file-manager-server.py       # JSON-RPC style MCP server for file ops
py_runner_server.py          # FastMCP server exposing run_python
url_scraper_mcp_fixed.py     # FastMCP server exposing scrape_url
shell-exec-server.js         # Node.js server exposing shell tools
setup.py                     # Packaging for the URL Scraper server

需求

  • python ≥ 3.9
  • Node.js (适用于Shell Exec服务器)
  • MCP Python SDK/CLI: pip install "mcp[cli]"
  • URL抓取器附加功能: httpx, beautifulsoup4, anyio

URL Scraper可以通过以下方式作为包安装 setup.py (参见 安装).


安装

选项A--从源代码运行(无需安装)

# Python deps (shared)
pip install "mcp[cli]"

# URL Scraper deps
pip install httpx beautifulsoup4 anyio

选项B——安装URL Scraper包

从repo根目录:

pip install -e .
# This installs the console entrypoint: `url-scraper-mcp`

运行服务器

文件管理器(Python)

python3 file-manager-server.py

Python运行程序(FastMCP)

python3 py_runner_server.py
# or, with the MCP CLI developer runner:
# uv run mcp dev py_runner_server.py     # if you use uv
# mcp dev py_runner_server.py            # if `mcp` is on PATH

URL抓取器(FastMCP)

python3 url_scraper_mcp_fixed.py
# or, with the MCP CLI developer runner:
# uv run mcp dev url_scraper_mcp_fixed.py
# If installed as a package:
url-scraper-mcp

Shell Exec(Node.js)

node shell-exec-server.js

配置您的MCP主机以通过stdio启动这些命令中的任何一个。


工具参考

1) 文件管理器服务器-- file-manager-server.py

方法 (通过通用JSON-RPC调用 tools/call):

  • read_file(path, encoding="utf-8")
  • write_file(path, content, encoding="utf-8", append=False)
  • list_files(path=".", pattern="*", recursive=False)
  • create_directory(path, parents=True)
  • delete_file(path, recursive=False)
  • move_file(source, destination)
  • copy_file(source, destination, recursive=False)
  • get_file_info(path) --包括可读大小、mime和MD5,适用于小于100MB的文件
  • search_files(directory=".", pattern, file_pattern="*")

JSON-RPC调用示例 (基于stdio行,每行一个JSON):

{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"read_file","arguments":{"path":"README.md"}}}

安全

  • 阻止对敏感根的访问(例如。, /etc, /sys, /proc,某些Windows系统路径)。
  • 读取的文本/二进制检测;二进制内容在响应中采用base64编码。

2) Python运行程序-- py_runner_server.py

服务器名称: py-runner (快速MCP)

工具

  • run_python(code: str, input_text: str | None = None, timeout_secs: int = 5) -> {stdout, stderr, exit_code, duration_ms}

行为和护栏

  • 奉献代码,将其写入临时目录,并通过子流程执行。
  • 支持可选的stdin(input_text)并强制超时(默认5s)。超时时,返回 {"error": "Timeout after ...s"}.

示例

{"method":"tools/call","params":{"name":"run_python","arguments":{"code":"print('hi')"}}}

3) URL抓取器-- url_scraper_mcp_fixed.py

服务器名称: URL Scraper (快速MCP)

工具

  • scrape_url(url: str, max_chars: int = 5000, max_links: int = 100, timeout_s: float = 20.0, user_agent: str = "...") -> {url, final_url, status_code, title, content, links}

行为

  • 跟随重定向、提取 <title>,可见文本(修剪为 max_chars),直至 max_links 绝对链接。
  • 请求失败时返回结构化错误信息;对于非HTML内容,返回一个简短的解码片段。
  • 仅接受 http(s) URL。

例子

{"method":"tools/call","params":{"name":"scrape_url","arguments":{"url":"https://example.org","max_chars":2000}}}

包装

  • 可安装包(url-scraper-mcp)带有控制台入口点,便于启动。

4) 壳牌高管-- shell-exec-server.js

工具

  • execute_command(command: string, cwd?: string, timeout?: number)
  • list_directory(path?: string)
  • get_system_info()
  • set_environment(name: string, value: string)

行为和护栏

  • 用途 exec 具有可配置的超时;阻挡明显危险的图案(例如。, rm -rf /,原始磁盘写入)。
  • list_directory 用途 ls -la 在POSIX或 dir 在Windows上自动。
  • get_system_info 返回一个JSON对象,其中包含平台、cpu计数、内存、节点版本、cwd等。

示例

{"method":"tools/call","params":{"name":"execute_command","arguments":{"command":"echo hello"}}}

使用MCP CLI进行开发

如果您使用MCP Python CLI,则可以在开发模式下运行FastMCP服务器:

uv run mcp dev py_runner_server.py
uv run mcp dev url_scraper_mcp_fixed.py

这将启动一个可以从兼容主机连接到的stdio MCP服务器进程。


安全说明和默认值

  • 文件管理器:路径门,避开系统目录;base64用于二进制读取;MD5仅适用于小于100MB的文件。
  • Python运行程序:在临时工作目录中运行代码;子进程超时默认为5秒。
  • URL抓取器:仅HTTP(S);默认超时20秒;条纹脚本/样式;规范文本和链接。
  • 壳牌高管:阻止危险命令;默认超时30秒;每个会话的可定制环境。

故障排除

  • ModuleNotFoundError: mcp.server.fastmcp --安装SDK: pip install "mcp[cli]".
  • 悬挂或无输出 --确保您通过stdio启动,并且每行只发出一个JSON-RPC对象。
  • URL抓取器中的网络故障 --验证该URL是否可以通过HTTP(S)访问,并且没有被您的环境阻止。
  • 权限/路径 --一些服务器故意通过设计阻止系统路径和破坏性命令。

许可证

在此处添加您的首选许可证(例如MIT)。