Skip to content

Commit d46e018

Browse files
committed
fix: change the tool result from NewToolResultStructured to NewToolResultText since there are a number of ai agents like opencode that does not support structured response
1 parent 7cfdbb3 commit d46e018

4 files changed

Lines changed: 27 additions & 35 deletions

File tree

tools/parseable_info.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package tools
22

33
import (
44
"context"
5+
"fmt"
6+
"strings"
57

68
"github.com/mark3labs/mcp-go/mcp"
79
"github.com/mark3labs/mcp-go/server"
@@ -32,17 +34,13 @@ Returned fields:
3234
if err != nil {
3335
return mcp.NewToolResultError("failed to get info: " + err.Error()), nil
3436
}
35-
fieldDescriptions := map[string]interface{}{
36-
"createdAt": "When the data stream was created (ISO 8601)",
37-
"firstEventAt": "Timestamp of the first event (ISO 8601)",
38-
"latestEventAt": "Timestamp of the latest event (ISO 8601)",
39-
"streamType": "Type of data stream (e.g. UserDefined)",
40-
"logSource": "Array of log source objects",
41-
"telemetryType": "Type of telemetry - logs, metrics or traces",
37+
// Default: return as text
38+
var lines []string
39+
for k, v := range info {
40+
lines = append(lines, k+": "+fmt.Sprintf("%v", v))
4241
}
43-
return mcp.NewToolResultStructured(map[string]interface{}{
44-
"info": info,
45-
"fieldDescriptions": fieldDescriptions,
46-
}, "Info returned"), nil
42+
return mcp.NewToolResultText(strings.Join(lines, "\n")), nil
43+
// Optionally, for structured output:
44+
// return mcp.NewToolResultStructured(map[string]interface{}{"info": info}, "Info returned"), nil
4745
})
4846
}

tools/parseable_list_stats.go

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package tools
22

33
import (
44
"context"
5+
"fmt"
6+
"strings"
57

68
"github.com/mark3labs/mcp-go/mcp"
79
"github.com/mark3labs/mcp-go/server"
@@ -39,28 +41,13 @@ Returned fields:
3941
if err != nil {
4042
return mcp.NewToolResultError("failed to get stats: " + err.Error()), nil
4143
}
42-
fieldDescriptions := map[string]interface{}{
43-
"stream": "Data stream name",
44-
"time": "Stats timestamp (ISO 8601)",
45-
"ingestion": map[string]string{
46-
"count": "Number of ingested records",
47-
"size": "Total bytes ingested",
48-
"format": "Data format (e.g. json)",
49-
"lifetime_count": "Cumulative ingested records",
50-
"lifetime_size": "Cumulative ingested bytes",
51-
"deleted_count": "Number of deleted records",
52-
"deleted_size": "Bytes deleted",
53-
},
54-
"storage": map[string]string{
55-
"size": "Total bytes stored",
56-
"format": "Storage format (e.g. parquet)",
57-
"lifetime_size": "Cumulative stored bytes",
58-
"deleted_size": "Bytes deleted from storage",
59-
},
44+
// Default: return as text
45+
var lines []string
46+
for k, v := range stats {
47+
lines = append(lines, k+": "+fmt.Sprintf("%v", v))
6048
}
61-
return mcp.NewToolResultStructured(map[string]interface{}{
62-
"stats": stats,
63-
"fieldDescriptions": fieldDescriptions,
64-
}, "Stats returned"), nil
49+
return mcp.NewToolResultText(strings.Join(lines, "\n")), nil
50+
// Optionally, for structured output:
51+
// return mcp.NewToolResultStructured(map[string]interface{}{"stats": stats}, "Stats returned"), nil
6552
})
6653
}

tools/parseable_list_streams.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tools
22

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

67
"github.com/mark3labs/mcp-go/mcp"
78
"github.com/mark3labs/mcp-go/server"
@@ -16,6 +17,8 @@ func RegisterListDataStreamsTool(mcpServer *server.MCPServer) {
1617
if err != nil {
1718
return mcp.NewToolResultError(err.Error()), nil
1819
}
19-
return mcp.NewToolResultStructured(map[string]interface{}{"streams": streams}, "Streams listed"), nil
20+
//return mcp.NewToolResultStructured(map[string]interface{}{"streams": streams}, "Streams listed"), nil
21+
return mcp.NewToolResultText(strings.Join(streams, "\n")), nil
22+
2023
})
2124
}

tools/parseable_query.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"encoding/json"
7+
"fmt"
78
"io"
89
"net/http"
910

@@ -51,6 +52,9 @@ func RegisterQueryDataStreamTool(mcpServer *server.MCPServer) {
5152
if err := json.Unmarshal(body, &result); err != nil {
5253
return mcp.NewToolResultError("failed to parse parseable response"), nil
5354
}
54-
return mcp.NewToolResultStructured(map[string]interface{}{"result": result}, "Query successful"), nil
55+
// Default: return as text
56+
return mcp.NewToolResultText(fmt.Sprintf("%v", result)), nil
57+
// Optionally, for structured output:
58+
// return mcp.NewToolResultStructured(map[string]interface{}{"result": result}, "Query successful"), nil
5559
})
5660
}

0 commit comments

Comments
 (0)