Skip to content

Commit 5a6e192

Browse files
authored
Add blocklist for community registry MCP servers
Add blocklist for community registry MCP servers
2 parents 64e5b0f + fe02061 commit 5a6e192

File tree

3 files changed

+216
-32
lines changed

3 files changed

+216
-32
lines changed

cmd/docker-mcp/commands/catalog_next.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func createCatalogNextCommand() *cobra.Command {
4040
FromLegacyCatalog string
4141
FromCommunityRegistry string
4242
Servers []string
43+
Exclude []string
4344
IncludePyPI bool
4445
}
4546

@@ -91,13 +92,17 @@ When using --server without --from-profile, --from-legacy-catalog, or --from-com
9192
return fmt.Errorf("--include-pypi can only be used when creating a catalog from a community registry")
9293
}
9394

95+
if len(opts.Exclude) > 0 && opts.FromCommunityRegistry == "" {
96+
return fmt.Errorf("--exclude can only be used when creating a catalog from a community registry")
97+
}
98+
9499
dao, err := db.New()
95100
if err != nil {
96101
return err
97102
}
98103
registryClient := registryapi.NewClient()
99104
ociService := oci.NewService()
100-
return catalognext.Create(cmd.Context(), dao, registryClient, ociService, args[0], opts.Servers, opts.FromWorkingSet, opts.FromLegacyCatalog, opts.FromCommunityRegistry, opts.Title, opts.IncludePyPI)
105+
return catalognext.Create(cmd.Context(), dao, registryClient, ociService, args[0], opts.Servers, opts.FromWorkingSet, opts.FromLegacyCatalog, opts.FromCommunityRegistry, opts.Title, opts.IncludePyPI, opts.Exclude)
101106
},
102107
}
103108

@@ -108,6 +113,7 @@ When using --server without --from-profile, --from-legacy-catalog, or --from-com
108113
flags.StringVar(&opts.FromCommunityRegistry, "from-community-registry", "", "Community registry hostname to fetch servers from (e.g. registry.modelcontextprotocol.io)")
109114
flags.StringVar(&opts.Title, "title", "", "Title of the catalog")
110115

116+
flags.StringArrayVar(&opts.Exclude, "exclude", []string{}, "Server name to exclude from the catalog (can be specified multiple times, only valid with --from-community-registry)")
111117
flags.BoolVar(&opts.IncludePyPI, "include-pypi", false, "Include PyPI servers when creating a catalog from a community registry")
112118
cmd.Flags().MarkHidden("include-pypi") //nolint:errcheck
113119

pkg/catalog_next/create.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"github.com/docker/mcp-gateway/pkg/workingset"
2222
)
2323

24-
func Create(ctx context.Context, dao db.DAO, registryClient registryapi.Client, ociService oci.Service, refStr string, servers []string, workingSetID string, legacyCatalogURL string, communityRegistryRef string, title string, includePyPI bool) error {
24+
func Create(ctx context.Context, dao db.DAO, registryClient registryapi.Client, ociService oci.Service, refStr string, servers []string, workingSetID string, legacyCatalogURL string, communityRegistryRef string, title string, includePyPI bool, excludeServers []string) error {
2525
telemetry.Init()
2626
start := time.Now()
2727
var success bool
@@ -49,7 +49,7 @@ func Create(ctx context.Context, dao db.DAO, registryClient registryapi.Client,
4949
return fmt.Errorf("failed to create catalog from legacy catalog: %w", err)
5050
}
5151
} else if communityRegistryRef != "" {
52-
catalog, err = createCatalogFromCommunityRegistry(ctx, registryClient, communityRegistryRef, includePyPI)
52+
catalog, err = createCatalogFromCommunityRegistry(ctx, registryClient, communityRegistryRef, includePyPI, excludeServers)
5353
if err != nil {
5454
return fmt.Errorf("failed to create catalog from community registry: %w", err)
5555
}
@@ -209,7 +209,7 @@ type communityRegistryResult struct {
209209
skippedByType map[string]int
210210
}
211211

212-
func createCatalogFromCommunityRegistry(ctx context.Context, registryClient registryapi.Client, registryRef string, includePyPI bool) (Catalog, error) {
212+
func createCatalogFromCommunityRegistry(ctx context.Context, registryClient registryapi.Client, registryRef string, includePyPI bool, excludeServers []string) (Catalog, error) {
213213
baseURL := "https://" + registryRef
214214
servers, err := registryClient.ListServers(ctx, baseURL, "")
215215
if err != nil {
@@ -221,6 +221,11 @@ func createCatalogFromCommunityRegistry(ctx context.Context, registryClient regi
221221
var ociCount, remoteCount, pypiCount int
222222

223223
for _, serverResp := range servers {
224+
if slices.Contains(excludeServers, serverResp.Server.Name) {
225+
skippedByType["excluded"]++
226+
continue
227+
}
228+
224229
catalogServer, transformSource, err := legacycatalog.TransformToDocker(ctx, serverResp.Server, legacycatalog.WithAllowPyPI(includePyPI), legacycatalog.WithPyPIResolver(legacycatalog.DefaultPyPIVersionResolver()))
225230
if err != nil {
226231
if !errors.Is(err, legacycatalog.ErrIncompatibleServer) {

0 commit comments

Comments
 (0)