subscribe
Subscribe to Redis channels to receive real-time messages and updates, enabling event-driven communication and data monitoring.
Instructions
Subscribe to a Redis channel.
Args: channel: The Redis channel to subscribe to.
Returns: A success message or an error message.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| channel | Yes |
Implementation Reference
- src/tools/pub_sub.py:26-42 (handler)The handler function for the 'subscribe' MCP tool. It uses Redis pubsub to subscribe to the specified channel and returns a confirmation or error message. The @mcp.tool() decorator registers it as an MCP tool.@mcp.tool() async def subscribe(channel: str) -> str: """Subscribe to a Redis channel. Args: channel: The Redis channel to subscribe to. Returns: A success message or an error message. """ try: r = RedisConnectionManager.get_connection() pubsub = r.pubsub() pubsub.subscribe(channel) return f"Subscribed to channel '{channel}'." except RedisError as e: return f"Error subscribing to channel '{channel}': {str(e)}"
- src/tools/pub_sub.py:26-26 (registration)The @mcp.tool() decorator registers the subscribe function as an MCP tool.@mcp.tool()
- src/tools/pub_sub.py:28-35 (schema)The docstring provides the input schema (channel: str) and output description for the subscribe tool."""Subscribe to a Redis channel. Args: channel: The Redis channel to subscribe to. Returns: A success message or an error message. """