Azure服务总线MCP服务器
Azure服务总线的MCP(模型上下文协议)服务器。兼容任何MCP客户端——Claude Code、Claude Desktop、Cursor等。
公开用于发送消息、检查队列和订阅内容以及清除测试数据的工具。Claude Code附带的内置Azure MCP服务器仅支持读取操作(队列详细信息、消息计数等),无法发送消息——此项目填补了这一空白。
身份验证使用 DefaultAzureCredential,它会拾取一个活动 az login 会话自动。或者,可以通过以下方式提供连接串 AZURE_SERVICEBUS_CONNECTION_STRING 环境变量。任何秘密或连接字符串都不会作为工具参数传递。
需求
- 紫外线
- Azure命令行界面 与活跃
az login会话,或AZURE_SERVICEBUS_CONNECTION_STRING设置在您的环境中 - 您的身份必须具有 Azure服务总线数据所有者 或 Azure服务总线数据接收器/发送器 目标命名空间上的角色
安装
安装 uv 如果你没有:
macOS
brew install uv azure-cliLinux
curl -LsSf https://astral.sh/uv/install.sh | sh
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash # Debian/Ubuntu有关其他Linux发行版,请参阅 Azure CLI安装文档.
视窗
winget install --id=astral-sh.uv
winget install --id=Microsoft.AzureCLI配置
克劳德代码 用户:
claude mcp add --scope user azure-service-bus -- uvx servicebus-mcp对于其他MCP客户端,请在服务器配置中添加以下内容:
{
"mcpServers": {
"azure-service-bus": {
"command": "uvx",
"args": ["servicebus-mcp"]
}
}
}添加服务器后重新启动MCP客户端。如果您通过身份验证,则不需要环境变量 az login。可选环境变量:
AZURE_SUBSCRIPTION_ID--被使用servicebus_list_namespaces如果设置AZURE_SERVICEBUS_CONNECTION_STRING--使用而不是az login用于数据平面操作(发送、查看、清除)
从源代码安装
如果您更喜欢从本地克隆运行:
git clone https://github.com/BrianDeacon/servicebus-mcp
cd servicebus-mcp
uv sync
az login然后使用克隆的路径进行配置:
{
"mcpServers": {
"azure-service-bus": {
"command": "uv",
"args": ["run", "--directory", "/path/to/servicebus-mcp", "servicebus-mcp"]
}
}
}添加服务器后重新启动MCP客户端。
工具
命名空间参数接受短名称(my-namespace)或完全限定的主机名(my-namespace.servicebus.windows.net).这 .servicebus.windows.net 如果缺少后缀,则会自动附加后缀。
servicebus_list_namespaces
列出当前Azure订阅中的所有Service Bus命名空间。订阅将自动解析——首先从 AZURE_SUBSCRIPTION_ID 环境变量,然后从活动变量 az login 会议。
servicebus_list_queues
列出Service Bus命名空间中的所有队列。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
namespace | string | yes | 服务总线命名空间 |
返回队列名称的排序JSON数组。
servicebus_list_topics
列出Service Bus命名空间中的所有主题。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
namespace | string | yes | 服务总线命名空间 |
include_subscriptions | boolean | no | 如果为true,则返回主题名称的映射→ 订阅名称的排序数组(默认值为false) |
servicebus_send_message
向队列或主题发送一条消息。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
namespace | string | yes | 服务总线命名空间 |
queue | string | yes | 队列或主题名称 |
body | string | yes | 消息体(通常为JSON,按原样发送) |
session_id | string | no | 启用会话的队列需要 |
correlation_id | string | no | 要在消息上设置的相关ID |
application_properties | object | no | 自定义消息属性的键/值映射 |
scheduled_enqueue_time | string | no | ISO 8601日期时间用于将消息排队(例如。 2026-03-05T10:00:00Z).如果省略,则立即发送消息。 |
返回一条成功消息,确认消息已发送或安排。
servicebus_send_batch
一次性发送多条消息。可用于播种试验数据。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
namespace | string | yes | 服务总线命名空间 |
queue | string | yes | 队列或主题名称 |
messages | array | yes | 消息对象数组,每个对象都有 body (必填), session_id, correlation_id, application_properties,以及 scheduled_enqueue_time (全部可选) |
servicebus_peek_messages
无损地查看队列中的消息。消息未被锁定或使用。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
namespace | string | yes | 服务总线命名空间 |
queue | string | yes | 队列名称 |
max_count | integer | no | 要返回的最大消息数(默认值10,最大值100) |
session_id | string | no | 在特定会话中查看。如果在启用会话的队列中省略,则会接受、查看并立即释放下一个可用会话。会话ID包含在每条返回的消息中,因此您可以将其用于后续的目标呼叫。 |
返回消息体和元数据(序列号、排队时间、属性)。使用 servicebus_peek_messages_to_file 相反,如果消息正文可能很大。
servicebus_peek_messages_to_file
同 servicebus_peek_messages 而是将消息正文写入文件。在上下文中只返回元数据,避免了大的有效载荷填充上下文窗口。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
namespace | string | yes | 服务总线命名空间 |
queue | string | yes | 队列名称 |
output_file | string | yes | 将消息正文写入JSON的路径 |
max_count | integer | no | 要返回的最大消息数(默认值10,最大值100) |
session_id | string | no | 在特定会话中查看。如果在启用会话的队列中省略,则会接受、查看并立即释放下一个可用会话。 |
servicebus_peek_dlq
无损地查看队列死信队列中的消息。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
namespace | string | yes | 服务总线命名空间 |
queue | string | yes | 队列名称 |
max_count | integer | no | 要返回的最大消息数(默认值10,最大值100) |
返回消息正文、死信原因、错误描述和其他元数据。
servicebus_peek_dlq_to_file
同 servicebus_peek_dlq 而是将消息正文写入文件。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
namespace | string | yes | 服务总线命名空间 |
queue | string | yes | 队列名称 |
output_file | string | yes | 将消息正文写入JSON的路径 |
max_count | integer | no | 要返回的最大消息数(默认值10,最大值100) |
servicebus_purge_queue
从队列中删除所有消息。这是破坏性的,无法逆转。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
namespace | string | yes | 服务总线命名空间 |
queue | string | yes | 队列名称 |
max_messages | integer | no | 安全上限--如果运行总数超过此值(默认值1000),则停止并保持剩余消息不变 |
servicebus_purge_dlq
删除队列死信队列中的所有邮件。这是破坏性的,无法逆转。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
namespace | string | yes | 服务总线命名空间 |
queue | string | yes | 队列名称 |
max_messages | integer | no | 安全上限--如果运行总数超过此值(默认值1000),则停止并保持剩余消息不变 |
servicebus_requeue_dlq
将消息从队列的死信队列移回主队列。保留主体、会话ID、关联ID和应用程序属性。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
namespace | string | yes | 服务总线命名空间 |
queue | string | yes | 队列名称 |
max_messages | integer | no | 如果运行总数超过此值(默认值100),则停止 |
servicebus_peek_subscription_messages
无损地查看主题订阅中的消息。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
namespace | string | yes | 服务总线命名空间 |
topic | string | yes | 主题名称 |
subscription | string | yes | 订阅名称 |
max_count | integer | no | 要返回的最大消息数(默认值10,最大值100) |
session_id | string | no | 在特定会话中查看。如果在启用会话的订阅中省略,则会接受、查看并立即释放下一个可用会话。 |
servicebus_peek_subscription_messages_to_file
同 servicebus_peek_subscription_messages 而是将消息正文写入文件。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
namespace | string | yes | 服务总线命名空间 |
topic | string | yes | 主题名称 |
subscription | string | yes | 订阅名称 |
output_file | string | yes | 将消息正文写入JSON的路径 |
max_count | integer | no | 要返回的最大消息数(默认值10,最大值100) |
session_id | string | no | 在特定会话中查看。如果在启用会话的订阅中省略,则会接受、查看并立即释放下一个可用会话。 |
servicebus_peek_subscription_dlq
无损地查看主题订阅死信队列中的消息。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
namespace | string | yes | 服务总线命名空间 |
topic | string | yes | 主题名称 |
subscription | string | yes | 订阅名称 |
max_count | integer | no | 要返回的最大消息数(默认值10,最大值100) |
servicebus_peek_subscription_dlq_to_file
同 servicebus_peek_subscription_dlq 而是将消息正文写入文件。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
namespace | string | yes | 服务总线命名空间 |
topic | string | yes | 主题名称 |
subscription | string | yes | 订阅名称 |
output_file | string | yes | 将消息正文写入JSON的路径 |
max_count | integer | no | 要返回的最大消息数(默认值10,最大值100) |
servicebus_purge_subscription
删除主题订阅中的所有邮件。这是破坏性的,无法逆转。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
namespace | string | yes | 服务总线命名空间 |
topic | string | yes | 主题名称 |
subscription | string | yes | 订阅名称 |
max_messages | integer | no | 安全上限--如果运行总数超过此值(默认值1000),则停止并保持剩余消息不变 |
servicebus_purge_subscription_dlq
从主题订阅的死信队列中删除所有邮件。这是破坏性的,无法逆转。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
namespace | string | yes | 服务总线命名空间 |
topic | string | yes | 主题名称 |
subscription | string | yes | 订阅名称 |
max_messages | integer | no | 安全上限--如果运行总数超过此值(默认值1000),则停止并保持剩余消息不变 |
servicebus_requeue_subscription_dlq
将邮件从主题订阅的死信队列移回主题。保留主体、会话ID、关联ID和应用程序属性。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
namespace | string | yes | 服务总线命名空间 |
topic | string | yes | 主题名称 |
subscription | string | yes | 订阅名称 |
max_messages | integer | no | 如果运行总数超过此值(默认值100),则停止 |
安全
- 此服务器只接受
DefaultAzureCredential--连接字符串和SAS密钥永远不会作为参数传递,确保秘密不会出现在对话历史中。 purge_*和requeue_*工具强制执行max_messages安全帽,防止对大量积压的货物进行意外的批量操作。
