Skip to content

Commit 8a845c0

Browse files
committed
add glama and also did minor refactoring
1 parent 6e310cc commit 8a845c0

File tree

5 files changed

+87
-77
lines changed

5 files changed

+87
-77
lines changed

glama.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$schema": "https://glama.ai/mcp/schemas/server.json",
3+
"maintainers": [
4+
"kenliao94"
5+
]
6+
}

src/mcp_server_rabbitmq/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@ def main():
1313
parser.add_argument("--username", type=str, help="Username for the connection")
1414
parser.add_argument("--password", type=str, help="Password for the connection")
1515
parser.add_argument("--use-tls", type=bool, help="Is the connection amqps")
16-
parser.add_argument("--log-level", type=str, help="Log level, supports DEBUG|INFO|WARNING|ERROR, default to WARNING")
1716

1817
args = parser.parse_args()
1918
asyncio.run(serve(
2019
rabbitmq_host=args.rabbitmq_host,
2120
port=args.port,
2221
username=args.username,
2322
password=args.password,
24-
use_tls=args.use_tls,
25-
log_level=args.log_level))
23+
use_tls=args.use_tls))
2624

2725

2826
if __name__ == "__main__":
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MCP_SERVER_VERSION = "2.0.0"

src/mcp_server_rabbitmq/server.py

Lines changed: 13 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@
66
)
77
import ssl
88
import logging
9-
from .models import (
10-
Enqueue,
11-
Fanout,
12-
ListQueues,
13-
ListExchanges,
14-
GetQueueInfo,
15-
DeleteQueue,
16-
PurgeQueue,
17-
DeleteExchange,
18-
GetExchangeInfo
19-
)
209
from .connection import RabbitMQConnection, validate_rabbitmq_name
2110
from .handlers import (
2211
handle_enqueue,
@@ -30,15 +19,14 @@
3019
handle_get_exchange_info
3120
)
3221
from .admin import RabbitMQAdmin
22+
from .tools import MCP_TOOLS
3323

34-
35-
async def serve(rabbitmq_host: str, port: int, username: str, password: str, use_tls: bool, log_level: str = "INFO", api_port: int = 15671) -> None:
24+
async def serve(rabbitmq_host: str, port: int, username: str, password: str, use_tls: bool, api_port: int = 15671) -> None:
3625
# Setup server
3726
server = Server("mcp-rabbitmq")
3827
# Setup logger
3928
logger = logging.getLogger("mcp-rabbitmq")
40-
logger.setLevel(log_level)
41-
# Configure logging with timestamp and file output
29+
logger.setLevel(logging.INFO)
4230
logging.basicConfig(
4331
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
4432
handlers=[
@@ -49,53 +37,7 @@ async def serve(rabbitmq_host: str, port: int, username: str, password: str, use
4937

5038
@server.list_tools()
5139
async def list_tools() -> list[Tool]:
52-
return [
53-
Tool(
54-
name="enqueue",
55-
description="""Enqueue a message to a queue hosted on RabbitMQ""",
56-
inputSchema=Enqueue.model_json_schema(),
57-
),
58-
Tool(
59-
name="fanout",
60-
description="""Publish a message to an exchange with fanout type""",
61-
inputSchema=Fanout.model_json_schema(),
62-
),
63-
Tool(
64-
name="list_queues",
65-
description="""List all the queues in the broker""",
66-
inputSchema=ListQueues.model_json_schema(),
67-
),
68-
Tool(
69-
name="list_exchanges",
70-
description="""List all the exchanges in the broker""",
71-
inputSchema=ListExchanges.model_json_schema(),
72-
),
73-
Tool(
74-
name="get_queue_info",
75-
description="""Get detailed information about a specific queue""",
76-
inputSchema=GetQueueInfo.model_json_schema(),
77-
),
78-
Tool(
79-
name="delete_queue",
80-
description="""Delete a specific queue""",
81-
inputSchema=DeleteQueue.model_json_schema(),
82-
),
83-
Tool(
84-
name="purge_queue",
85-
description="""Remove all messages from a specific queue""",
86-
inputSchema=PurgeQueue.model_json_schema(),
87-
),
88-
Tool(
89-
name="delete_exchange",
90-
description="""Delete a specific exchange""",
91-
inputSchema=DeleteExchange.model_json_schema(),
92-
),
93-
Tool(
94-
name="get_exchange_info",
95-
description="""Get detailed information about a specific exchange""",
96-
inputSchema=GetExchangeInfo.model_json_schema(),
97-
)
98-
]
40+
return MCP_TOOLS
9941

10042
@server.call_tool()
10143
async def call_tool(
@@ -106,17 +48,15 @@ async def call_tool(
10648
logger.debug("Executing enqueue tool")
10749
message = arguments["message"]
10850
queue = arguments["queue"]
109-
11051
validate_rabbitmq_name(queue, "Queue name")
111-
11252
try:
11353
# Setup RabbitMQ connection
11454
rabbitmq = RabbitMQConnection(rabbitmq_host, port, username, password, use_tls)
11555
handle_enqueue(rabbitmq, queue, message)
11656
return [TextContent(type="text", text=str("suceeded"))]
11757
except Exception as e:
11858
logger.error(f"{e}")
119-
return [TextContent(type="text", text=str("failed"))]
59+
return [TextContent(type="text", text=str(f"failed: {e}"))]
12060
elif name == "fanout":
12161
logger.debug("Executing fanout tool")
12262
message = arguments["message"]
@@ -131,24 +71,23 @@ async def call_tool(
13171
return [TextContent(type="text", text=str("suceeded"))]
13272
except Exception as e:
13373
logger.error(f"{e}")
134-
return [TextContent(type="text", text=str("failed"))]
74+
return [TextContent(type="text", text=str(f"failed: {e}"))]
13575
elif name == "list_queues":
13676
try:
13777
admin = RabbitMQAdmin(rabbitmq_host, api_port, username, password, use_tls)
13878
result = handle_list_queues(admin)
13979
return [TextContent(type="text", text=str(result))]
14080
except Exception as e:
14181
logger.error(f"{e}")
142-
return [TextContent(type="text", text=str("failed"))]
143-
return [TextContent(type="text", text=str("succeeded"))]
82+
return [TextContent(type="text", text=str(f"failed: {e}"))]
14483
elif name == "list_exchanges":
14584
try:
14685
admin = RabbitMQAdmin(rabbitmq_host, api_port, username, password, use_tls)
14786
result = handle_list_exchanges(admin)
14887
return [TextContent(type="text", text=str(result))]
14988
except Exception as e:
15089
logger.error(f"{e}")
151-
return [TextContent(type="text", text=str("failed"))]
90+
return [TextContent(type="text", text=str(f"failed: {e}"))]
15291
elif name == "get_queue_info":
15392
try:
15493
admin = RabbitMQAdmin(rabbitmq_host, api_port, username, password, use_tls)
@@ -159,7 +98,7 @@ async def call_tool(
15998
return [TextContent(type="text", text=str(result))]
16099
except Exception as e:
161100
logger.error(f"{e}")
162-
return [TextContent(type="text", text=str("failed"))]
101+
return [TextContent(type="text", text=str(f"failed: {e}"))]
163102
elif name == "delete_queue":
164103
try:
165104
admin = RabbitMQAdmin(rabbitmq_host, api_port, username, password, use_tls)
@@ -170,7 +109,7 @@ async def call_tool(
170109
return [TextContent(type="text", text=str("succeeded"))]
171110
except Exception as e:
172111
logger.error(f"{e}")
173-
return [TextContent(type="text", text=str("failed"))]
112+
return [TextContent(type="text", text=str(f"failed: {e}"))]
174113
elif name == "purge_queue":
175114
try:
176115
admin = RabbitMQAdmin(rabbitmq_host, api_port, username, password, use_tls)
@@ -181,7 +120,7 @@ async def call_tool(
181120
return [TextContent(type="text", text=str("succeeded"))]
182121
except Exception as e:
183122
logger.error(f"{e}")
184-
return [TextContent(type="text", text=str("failed"))]
123+
return [TextContent(type="text", text=str(f"failed: {e}"))]
185124
elif name == "delete_exchange":
186125
try:
187126
admin = RabbitMQAdmin(rabbitmq_host, api_port, username, password, use_tls)
@@ -192,7 +131,7 @@ async def call_tool(
192131
return [TextContent(type="text", text=str("succeeded"))]
193132
except Exception as e:
194133
logger.error(f"{e}")
195-
return [TextContent(type="text", text=str("failed"))]
134+
return [TextContent(type="text", text=str(f"failed: {e}"))]
196135
elif name == "get_exchange_info":
197136
try:
198137
admin = RabbitMQAdmin(rabbitmq_host, api_port, username, password, use_tls)
@@ -203,7 +142,7 @@ async def call_tool(
203142
return [TextContent(type="text", text=str(result))]
204143
except Exception as e:
205144
logger.error(f"{e}")
206-
return [TextContent(type="text", text=str("failed"))]
145+
return [TextContent(type="text", text=str(f"failed: {e}"))]
207146
raise ValueError(f"Tool not found: {name}")
208147

209148
options = server.create_initialization_options()

src/mcp_server_rabbitmq/tools.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from .models import (
2+
Enqueue,
3+
Fanout,
4+
ListQueues,
5+
ListExchanges,
6+
GetQueueInfo,
7+
DeleteQueue,
8+
PurgeQueue,
9+
DeleteExchange,
10+
GetExchangeInfo
11+
)
12+
from mcp.types import (
13+
Tool,
14+
)
15+
16+
MCP_TOOLS = [
17+
Tool(
18+
name="enqueue",
19+
description="""Enqueue a message to a queue hosted on RabbitMQ""",
20+
inputSchema=Enqueue.model_json_schema(),
21+
),
22+
Tool(
23+
name="fanout",
24+
description="""Publish a message to an exchange with fanout type""",
25+
inputSchema=Fanout.model_json_schema(),
26+
),
27+
Tool(
28+
name="list_queues",
29+
description="""List all the queues in the broker""",
30+
inputSchema=ListQueues.model_json_schema(),
31+
),
32+
Tool(
33+
name="list_exchanges",
34+
description="""List all the exchanges in the broker""",
35+
inputSchema=ListExchanges.model_json_schema(),
36+
),
37+
Tool(
38+
name="get_queue_info",
39+
description="""Get detailed information about a specific queue""",
40+
inputSchema=GetQueueInfo.model_json_schema(),
41+
),
42+
Tool(
43+
name="delete_queue",
44+
description="""Delete a specific queue""",
45+
inputSchema=DeleteQueue.model_json_schema(),
46+
),
47+
Tool(
48+
name="purge_queue",
49+
description="""Remove all messages from a specific queue""",
50+
inputSchema=PurgeQueue.model_json_schema(),
51+
),
52+
Tool(
53+
name="delete_exchange",
54+
description="""Delete a specific exchange""",
55+
inputSchema=DeleteExchange.model_json_schema(),
56+
),
57+
Tool(
58+
name="get_exchange_info",
59+
description="""Get detailed information about a specific exchange""",
60+
inputSchema=GetExchangeInfo.model_json_schema(),
61+
)
62+
]
63+
64+
MCP_TOOL_ROUTING = {
65+
66+
}

0 commit comments

Comments
 (0)