You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Introduced builder pattern for Kafka client consume and produce tools, enhancing modularity and maintainability.
- Migrated tool definitions for Kafka consumption and production to respective builders, improving code organization.
- Updated tool registration logic to utilize the new builders, ensuring a unified approach for managing Kafka operations.
- Added comprehensive tests for the new builders, ensuring robust functionality and adherence to requirements.
- Enhanced error handling and added comments for better clarity and understanding of the code structure.
toolDesc:="Consume messages from a Kafka topic.\n"+
100
+
"This tool allows you to read messages from Kafka topics, specifying various consumption parameters.\n\n"+
101
+
"Kafka Consumer Concepts:\n"+
102
+
"- Consumers read data from Kafka topics, which can be spread across multiple partitions\n"+
103
+
"- Consumer Groups enable multiple consumers to cooperatively process messages from the same topic\n"+
104
+
"- Offsets track the position of consumers in each partition, allowing resumption after failures\n"+
105
+
"- Partitions are independent ordered sequences of messages that enable parallel processing\n\n"+
106
+
"This tool provides a temporary consumer instance for diagnostic and testing purposes. "+
107
+
"It does not commit offsets back to Kafka unless the 'group' parameter is explicitly specified. Do not use this tool for Pulsar protocol operations. Use 'pulsar_client_consume' instead.\n\n"+
108
+
"Usage Examples:\n\n"+
109
+
"1. Basic consumption - Get 10 earliest messages from a topic:\n"+
110
+
" topic: \"my-topic\"\n"+
111
+
" max-messages: 10\n\n"+
112
+
"2. Consumer group - Join an existing consumer group and resume from committed offset:\n"+
113
+
" topic: \"my-topic\"\n"+
114
+
" offset: \"atstart\"\n"+
115
+
" max-messages: 20\n\n"+
116
+
"3. Consumer group - Join an existing consumer group and resume from committed offset:\n"+
117
+
" topic: \"my-topic\"\n"+
118
+
" group: \"my-consumer-group\"\n"+
119
+
" offset: \"atcommitted\"\n\n"+
120
+
"4. Time-limited consumption - Set a longer timeout for slow topics:\n"+
121
+
" topic: \"my-topic\"\n"+
122
+
" max-messages: 100\n"+
123
+
" timeout: 30\n\n"+
124
+
"This tool requires Kafka consumer permissions on the specified topic."
125
+
126
+
returnmcp.NewTool("kafka_client_consume",
127
+
mcp.WithDescription(toolDesc),
128
+
mcp.WithString("topic", mcp.Required(),
129
+
mcp.Description("The name of the Kafka topic to consume messages from. "+
130
+
"Must be an existing topic that the user has read permissions for. "+
131
+
"For partitioned topics, this will consume from all partitions unless a specific partition is specified."),
132
+
),
133
+
mcp.WithString("group",
134
+
mcp.Description("The consumer group ID to use for consumption. "+
135
+
"Optional. If provided, the consumer will join this consumer group and track offsets with Kafka. "+
136
+
"If not provided, a random group ID will be generated, and offsets won't be committed back to Kafka. "+
137
+
"Using a meaningful group ID is important when you want to resume consumption later or coordinate multiple consumers."),
138
+
),
139
+
mcp.WithString("offset",
140
+
mcp.Description("The offset position to start consuming from. "+
141
+
"Optional. Must be one of these values:\n"+
142
+
"- 'atstart': Begin from the earliest available message in the topic/partition\n"+
143
+
"- 'atend': Begin from the next message that arrives after the consumer starts\n"+
144
+
"- 'atcommitted': Begin from the last committed offset (only works with specified 'group')\n"+
145
+
"Default: 'atstart'"),
146
+
),
147
+
mcp.WithNumber("max-messages",
148
+
mcp.Description("Maximum number of messages to consume in this request. "+
149
+
"Optional. Limits the total number of messages returned, across all partitions if no specific partition is specified. "+
150
+
"Higher values retrieve more data but may increase response time and size. "+
151
+
"Default: 10"),
152
+
),
153
+
mcp.WithNumber("timeout",
154
+
mcp.Description("Maximum time in seconds to wait for messages. "+
155
+
"Optional. The consumer will wait up to this long to collect the requested number of messages. "+
156
+
"If fewer than 'max-messages' are available within this time, the available messages are returned. "+
157
+
"Longer timeouts are useful for low-volume topics or when consuming with 'atend'. "+
158
+
"Default: 10 seconds"),
159
+
),
160
+
)
161
+
}
162
+
163
+
// buildKafkaConsumeHandler builds the Kafka consume handler function
0 commit comments