publish
Send messages to Redis channels for real-time communication and data distribution in applications.
Instructions
Publish a message to a Redis channel.
Args: channel: The Redis channel to publish to. message: The message to send.
Returns: A success message or an error message.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| channel | Yes | ||
| message | Yes |
Implementation Reference
- src/tools/pub_sub.py:7-23 (handler)The core handler function for the 'publish' MCP tool. It is decorated with @mcp.tool() which registers it as an MCP tool. The function publishes a message to a specified Redis channel and returns a success or error message.@mcp.tool() async def publish(channel: str, message: str) -> str: """Publish a message to a Redis channel. Args: channel: The Redis channel to publish to. message: The message to send. Returns: A success message or an error message. """ try: r = RedisConnectionManager.get_connection() r.publish(channel, message) return f"Message published to channel '{channel}'." except RedisError as e: return f"Error publishing message to channel '{channel}': {str(e)}"
- src/tools/pub_sub.py:7-7 (registration)The @mcp.tool() decorator registers the publish function as an MCP tool.@mcp.tool()