Granting or taking back a server's tools leaves the rest as it was
CI / test (push) Successful in 10m29s
CI / test (push) Successful in 10m29s
A tool is seen where every level above that names tools names it (store Effective.AllowsTool). The console and /admin/mcp wrote a level's list as given, so a team that saw its organization's hr.* through having no list was given jira.* and then saw neither; and revoking a level's last server left [] in the store, closed to every tool, shown nowhere. store.GrantTools and RevokeTools now do both screens' work: a level's first list starts from the nearest list above it; taking a server away leaves the others, and a level left naming nothing goes back to no list, or stays closed when a level above names tools, so it opens to nothing it was kept from. GrantTools says which levels above still keep the granted tools out of reach, and both screens say so. The page shows closed levels and member scopes by name, and offers no revoke for a * grant it would not change. The console calls the store instead of keys limits with a list built from what it had loaded, which overwrote changes made since. Found in review. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7a04248148
commit
44451bacd9
11 files changed
+422
-71
No files matched your search
+40
-24
@@ -82,13 +82,13 @@ func (m consoleModel) fetchMCP() tea.Cmd {
|
||||
}
|
||||
msg.grants = []mcpGrant{}
|
||||
for _, l := range limits {
|
||||
if len(l.AllowedTools) == 0 {
|
||||
if l.AllowedTools == nil {
|
||||
continue
|
||||
}
|
||||
o := store.LimitOwner{Scope: l.Scope, ID: l.ScopeID}
|
||||
label := msg.where[o.CounterKey()]
|
||||
if label == "" {
|
||||
label = string(l.Scope) + " " + l.ScopeID
|
||||
label = l.ScopeID
|
||||
}
|
||||
msg.grants = append(msg.grants, mcpGrant{owner: o, label: string(l.Scope) + " " + label, tools: l.AllowedTools})
|
||||
}
|
||||
@@ -100,7 +100,10 @@ func (m consoleModel) fetchMCP() tea.Cmd {
|
||||
func (s *consoleMCPMsg) name(scope store.Scope, id, label string) {
|
||||
o := store.LimitOwner{Scope: scope, ID: id}
|
||||
s.where[o.CounterKey()] = label
|
||||
s.ids[string(scope)+":"+label] = o
|
||||
s.ids[string(scope)+":"+strings.ToLower(label)] = o
|
||||
if m := store.MemberScope(scope); m != "" {
|
||||
s.where[store.LimitOwner{Scope: m, ID: id}.CounterKey()] = label
|
||||
}
|
||||
}
|
||||
|
||||
// mcpGrantsOf is who may use a server's tools, and which of them.
|
||||
@@ -278,8 +281,8 @@ func (m consoleModel) mcpMenu(s adminapi.MCPServerView) *menuDialog {
|
||||
items = append(items, menuItem{"Revoke from " + g.label + " (" + strings.Join(g.tools, ", ") + ")…",
|
||||
func(m *consoleModel) tea.Cmd {
|
||||
m.confirmD = &confirmDialog{title: "Revoke " + s.Name + " from " + g.label,
|
||||
text: "It and everything below it then no longer see " + strings.Join(g.tools, ", ") +
|
||||
",\nunless another level grants them.",
|
||||
text: "It then sees " + strings.Join(g.tools, ", ") + " only if the levels above grant them\n" +
|
||||
"and it names no tools of its own. Its other grants stay.",
|
||||
yes: func(m *consoleModel) tea.Cmd { return m.mcpSetTools(s.Name, g.owner, nil) }}
|
||||
return nil
|
||||
}})
|
||||
@@ -397,8 +400,8 @@ func (m *consoleModel) mcpGrantForm(s adminapi.MCPServerView) {
|
||||
return
|
||||
}
|
||||
m.openForm(&formDialog{title: "Grant " + s.Name + "'s tools",
|
||||
note: "It and everything below it then see them, unless a level below grants\n" +
|
||||
"tools and not these. Other grants at that level stay.",
|
||||
note: "Seen there, and below, where every level above that names tools names these too.\n" +
|
||||
"A level given its first grant keeps what it saw from above; other grants stay.",
|
||||
fields: []formField{
|
||||
choiceF("to", []string{"team", "project", "org", "user", "key"}, "team"),
|
||||
textF("which", "", "ORG/TEAM/PROJECT, ORG/TEAM, ORG, an e-mail, or a key's ID"),
|
||||
@@ -409,7 +412,7 @@ func (m *consoleModel) mcpGrantForm(s adminapi.MCPServerView) {
|
||||
if which == "" {
|
||||
return nil, fmt.Errorf("which %s?", v[0])
|
||||
}
|
||||
owner, ok := m.mcp.ids[v[0]+":"+which]
|
||||
owner, ok := m.mcp.ids[v[0]+":"+strings.ToLower(which)]
|
||||
if v[0] == "key" {
|
||||
owner, ok = store.LimitOwner{Scope: store.ScopeKey, ID: which}, true
|
||||
}
|
||||
@@ -432,25 +435,38 @@ func (m *consoleModel) mcpGrantForm(s adminapi.MCPServerView) {
|
||||
}})
|
||||
}
|
||||
|
||||
// mcpSetTools makes a level's grants of a server's tools these, leaving its
|
||||
// grants of other servers' as they are. None revokes them.
|
||||
// mcpSetTools grants a level these of a server's tools, or with none takes
|
||||
// them away, in the store (store.GrantTools, store.RevokeTools): read and
|
||||
// written at once, so another administrator's change since this screen
|
||||
// was loaded is kept.
|
||||
func (m *consoleModel) mcpSetTools(server string, owner store.LimitOwner, tools []string) tea.Cmd {
|
||||
var keep []string
|
||||
for _, g := range m.mcp.grants {
|
||||
if g.owner != owner {
|
||||
continue
|
||||
}
|
||||
for _, t := range g.tools {
|
||||
if !strings.HasPrefix(t, server+".") {
|
||||
keep = append(keep, t)
|
||||
}
|
||||
}
|
||||
}
|
||||
all := append(keep, tools...)
|
||||
h, where := m.st, m.mcp.where
|
||||
title := "Grant " + server
|
||||
if len(tools) == 0 {
|
||||
title = "Revoke " + server
|
||||
}
|
||||
return m.runCLI(title, "keys", "limits", "--scope="+string(owner.Scope), "--id="+owner.ID,
|
||||
"--tools="+strings.Join(all, ","))
|
||||
return func() tea.Msg {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
s, err := h.get(ctx)
|
||||
if err != nil {
|
||||
return actionDoneMsg{title: title, err: err}
|
||||
}
|
||||
if len(tools) == 0 {
|
||||
if err := s.RevokeTools(ctx, owner.Scope, owner.ID, server); err != nil {
|
||||
return actionDoneMsg{title: title, err: err}
|
||||
}
|
||||
return actionDoneMsg{title: title, text: server + "'s tools taken back there; its other grants stay."}
|
||||
}
|
||||
g, err := s.GrantTools(ctx, owner.Scope, owner.ID, server, tools)
|
||||
if err != nil {
|
||||
return actionDoneMsg{title: title, err: err}
|
||||
}
|
||||
text := "Granted " + strings.Join(tools, ", ") + "."
|
||||
for _, b := range g.BlockedBy {
|
||||
text += "\n\nBut " + string(b.Scope) + " " + or(where[b.CounterKey()], b.ID) + " names tools and not these:\n" +
|
||||
server + "'s stay out of reach there until it grants them too."
|
||||
}
|
||||
return actionDoneMsg{title: title, text: text}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user