Skip to content

Commit ef77aba

Browse files
authored
fix: Pulsar functions admin client retrieval in handler to use session context (#53)
Updated the PulsarAdminFunctionsToolBuilder to obtain the Pulsar client from the session context instead of a static configuration. This change enhances error handling by checking for a valid session and returning appropriate error messages if the session is not found or if client retrieval fails.
1 parent 122fd01 commit ef77aba

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pkg/mcp/builders/pulsar/functions.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ import (
2222
"encoding/json"
2323
"fmt"
2424

25-
"github.com/apache/pulsar-client-go/pulsaradmin/pkg/admin/config"
2625
"github.com/apache/pulsar-client-go/pulsaradmin/pkg/utils"
2726
"github.com/mark3labs/mcp-go/mcp"
2827
"github.com/mark3labs/mcp-go/server"
2928
"github.com/streamnative/pulsarctl/pkg/cmdutils"
3029
"github.com/streamnative/streamnative-mcp-server/pkg/mcp/builders"
30+
mcpCtx "github.com/streamnative/streamnative-mcp-server/pkg/mcp/internal/context"
3131
)
3232

3333
// PulsarAdminFunctionsToolBuilder implements the ToolBuilder interface for Pulsar admin functions operations
@@ -211,8 +211,16 @@ func (b *PulsarAdminFunctionsToolBuilder) buildPulsarAdminFunctionsTool() mcp.To
211211
// Migrated from the original handler logic
212212
func (b *PulsarAdminFunctionsToolBuilder) buildPulsarAdminFunctionsHandler(readOnly bool) func(context.Context, mcp.CallToolRequest) (*mcp.CallToolResult, error) {
213213
return func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
214-
// Create Pulsar client with API version V3
215-
client := cmdutils.NewPulsarClientWithAPIVersion(config.V3)
214+
// Get Pulsar session from context
215+
session := mcpCtx.GetPulsarSession(ctx)
216+
if session == nil {
217+
return mcp.NewToolResultError("Pulsar session not found in context"), nil
218+
}
219+
220+
client, err := session.GetAdminV3Client()
221+
if err != nil {
222+
return mcp.NewToolResultError(fmt.Sprintf("Failed to get Pulsar client: %v", err)), nil
223+
}
216224

217225
// Extract and validate operation parameter
218226
operation, err := request.RequireString("operation")

0 commit comments

Comments
 (0)