Skip to content

Commit 9c87ef7

Browse files
committed
Add list_exchange method
1 parent 273ae56 commit 9c87ef7

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/mcp_server_rabbitmq/handlers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ def handle_fanout(rabbitmq: RabbitMQConnection, exchange: str, message: str):
1717
def handle_list_queues(rabbitmq_admin: RabbitMQAdmin) -> List[str]:
1818
result = rabbitmq_admin.list_queues()
1919
return [queue['name'] for queue in result]
20+
21+
def handle_list_exchanges(rabbitmq_admin: RabbitMQAdmin) -> List[str]:
22+
result = rabbitmq_admin.list_exchanges()
23+
return [exchange['name'] for exchange in result]

src/mcp_server_rabbitmq/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ class Fanout(BaseModel):
1111

1212
class ListQueues(BaseModel):
1313
pass
14+
15+
class ListExchanges(BaseModel):
16+
pass

src/mcp_server_rabbitmq/server.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
Tool,
66
)
77
import ssl
8-
from .models import Enqueue, Fanout, ListQueues
8+
from .models import Enqueue, Fanout, ListQueues, ListExchanges
99
from .logger import Logger, LOG_LEVEL
1010
from .connection import RabbitMQConnection, validate_rabbitmq_name
11-
from .handlers import handle_enqueue, handle_fanout, handle_list_queues
11+
from .handlers import handle_enqueue, handle_fanout, handle_list_queues, handle_list_exchanges
1212
from .admin import RabbitMQAdmin
1313

1414

@@ -43,6 +43,11 @@ async def list_tools() -> list[Tool]:
4343
name="list_queues",
4444
description="""List all the queues in the broker""",
4545
inputSchema=ListQueues.model_json_schema(),
46+
),
47+
Tool(
48+
name="list_exchanges",
49+
description="""List all the exchanges in the broker""",
50+
inputSchema=ListExchanges.model_json_schema(),
4651
)
4752
]
4853

@@ -90,6 +95,14 @@ async def call_tool(
9095
logger.error(f"{e}")
9196
return [TextContent(type="text", text=str("failed"))]
9297
return [TextContent(type="text", text=str("succeeded"))]
98+
elif name == "list_exchanges":
99+
try:
100+
admin = RabbitMQAdmin(rabbitmq_host, api_port, username, password, use_tls)
101+
result = handle_list_exchanges(admin)
102+
return [TextContent(type="text", text=str(result))]
103+
except Exception as e:
104+
logger.error(f"{e}")
105+
return [TextContent(type="text", text=str("failed"))]
93106
raise ValueError(f"Tool not found: {name}")
94107

95108
options = server.create_initialization_options()

0 commit comments

Comments
 (0)