Skip to content

Commit 96dee32

Browse files
committed
wip
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
1 parent 45e4b34 commit 96dee32

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

mcp.go

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import (
1616
"github.com/spf13/cobra"
1717
)
1818

19-
//go:embed docs
20-
var docs embed.FS
21-
2219
//go:embed prompts/update.md
2320
var updatePrompt string
2421

22+
//go:embed docs
23+
var docs embed.FS
24+
2525
var cmd = &cobra.Command{
2626
Use: "goreleaser-mcp",
2727
Short: "The GoReleaser MCP server",
@@ -49,6 +49,11 @@ var cmd = &cobra.Command{
4949
}, nil
5050
})
5151

52+
mcp.AddTool(server, &mcp.Tool{
53+
Name: "check",
54+
Description: "Checks a GoReleaser configuration for errors or deprecations",
55+
}, checkTool)
56+
5257
fsys, err := fs.Sub(docs, "docs")
5358
if err != nil {
5459
return err
@@ -83,11 +88,6 @@ var cmd = &cobra.Command{
8388
return err
8489
}
8590

86-
mcp.AddTool(server, &mcp.Tool{
87-
Name: "check",
88-
Description: "Checks a GoReleaser configuration for errors or deprecations",
89-
}, checkTool)
90-
9191
return server.Run(cmd.Context(), &mcp.StdioTransport{})
9292
},
9393
}
@@ -113,7 +113,9 @@ type (
113113
Configuration string `json:"configuration,omitempty" jsonschema:"Path to the goreleaser YAML configuration file. If empty will use the default."`
114114
}
115115
checkOutput struct {
116-
Message string `json:"message"`
116+
Message string `json:"message"`
117+
Filepath string `json:"filepath"`
118+
Instructions string `json:"instructions,omitempty"`
117119
}
118120
)
119121

@@ -144,12 +146,17 @@ func openConfig(name string) (string, []byte, error) {
144146
return "", nil, fmt.Errorf("could not find any configuration file")
145147
}
146148

147-
func checkTool(ctx context.Context, _ *mcp.CallToolRequest, args checkArgs) (*mcp.CallToolResult, checkOutput, error) {
149+
func checkTool(ctx context.Context, req *mcp.CallToolRequest, args checkArgs) (*mcp.CallToolResult, checkOutput, error) {
148150
name, bts, err := openConfig(args.Configuration)
149151
if err != nil {
150152
return nil, checkOutput{}, fmt.Errorf("could not check configuration: %w", err)
151153
}
152154

155+
_ = req.Session.Log(ctx, &mcp.LoggingMessageParams{
156+
Data: fmt.Sprintf("using configuration file at %s", name),
157+
Level: mcp.LoggingLevel("info"),
158+
})
159+
153160
var cfg config.Project
154161
if err := yaml.UnmarshalStrict(bts, &cfg); err != nil {
155162
return nil, checkOutput{}, fmt.Errorf("invalid configuration file: %s: %w", name, err)
@@ -158,16 +165,32 @@ func checkTool(ctx context.Context, _ *mcp.CallToolRequest, args checkArgs) (*mc
158165
deprecations := findDeprecated(cfg)
159166
if len(deprecations) == 0 {
160167
return nil, checkOutput{
161-
Message: fmt.Sprintf("Configuration at %q is valid!", name),
168+
Message: "Configuration is valid!",
169+
Filepath: name,
170+
}, nil
171+
}
172+
173+
res, err := req.Session.Elicit(ctx, &mcp.ElicitParams{
174+
Message: "You have deprecated configuration options in your GoReleaser config. Do you want to fix it?",
175+
RequestedSchema: nil,
176+
})
177+
if err != nil || res.Action == "decline" {
178+
return nil, checkOutput{
179+
Message: "Configuration is valid, but uses deprecated options",
180+
Filepath: name,
162181
}, nil
163182
}
164183

184+
// if action is 'cancel' let's just add the instructions anyway...
165185
var sb strings.Builder
166-
sb.WriteString("Configuration is valid, but uses the following deprecated properties:\n")
186+
sb.WriteString("# Deprecated Options\n\n")
187+
sb.WriteString("Here's the instructions to fix each of deprecation:\n\n")
167188
for _, key := range slices.Collect(maps.Keys(deprecations)) {
168189
sb.WriteString(fmt.Sprintf("## %s\n\nInstructions: %s\n\n", key, instructions[key]))
169190
}
170191
return nil, checkOutput{
171-
Message: sb.String(),
192+
Message: "Configuration is valid, but uses deprecated options",
193+
Instructions: sb.String(),
194+
Filepath: name,
172195
}, nil
173196
}

prompts/update.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Here's your tasks:
55

66
Let's update the GoReleaser configuration to latest.
77

8-
We can use the GoReleaser's MCP `check` tool to grab the deprecation notices, and how to fix them.
8+
You should have a tool called `check` available (coming from the GoReleaser MCP), use it to grab the deprecation notices and how to fix them.
99

1010
If that's not enough, use the documentation resources to find out more details.
1111
The resource paths to look at are:

0 commit comments

Comments
 (0)