Skip to content

Commit 3a43c24

Browse files
Restrict get_canvas AI tool to Rill user agents (#9256)
* Restrict get_canvas AI tool to Rill user agents with AI access * Fix test
1 parent b65835c commit 3a43c24

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

runtime/ai/canvas_get.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"strings"
78

89
"github.com/modelcontextprotocol/go-sdk/mcp"
910
"github.com/rilldata/rill/runtime"
@@ -48,8 +49,18 @@ func (t *GetCanvas) Spec() *mcp.Tool {
4849
}
4950

5051
func (t *GetCanvas) CheckAccess(ctx context.Context) (bool, error) {
52+
// Must be allowed to use AI and query objects
5153
s := GetSession(ctx)
52-
return s.Claims().Can(runtime.ReadObjects), nil
54+
if !s.Claims().Can(runtime.UseAI) || !s.Claims().Can(runtime.ReadObjects) {
55+
return false, nil
56+
}
57+
58+
// Only allow for rill user agents since it's not useful in MCP contexts.
59+
if !strings.HasPrefix(s.CatalogSession().UserAgent, "rill") {
60+
return false, nil
61+
}
62+
63+
return true, nil
5364
}
5465

5566
func (t *GetCanvas) Handler(ctx context.Context, args *GetCanvasArgs) (*GetCanvasResult, error) {

runtime/server/mcp_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ explore:
7171
expectedTools := []string{
7272
ai.ListMetricsViewsName,
7373
ai.GetMetricsViewName,
74-
ai.GetCanvasName,
7574
ai.QueryMetricsViewName,
7675
ai.QueryMetricsViewSummaryName,
7776
ai.ProjectStatusName,

0 commit comments

Comments
 (0)