Skip to content

Commit fc24b2c

Browse files
Copilotdata-douser
andauthored
fix: exit non-zero when use tool gets MCP-level error; replace cutString with strings.Cut
- outputToolResult() now returns an error when result.IsError is true, so the CLI exits 1 on MCP-level tool errors (e.g. nonexistent tool) - Replace custom cutString() with stdlib strings.Cut (available since Go 1.18) Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/cc25a44f-aecb-453c-be59-8064533607d3 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
1 parent 509393d commit fc24b2c

2 files changed

Lines changed: 6 additions & 12 deletions

File tree

client/cmd/use.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"fmt"
5+
"strings"
56

67
"github.com/spf13/cobra"
78
)
@@ -21,7 +22,7 @@ Subcommands:
2122
func parseArgs(args []string) (map[string]string, error) {
2223
result := make(map[string]string, len(args))
2324
for _, a := range args {
24-
key, value, found := cutString(a, "=")
25+
key, value, found := strings.Cut(a, "=")
2526
if !found || key == "" {
2627
return nil, fmt.Errorf("invalid argument %q: expected key=value format", a)
2728
}
@@ -34,7 +35,7 @@ func parseArgs(args []string) (map[string]string, error) {
3435
func parseArgsAny(args []string) (map[string]any, error) {
3536
result := make(map[string]any, len(args))
3637
for _, a := range args {
37-
key, value, found := cutString(a, "=")
38+
key, value, found := strings.Cut(a, "=")
3839
if !found || key == "" {
3940
return nil, fmt.Errorf("invalid argument %q: expected key=value format", a)
4041
}
@@ -43,16 +44,6 @@ func parseArgsAny(args []string) (map[string]any, error) {
4344
return result, nil
4445
}
4546

46-
// cutString splits s around the first instance of sep.
47-
func cutString(s, sep string) (before, after string, found bool) {
48-
for i := 0; i+len(sep) <= len(s); i++ {
49-
if s[i:i+len(sep)] == sep {
50-
return s[:i], s[i+len(sep):], true
51-
}
52-
}
53-
return s, "", false
54-
}
55-
5647
func init() {
5748
rootCmd.AddCommand(useCmd)
5849
}

client/cmd/use_tool.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,8 @@ func outputToolResult(result *mcpclient.ToolResult) error {
6565
default:
6666
fmt.Fprint(os.Stdout, mcpclient.FormatToolResultText(result))
6767
}
68+
if result.IsError {
69+
return fmt.Errorf("tool returned error")
70+
}
6871
return nil
6972
}

0 commit comments

Comments
 (0)