From 763c567e0c6ac027fb0bc903aba8a738d1c5b300 Mon Sep 17 00:00:00 2001 From: Ivan Pusic <450140+ivpusic@users.noreply.github.com> Date: Fri, 20 Nov 2026 09:47:07 +0000 Subject: [PATCH 1/2] Report docs search tool errors A failed search_dune_docs call comes back as a result with IsError set. docs search parsed its error text as a search result and exited 0; it now returns the error. Amp-Thread-ID: https://ampcode.com/threads/T-01a1f46d-4de8-7404-a66a-7e2a8be6632a Co-authored-by: Amp --- cmd/docs/search.go | 13 +++++++++++++ cmd/docs/search_test.go | 29 ++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/cmd/docs/search.go b/cmd/docs/search.go index 81dcf27..9216ad8 100644 --- a/cmd/docs/search.go +++ b/cmd/docs/search.go @@ -93,6 +93,19 @@ func runSearch(cmd *cobra.Command, _ []string) error { if err != nil { return fmt.Errorf("searching docs: %w", err) } + if result.IsError { + // A failed search comes back as a result whose text says what went wrong. + var msgs []string + for _, c := range result.Content { + if tc, ok := c.(*mcp.TextContent); ok && tc.Text != "" { + msgs = append(msgs, tc.Text) + } + } + if len(msgs) == 0 { + msgs = append(msgs, "no details") + } + return fmt.Errorf("searching docs: %s", strings.Join(msgs, "; ")) + } // Parse results from content blocks. results := parseResults(result) diff --git a/cmd/docs/search_test.go b/cmd/docs/search_test.go index a57a57b..743a346 100644 --- a/cmd/docs/search_test.go +++ b/cmd/docs/search_test.go @@ -24,6 +24,16 @@ type searchArgs struct { func startMCPServer(t *testing.T, results []string) *httptest.Server { t.Helper() + var content []mcp.Content + for _, r := range results { + content = append(content, &mcp.TextContent{Text: r}) + } + return startMCPServerResult(t, &mcp.CallToolResult{Content: content}) +} + +// startMCPServerResult starts a docs server whose search tool returns result. +func startMCPServerResult(t *testing.T, result *mcp.CallToolResult) *httptest.Server { + t.Helper() server := mcp.NewServer(&mcp.Implementation{ Name: "test-docs", @@ -34,11 +44,7 @@ func startMCPServer(t *testing.T, results []string) *httptest.Server { Name: "search_dune_docs", Description: "Search Dune docs", }, func(ctx context.Context, req *mcp.CallToolRequest, args searchArgs) (*mcp.CallToolResult, any, error) { - var content []mcp.Content - for _, r := range results { - content = append(content, &mcp.TextContent{Text: r}) - } - return &mcp.CallToolResult{Content: content}, nil, nil + return result, nil, nil }) handler := mcp.NewStreamableHTTPHandler(func(_ *http.Request) *mcp.Server { @@ -116,6 +122,19 @@ func TestSearchEmptyResults(t *testing.T) { assert.Contains(t, buf.String(), "No results found.") } +func TestSearchToolError(t *testing.T) { + ts := startMCPServerResult(t, &mcp.CallToolResult{ + IsError: true, + Content: []mcp.Content{&mcp.TextContent{Text: "search index unavailable"}}, + }) + + root, buf := newTestRoot() + root.SetArgs([]string{"docs", "search", "--query", "decoded tables", "--mcp-endpoint", ts.URL}) + + assert.EqualError(t, root.Execute(), "searching docs: search index unavailable") + assert.NotContains(t, buf.String(), "result(s)") +} + func TestSearchRequiresQuery(t *testing.T) { root, _ := newTestRoot() root.SetArgs([]string{"docs", "search"}) From 630c200229665b2873c4eab16099a01f4011f225 Mon Sep 17 00:00:00 2001 From: Ivan Pusic <450140+ivpusic@users.noreply.github.com> Date: Fri, 20 Nov 2026 09:59:21 +0000 Subject: [PATCH 2/2] Share the MCP tool error formatting with docs search dunemcp.ToolError is the error path of dunemcp.Result, so docs search reports a tool error the same way the other MCP commands do: text blocks joined by newlines, no trailing period, and a message naming the tool when there is no text. Amp-Thread-ID: https://ampcode.com/threads/T-01a1f46d-4de8-7404-a66a-7e2a8be6632a Co-authored-by: Amp --- cmd/docs/search.go | 15 +++------------ cmd/docs/search_test.go | 4 ++-- dunemcp/dunemcp.go | 22 +++++++++++++++------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/cmd/docs/search.go b/cmd/docs/search.go index 9216ad8..eefa443 100644 --- a/cmd/docs/search.go +++ b/cmd/docs/search.go @@ -4,6 +4,7 @@ import ( "fmt" "strings" + "github.com/duneanalytics/cli/dunemcp" "github.com/duneanalytics/cli/output" "github.com/modelcontextprotocol/go-sdk/mcp" "github.com/spf13/cobra" @@ -93,18 +94,8 @@ func runSearch(cmd *cobra.Command, _ []string) error { if err != nil { return fmt.Errorf("searching docs: %w", err) } - if result.IsError { - // A failed search comes back as a result whose text says what went wrong. - var msgs []string - for _, c := range result.Content { - if tc, ok := c.(*mcp.TextContent); ok && tc.Text != "" { - msgs = append(msgs, tc.Text) - } - } - if len(msgs) == 0 { - msgs = append(msgs, "no details") - } - return fmt.Errorf("searching docs: %s", strings.Join(msgs, "; ")) + if err := dunemcp.ToolError("search_dune_docs", result); err != nil { + return fmt.Errorf("searching docs: %w", err) } // Parse results from content blocks. diff --git a/cmd/docs/search_test.go b/cmd/docs/search_test.go index 743a346..bd4f098 100644 --- a/cmd/docs/search_test.go +++ b/cmd/docs/search_test.go @@ -125,13 +125,13 @@ func TestSearchEmptyResults(t *testing.T) { func TestSearchToolError(t *testing.T) { ts := startMCPServerResult(t, &mcp.CallToolResult{ IsError: true, - Content: []mcp.Content{&mcp.TextContent{Text: "search index unavailable"}}, + Content: []mcp.Content{&mcp.TextContent{Text: "Search index unavailable."}}, }) root, buf := newTestRoot() root.SetArgs([]string{"docs", "search", "--query", "decoded tables", "--mcp-endpoint", ts.URL}) - assert.EqualError(t, root.Execute(), "searching docs: search index unavailable") + assert.EqualError(t, root.Execute(), "searching docs: Search index unavailable") assert.NotContains(t, buf.String(), "result(s)") } diff --git a/dunemcp/dunemcp.go b/dunemcp/dunemcp.go index 566ffb0..133c493 100644 --- a/dunemcp/dunemcp.go +++ b/dunemcp/dunemcp.go @@ -80,13 +80,8 @@ func (c *Client) connect(ctx context.Context) (*mcp.ClientSession, error) { // the tool reported. A result without structured content falls back to its // first text block, which Dune tools fill with the same JSON. func Result(tool string, res *mcp.CallToolResult) (json.RawMessage, error) { - if res.IsError { - // Go error strings end without punctuation; the CLI's error printer adds a period. - msg := strings.TrimSuffix(strings.TrimSpace(text(res)), ".") - if msg == "" { - msg = tool + " failed without a message" - } - return nil, errors.New(msg) + if err := ToolError(tool, res); err != nil { + return nil, err } if res.StructuredContent != nil { var buf bytes.Buffer @@ -103,6 +98,19 @@ func Result(tool string, res *mcp.CallToolResult) (json.RawMessage, error) { return nil, errors.New(tool + ": the tool returned no structured result") } +// ToolError returns the error a tool result reports, or nil when it reports none. +func ToolError(tool string, res *mcp.CallToolResult) error { + if !res.IsError { + return nil + } + // Go error strings end without punctuation; the CLI's error printer adds a period. + msg := strings.TrimSuffix(strings.TrimSpace(text(res)), ".") + if msg == "" { + msg = tool + " failed without a message" + } + return errors.New(msg) +} + func text(res *mcp.CallToolResult) string { var parts []string for _, c := range res.Content {