Skip to content

Commit 785bc84

Browse files
authored
Fix registry data corruption and normalize server ID handling (#184)
* Fix Mozilla.ai registry entry for monday.com * Update Mozilla.ai registry validation to catch any future issues * registry: fix resolve/search issue for ID vs. Name * Align test expectations with fixes
1 parent c5c87f7 commit 785bc84

File tree

7 files changed

+203
-86
lines changed

7 files changed

+203
-86
lines changed

internal/provider/mcpm/registry.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ func (r *Registry) Search(
205205
// Returns the transformed result, and a flag to indicate if the transformation was successful.
206206
// If the server cannot be transformed due to unsupported or malformed runtime installations, false is returned.
207207
func (r *Registry) serverForID(pkgKey string) (packages.Server, bool) {
208+
// Normalize pkgKey to ensure consistency with map keys.
209+
pkgKey = filter.NormalizeString(pkgKey)
210+
208211
// Sanity check to ensure things work when a random ID gets supplied.
209212
sd, foundServer := r.mcpServers[pkgKey]
210213
if !foundServer {
@@ -243,7 +246,7 @@ func (r *Registry) serverForID(pkgKey string) (packages.Server, bool) {
243246
Description: sd.Description,
244247
DisplayName: sd.DisplayName,
245248
Homepage: sd.Homepage,
246-
ID: sd.Name,
249+
ID: pkgKey,
247250
Installations: installations,
248251
IsOfficial: sd.IsOfficial,
249252
License: sd.License,

internal/provider/mozilla_ai/data/registry.json

Lines changed: 129 additions & 60 deletions
Large diffs are not rendered by default.

internal/provider/mozilla_ai/model.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func (m *MCPRegistry) UnmarshalJSON(data []byte) error {
219219
return nil
220220
}
221221

222-
// UnmarshalJSON implements custom JSON unmarshaling for Server to normalize the Name field.
222+
// UnmarshalJSON implements custom JSON unmarshaling for Server to normalize the ID field.
223223
func (s *Server) UnmarshalJSON(data []byte) error {
224224
// Create a temporary struct with the same fields to avoid infinite recursion.
225225
type serverAlias Server
@@ -228,10 +228,10 @@ func (s *Server) UnmarshalJSON(data []byte) error {
228228
return err
229229
}
230230

231-
// Normalize the name field.
232-
alias.Name = filter.NormalizeString(alias.Name)
231+
// Normalize the ID field.
232+
alias.ID = filter.NormalizeString(alias.ID)
233233

234-
// Assign the normalized values to the receiver.
234+
// Assign the values to the receiver.
235235
*s = Server(alias)
236236
return nil
237237
}

internal/provider/mozilla_ai/model_test.go

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,34 @@ func TestServer_UnmarshalJSON(t *testing.T) {
1111
t.Parallel()
1212

1313
tests := []struct {
14-
name string
15-
input string
16-
expected string
14+
name string
15+
input string
16+
expectedID string
17+
expectedName string
1718
}{
1819
{
19-
name: "Normalize mixed case name",
20-
input: `{"name": "GitHub-Server", "description": "Test server"}`,
21-
expected: "github-server",
20+
name: "Normalize mixed case ID, keep original name",
21+
input: `{"id": "GitHub-Server", "name": "GitHub Server", "description": "Test server"}`,
22+
expectedID: "github-server",
23+
expectedName: "GitHub Server",
2224
},
2325
{
24-
name: "Normalize uppercase name",
25-
input: `{"name": "TIME_SERVER", "description": "Test server"}`,
26-
expected: "time_server",
26+
name: "Normalize uppercase ID, keep original name",
27+
input: `{"id": "TIME_SERVER", "name": "Time Server", "description": "Test server"}`,
28+
expectedID: "time_server",
29+
expectedName: "Time Server",
2730
},
2831
{
29-
name: "Normalize name with spaces",
30-
input: `{"name": " Mixed Case Server ", "description": "Test server"}`,
31-
expected: "mixed case server",
32+
name: "Normalize ID with spaces, keep original name",
33+
input: `{"id": " Mixed Case Server ", "name": "Mixed Case Server", "description": "Test server"}`,
34+
expectedID: "mixed case server",
35+
expectedName: "Mixed Case Server",
3236
},
3337
{
34-
name: "Already normalized name unchanged",
35-
input: `{"name": "simple-server", "description": "Test server"}`,
36-
expected: "simple-server",
38+
name: "Already normalized ID unchanged, keep original name",
39+
input: `{"id": "simple-server", "name": "Simple Server", "description": "Test server"}`,
40+
expectedID: "simple-server",
41+
expectedName: "Simple Server",
3742
},
3843
}
3944

@@ -44,7 +49,8 @@ func TestServer_UnmarshalJSON(t *testing.T) {
4449
var server Server
4550
err := json.Unmarshal([]byte(tc.input), &server)
4651
require.NoError(t, err)
47-
require.Equal(t, tc.expected, server.Name)
52+
require.Equal(t, tc.expectedID, server.ID)
53+
require.Equal(t, tc.expectedName, server.Name)
4854
require.Equal(t, "Test server", server.Description)
4955
})
5056
}

internal/provider/mozilla_ai/registry.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ func (r *Registry) Search(
204204
// serverForID attempts to convert the Server associated with the specified ID, into a packages.Server.
205205
// Returns the packages.Server and a boolean value indicating success.
206206
func (r *Registry) serverForID(pkgKey string) (packages.Server, bool) {
207+
// Normalize pkgKey to ensure consistency with map keys.
208+
pkgKey = filter.NormalizeString(pkgKey)
209+
207210
// Sanity check to ensure things work when a random ID gets supplied.
208211
sd, foundServer := r.mcpServers[pkgKey]
209212
if !foundServer {
@@ -238,7 +241,7 @@ func (r *Registry) serverForID(pkgKey string) (packages.Server, bool) {
238241

239242
return packages.Server{
240243
Source: RegistryName,
241-
ID: sd.Name,
244+
ID: sd.ID,
242245
Name: sd.Name,
243246
DisplayName: sd.DisplayName,
244247
Description: sd.Description,

internal/provider/mozilla_ai/registry_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ func TestRegistry_BuildPackageResult_ValidServer(t *testing.T) {
301301
// Test building package result
302302
pkg, ok := registry.serverForID(validServerKey)
303303
require.True(t, ok, "Should successfully build package result")
304-
require.Equal(t, validServerKey, pkg.Name)
304+
require.Equal(t, validServerKey, pkg.ID)
305305
require.Equal(t, RegistryName, pkg.Source)
306306
}
307307

@@ -684,9 +684,9 @@ func TestNewRegistry_NormalizationIntegration(t *testing.T) {
684684
require.NoError(t, err)
685685
require.Len(t, results, 1)
686686

687-
// Verify server name (and ID) was normalized.
687+
// Verify server ID was normalized, name kept original.
688688
result := results[0]
689-
require.Equal(t, "github-server", result.Name)
689+
require.Equal(t, "GitHub-Server", result.Name)
690690
require.Equal(t, "github-server", result.ID)
691691

692692
// Verify tool names were normalized.

tools/validate/registry.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package main
55

66
import (
7+
"encoding/json"
78
"fmt"
89
"os"
910

@@ -12,7 +13,10 @@ import (
1213

1314
func main() {
1415
if len(os.Args) != 3 {
15-
fmt.Fprintf(os.Stderr, "Usage: go run -tags=validate_registry ./tools/validate/registry.go <schema.json> <data.json>\n")
16+
fmt.Fprintf(
17+
os.Stderr,
18+
"Usage: go run -tags=validate_registry ./tools/validate/registry.go <schema.json> <data.json>\n",
19+
)
1620
os.Exit(1)
1721
}
1822

@@ -50,5 +54,37 @@ func main() {
5054
os.Exit(1)
5155
}
5256

57+
// Additional business rule validation: check that map keys match server IDs
58+
var registry map[string]any
59+
err = json.Unmarshal(absDataPath, &registry)
60+
if err != nil {
61+
fmt.Fprintf(os.Stderr, "Error parsing registry data for business rule validation: %v\n", err)
62+
os.Exit(1)
63+
}
64+
65+
for key, value := range registry {
66+
server, ok := value.(map[string]any)
67+
if !ok {
68+
continue
69+
}
70+
71+
id, exists := server["id"].(string)
72+
// This should never be able to happen as we've validated the schema, but no harm in the sanity check.
73+
if !exists {
74+
fmt.Fprintf(os.Stderr, "❌ Server at key '%s' missing required ID field\n", key)
75+
os.Exit(1)
76+
}
77+
78+
if id != key {
79+
fmt.Fprintf(
80+
os.Stderr,
81+
"❌ Registry inconsistency: registry key '%s' does not match server ID '%s'\n",
82+
key,
83+
id,
84+
)
85+
os.Exit(1)
86+
}
87+
}
88+
5389
fmt.Println("✅ Mozilla AI registry validation succeeded")
5490
}

0 commit comments

Comments
 (0)