@@ -2,10 +2,8 @@ package tools
2
2
3
3
import (
4
4
"context"
5
- "encoding/json"
6
5
"fmt"
7
6
8
- "github.com/mark3labs/mcp-go/mcp"
9
7
"github.com/mark3labs/mcp-go/server"
10
8
11
9
"github.com/grafana/grafana-openapi-client-go/client/datasources"
@@ -33,17 +31,13 @@ type GetDatasourceByUIDParams struct {
33
31
UID string `json:"uid" jsonschema:"required,description=The uid of the datasource"`
34
32
}
35
33
36
- func getDatasourceByUID (ctx context.Context , args GetDatasourceByUIDParams ) (* mcp. CallToolResult , error ) {
34
+ func getDatasourceByUID (ctx context.Context , args GetDatasourceByUIDParams ) (* datasources. GetDataSourceByUIDOK , error ) {
37
35
c := mcpgrafana .GrafanaClientFromContext (ctx )
38
36
datasource , err := c .Datasources .GetDataSourceByUID (args .UID )
39
37
if err != nil {
40
38
return nil , fmt .Errorf ("get datasource by uid %s: %w" , args .UID , err )
41
39
}
42
- b , err := json .Marshal (datasource .Payload )
43
- if err != nil {
44
- return nil , fmt .Errorf ("marshal datasource: %w" , err )
45
- }
46
- return mcp .NewToolResultText (string (b )), nil
40
+ return datasource , nil
47
41
}
48
42
49
43
var GetDatasourceByUID = mcpgrafana .MustTool (
@@ -56,17 +50,13 @@ type GetDatasourceByNameParams struct {
56
50
Name string `json:"name" jsonschema:"required,description=The name of the datasource"`
57
51
}
58
52
59
- func getDatasourceByName (ctx context.Context , args GetDatasourceByNameParams ) (* mcp. CallToolResult , error ) {
53
+ func getDatasourceByName (ctx context.Context , args GetDatasourceByNameParams ) (* datasources. GetDataSourceByNameOK , error ) {
60
54
c := mcpgrafana .GrafanaClientFromContext (ctx )
61
55
datasource , err := c .Datasources .GetDataSourceByName (args .Name )
62
56
if err != nil {
63
57
return nil , fmt .Errorf ("get datasource by name %s: %w" , args .Name , err )
64
58
}
65
- b , err := json .Marshal (datasource .Payload )
66
- if err != nil {
67
- return nil , fmt .Errorf ("marshal datasource: %w" , err )
68
- }
69
- return mcp .NewToolResultText (string (b )), nil
59
+ return datasource , nil
70
60
}
71
61
72
62
var GetDatasourceByName = mcpgrafana .MustTool (
0 commit comments