Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions cmd/query/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ func newGetCmd() *cobra.Command {
Use: "get <query-id>",
Short: "Fetch a saved Dune query by ID, including SQL and metadata",
Long: "Retrieve SQL, metadata, owner, privacy flags, tags, and execution state for\n" +
"an existing Dune query. Only queries visible to the authenticated user are returned.\n\n" +
"an existing Dune query. Only queries visible to the authenticated user are returned.\n" +
"The folder is shown only for queries that the API key's user or team owns.\n\n" +
"The latest execution ID reads its results without running the query again:\n" +
" dune execution results <latest-execution-id>",
Args: cobra.ExactArgs(1),
Expand All @@ -42,8 +43,13 @@ func runGet(cmd *cobra.Command, args []string) error {
// The REST API does not report executions; the MCP tool getDuneQuery does. The
// latest execution is an extra, so the command still prints the query without it.
var latest struct {
ID *string `json:"latest_execution_id"`
State *string `json:"latest_execution_state"`
ID *string `json:"latest_execution_id"`
State *string `json:"latest_execution_state"`
Folder *struct {
FolderID string `json:"folder_id"`
Path string `json:"path"`
} `json:"folder"`
FolderAccess string `json:"folder_access"`
}
latestKnown := true
if _, err := cmdutil.CallTool(cmd, "getDuneQuery", map[string]any{"query_id": queryID}, &latest); err != nil {
Expand All @@ -62,7 +68,9 @@ func runGet(cmd *cobra.Command, args []string) error {
*models.GetQueryResponse
LatestExecutionID *string `json:"latest_execution_id"`
LatestExecutionState *string `json:"latest_execution_state"`
}{resp, latest.ID, latest.State})
Folder any `json:"folder"`
FolderAccess string `json:"folder_access,omitempty"`
}{resp, latest.ID, latest.State, latest.Folder, latest.FolderAccess})
default:
fmt.Fprintf(w, "ID: %d\n", resp.QueryID)
fmt.Fprintf(w, "Name: %s\n", resp.Name)
Expand All @@ -77,6 +85,9 @@ func runGet(cmd *cobra.Command, args []string) error {
if len(resp.Tags) > 0 {
fmt.Fprintf(w, "Tags: %s\n", strings.Join(resp.Tags, ", "))
}
if latest.Folder != nil {
fmt.Fprintf(w, "Folder: %s (%s)\n", latest.Folder.Path, latest.Folder.FolderID)
}
switch {
case !latestKnown:
fmt.Fprintln(w, "Last run: unknown")
Expand Down
6 changes: 5 additions & 1 deletion cmd/query/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,15 @@ func TestGetEmptyDescriptionAndTags(t *testing.T) {
func TestGetShowsTheLatestExecution(t *testing.T) {
mock := &mockClient{getQueryFn: func(int) (*models.GetQueryResponse, error) { return testQueryResponse, nil }}
fake := &dunemcptest.Fake{Results: map[string]string{"getDuneQuery": `{"query_id":4125432,
"latest_execution_id":"01EXEC","latest_execution_state":"QUERY_STATE_COMPLETED"}`}}
"latest_execution_id":"01EXEC","latest_execution_state":"QUERY_STATE_COMPLETED",
"folder":{"folder_id":"fld_1","path":"/Research/RWA"},"folder_access":"available"}`}}

root, buf := newTestRootWithMCP(mock, fake)
root.SetArgs([]string{"query", "get", "4125432"})
require.NoError(t, root.Execute())
assert.JSONEq(t, `{"query_id":4125432}`, fake.Last().Args)
assert.Contains(t, buf.String(), "Last run: 01EXEC (COMPLETED)")
assert.Contains(t, buf.String(), "Folder: /Research/RWA (fld_1)")

// JSON keeps every REST field and adds the latest execution.
root, buf = newTestRootWithMCP(mock, fake)
Expand All @@ -146,6 +148,8 @@ func TestGetShowsTheLatestExecution(t *testing.T) {
assert.Equal(t, "SELECT 1", got["query_sql"])
assert.Equal(t, "01EXEC", got["latest_execution_id"])
assert.Equal(t, "QUERY_STATE_COMPLETED", got["latest_execution_state"])
assert.Equal(t, map[string]any{"folder_id": "fld_1", "path": "/Research/RWA"}, got["folder"])
assert.Equal(t, "available", got["folder_access"])
}

func TestGetNeverRun(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions cmd/query/mcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ func TestSearchOwnedOnly(t *testing.T) {

assert.JSONEq(t, `{"search_string":"dex","scope":"owned_only"}`, fake.Last().Args)
assert.Regexp(t, `4700\s+DEX Volume\s+remix`, buf.String())

root, _ = newMCPRoot(fake)
root.SetArgs([]string{"query", "search", "--query", "dex", "--folder-id", "fld_1"})
require.NoError(t, root.Execute())
assert.JSONEq(t, `{"search_string":"dex","folder_id":"fld_1"}`, fake.Last().Args)
}

func TestCreateAndRunJSONIsTheToolResult(t *testing.T) {
Expand Down
9 changes: 6 additions & 3 deletions cmd/query/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,26 @@ func newSearchCmd() *cobra.Command {
Long: "Find saved queries whose name contains the given text (not case-sensitive), to get\n" +
"a query ID to run, edit, or chart. Results include public queries and the private\n" +
"queries you or your team can access; --owned-only keeps only the ones the API key's\n" +
"user or team owns.\n\n" +
"user or team owns, and --folder-id keeps only the queries in a folder or its\n" +
"subfolders.\n\n" +
"Examples:\n" +
" dune query search --query \"dex volume\"\n" +
" dune query search --query stablecoin --owned-only --limit 50 -o json",
" dune query search --query stablecoin --owned-only --limit 50 -o json\n" +
" dune query search --query volume --folder-id <folder-id>",
Args: cobra.NoArgs,
RunE: runSearch,
}
cmd.Flags().String("query", "", "text to find in the query name (required)")
cmd.Flags().Bool("owned-only", false, "only return queries owned by the API key's user or team")
cmd.Flags().String("folder-id", "", "only return queries in this folder or its subfolders (see 'dune folder list')")
cmd.Flags().Int("limit", 20, "maximum number of queries to return (1-50)")
_ = cmd.MarkFlagRequired("query")
output.AddFormatFlag(cmd, "text")
return cmd
}

func runSearch(cmd *cobra.Command, _ []string) error {
args := cmdutil.ToolArgs(cmd, map[string]string{"query": "search_string", "limit": "limit"})
args := cmdutil.ToolArgs(cmd, map[string]string{"query": "search_string", "folder-id": "folder_id", "limit": "limit"})
if owned, _ := cmd.Flags().GetBool("owned-only"); owned {
args["scope"] = "owned_only"
}
Expand Down
Loading