Skip to content

Commit 7da0d3f

Browse files
authored
Fix: Failing to create template (#167)
The secret provided via argument (`-e` flag) [1] was losing the value before listing the tools. This caused failures to connect to the MCP server. The strategy now is to replace the secret value only when encoding the object to generate the template. There was also a missing `--load` flag when executing `docker buildx build` to correctly load the image into the memory. [1] https://github.com/rafaeljusto/mcp-registry/blob/17fdb6eb0a4b47d4ac1a33535554a6fa7e2b2dd3/cmd/create/main.go#L177-L181
1 parent e813c03 commit 7da0d3f

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

cmd/build/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func buildMcpImage(ctx context.Context, server servers.Server) error {
128128
token := os.Getenv("GITHUB_TOKEN")
129129

130130
buildArgs := []string{
131-
"-f", server.GetDockerfile(), "-t", "check", "-t", server.Image, "--label", "org.opencontainers.image.revision=" + sha,
131+
"-f", server.GetDockerfile(), "-t", "check", "-t", server.Image, "--label", "org.opencontainers.image.revision=" + sha, "--load",
132132
}
133133

134134
if server.Source.BuildTarget != "" {

cmd/create/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ func run(ctx context.Context, buildURL, name, category, userProvidedImage string
140140
token := os.Getenv("GITHUB_TOKEN")
141141

142142
if token != "" {
143-
cmd = exec.CommandContext(ctx, "docker", "buildx", "build", "--secret", "id=GIT_AUTH_TOKEN", "-t", "check", "-t", tag, "--label", "org.opencontainers.image.revision="+sha, gitURL)
143+
cmd = exec.CommandContext(ctx, "docker", "buildx", "build", "--secret", "id=GIT_AUTH_TOKEN", "-t", "check", "-t", tag, "--label", "org.opencontainers.image.revision="+sha, "--load", gitURL)
144144
cmd.Env = []string{"GIT_AUTH_TOKEN=" + token, "PATH=" + os.Getenv("PATH")}
145145
} else {
146-
cmd = exec.CommandContext(ctx, "docker", "buildx", "build", "-t", "check", "-t", tag, "--label", "org.opencontainers.image.revision="+sha, gitURL)
146+
cmd = exec.CommandContext(ctx, "docker", "buildx", "build", "-t", "check", "-t", tag, "--label", "org.opencontainers.image.revision="+sha, "--load", gitURL)
147147
cmd.Env = []string{"PATH=" + os.Getenv("PATH")}
148148
}
149149

@@ -177,7 +177,7 @@ func run(ctx context.Context, buildURL, name, category, userProvidedImage string
177177
secrets = append(secrets, servers.Secret{
178178
Name: secretName(name, parts[0]),
179179
Env: parts[0],
180-
Example: "<" + parts[0] + ">",
180+
Example: parts[1],
181181
})
182182
} else {
183183
env = append(env, servers.Env{

pkg/servers/types.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ THE SOFTWARE.
2323
package servers
2424

2525
import (
26+
"encoding/json"
27+
2628
"gopkg.in/yaml.v3"
2729
)
2830

@@ -48,6 +50,21 @@ type Secret struct {
4850
Required *bool `yaml:"required,omitempty" json:"required,omitempty"`
4951
}
5052

53+
// secret is an alias used to drop encoding methods to avoid infinite recursion.
54+
type secret Secret
55+
56+
func (s Secret) MarshalYAML() (any, error) {
57+
a := secret(s)
58+
a.Example = "<" + s.Env + ">"
59+
return a, nil
60+
}
61+
62+
func (s Secret) MarshalJSON() ([]byte, error) {
63+
a := secret(s)
64+
a.Example = "<" + s.Env + ">"
65+
return json.Marshal(a)
66+
}
67+
5168
type Env struct {
5269
Name string `yaml:"name" json:"name"`
5370
Example any `yaml:"example,omitempty" json:"example,omitempty"`

0 commit comments

Comments
 (0)