Skip to content

Commit f4d2258

Browse files
authored
Fix CI check for non-mcp namespaces. (#72)
1 parent d07e8d8 commit f4d2258

File tree

2 files changed

+50
-26
lines changed

2 files changed

+50
-26
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
while IFS= read -r file; do
3535
dir=$(dirname "$file")
3636
name=$(basename "$dir")
37-
task build -- --tools $name
37+
task build -- --tools --pull-community $name
3838
echo "--------------------------------"
3939
task catalog -- $name
4040
echo "--------------------------------"

cmd/build/main.go

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717

1818
func main() {
1919
listTools := flag.Bool("tools", false, "List the tools")
20+
pullCommunity := flag.Bool("pull-community", false, "Pull images that are not in the mcp/ namespace")
2021

2122
flag.Parse()
2223
args := flag.Args()
@@ -26,12 +27,12 @@ func main() {
2627
os.Exit(1)
2728
}
2829

29-
if err := run(context.Background(), args[0], *listTools); err != nil {
30+
if err := run(context.Background(), args[0], *listTools, *pullCommunity); err != nil {
3031
log.Fatal(err)
3132
}
3233
}
3334

34-
func run(ctx context.Context, name string, listTools bool) error {
35+
func run(ctx context.Context, name string, listTools bool, pullCommunity bool) error {
3536
server, err := servers.Read(filepath.Join("servers", name, "server.yaml"))
3637
if err != nil {
3738
if os.IsNotExist(err) {
@@ -40,10 +41,47 @@ func run(ctx context.Context, name string, listTools bool) error {
4041
return err
4142
}
4243

43-
if !strings.HasPrefix(server.Image, "mcp/") {
44-
return fmt.Errorf("server is not docker built (ie, in the 'mcp/' namespace), you must either build it yourself or pull it with `docker pull %s` if you want to use it", server.Image)
44+
isMcpImage := strings.HasPrefix(server.Image, "mcp/")
45+
46+
if isMcpImage {
47+
if err := buildMcpImage(ctx, server); err != nil {
48+
return err
49+
}
50+
} else {
51+
if !pullCommunity {
52+
return fmt.Errorf("server is not docker built (ie, in the 'mcp/' namespace), you must either build it yourself or pull it with `docker pull %s` if you want to use it", server.Image)
53+
}
54+
if err := pullCommunityImage(ctx, server); err != nil {
55+
return err
56+
}
57+
}
58+
59+
if listTools {
60+
tools, err := mcp.Tools(ctx, server, false, false, false)
61+
if err != nil {
62+
return err
63+
}
64+
65+
if len(tools) == 0 {
66+
fmt.Println()
67+
fmt.Println("No tools found.")
68+
} else {
69+
fmt.Println()
70+
fmt.Println(len(tools), "tools found.")
71+
}
72+
}
73+
fmt.Printf("\n-----------------------------------------\n\n")
74+
75+
if isMcpImage {
76+
fmt.Println("✅ Image built as", server.Image)
77+
} else {
78+
fmt.Println("✅ Image pulled as", server.Image)
4579
}
4680

81+
return nil
82+
}
83+
84+
func buildMcpImage(ctx context.Context, server servers.Server) error {
4785
projectURL := server.Source.Project
4886
branch := server.Source.Branch
4987
directory := server.Source.Directory
@@ -87,27 +125,13 @@ func run(ctx context.Context, name string, listTools bool) error {
87125
cmd.Stdout = os.Stdout
88126
cmd.Stderr = os.Stderr
89127

90-
if err := cmd.Run(); err != nil {
91-
return err
92-
}
93-
94-
if listTools {
95-
tools, err := mcp.Tools(ctx, server, false, false, false)
96-
if err != nil {
97-
return err
98-
}
99-
100-
if len(tools) == 0 {
101-
fmt.Println()
102-
fmt.Println("No tools found.")
103-
} else {
104-
fmt.Println()
105-
fmt.Println(len(tools), "tools found.")
106-
}
107-
}
108-
fmt.Printf("\n-----------------------------------------\n\n")
128+
return cmd.Run()
129+
}
109130

110-
fmt.Println("✅ Image built as", server.Image)
131+
func pullCommunityImage(ctx context.Context, server servers.Server) error {
132+
cmd := exec.CommandContext(ctx, "docker", "pull", server.Image)
133+
cmd.Stdout = os.Stdout
134+
cmd.Stderr = os.Stderr
111135

112-
return nil
136+
return cmd.Run()
113137
}

0 commit comments

Comments
 (0)