@@ -9,10 +9,13 @@ import (
99 "strings"
1010
1111 "github.com/sleuth-io/skills/internal/artifact"
12+ "github.com/sleuth-io/skills/internal/handlers/dirartifact"
1213 "github.com/sleuth-io/skills/internal/metadata"
1314 "github.com/sleuth-io/skills/internal/utils"
1415)
1516
17+ var mcpOps = dirartifact .NewOperations ("mcp-servers" , & artifact .TypeMCP )
18+
1619// MCPHandler handles MCP server artifact installation
1720type MCPHandler struct {
1821 metadata * metadata.Metadata
@@ -93,27 +96,13 @@ func (h *MCPHandler) Install(ctx context.Context, zipData []byte, targetBase str
9396 return fmt .Errorf ("validation failed: %w" , err )
9497 }
9598
96- // Determine installation path
97- installPath := filepath .Join (targetBase , h .GetInstallPath ())
98-
99- // Remove existing installation if present
100- if utils .IsDirectory (installPath ) {
101- if err := os .RemoveAll (installPath ); err != nil {
102- return fmt .Errorf ("failed to remove existing installation: %w" , err )
103- }
104- }
105-
106- // Create installation directory
107- if err := utils .EnsureDir (installPath ); err != nil {
108- return fmt .Errorf ("failed to create installation directory: %w" , err )
109- }
110-
111- // Extract zip to installation directory
112- if err := utils .ExtractZip (zipData , installPath ); err != nil {
113- return fmt .Errorf ("failed to extract zip: %w" , err )
99+ // Extract to mcp-servers directory
100+ if err := mcpOps .Install (ctx , zipData , targetBase , h .metadata .Artifact .Name ); err != nil {
101+ return err
114102 }
115103
116104 // Update .mcp.json to register the MCP server
105+ installPath := filepath .Join (targetBase , h .GetInstallPath ())
117106 if err := h .updateMCPConfig (targetBase , installPath ); err != nil {
118107 return fmt .Errorf ("failed to update MCP config: %w" , err )
119108 }
@@ -123,21 +112,13 @@ func (h *MCPHandler) Install(ctx context.Context, zipData []byte, targetBase str
123112
124113// Remove uninstalls the MCP server artifact
125114func (h * MCPHandler ) Remove (ctx context.Context , targetBase string ) error {
126- installPath := filepath .Join (targetBase , h .GetInstallPath ())
127-
128115 // Remove from .mcp.json first
129116 if err := h .removeFromMCPConfig (targetBase ); err != nil {
130117 return fmt .Errorf ("failed to remove from MCP config: %w" , err )
131118 }
132119
133120 // Remove installation directory
134- if utils .IsDirectory (installPath ) {
135- if err := os .RemoveAll (installPath ); err != nil {
136- return fmt .Errorf ("failed to remove MCP server: %w" , err )
137- }
138- }
139-
140- return nil
121+ return mcpOps .Remove (ctx , targetBase , h .metadata .Artifact .Name )
141122}
142123
143124// GetInstallPath returns the installation path relative to targetBase
@@ -315,3 +296,8 @@ func (h *MCPHandler) buildMCPServerConfig(installPath string) map[string]interfa
315296func (h * MCPHandler ) CanDetectInstalledState () bool {
316297 return true
317298}
299+
300+ // VerifyInstalled checks if the MCP server is properly installed
301+ func (h * MCPHandler ) VerifyInstalled (targetBase string ) (bool , string ) {
302+ return mcpOps .VerifyInstalled (targetBase , h .metadata .Artifact .Name , h .metadata .Artifact .Version )
303+ }
0 commit comments