|
5 | 5 | Tool,
|
6 | 6 | )
|
7 | 7 | import ssl
|
8 |
| -from .models import Enqueue, Fanout, ListQueues, ListExchanges, GetQueueInfo, DeleteQueue |
| 8 | +from .models import ( |
| 9 | + Enqueue, |
| 10 | + Fanout, |
| 11 | + ListQueues, |
| 12 | + ListExchanges, |
| 13 | + GetQueueInfo, |
| 14 | + DeleteQueue, |
| 15 | + PurgeQueue, |
| 16 | + DeleteExchange, |
| 17 | + GetExchangeInfo |
| 18 | +) |
9 | 19 | from .logger import Logger, LOG_LEVEL
|
10 | 20 | from .connection import RabbitMQConnection, validate_rabbitmq_name
|
11 | 21 | from .handlers import (
|
|
14 | 24 | handle_list_queues,
|
15 | 25 | handle_list_exchanges,
|
16 | 26 | handle_get_queue_info,
|
17 |
| - handle_delete_queue |
| 27 | + handle_delete_queue, |
| 28 | + handle_purge_queue, |
| 29 | + handle_delete_exchange, |
| 30 | + handle_get_exchange_info |
18 | 31 | )
|
19 | 32 | from .admin import RabbitMQAdmin
|
20 | 33 |
|
@@ -65,6 +78,21 @@ async def list_tools() -> list[Tool]:
|
65 | 78 | name="delete_queue",
|
66 | 79 | description="""Delete a specific queue""",
|
67 | 80 | inputSchema=DeleteQueue.model_json_schema(),
|
| 81 | + ), |
| 82 | + Tool( |
| 83 | + name="purge_queue", |
| 84 | + description="""Remove all messages from a specific queue""", |
| 85 | + inputSchema=PurgeQueue.model_json_schema(), |
| 86 | + ), |
| 87 | + Tool( |
| 88 | + name="delete_exchange", |
| 89 | + description="""Delete a specific exchange""", |
| 90 | + inputSchema=DeleteExchange.model_json_schema(), |
| 91 | + ), |
| 92 | + Tool( |
| 93 | + name="get_exchange_info", |
| 94 | + description="""Get detailed information about a specific exchange""", |
| 95 | + inputSchema=GetExchangeInfo.model_json_schema(), |
68 | 96 | )
|
69 | 97 | ]
|
70 | 98 |
|
@@ -142,6 +170,39 @@ async def call_tool(
|
142 | 170 | except Exception as e:
|
143 | 171 | logger.error(f"{e}")
|
144 | 172 | return [TextContent(type="text", text=str("failed"))]
|
| 173 | + elif name == "purge_queue": |
| 174 | + try: |
| 175 | + admin = RabbitMQAdmin(rabbitmq_host, api_port, username, password, use_tls) |
| 176 | + queue = arguments["queue"] |
| 177 | + vhost = arguments.get("vhost", "/") |
| 178 | + validate_rabbitmq_name(queue, "Queue name") |
| 179 | + handle_purge_queue(admin, queue, vhost) |
| 180 | + return [TextContent(type="text", text=str("succeeded"))] |
| 181 | + except Exception as e: |
| 182 | + logger.error(f"{e}") |
| 183 | + return [TextContent(type="text", text=str("failed"))] |
| 184 | + elif name == "delete_exchange": |
| 185 | + try: |
| 186 | + admin = RabbitMQAdmin(rabbitmq_host, api_port, username, password, use_tls) |
| 187 | + exchange = arguments["exchange"] |
| 188 | + vhost = arguments.get("vhost", "/") |
| 189 | + validate_rabbitmq_name(exchange, "Exchange name") |
| 190 | + handle_delete_exchange(admin, exchange, vhost) |
| 191 | + return [TextContent(type="text", text=str("succeeded"))] |
| 192 | + except Exception as e: |
| 193 | + logger.error(f"{e}") |
| 194 | + return [TextContent(type="text", text=str("failed"))] |
| 195 | + elif name == "get_exchange_info": |
| 196 | + try: |
| 197 | + admin = RabbitMQAdmin(rabbitmq_host, api_port, username, password, use_tls) |
| 198 | + exchange = arguments["exchange"] |
| 199 | + vhost = arguments.get("vhost", "/") |
| 200 | + validate_rabbitmq_name(exchange, "Exchange name") |
| 201 | + result = handle_get_exchange_info(admin, exchange, vhost) |
| 202 | + return [TextContent(type="text", text=str(result))] |
| 203 | + except Exception as e: |
| 204 | + logger.error(f"{e}") |
| 205 | + return [TextContent(type="text", text=str("failed"))] |
145 | 206 | raise ValueError(f"Tool not found: {name}")
|
146 | 207 |
|
147 | 208 | options = server.create_initialization_options()
|
|
0 commit comments