发现优秀的 MCP 服务器

通过 MCP 服务器扩展您的代理能力,拥有 14,237 个能力。

全部14,237
MCP Chart Server

MCP Chart Server

A Model Context Protocol server that generates TradingView chart visualizations with real-time updates, enabling AI assistants to create and display financial charts through an integration with Chart-IMG API.

MCP server proxy

MCP server proxy

Okay, I understand. You want to extend the functionality of an MCP (Minecraft Protocol) server to also act as a worker in a distributed system. This means the server would not only handle Minecraft client connections but also perform tasks assigned to it by a central controller or manager. Here's a breakdown of the concepts, potential approaches, and considerations for achieving this, along with example code snippets (in Python, as it's commonly used for server-side scripting and automation): **1. Understanding the Core Concepts** * **MCP Server:** This is your existing Minecraft server (likely based on Spigot, Paper, Fabric, or a custom implementation). It handles player connections, game logic, and world management. * **Worker:** The extended MCP server will now also be a worker. A worker receives tasks from a central controller, executes those tasks, and reports the results back. * **Controller/Manager:** This is a separate application (or a module within the MCP server itself, though less ideal for scalability) that distributes tasks to the workers. It monitors worker status, assigns jobs, and collects results. * **Task:** A unit of work that the worker needs to perform. Examples: * Generating a specific region of the world. * Running a complex calculation related to game mechanics. * Performing automated actions (e.g., building structures). * Executing commands on the server. * **Communication:** The controller and workers need a way to communicate. Common options: * **Message Queue (e.g., RabbitMQ, Redis Pub/Sub):** A robust and scalable solution for asynchronous communication. The controller publishes tasks to a queue, and workers subscribe to the queue to receive tasks. * **RPC (Remote Procedure Call) (e.g., gRPC, Thrift):** Allows the controller to directly call functions on the worker. Suitable for more synchronous or request-response style interactions. * **HTTP/REST API:** The worker exposes an API that the controller can use to send tasks and retrieve results. Simple to implement but potentially less efficient than message queues or RPC. * **Database:** The controller writes tasks to a database, and the workers periodically check the database for new tasks. Less efficient for real-time task assignment. * **Serialization:** Tasks and results need to be serialized (converted to a format that can be transmitted over the network). Common options: * **JSON:** Human-readable and widely supported. * **Protocol Buffers (protobuf):** More efficient than JSON, especially for complex data structures. * **MessagePack:** Another efficient binary serialization format. **2. Architectural Approaches** * **Embedded Worker:** The worker functionality is integrated directly into the MCP server process. This is simpler to set up but can impact the server's performance if the worker tasks are resource-intensive. * **Separate Worker Process:** The worker runs in a separate process (potentially on the same machine or a different machine) and communicates with the MCP server via a plugin or API. This isolates the worker's workload and prevents it from directly affecting the server's performance. This is the generally preferred approach for production environments. **3. Implementation Steps (Example using Python and RabbitMQ)** This example outlines the steps using a separate worker process and RabbitMQ for communication. It assumes you have a basic understanding of RabbitMQ. **A. Controller (Python):** ```python import pika import json import time import uuid # RabbitMQ connection parameters RABBITMQ_HOST = 'localhost' RABBITMQ_QUEUE = 'mcp_tasks' def send_task(task_type, task_data): """Sends a task to the RabbitMQ queue.""" connection = pika.BlockingConnection(pika.ConnectionParameters(host=RABBITMQ_HOST)) channel = connection.channel() channel.queue_declare(queue=RABBITMQ_QUEUE, durable=True) # Ensure queue exists task_id = str(uuid.uuid4()) # Generate a unique task ID task = { 'task_id': task_id, 'task_type': task_type, 'task_data': task_data } channel.basic_publish( exchange='', routing_key=RABBITMQ_QUEUE, body=json.dumps(task).encode('utf-8'), properties=pika.BasicProperties( delivery_mode=2, # Make message persistent ) ) print(f" [x] Sent task: {task}") connection.close() return task_id if __name__ == '__main__': # Example usage: task_id = send_task( task_type='generate_region', task_data={'x': 0, 'z': 0, 'radius': 100} ) print(f"Task ID: {task_id}") task_id = send_task( task_type='execute_command', task_data={'command': 'say Hello from the controller!'} ) print(f"Task ID: {task_id}") ``` **B. Worker (Python):** ```python import pika import json import time import subprocess # For executing Minecraft commands import os # RabbitMQ connection parameters RABBITMQ_HOST = 'localhost' RABBITMQ_QUEUE = 'mcp_tasks' # Path to the Minecraft server's command execution script (e.g., a shell script) MINECRAFT_COMMAND_SCRIPT = '/path/to/minecraft_command.sh' # Replace with your actual path def execute_minecraft_command(command): """Executes a command on the Minecraft server using a script.""" try: # Ensure the script is executable os.chmod(MINECRAFT_COMMAND_SCRIPT, 0o755) # Make executable (if needed) result = subprocess.run([MINECRAFT_COMMAND_SCRIPT, command], capture_output=True, text=True, check=True) return result.stdout.strip() except subprocess.CalledProcessError as e: print(f"Error executing command: {e}") return f"Error: {e.stderr.strip()}" except FileNotFoundError: print(f"Error: Command execution script not found at {MINECRAFT_COMMAND_SCRIPT}") return "Error: Command execution script not found." def process_task(task): """Processes a task received from the queue.""" task_type = task['task_type'] task_data = task['task_data'] task_id = task['task_id'] print(f" [x] Received task: {task}") if task_type == 'generate_region': # Simulate region generation (replace with actual logic) x = task_data['x'] z = task_data['z'] radius = task_data['radius'] print(f"Generating region at ({x}, {z}) with radius {radius}...") time.sleep(5) # Simulate work result = f"Region generated successfully at ({x}, {z}) with radius {radius}." elif task_type == 'execute_command': command = task_data['command'] print(f"Executing command: {command}") result = execute_minecraft_command(command) # Execute the command else: result = f"Unknown task type: {task_type}" print(f" [x] Task {task_id} completed. Result: {result}") return result def callback(ch, method, properties, body): """Callback function for handling messages from the queue.""" try: task = json.loads(body.decode('utf-8')) result = process_task(task) # Acknowledge the message (important for RabbitMQ) ch.basic_ack(delivery_tag=method.delivery_tag) # Optionally, send the result back to the controller (using another queue or RPC) # (Implementation omitted for brevity) except Exception as e: print(f"Error processing task: {e}") ch.basic_nack(delivery_tag=method.delivery_tag, requeue=False) # Reject and don't requeue on error def start_worker(): """Starts the RabbitMQ worker.""" connection = pika.BlockingConnection(pika.ConnectionParameters(host=RABBITMQ_HOST)) channel = connection.channel() channel.queue_declare(queue=RABBITMQ_QUEUE, durable=True) # Ensure queue exists channel.basic_qos(prefetch_count=1) # Process one message at a time channel.basic_consume(queue=RABBITMQ_QUEUE, on_message_callback=callback) print(' [*] Waiting for messages. To exit press CTRL+C') channel.start_consuming() if __name__ == '__main__': start_worker() ``` **C. Minecraft Command Execution Script (Bash - `minecraft_command.sh`):** ```bash #!/bin/bash # This script executes a command on the Minecraft server using rcon-cli. # Make sure rcon-cli is installed and configured correctly. COMMAND="$1" # Replace with your rcon-cli command and credentials rcon-cli -H localhost -p 25575 -P your_rcon_password "$COMMAND" ``` **D. Minecraft Server Plugin (Spigot/Paper Example - Java):** This plugin is necessary if you want the worker to directly interact with the Minecraft server's API. If you're only executing commands, the `minecraft_command.sh` script might be sufficient. ```java import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.Bukkit; public class WorkerPlugin extends JavaPlugin { @Override public void onEnable() { getLogger().info("WorkerPlugin has been enabled!"); // Example: Register a command that can be triggered by the worker getCommand("workercommand").setExecutor((sender, command, label, args) -> { if (args.length > 0) { String message = String.join(" ", args); Bukkit.broadcastMessage("Worker Command: " + message); return true; } else { sender.sendMessage("Usage: /workercommand <message>"); return false; } }); } @Override public void onDisable() { getLogger().info("WorkerPlugin has been disabled!"); } } ``` **Explanation:** 1. **Controller:** * Connects to RabbitMQ. * Defines a `send_task` function to publish tasks to the `mcp_tasks` queue. * Each task is a JSON object containing a `task_id`, `task_type`, and `task_data`. * The `delivery_mode=2` property ensures that messages are persistent (survive RabbitMQ restarts). * Example usage demonstrates sending two types of tasks: `generate_region` and `execute_command`. 2. **Worker:** * Connects to RabbitMQ. * Declares the `mcp_tasks` queue. * Sets `prefetch_count=1` to process one message at a time. * The `callback` function is called whenever a new message arrives. * `process_task` handles the different task types. * For `generate_region`, it simulates region generation (replace with your actual world generation logic). * For `execute_command`, it calls the `execute_minecraft_command` function. * `execute_minecraft_command` uses `subprocess.run` to execute a shell script (`minecraft_command.sh`) that uses `rcon-cli` to send commands to the Minecraft server. * `ch.basic_ack` acknowledges the message, telling RabbitMQ that the task has been successfully processed. This is crucial to prevent messages from being re-queued indefinitely if the worker crashes. * Error handling is included to catch exceptions during task processing and reject the message (with `ch.basic_nack`) to prevent infinite loops. 3. **`minecraft_command.sh`:** * A simple Bash script that takes a command as an argument and uses `rcon-cli` to execute it on the Minecraft server. * **Important:** Replace `localhost`, `25575`, and `your_rcon_password` with your actual RCON settings. * Make sure `rcon-cli` is installed and configured correctly on the worker machine. 4. **`WorkerPlugin.java` (Spigot/Paper):** * A basic Spigot/Paper plugin that demonstrates how to register a command that can be triggered by the worker. * This is only necessary if you need the worker to directly interact with the Minecraft server's API (e.g., to modify blocks, spawn entities, etc.). * The example registers a command `/workercommand` that broadcasts a message to all players. **To Run the Example:** 1. **Install RabbitMQ:** Follow the instructions on the RabbitMQ website to install and configure RabbitMQ on your system. 2. **Install `rcon-cli`:** Install `rcon-cli` on the worker machine (if you're using the `execute_command` task). You might need to install it using your system's package manager (e.g., `apt-get install rcon-cli` on Debian/Ubuntu). 3. **Configure RCON:** Enable RCON on your Minecraft server and set a password. 4. **Update Paths:** In the `worker.py` script, update the `MINECRAFT_COMMAND_SCRIPT` variable to point to the correct path of your `minecraft_command.sh` script. Also, update the RCON credentials in `minecraft_command.sh`. 5. **Install Python Libraries:** Install the required Python libraries: `pip install pika`. 6. **Run the Controller:** `python controller.py` 7. **Run the Worker:** `python worker.py` 8. **Start your Minecraft server.** 9. **Test:** The controller will send tasks to the worker, and the worker will execute them. You should see the results in the worker's console and in the Minecraft server's console (or in-game if you're using the plugin). **Important Considerations:** * **Security:** Secure your RabbitMQ connection with proper authentication and authorization. Never expose your RCON password directly in your code. Use environment variables or a configuration file to store sensitive information. * **Error Handling:** Implement robust error handling in both the controller and the worker. Use try-except blocks to catch exceptions and handle them gracefully. Consider using a logging library to log errors and other important events. * **Scalability:** For high-volume task processing, consider using multiple worker instances. RabbitMQ will automatically distribute tasks to available workers. * **Task Prioritization:** If you have tasks with different priorities, you can use RabbitMQ's priority queues to ensure that high-priority tasks are processed first. * **Task Results:** The example doesn't include a mechanism for sending results back to the controller. You can implement this using another RabbitMQ queue, RPC, or a database. * **Minecraft Server API:** If you need to interact with the Minecraft server's API, you'll need to use a plugin (like the example `WorkerPlugin.java`). The plugin can expose functions that the worker can call (e.g., using a custom protocol or a REST API). * **Resource Management:** Monitor the resource usage of the worker processes to ensure that they don't overload the system. Consider using resource limits (e.g., CPU and memory limits) to prevent workers from consuming too many resources. * **Idempotency:** Design your tasks to be idempotent, meaning that they can be executed multiple times without causing unintended side effects. This is important in case a task fails and needs to be retried. * **Concurrency:** If your tasks are CPU-bound, consider using multiple threads or processes within the worker to improve performance. However, be careful to avoid race conditions and other concurrency issues. * **Configuration:** Use a configuration file to store settings such as RabbitMQ connection parameters, RCON credentials, and task-specific parameters. This makes it easier to manage and deploy your system. * **Monitoring:** Implement monitoring to track the status of the controller, workers, and RabbitMQ. Use metrics such as task queue length, task processing time, and error rates to identify potential problems. **Choosing a Communication Method:** * **RabbitMQ:** Best for asynchronous, reliable task processing. Good for scalability and fault tolerance. Requires setting up a RabbitMQ server. * **gRPC:** Good for synchronous or request-response style interactions. Provides strong typing and efficient serialization. Requires defining gRPC services and messages. * **HTTP/REST:** Simple to implement but potentially less efficient than RabbitMQ or gRPC. Suitable for simple tasks and when you don't need high performance. **Example Task Types:** * **`generate_region`:** Generates a specific region of the world. Task data: `x`, `z`, `radius`, `world`. * **`execute_command`:** Executes a command on the server. Task data: `command`. * **`build_structure`:** Builds a predefined structure at a specific location. Task data: `x`, `y`, `z`, `structure_name`. * **`calculate_stats`:** Calculates statistics about the server (e.g., number of players, number of entities, memory usage). Task data: None. This comprehensive guide should give you a solid foundation for extending your MCP server to work as a worker. Remember to adapt the code and architecture to your specific needs and requirements. Good luck!

MCP Server

MCP Server

A configurable server implementation that provides MCP (Model-Controller-Protocol) functionality, supporting both Node.js and Docker environments with automated setup and configuration options.

Discord MCP Server

Discord MCP Server

使大型语言模型能够通过 Discord 的 API 发送和读取消息,从而与 Discord 频道进行交互,同时侧重于维护用户控制和安全性。

openrpc-mpc-server

openrpc-mpc-server

一个模型上下文协议(MCP)服务器,通过 OpenRPC 提供 JSON-RPC 功能。

FRED Macroeconomic Data MCP Server

FRED Macroeconomic Data MCP Server

通过 Claude 和其他 LLM 客户端提供对联邦储备经济数据 (FRED) 的访问,使用户能够搜索、检索和可视化 GDP、就业和通货膨胀数据等经济指标。

Lens Protocol MCP Server

Lens Protocol MCP Server

Enables AI tools to interact with the Lens Protocol decentralized social network ecosystem. Supports fetching profiles, posts, followers, searching content, and accessing social graph data through standardized MCP interfaces.

Airtable MCP

Airtable MCP

使 AI 驱动的应用程序能够直接从您的 IDE 访问和操作 Airtable 数据,支持通过自然语言命令进行查询、创建、更新和删除记录等操作。

MCP Airtable Server

MCP Airtable Server

Provides tools for AI assistants to interact with Airtable databases, enabling CRUD operations on Airtable bases and tables.

Cloud Filestore API MCP Server

Cloud Filestore API MCP Server

An MCP server that enables interaction with Google Cloud Filestore API, allowing management of Filestore instances, backups, and shares through natural language commands.

octomind-mcp

octomind-mcp

MCP服务器与Octomind平台交互。 Octomind为端到端Web测试提供创建、运行和修复解决方案,请访问https://octomind.dev。

SSH MCP Server

SSH MCP Server

Enables AI assistants to securely execute shell commands on local machines through an SSH interface with session management, command execution, and sudo support.

Torrent Search MCP Server

Torrent Search MCP Server

A Python MCP server that allows programmatic interaction to find torrents programmatically on ThePirateBay, Nyaa and YggTorrent.

MCP Gateway

MCP Gateway

A secure bridge that allows Large Language Models (LLMs) to interact with corporate APIs and services in a controlled and contextualized manner.

MCP Relay Server

MCP Relay Server

这个服务器允许与 Discord 集成,从而可以使用提示和通知在 Claude 和 Discord 频道之间进行消息交换。

allabout-mcp

allabout-mcp

MCP 服务器及其他 (MCP fúwùqì jí qítā)

Remote MCP Server on Cloudflare

Remote MCP Server on Cloudflare

RootData MCP Server

RootData MCP Server

一个模型上下文协议服务器,允许像 Claude 这样的人工智能助手直接从 RootData 查询加密货币和区块链项目数据,包括项目信息、组织详情和搜索结果。

Twilio Routes MCP Server

Twilio Routes MCP Server

An MCP server that enables interaction with Twilio's Routes service through natural language, allowing users to manage SIP domains, trunks, and call routing configurations.

mcp-dice

mcp-dice

一个 MCP 服务器,使 LLM 能够掷骰子。 (Yī gè MCP fúwùqì, shǐ LLM nénggòu zhì shǎizi.)

weibo-mcp-server

weibo-mcp-server

一个获取前N微博热搜的 MCP 服务,支持 stdio 和 SSE 模式调用。 (Simplified Chinese)

Simple Weather MCP Server example from Quickstart

Simple Weather MCP Server example from Quickstart

镜子 (jìng zi)

Python MCP Server Template

Python MCP Server Template

Public MCP Server

Public MCP Server

A basic Model Context Protocol (MCP) server implementation that provides a foundation for MCP server development. The README doesn't specify particular functionality, suggesting it may be a template or starting point for building custom MCP servers.

Aptly MCP Server

Aptly MCP Server

Enables AI assistants to manage Debian package repositories through natural language using the Aptly package management tool. Supports repository creation, package operations, snapshot management, publishing, and mirror synchronization.

Database Query MCP

Database Query MCP

A versatile tool that enables querying and exporting data from multiple relational databases (MySQL, PostgreSQL, Oracle, SQLite, etc.) in read-only mode for data safety.

Unconventional-thinking MCP server

Unconventional-thinking MCP server

这是一个 MCP 服务器,它实现了一个非理性思维系统。它可以帮助产生非常规的解决方案:产生挑战传统智慧的非理性想法,并在不同的方向上创建思维分支。

Arcanna Input MCP Server

Arcanna Input MCP Server

MCP Analytics Middleware

MCP Analytics Middleware

一个轻量级的 TypeScript 中间件,用于 MCP SDK 服务器,可提供分析功能。它以最小的开销捕获请求指标、性能数据和使用模式。 具有实时监控、可配置的数据收集和详细的报告功能 - 所有这些都具有完整的类型安全性。

mcp-server-diceroll

mcp-server-diceroll

芙美惠的抄袭