Skip to main content
Glama
grafana

Grafana

Official
by grafana
folder.go1.58 kB
package tools import ( "context" "fmt" "github.com/mark3labs/mcp-go/mcp" "github.com/mark3labs/mcp-go/server" "github.com/grafana/grafana-openapi-client-go/models" mcpgrafana "github.com/grafana/mcp-grafana" ) type CreateFolderParams struct { Title string `json:"title" jsonschema:"required,description=The title of the folder."` UID string `json:"uid,omitempty" jsonschema:"description=Optional folder UID. If omitted\\, Grafana will generate one."` ParentUID string `json:"parentUid,omitempty" jsonschema:"description=Optional parent folder UID. If set\\, the folder will be created under this parent."` } func createFolder(ctx context.Context, args CreateFolderParams) (*models.Folder, error) { if args.Title == "" { return nil, fmt.Errorf("title is required") } c := mcpgrafana.GrafanaClientFromContext(ctx) cmd := &models.CreateFolderCommand{Title: args.Title} if args.UID != "" { cmd.UID = args.UID } if args.ParentUID != "" { cmd.ParentUID = args.ParentUID } resp, err := c.Folders.CreateFolder(cmd) if err != nil { return nil, fmt.Errorf("create folder '%s': %w", args.Title, err) } return resp.Payload, nil } var CreateFolder = mcpgrafana.MustTool( "create_folder", "Create a Grafana folder. Provide a title and optional UID. Returns the created folder.", createFolder, mcp.WithTitleAnnotation("Create folder"), mcp.WithIdempotentHintAnnotation(false), mcp.WithReadOnlyHintAnnotation(false), ) func AddFolderTools(mcp *server.MCPServer, enableWriteTools bool) { if enableWriteTools { CreateFolder.Register(mcp) } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/grafana/mcp-grafana'

If you have feedback or need assistance with the MCP directory API, please join our Discord server