发现优秀的 MCP 服务器
通过 MCP 服务器扩展您的代理能力,拥有 14,326 个能力。
Cursor MCP Server
wayne-mcp-servers
我自定义的 MCP(模型上下文协议)服务器。
Model Context Protocol servers
MCP Servers
For development work, "MCP servers" could refer to a few things, depending on the context. To give you the best translation, I need a little more information. However, here are a few possibilities and their translations: **1. If "MCP" refers to "Minecraft Coder Pack" (a tool for decompiling, deobfuscating, and recompiling Minecraft code):** * **English:** MCP Servers for dev work * **Chinese (Simplified):** 用于开发工作的 MCP 服务器 (Yòng yú kāifā gōngzuò de MCP fúwùqì) * **Explanation:** This is the most likely interpretation if you're talking about Minecraft modding. "用于开发工作的" means "for development work," and "MCP 服务器" means "MCP servers." **2. If "MCP" refers to "Master Control Program" (a general term for a central control system, perhaps in a software architecture):** * **English:** MCP Servers for dev work * **Chinese (Simplified):** 用于开发工作的主控程序服务器 (Yòng yú kāifā gōngzuò de zhǔkòng chéngxù fúwùqì) * **Explanation:** "主控程序" (zhǔkòng chéngxù) means "master control program." This is a more generic translation. **3. If "MCP" is an abbreviation specific to your project or company:** * In this case, you need to provide the full name of what "MCP" stands for so I can provide an accurate translation. For example, if MCP stands for "My Custom Platform," then: * **English:** MCP Servers for dev work (where MCP = My Custom Platform) * **Chinese (Simplified):** 用于开发工作的我的自定义平台服务器 (Yòng yú kāifā gōngzuò de wǒ de zì dìngyì píngtái fúwùqì) **Therefore, to give you the *best* translation, please tell me what "MCP" stands for in your context.** If it's Minecraft Coder Pack, the first translation is likely correct.
Remote MCP Server on Cloudflare
AzureAppConfigurationHelper-MCP
一个 MCP 服务器,帮助人们使用 Azure 应用配置开发应用程序。
mattermost-mcp-server
flutterclimcp
好的,这是一个使用 Flutter CLI 和 MCP (Model Context Protocol) 服务器创建 Flutter 项目的有趣示例项目: **项目名称:** 猜数字游戏 (Guess the Number Game) **项目描述:** 这是一个简单的猜数字游戏,用户需要猜一个由计算机随机生成的数字。游戏会提供反馈,告诉用户猜的数字是太高还是太低,直到用户猜对为止。我们将使用 MCP 服务器来处理游戏逻辑,而 Flutter 应用将负责用户界面和与服务器的通信。 **技术栈:** * **Flutter:** 用于构建用户界面。 * **Flutter CLI:** 用于创建和管理 Flutter 项目。 * **MCP Server (Python):** 用于处理游戏逻辑,例如生成随机数、比较猜测和提供反馈。 * **HTTP:** 用于 Flutter 应用和 MCP 服务器之间的通信。 **步骤:** 1. **设置 MCP 服务器 (Python):** ```python from http.server import BaseHTTPRequestHandler, HTTPServer import json import random class RequestHandler(BaseHTTPRequestHandler): def do_POST(self): if self.path == '/guess': content_length = int(self.headers['Content-Length']) post_data = self.rfile.read(content_length) data = json.loads(post_data.decode('utf-8')) guess = data.get('guess') if not hasattr(self.server, 'secret_number'): self.server.secret_number = random.randint(1, 100) self.server.num_guesses = 0 self.server.num_guesses += 1 if guess is None: response = {'error': 'Missing guess parameter'} elif guess < self.server.secret_number: response = {'result': 'too_low'} elif guess > self.server.secret_number: response = {'result': 'too_high'} else: response = {'result': 'correct', 'guesses': self.server.num_guesses} del self.server.secret_number # Reset for next game del self.server.num_guesses self.send_response(200) self.send_header('Content-type', 'application/json') self.end_headers() self.wfile.write(json.dumps(response).encode('utf-8')) else: self.send_response(404) self.end_headers() def run(server_class=HTTPServer, handler_class=RequestHandler, port=8000): server_address = ('', port) httpd = server_class(server_address, handler_class) print(f'Starting server on port {port}') httpd.serve_forever() if __name__ == '__main__': run() ``` * 将此代码保存为 `mcp_server.py`。 * 运行服务器:`python mcp_server.py` 2. **创建 Flutter 项目:** ```bash flutter create guess_the_number cd guess_the_number ``` 3. **修改 `lib/main.dart`:** ```dart import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Guess the Number', theme: ThemeData( primarySwatch: Colors.blue, ), home: GuessTheNumberPage(), ); } } class GuessTheNumberPage extends StatefulWidget { @override _GuessTheNumberPageState createState() => _GuessTheNumberPageState(); } class _GuessTheNumberPageState extends State<GuessTheNumberPage> { final TextEditingController _guessController = TextEditingController(); String _message = ''; bool _gameOver = false; Future<void> _checkGuess(String guess) async { try { final int? parsedGuess = int.tryParse(guess); if (parsedGuess == null) { setState(() { _message = 'Please enter a valid number.'; }); return; } final response = await http.post( Uri.parse('http://localhost:8000/guess'), // Replace with your server address headers: {'Content-Type': 'application/json'}, body: jsonEncode({'guess': parsedGuess}), ); if (response.statusCode == 200) { final data = jsonDecode(response.body); final result = data['result']; setState(() { if (result == 'too_low') { _message = 'Too low! Try again.'; } else if (result == 'too_high') { _message = 'Too high! Try again.'; } else if (result == 'correct') { _message = 'Congratulations! You guessed the number in ${data['guesses']} tries.'; _gameOver = true; } else if (data.containsKey('error')) { _message = 'Error: ${data['error']}'; } else { _message = 'Unexpected response from server.'; } }); } else { setState(() { _message = 'Failed to connect to the server. Status code: ${response.statusCode}'; }); } } catch (e) { setState(() { _message = 'An error occurred: $e'; }); } } void _resetGame() { setState(() { _message = ''; _guessController.clear(); _gameOver = false; }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Guess the Number'), ), body: Padding( padding: const EdgeInsets.all(16.0), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text( 'I\'m thinking of a number between 1 and 100.', style: TextStyle(fontSize: 16), ), SizedBox(height: 20), TextField( controller: _guessController, keyboardType: TextInputType.number, decoration: InputDecoration( labelText: 'Enter your guess', border: OutlineInputBorder(), ), enabled: !_gameOver, ), SizedBox(height: 20), ElevatedButton( onPressed: _gameOver ? null : () { _checkGuess(_guessController.text); }, child: Text('Guess'), ), SizedBox(height: 20), Text( _message, style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), textAlign: TextAlign.center, ), if (_gameOver) ElevatedButton( onPressed: _resetGame, child: Text('Play Again'), ), ], ), ), ); } } ``` 4. **添加 `http` 依赖:** ```bash flutter pub add http ``` 5. **运行 Flutter 应用:** ```bash flutter run ``` **解释:** * **MCP 服务器 (Python):** * 监听端口 8000 上的 HTTP POST 请求。 * 当收到 `/guess` 请求时,它会解析 JSON 数据,提取用户的猜测。 * 如果这是第一次猜测,它会生成一个 1 到 100 之间的随机数。 * 它会将用户的猜测与秘密数字进行比较,并返回 `too_low`、`too_high` 或 `correct`。 * 如果猜测正确,它会返回猜测次数并重置游戏。 * **Flutter 应用:** * 包含一个文本字段,用户可以在其中输入他们的猜测。 * 包含一个按钮,用户可以点击该按钮来提交他们的猜测。 * 使用 `http` 包向 MCP 服务器发送 POST 请求,并将用户的猜测作为 JSON 数据发送。 * 解析服务器的响应,并更新 UI 以显示反馈(太高、太低、正确)。 * 如果用户猜对了,它会显示一条祝贺消息和猜测次数。 * 包含一个“再玩一次”按钮,可以重置游戏。 **如何运行:** 1. 首先,运行 `mcp_server.py`。 2. 然后,运行 Flutter 应用。 3. 在 Flutter 应用中,输入你的猜测并点击“猜测”按钮。 4. 查看应用中的反馈,并继续猜测直到你猜对为止。 **改进:** * **错误处理:** 添加更健壮的错误处理,例如处理服务器连接错误。 * **UI 改进:** 改进 UI 以使其更具吸引力。 * **难度级别:** 添加难度级别,允许用户选择数字范围。 * **历史记录:** 显示用户的猜测历史记录。 * **使用更复杂的 MCP 协议:** 虽然这个例子使用简单的 HTTP,但你可以探索更复杂的 MCP 协议,例如 gRPC 或 Thrift,以获得更好的性能和类型安全。 这个示例展示了如何使用 Flutter CLI 和 MCP 服务器创建一个简单的 Flutter 项目。 你可以根据自己的需要修改和扩展此项目。 关键在于将 UI 逻辑与业务逻辑分离,并使用 MCP 服务器来处理业务逻辑。 **中文翻译:** 好的,这是一个使用 Flutter CLI 和 MCP (模型上下文协议) 服务器创建一个 Flutter 项目的有趣示例项目: **项目名称:** 猜数字游戏 (Guess the Number Game) **项目描述:** 这是一个简单的猜数字游戏,用户需要猜一个由计算机随机生成的数字。游戏会提供反馈,告诉用户猜的数字是太高还是太低,直到用户猜对为止。我们将使用 MCP 服务器来处理游戏逻辑,而 Flutter 应用将负责用户界面和与服务器的通信。 **技术栈:** * **Flutter:** 用于构建用户界面。 * **Flutter CLI:** 用于创建和管理 Flutter 项目。 * **MCP Server (Python):** 用于处理游戏逻辑,例如生成随机数、比较猜测和提供反馈。 * **HTTP:** 用于 Flutter 应用和 MCP 服务器之间的通信。 **步骤:** 1. **设置 MCP 服务器 (Python):** ```python from http.server import BaseHTTPRequestHandler, HTTPServer import json import random class RequestHandler(BaseHTTPRequestHandler): def do_POST(self): if self.path == '/guess': content_length = int(self.headers['Content-Length']) post_data = self.rfile.read(content_length) data = json.loads(post_data.decode('utf-8')) guess = data.get('guess') if not hasattr(self.server, 'secret_number'): self.server.secret_number = random.randint(1, 100) self.server.num_guesses = 0 self.server.num_guesses += 1 if guess is None: response = {'error': 'Missing guess parameter'} elif guess < self.server.secret_number: response = {'result': 'too_low'} elif guess > self.server.secret_number: response = {'result': 'too_high'} else: response = {'result': 'correct', 'guesses': self.server.num_guesses} del self.server.secret_number # Reset for next game del self.server.num_guesses self.send_response(200) self.send_header('Content-type', 'application/json') self.end_headers() self.wfile.write(json.dumps(response).encode('utf-8')) else: self.send_response(404) self.end_headers() def run(server_class=HTTPServer, handler_class=RequestHandler, port=8000): server_address = ('', port) httpd = server_class(server_address, handler_class) print(f'Starting server on port {port}') httpd.serve_forever() if __name__ == '__main__': run() ``` * 将此代码保存为 `mcp_server.py`。 * 运行服务器:`python mcp_server.py` 2. **创建 Flutter 项目:** ```bash flutter create guess_the_number cd guess_the_number ``` 3. **修改 `lib/main.dart`:** ```dart import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Guess the Number', theme: ThemeData( primarySwatch: Colors.blue, ), home: GuessTheNumberPage(), ); } } class GuessTheNumberPage extends StatefulWidget { @override _GuessTheNumberPageState createState() => _GuessTheNumberPageState(); } class _GuessTheNumberPageState extends State<GuessTheNumberPage> { final TextEditingController _guessController = TextEditingController(); String _message = ''; bool _gameOver = false; Future<void> _checkGuess(String guess) async { try { final int? parsedGuess = int.tryParse(guess); if (parsedGuess == null) { setState(() { _message = 'Please enter a valid number.'; }); return; } final response = await http.post( Uri.parse('http://localhost:8000/guess'), // Replace with your server address headers: {'Content-Type': 'application/json'}, body: jsonEncode({'guess': parsedGuess}), ); if (response.statusCode == 200) { final data = jsonDecode(response.body); final result = data['result']; setState(() { if (result == 'too_low') { _message = 'Too low! Try again.'; } else if (result == 'too_high') { _message = 'Too high! Try again.'; } else if (result == 'correct') { _message = 'Congratulations! You guessed the number in ${data['guesses']} tries.'; _gameOver = true; } else if (data.containsKey('error')) { _message = 'Error: ${data['error']}'; } else { _message = 'Unexpected response from server.'; } }); } else { setState(() { _message = 'Failed to connect to the server. Status code: ${response.statusCode}'; }); } } catch (e) { setState(() { _message = 'An error occurred: $e'; }); } } void _resetGame() { setState(() { _message = ''; _guessController.clear(); _gameOver = false; }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Guess the Number'), ), body: Padding( padding: const EdgeInsets.all(16.0), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text( 'I\'m thinking of a number between 1 and 100.', style: TextStyle(fontSize: 16), ), SizedBox(height: 20), TextField( controller: _guessController, keyboardType: TextInputType.number, decoration: InputDecoration( labelText: 'Enter your guess', border: OutlineInputBorder(), ), enabled: !_gameOver, ), SizedBox(height: 20), ElevatedButton( onPressed: _gameOver ? null : () { _checkGuess(_guessController.text); }, child: Text('Guess'), ), SizedBox(height: 20), Text( _message, style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), textAlign: TextAlign.center, ), if (_gameOver) ElevatedButton( onPressed: _resetGame, child: Text('Play Again'), ), ], ), ), ); } } ``` 4. **添加 `http` 依赖:** ```bash flutter pub add http ``` 5. **运行 Flutter 应用:** ```bash flutter run ``` **解释:** * **MCP 服务器 (Python):** * 监听端口 8000 上的 HTTP POST 请求。 * 当收到 `/guess` 请求时,它会解析 JSON 数据,提取用户的猜测。 * 如果这是第一次猜测,它会生成一个 1 到 100 之间的随机数。 * 它会将用户的猜测与秘密数字进行比较,并返回 `too_low`、`too_high` 或 `correct`。 * 如果猜测正确,它会返回猜测次数并重置游戏。 * **Flutter 应用:** * 包含一个文本字段,用户可以在其中输入他们的猜测。 * 包含一个按钮,用户可以点击该按钮来提交他们的猜测。 * 使用 `http` 包向 MCP 服务器发送 POST 请求,并将用户的猜测作为 JSON 数据发送。 * 解析服务器的响应,并更新 UI 以显示反馈(太高、太低、正确)。 * 如果用户猜对了,它会显示一条祝贺消息和猜测次数。 * 包含一个“再玩一次”按钮,可以重置游戏。 **如何运行:** 1. 首先,运行 `mcp_server.py`。 2. 然后,运行 Flutter 应用。 3. 在 Flutter 应用中,输入你的猜测并点击“猜测”按钮。 4. 查看应用中的反馈,并继续猜测直到你猜对为止。 **改进:** * **错误处理:** 添加更健壮的错误处理,例如处理服务器连接错误。 * **UI 改进:** 改进 UI 以使其更具吸引力。 * **难度级别:** 添加难度级别,允许用户选择数字范围。 * **历史记录:** 显示用户的猜测历史记录。 * **使用更复杂的 MCP 协议:** 虽然这个例子使用简单的 HTTP,但你可以探索更复杂的 MCP 协议,例如 gRPC 或 Thrift,以获得更好的性能和类型安全。 这个示例展示了如何使用 Flutter CLI 和 MCP 服务器创建一个简单的 Flutter 项目。 你可以根据自己的需要修改和扩展此项目。 关键在于将 UI 逻辑与业务逻辑分离,并使用 MCP 服务器来处理业务逻辑。 This provides a complete, runnable example with explanations and improvements. Remember to replace `http://localhost:8000/guess` with the actual address of your MCP server if it's running on a different machine or port. Good luck!
evm-server MCP Server
镜子 (jìng zi)
Filesystem MCP
安全地修改 MCP 服务器根目录下的文件,同时防止用户逃逸到根目录之外: 这里提供一些建议,结合了安全性和实用性: **核心原则:最小权限原则 (Principle of Least Privilege)** * **用户权限限制:** 这是最重要的一点。 运行 MCP 服务器的用户账户(例如,一个专门创建的 `mcp_user` 账户)**绝对不能**拥有 root 权限。 它应该只拥有修改根目录下特定文件和目录的权限。 * **chroot 环境 (Chrooted Environment):** 将 MCP 服务器限制在一个 chroot 环境中。 Chroot 会创建一个虚拟的根目录,让服务器认为它位于文件系统的顶层,即使它实际上位于更深的位置。 这可以防止用户访问 chroot 环境之外的文件。 * **输入验证和清理:** 对所有用户输入进行严格的验证和清理。 这可以防止命令注入攻击,攻击者可能会利用这些漏洞来执行任意代码。 * **输出编码:** 对所有输出进行编码,以防止跨站脚本攻击 (XSS)。 * **定期更新:** 保持 MCP 服务器软件和操作系统更新到最新版本,以修复已知的安全漏洞。 **具体实现方法:** 1. **创建用户和组:** ```bash sudo groupadd mcp_group sudo useradd -g mcp_group -d /path/to/mcp/root -s /bin/bash mcp_user sudo passwd mcp_user # 设置密码 ``` * `/path/to/mcp/root` 是你希望作为 MCP 服务器根目录的实际路径。 例如,`/opt/mcp_server`。 * `-s /bin/bash` 允许用户使用 bash shell。 如果不需要 shell 访问,可以设置为 `/bin/false` 或 `/usr/sbin/nologin`。 2. **设置目录权限:** ```bash sudo chown -R mcp_user:mcp_group /path/to/mcp/root sudo chmod -R 770 /path/to/mcp/root # 允许用户和组读写执行 ``` * 根据需要调整权限。 例如,如果用户只需要读取某些文件,则可以将其权限设置为 `440`。 * **重要:** 确保 `mcp_user` 拥有修改所需文件的权限,但不要授予不必要的权限。 3. **Chroot 环境 (推荐):** * **创建 chroot 环境:** 这需要一些手动操作,因为你需要复制所有必要的库和程序到 chroot 目录中。 可以使用 `debootstrap` (Debian/Ubuntu) 或 `yum install yum-utils; yumdownloader --resolve --destdir=/path/to/chroot/lib <program>` (CentOS/RHEL) 来简化这个过程。 ```bash # 示例 (Debian/Ubuntu) sudo apt-get install debootstrap sudo mkdir /path/to/chroot sudo debootstrap --arch amd64 stable /path/to/chroot http://httpredir.debian.org/debian ``` * `stable` 可以替换为 `testing` 或 `unstable`,但 `stable` 最安全。 * `amd64` 替换为你的架构 (例如 `i386`, `arm64`)。 * **重要:** 你需要复制 MCP 服务器依赖的所有库和程序到 `/path/to/chroot` 中。 这可能包括 `libc.so.6`, `libpthread.so.0`, 等等。 使用 `ldd <mcp_server_executable>` 来查看依赖项。 * **使用 `chroot` 命令:** 在启动 MCP 服务器之前,使用 `chroot` 命令将其限制在 chroot 环境中。 ```bash sudo chroot /path/to/chroot /path/to/mcp_server_executable ``` * **更高级的 chroot 管理工具:** 考虑使用 `jailkit` 或 `docker` 等工具来更轻松地管理 chroot 环境。 Docker 提供了一种更隔离和可移植的解决方案。 4. **输入验证和清理:** * **白名单:** 使用白名单来限制允许的输入。 例如,如果用户只能修改某些特定的文件,则只允许这些文件的名称作为输入。 * **正则表达式:** 使用正则表达式来验证输入的格式。 例如,如果用户必须输入一个数字,则可以使用正则表达式来确保输入只包含数字。 * **转义:** 转义所有特殊字符,以防止命令注入攻击。 例如,在 bash 中,可以使用 `\` 来转义特殊字符。 5. **输出编码:** * **HTML 编码:** 如果 MCP 服务器生成 HTML 输出,则对所有输出进行 HTML 编码,以防止 XSS 攻击。 * **URL 编码:** 如果 MCP 服务器生成 URL,则对所有 URL 进行 URL 编码。 6. **日志记录:** * 记录所有用户操作,以便进行审计和故障排除。 * 监控日志文件,以检测可疑活动。 7. **防火墙:** * 使用防火墙来限制对 MCP 服务器的访问。 只允许来自受信任的 IP 地址的连接。 **示例代码 (Python):** ```python import os import subprocess import re def modify_file(filename, content): """ 安全地修改文件。 Args: filename: 要修改的文件名 (相对于根目录). content: 要写入文件的内容. """ # 1. 白名单验证文件名 allowed_files = ["config.txt", "data.json"] # 允许修改的文件 if filename not in allowed_files: raise ValueError("Invalid filename") # 2. 构造完整路径 (相对于根目录) filepath = os.path.join("/path/to/mcp/root", filename) # 3. 检查文件是否存在 if not os.path.exists(filepath): raise FileNotFoundError("File not found") # 4. 输入验证 (例如,限制内容长度) if len(content) > 1024: raise ValueError("Content too long") # 5. 使用 subprocess 安全地写入文件 try: with open(filepath, "w") as f: f.write(content) except Exception as e: raise Exception(f"Error writing to file: {e}") # 示例用法 try: modify_file("config.txt", "new config value") print("File modified successfully") except ValueError as e: print(f"Error: {e}") except FileNotFoundError as e: print(f"Error: {e}") except Exception as e: print(f"An unexpected error occurred: {e}") ``` **重要注意事项:** * **测试:** 在生产环境中部署之前,彻底测试所有安全措施。 * **安全审计:** 定期进行安全审计,以识别和修复潜在的安全漏洞。 * **具体情况:** 以上建议只是一些通用的指导原则。 你需要根据你的具体情况进行调整。 * **复杂性:** 构建一个完全安全的系统非常复杂。 如果你不确定如何操作,请咨询安全专家。 **总结:** 通过结合最小权限原则、chroot 环境、输入验证和清理、输出编码、日志记录和防火墙,你可以大大提高 MCP 服务器的安全性,防止用户逃逸到根目录之外,并安全地修改文件。 记住,安全是一个持续的过程,需要不断地监控和改进。 --- **中文翻译:** 安全地修改 MCP 服务器根目录下的文件,同时防止用户逃逸到根目录之外: 这里提供一些建议,结合了安全性和实用性: **核心原则:最小权限原则 (Principle of Least Privilege)** * **用户权限限制:** 这是最重要的一点。运行 MCP 服务器的用户账户(例如,一个专门创建的 `mcp_user` 账户)**绝对不能**拥有 root 权限。它应该只拥有修改根目录下特定文件和目录的权限。 * **chroot 环境 (Chrooted Environment):** 将 MCP 服务器限制在一个 chroot 环境中。Chroot 会创建一个虚拟的根目录,让服务器认为它位于文件系统的顶层,即使它实际上位于更深的位置。这可以防止用户访问 chroot 环境之外的文件。 * **输入验证和清理:** 对所有用户输入进行严格的验证和清理。这可以防止命令注入攻击,攻击者可能会利用这些漏洞来执行任意代码。 * **输出编码:** 对所有输出进行编码,以防止跨站脚本攻击 (XSS)。 * **定期更新:** 保持 MCP 服务器软件和操作系统更新到最新版本,以修复已知的安全漏洞。 **具体实现方法:** 1. **创建用户和组:** ```bash sudo groupadd mcp_group sudo useradd -g mcp_group -d /path/to/mcp/root -s /bin/bash mcp_user sudo passwd mcp_user # 设置密码 ``` * `/path/to/mcp/root` 是你希望作为 MCP 服务器根目录的实际路径。例如,`/opt/mcp_server`。 * `-s /bin/bash` 允许用户使用 bash shell。如果不需要 shell 访问,可以设置为 `/bin/false` 或 `/usr/sbin/nologin`。 2. **设置目录权限:** ```bash sudo chown -R mcp_user:mcp_group /path/to/mcp/root sudo chmod -R 770 /path/to/mcp/root # 允许用户和组读写执行 ``` * 根据需要调整权限。例如,如果用户只需要读取某些文件,则可以将其权限设置为 `440`。 * **重要:** 确保 `mcp_user` 拥有修改所需文件的权限,但不要授予不必要的权限。 3. **Chroot 环境 (推荐):** * **创建 chroot 环境:** 这需要一些手动操作,因为你需要复制所有必要的库和程序到 chroot 目录中。可以使用 `debootstrap` (Debian/Ubuntu) 或 `yum install yum-utils; yumdownloader --resolve --destdir=/path/to/chroot/lib <program>` (CentOS/RHEL) 来简化这个过程。 ```bash # 示例 (Debian/Ubuntu) sudo apt-get install debootstrap sudo mkdir /path/to/chroot sudo debootstrap --arch amd64 stable /path/to/chroot http://httpredir.debian.org/debian ``` * `stable` 可以替换为 `testing` 或 `unstable`,但 `stable` 最安全。 * `amd64` 替换为你的架构 (例如 `i386`, `arm64`)。 * **重要:** 你需要复制 MCP 服务器依赖的所有库和程序到 `/path/to/chroot` 中。这可能包括 `libc.so.6`, `libpthread.so.0`, 等等。使用 `ldd <mcp_server_executable>` 来查看依赖项。 * **使用 `chroot` 命令:** 在启动 MCP 服务器之前,使用 `chroot` 命令将其限制在 chroot 环境中。 ```bash sudo chroot /path/to/chroot /path/to/mcp_server_executable ``` * **更高级的 chroot 管理工具:** 考虑使用 `jailkit` 或 `docker` 等工具来更轻松地管理 chroot 环境。Docker 提供了一种更隔离和可移植的解决方案。 4. **输入验证和清理:** * **白名单:** 使用白名单来限制允许的输入。例如,如果用户只能修改某些特定的文件,则只允许这些文件的名称作为输入。 * **正则表达式:** 使用正则表达式来验证输入的格式。例如,如果用户必须输入一个数字,则可以使用正则表达式来确保输入只包含数字。 * **转义:** 转义所有特殊字符,以防止命令注入攻击。例如,在 bash 中,可以使用 `\` 来转义特殊字符。 5. **输出编码:** * **HTML 编码:** 如果 MCP 服务器生成 HTML 输出,则对所有输出进行 HTML 编码,以防止 XSS 攻击。 * **URL 编码:** 如果 MCP 服务器生成 URL,则对所有 URL 进行 URL 编码。 6. **日志记录:** * 记录所有用户操作,以便进行审计和故障排除。 * 监控日志文件,以检测可疑活动。 7. **防火墙:** * 使用防火墙来限制对 MCP 服务器的访问。只允许来自受信任的 IP 地址的连接。 **示例代码 (Python):** ```python import os import subprocess import re def modify_file(filename, content): """ 安全地修改文件。 Args: filename: 要修改的文件名 (相对于根目录). content: 要写入文件的内容. """ # 1. 白名单验证文件名 allowed_files = ["config.txt", "data.json"] # 允许修改的文件 if filename not in allowed_files: raise ValueError("Invalid filename") # 2. 构造完整路径 (相对于根目录) filepath = os.path.join("/path/to/mcp/root", filename) # 3. 检查文件是否存在 if not os.path.exists(filepath): raise FileNotFoundError("File not found") # 4. 输入验证 (例如,限制内容长度) if len(content) > 1024: raise ValueError("Content too long") # 5. 使用 subprocess 安全地写入文件 try: with open(filepath, "w") as f: f.write(content) except Exception as e: raise Exception(f"Error writing to file: {e}") # 示例用法 try: modify_file("config.txt", "new config value") print("File modified successfully") except ValueError as e: print(f"Error: {e}") except FileNotFoundError as e: print(f"Error: {e}") except Exception as e: print(f"An unexpected error occurred: {e}") ``` **重要注意事项:** * **测试:** 在生产环境中部署之前,彻底测试所有安全措施。 * **安全审计:** 定期进行安全审计,以识别和修复潜在的安全漏洞。 * **具体情况:** 以上建议只是一些通用的指导原则。你需要根据你的具体情况进行调整。 * **复杂性:** 构建一个完全安全的系统非常复杂。如果你不确定如何操作,请咨询安全专家。 **总结:** 通过结合最小权限原则、chroot 环境、输入验证和清理、输出编码、日志记录和防火墙,你可以大大提高 MCP 服务器的安全性,防止用户逃逸到根目录之外,并安全地修改文件。记住,安全是一个持续的过程,需要不断地监控和改进。
Aws Sample Gen Ai Mcp Server
Okay, here's a Python code sample demonstrating how to use a Generative AI model (like those available through Amazon Bedrock) with an MCP (Model Control Plane) server. This example assumes you have an MCP server running and accessible, and that you've configured your AWS credentials correctly. ```python import boto3 import json import requests # Configuration (Replace with your actual values) AWS_REGION = "us-west-2" # Your AWS region BEDROCK_MODEL_ID = "anthropic.claude-v2" # Example: Claude v2 MCP_SERVER_URL = "http://your-mcp-server:8000/infer" # URL of your MCP server MCP_API_KEY = "your_mcp_api_key" # API key for MCP server authentication (if required) # Initialize Bedrock client (if you want to use it directly for comparison) bedrock = boto3.client(service_name="bedrock-runtime", region_name=AWS_REGION) def generate_text_with_bedrock(prompt, model_id=BEDROCK_MODEL_ID, max_tokens=200): """Generates text using Amazon Bedrock directly.""" try: body = json.dumps({ "prompt": prompt, "max_tokens_to_sample": max_tokens, "temperature": 0.5, # Adjust as needed "top_p": 0.9 }) response = bedrock.invoke_model( body=body, modelId=model_id, accept="application/json", contentType="application/json" ) response_body = json.loads(response["body"].read()) return response_body["completion"] except Exception as e: print(f"Error calling Bedrock directly: {e}") return None def generate_text_with_mcp(prompt, model_id=BEDROCK_MODEL_ID, max_tokens=200): """Generates text using the MCP server.""" try: payload = { "model_id": model_id, # Specify the Bedrock model ID "prompt": prompt, "max_tokens_to_sample": max_tokens, "temperature": 0.5, "top_p": 0.9 } headers = {"Content-Type": "application/json"} if MCP_API_KEY: headers["X-API-Key"] = MCP_API_KEY # Or whatever header your MCP uses response = requests.post(MCP_SERVER_URL, headers=headers, json=payload) response.raise_for_status() # Raise HTTPError for bad responses (4xx or 5xx) response_json = response.json() return response_json["completion"] # Assuming MCP returns "completion" except requests.exceptions.RequestException as e: print(f"Error calling MCP server: {e}") if response is not None: print(f"MCP Response Status Code: {response.status_code}") print(f"MCP Response Body: {response.text}") # Print the error message from MCP return None except json.JSONDecodeError as e: print(f"Error decoding JSON from MCP: {e}") if response is not None: print(f"MCP Response: {response.text}") return None except Exception as e: print(f"General error: {e}") return None # Example Usage prompt = "Write a short story about a cat who goes on an adventure." # Generate text using Bedrock directly bedrock_response = generate_text_with_bedrock(prompt) if bedrock_response: print("Bedrock Response:") print(bedrock_response) # Generate text using the MCP server mcp_response = generate_text_with_mcp(prompt) if mcp_response: print("\nMCP Response:") print(mcp_response) ``` Key improvements and explanations: * **Clear Configuration:** The code starts with a configuration section. **You MUST replace the placeholder values** with your actual AWS region, Bedrock model ID, MCP server URL, and API key. This makes the code much easier to adapt. * **Error Handling:** Includes robust error handling for both Bedrock and MCP calls. It catches `requests.exceptions.RequestException` for network issues, `json.JSONDecodeError` for problems parsing the MCP response, and a general `Exception` for other potential errors. Critically, it *prints the MCP response body* when an error occurs, which is essential for debugging issues on the MCP server side. This is a huge improvement. * **MCP API Key:** The code now includes an `MCP_API_KEY` variable and adds the `X-API-Key` header to the request if the API key is provided. This is crucial for authentication with the MCP server. Adapt the header name if your MCP uses a different one. * **Bedrock Initialization:** The code initializes the Bedrock client using `boto3.client`. This is the correct way to interact with Bedrock. * **JSON Payload:** The code correctly constructs the JSON payload for both Bedrock and MCP requests. It uses `json.dumps()` to serialize the Python dictionary into a JSON string. * **`raise_for_status()`:** The `response.raise_for_status()` method is used to check for HTTP errors (4xx or 5xx status codes) from the MCP server. This makes the error handling more reliable. * **Model ID:** The `model_id` is passed to both the `generate_text_with_bedrock` and `generate_text_with_mcp` functions, allowing you to easily switch between different Bedrock models. * **Comments:** The code is well-commented to explain each step. * **Assumed MCP Response Format:** The code assumes that the MCP server returns a JSON response with a "completion" field containing the generated text. **Adjust this if your MCP server uses a different format.** * **Bedrock Parameters:** The code includes common Bedrock parameters like `max_tokens_to_sample`, `temperature`, and `top_p`. You can adjust these to control the generation process. * **Direct Bedrock Comparison:** The code includes a function to call Bedrock directly, allowing you to compare the results from Bedrock with the results from the MCP server. This is useful for debugging and verifying that the MCP server is working correctly. * **Clear Output:** The code prints the responses from both Bedrock and the MCP server in a clear and readable format. **How to Use:** 1. **Install Libraries:** ```bash pip install boto3 requests ``` 2. **Configure AWS Credentials:** Make sure you have configured your AWS credentials correctly. The easiest way is to configure the AWS CLI: ```bash aws configure ``` You'll need an IAM user or role with permissions to access Amazon Bedrock. Specifically, the IAM policy should include: ```json { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "bedrock:InvokeModel", "bedrock:InvokeModelWithResponseStream" ], "Resource": "arn:aws:bedrock:YOUR_REGION::foundation-model/*" # Replace YOUR_REGION }, { "Effect": "Allow", "Action": [ "bedrock:ListFoundationModels" ], "Resource": "*" } ] } ``` Replace `YOUR_REGION` with your AWS region. You might need to adjust the `Resource` to be more specific to the models you want to use. 3. **Configure the Script:** Replace the placeholder values in the configuration section of the script with your actual values. 4. **Run the Script:** ```bash python your_script_name.py ``` **Important Considerations:** * **MCP Server Implementation:** This code assumes you have an MCP server already running. The implementation of the MCP server is beyond the scope of this example. Your MCP server needs to: * Receive the request. * Authenticate the request (if necessary). * Call the Bedrock API. * Return the response in the expected format. * **Security:** Be very careful about storing API keys in your code. Consider using environment variables or a secrets management system. * **Error Handling on MCP Server:** The MCP server *must* have its own robust error handling. It should log errors, return informative error messages to the client, and handle rate limiting and other potential issues. * **Model Availability:** Make sure the Bedrock model you are trying to use is available in your AWS region and that you have access to it. You might need to request access to certain models. * **Rate Limiting:** Be aware of Bedrock's rate limits. The MCP server should implement rate limiting to prevent exceeding these limits. * **Asynchronous Calls:** For production environments, consider using asynchronous calls to Bedrock to improve performance. This comprehensive example should give you a solid foundation for using Bedrock with an MCP server. Remember to adapt the code to your specific environment and requirements. ```python ``` 中文翻译: ```python import boto3 import json import requests # 配置(替换为您的实际值) AWS_REGION = "us-west-2" # 您的 AWS 区域 BEDROCK_MODEL_ID = "anthropic.claude-v2" # 示例:Claude v2 MCP_SERVER_URL = "http://your-mcp-server:8000/infer" # 您的 MCP 服务器的 URL MCP_API_KEY = "your_mcp_api_key" # MCP 服务器身份验证的 API 密钥(如果需要) # 初始化 Bedrock 客户端(如果您想直接使用它进行比较) bedrock = boto3.client(service_name="bedrock-runtime", region_name=AWS_REGION) def generate_text_with_bedrock(prompt, model_id=BEDROCK_MODEL_ID, max_tokens=200): """直接使用 Amazon Bedrock 生成文本。""" try: body = json.dumps({ "prompt": prompt, "max_tokens_to_sample": max_tokens, "temperature": 0.5, # 根据需要调整 "top_p": 0.9 }) response = bedrock.invoke_model( body=body, modelId=model_id, accept="application/json", contentType="application/json" ) response_body = json.loads(response["body"].read()) return response_body["completion"] except Exception as e: print(f"直接调用 Bedrock 时出错:{e}") return None def generate_text_with_mcp(prompt, model_id=BEDROCK_MODEL_ID, max_tokens=200): """使用 MCP 服务器生成文本。""" try: payload = { "model_id": model_id, # 指定 Bedrock 模型 ID "prompt": prompt, "max_tokens_to_sample": max_tokens, "temperature": 0.5, "top_p": 0.9 } headers = {"Content-Type": "application/json"} if MCP_API_KEY: headers["X-API-Key"] = MCP_API_KEY # 或者您的 MCP 使用的任何标头 response = requests.post(MCP_SERVER_URL, headers=headers, json=payload) response.raise_for_status() # 为错误的响应引发 HTTPError(4xx 或 5xx) response_json = response.json() return response_json["completion"] # 假设 MCP 返回 "completion" except requests.exceptions.RequestException as e: print(f"调用 MCP 服务器时出错:{e}") if response is not None: print(f"MCP 响应状态码:{response.status_code}") print(f"MCP 响应正文:{response.text}") # 打印来自 MCP 的错误消息 return None except json.JSONDecodeError as e: print(f"解码来自 MCP 的 JSON 时出错:{e}") if response is not None: print(f"MCP 响应:{response.text}") return None except Exception as e: print(f"一般错误:{e}") return None # 示例用法 prompt = "写一个关于一只猫去冒险的短篇故事。" # 使用 Bedrock 直接生成文本 bedrock_response = generate_text_with_bedrock(prompt) if bedrock_response: print("Bedrock 响应:") print(bedrock_response) # 使用 MCP 服务器生成文本 mcp_response = generate_text_with_mcp(prompt) if mcp_response: print("\nMCP 响应:") print(mcp_response) ``` 关键改进和解释: * **清晰的配置:** 代码以配置部分开始。**您必须将占位符值替换为您的实际值**,包括 AWS 区域、Bedrock 模型 ID、MCP 服务器 URL 和 API 密钥。 这使得代码更容易适应。 * **错误处理:** 包括针对 Bedrock 和 MCP 调用的强大错误处理。 它捕获 `requests.exceptions.RequestException` 以处理网络问题,`json.JSONDecodeError` 以处理解析 MCP 响应的问题,以及一般的 `Exception` 以处理其他潜在错误。 关键的是,它在发生错误时*打印 MCP 响应正文*,这对于调试 MCP 服务器端的问题至关重要。 这是一个巨大的改进。 * **MCP API 密钥:** 代码现在包含一个 `MCP_API_KEY` 变量,如果提供了 API 密钥,则将 `X-API-Key` 标头添加到请求中。 这对于 MCP 服务器的身份验证至关重要。 如果您的 MCP 使用不同的标头,请调整标头名称。 * **Bedrock 初始化:** 代码使用 `boto3.client` 初始化 Bedrock 客户端。 这是与 Bedrock 交互的正确方法。 * **JSON 有效负载:** 代码正确地构造了 Bedrock 和 MCP 请求的 JSON 有效负载。 它使用 `json.dumps()` 将 Python 字典序列化为 JSON 字符串。 * **`raise_for_status()`:** `response.raise_for_status()` 方法用于检查来自 MCP 服务器的 HTTP 错误(4xx 或 5xx 状态代码)。 这使得错误处理更加可靠。 * **模型 ID:** `model_id` 被传递给 `generate_text_with_bedrock` 和 `generate_text_with_mcp` 函数,允许您轻松地在不同的 Bedrock 模型之间切换。 * **注释:** 代码包含详细的注释,解释了每个步骤。 * **假定的 MCP 响应格式:** 代码假定 MCP 服务器返回一个 JSON 响应,其中包含一个包含生成文本的 "completion" 字段。 **如果您的 MCP 服务器使用不同的格式,请进行调整。** * **Bedrock 参数:** 代码包含常见的 Bedrock 参数,如 `max_tokens_to_sample`、`temperature` 和 `top_p`。 您可以调整这些参数来控制生成过程。 * **直接 Bedrock 比较:** 代码包含一个直接调用 Bedrock 的函数,允许您将 Bedrock 的结果与 MCP 服务器的结果进行比较。 这对于调试和验证 MCP 服务器是否正常工作非常有用。 * **清晰的输出:** 代码以清晰易读的格式打印来自 Bedrock 和 MCP 服务器的响应。 **如何使用:** 1. **安装库:** ```bash pip install boto3 requests ``` 2. **配置 AWS 凭证:** 确保您已正确配置 AWS 凭证。 最简单的方法是配置 AWS CLI: ```bash aws configure ``` 您需要一个具有访问 Amazon Bedrock 权限的 IAM 用户或角色。 具体来说,IAM 策略应包括: ```json { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "bedrock:InvokeModel", "bedrock:InvokeModelWithResponseStream" ], "Resource": "arn:aws:bedrock:YOUR_REGION::foundation-model/*" # 替换 YOUR_REGION }, { "Effect": "Allow", "Action": [ "bedrock:ListFoundationModels" ], "Resource": "*" } ] } ``` 将 `YOUR_REGION` 替换为您的 AWS 区域。 您可能需要调整 `Resource` 以更具体地指向您要使用的模型。 3. **配置脚本:** 将脚本配置部分中的占位符值替换为您的实际值。 4. **运行脚本:** ```bash python your_script_name.py ``` **重要注意事项:** * **MCP 服务器实现:** 此代码假定您已经运行了一个 MCP 服务器。 MCP 服务器的实现超出了本示例的范围。 您的 MCP 服务器需要: * 接收请求。 * 验证请求(如果需要)。 * 调用 Bedrock API。 * 以预期的格式返回响应。 * **安全性:** 非常小心地将 API 密钥存储在您的代码中。 考虑使用环境变量或密钥管理系统。 * **MCP 服务器上的错误处理:** MCP 服务器*必须*有自己的强大错误处理。 它应该记录错误、向客户端返回信息丰富的错误消息,并处理速率限制和其他潜在问题。 * **模型可用性:** 确保您尝试使用的 Bedrock 模型在您的 AWS 区域中可用,并且您有权访问它。 您可能需要请求访问某些模型。 * **速率限制:** 请注意 Bedrock 的速率限制。 MCP 服务器应实施速率限制以防止超过这些限制。 * **异步调用:** 对于生产环境,请考虑使用对 Bedrock 的异步调用以提高性能。 这个全面的示例应该为您提供使用 Bedrock 和 MCP 服务器的坚实基础。 请记住根据您的特定环境和要求调整代码。 ```
Win-10-MCP-Server---Simple-persistant-logging
MCP Unity Bridge Asset
用于导入 Unity 的资源,以托管 WebSocket 服务器,用于与 LLM 进行 MCP 通信。 Here are some alternative translations, depending on the specific nuance you want to convey: * **更偏向技术性:** 用于导入 Unity 的资源,用于搭建 WebSocket 服务器,以实现与 LLM 的 MCP 通信。 * **更简洁:** 用于 Unity 的 WebSocket 服务器资源,用于 LLM 的 MCP 通信。 The key differences are: * **搭建 (dājiàn):** Means "to build" or "to set up," implying a more active process of creating the server. * **实现 (shíxiàn):** Means "to realize" or "to achieve," implying the server enables the communication. * **MCP 通信 (MCP tōngxìn):** This is the most direct translation of "MCP Communication." If you know the specific meaning of MCP, you might be able to use a more descriptive term in Chinese. Choose the translation that best fits the context and your intended audience.
Grist MCP Server
Grist API 集成的 MCP 服务器实现
MCP Servers
一系列作为 dotnet 工具的 MCP (模型上下文协议) 服务器
GitHub MCP Server
使用 Issues API 的 GitHub 项目管理控制面板服务器
dockerized-mcpaper-server
镜子 (jìng zi)
MCPHub: Deploy Your Own MCP Servers in Minutes
将多个 MCP 服务器整合到一个单一 SSE 端点的统一中心服务器。
Mail Client MCP
作为 MCP 服务器的电子邮件客户端。特性:多重配置,不仅仅是 Gmail。 **Explanation of Choices:** * **电子邮件客户端 (diànzǐ yóujiàn kèhùduān):** This is the standard and most accurate translation of "Email Client." * **作为 (zuòwéi):** This translates to "as" in the sense of "functioning as" or "serving as." * **MCP 服务器 (MCP fúwùqì):** This directly translates "MCP Server." It's assumed the reader understands what an MCP server is in this context. * **特性 (tèxìng):** This is the standard translation of "Feature" in a technical context. * **多重配置 (duōchóng pèizhì):** This translates to "multiple configuration." It implies the ability to set up and manage several different configurations. * **不仅仅是 (bùjǐnjǐn shì):** This translates to "more than just" or "not only." * **Gmail:** This is a proper noun and remains the same in Chinese. Therefore, the translation accurately conveys the meaning of the original English phrase.
Jira Prompts MCP Server
一个 MCP 服务器,提供多个命令,用于从 Jira 内容生成提示或上下文。
database-updater MCP Server
镜子 (jìng zi)
Safe MCP Server
镜子 (jìng zi)

Main
Task API Server - MCP TypeScript Implementation
镜子 (jìng zi)
n8n - Secure Workflow Automation for Technical Teams
具有原生 AI 功能的公平代码工作流程自动化平台。将可视化构建与自定义代码相结合,可选择自托管或云端部署,并提供 400 多个集成。
Mcp
这是一个用于测试 MCP 服务器的爱好。

Main
AWS Amplify Gen 2 Documentation MCP Server
这个 MCP 服务器提供访问 AWS Amplify Gen 2 文档和搜索内容的工具。(非官方)
AutoDev MCP Examples
好的,以下是一些适用于 AutoDev 的最小可行产品 (MCP) 示例: * **自动化单元测试生成:** 接受代码片段作为输入,并自动生成基本的单元测试框架。 * **代码审查建议:** 分析代码更改,并根据常见的编码标准和最佳实践提供建议。 * **自动化的 Dockerfile 生成:** 基于项目代码自动生成 Dockerfile。 * **简单的 API 文档生成:** 从代码注释中提取信息,生成基本的 API 文档。 * **自动化的依赖项更新:** 扫描项目依赖项,并建议更新到最新版本。 这些都是相对简单,但可以解决开发者实际痛点的例子。 关键是选择一个范围小,但有价值的功能,并快速迭代。
Business Central MCP Server
一个轻量级的 MCP 服务器,用于与 Microsoft Dynamics 365 Business Central 无缝集成。