role.go•1.78 kB
package tools
import (
"context"
"github.com/thunderboltsid/mcp-nutanix/internal/client"
"github.com/thunderboltsid/mcp-nutanix/pkg/resources"
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
)
// Role defines the Role tool
func RoleList() mcp.Tool {
return mcp.NewTool("role_list",
mcp.WithDescription("List role resources"),
mcp.WithString("filter",
mcp.Description("Optional text filter (interpreted by LLM)"),
),
)
}
// RoleListHandler implements the handler for the Role list tool
func RoleListHandler() server.ToolHandlerFunc {
return CreateListToolHandler(
resources.ResourceTypeRole,
// Define the ListResourceFunc implementation
func(ctx context.Context, client *client.NutanixClient, filter string) (interface{}, error) {
// Use ListAll function to get all resources
return client.V3().ListAllRole(ctx, "")
},
)
}
// RoleCount defines the Role count tool
func RoleCount() mcp.Tool {
return mcp.NewTool("role_count",
mcp.WithDescription("Count role resources"),
mcp.WithString("filter",
mcp.Description("Optional text filter (interpreted by LLM)"),
),
)
}
// RoleCountHandler implements the handler for the Role count tool
func RoleCountHandler() server.ToolHandlerFunc {
return CreateCountToolHandler(
resources.ResourceTypeRole,
// Define the ListResourceFunc implementation
func(ctx context.Context, client *client.NutanixClient, filter string) (interface{}, error) {
// Use ListAll function to get all resources
resp, err := client.V3().ListAllRole(ctx, "")
if err != nil {
return nil, err
}
res := map[string]interface{}{
"resource_type": "Role",
"count": len(resp.Entities),
"metadata": resp.Metadata,
}
return res, nil
},
)
}