Skip to content

Commit 8d8ed9c

Browse files
authored
fix: help configure partitioned flag for pulsar topics stats tool (#32)
1 parent f7390a0 commit 8d8ed9c

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

pkg/mcp/pulsar_admin_topic_tools.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func PulsarAdminAddTopicTools(s *server.MCPServer, readOnly bool, features []str
110110
),
111111
mcp.WithBoolean("partitioned",
112112
mcp.Description("Get stats for a partitioned topic. Optional for 'stats' operation. "+
113-
"When true, returns aggregated statistics for the partitioned topic."),
113+
"It has to be true if the topic is partitioned. Leave it empty or false for non-partitioned topic."),
114114
),
115115
mcp.WithBoolean("per-partition",
116116
mcp.Description("Include per-partition stats. Optional for 'stats' operation. "+
@@ -307,6 +307,25 @@ func handleTopicStats(admin cmdutils.Client, request mcp.CallToolRequest) (*mcp.
307307
return mcp.NewToolResultError(fmt.Sprintf("Invalid topic name '%s': %v", topic, err)), nil
308308
}
309309

310+
namespaceName, err := utils.GetNamespaceName(topicName.GetTenant() + "/" + topicName.GetNamespace())
311+
if err != nil {
312+
return mcp.NewToolResultError(fmt.Sprintf("Invalid namespace name '%s': %v", namespaceName, err)), nil
313+
}
314+
315+
// List topics
316+
partitionedTopics, nonPartitionedTopics, err := admin.Topics().List(*namespaceName)
317+
if err != nil {
318+
return mcp.NewToolResultError(fmt.Sprintf("Failed to list topics in namespace '%s': %v",
319+
namespaceName, err)), nil
320+
}
321+
322+
if slices.Contains(partitionedTopics, topicName.String()) {
323+
partitioned = true
324+
}
325+
if slices.Contains(nonPartitionedTopics, topicName.String()) {
326+
partitioned = false
327+
}
328+
310329
var jsonBytes []byte
311330
if partitioned {
312331
// Get partitioned topic stats

0 commit comments

Comments
 (0)