MCP servers: fields that can be emptied, addresses without passwords

From review. A server's description, timeout and rate can be emptied from
the console and the page (MCPServerRequest.Clear), where an empty field
used to leave them as they were. An address with a user and password in
it is refused (adminapi.CheckMCPAddress): the credential belongs in a
header, sealed, and the address is shown and audited as written. The
console accepts llmgw:admin and the page lets it be changed, address
fixed. A grant to a key that is not there is refused rather than said
done.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5.5 committed 2026-10-29 10:03:27 +01:00
1 parent 721705b29d
commit f94d902cc3
5 files changed
+106 -18

No files matched your search

+25 -8
View File
@@ -33,6 +33,8 @@ type mcpState struct {
grants []mcpGrant
where map[string]string
ids map[string]store.LimitOwner
// keys are the IDs of the keys there are, for a grant to one.
keys map[string]bool
}
// mcpGrant is one level of the tree that grants tools, and which.
@@ -80,6 +82,13 @@ func (m consoleModel) fetchMCP() tea.Cmd {
msg.name(store.ScopeUser, u.ID, u.Email)
}
}
msg.keys = map[string]bool{}
if keys, err := s.AllKeys(ctx); err == nil {
for _, k := range keys {
msg.keys[k.ID] = true
msg.where[store.LimitOwner{Scope: store.ScopeKey, ID: k.ID}.CounterKey()] = k.Name
}
}
msg.grants = []mcpGrant{}
for _, l := range limits {
if l.AllowedTools == nil {
@@ -244,8 +253,8 @@ func (m *consoleModel) mcpAddForm() {
if name == "" || addr == "" {
return nil, fmt.Errorf("a name and an address")
}
if u, err := url.Parse(addr); err != nil || (u.Scheme != "http" && u.Scheme != "https") || u.Host == "" {
return nil, fmt.Errorf("the address is http(s)://host/path")
if err := adminapi.CheckMCPAddress(addr); err != nil {
return nil, err
}
secrets, err := mcpAuth(v[3], strings.TrimSpace(v[4]), v[5])
if err != nil {
@@ -350,8 +359,8 @@ func (m *consoleModel) mcpEditForm(s adminapi.MCPServerView) {
textF("rate", rate, "calls a minute per caller; 0 is no bound"),
},
submit: func(m *consoleModel, v []string) (tea.Cmd, error) {
if u, err := url.Parse(v[0]); err != nil || (u.Scheme != "http" && u.Scheme != "https") || u.Host == "" {
return nil, fmt.Errorf("the address is http(s)://host/path")
if err := adminapi.CheckMCPAddress(strings.TrimSpace(v[0])); err != nil {
return nil, err
}
timeout, err := atoiOr(v[2], 0)
if err != nil || timeout < 0 {
@@ -361,10 +370,18 @@ func (m *consoleModel) mcpEditForm(s adminapi.MCPServerView) {
if err != nil || rate < 0 {
return nil, fmt.Errorf("rate is calls a minute")
}
if rate == 0 && s.RatePerMinute > 0 {
rate = -1 // the API's way of taking the bound away
req := adminapi.MCPServerRequest{URL: strings.TrimSpace(v[0]), Description: v[1], TimeoutSeconds: timeout,
RatePerMinute: rate}
// An emptied field empties it, rather than leaving it as it was.
if strings.TrimSpace(v[1]) == "" {
req.Clear = append(req.Clear, "description")
}
if timeout == 0 {
req.Clear = append(req.Clear, "timeout")
}
if rate == 0 {
req.Clear = append(req.Clear, "rate")
}
req := adminapi.MCPServerRequest{URL: v[0], Description: v[1], TimeoutSeconds: timeout, RatePerMinute: rate}
return m.call("Change "+s.Name, http.MethodPut, mcpPath(s.Name), req, nil), nil
}})
}
@@ -414,7 +431,7 @@ func (m *consoleModel) mcpGrantForm(s adminapi.MCPServerView) {
}
owner, ok := m.mcp.ids[v[0]+":"+strings.ToLower(which)]
if v[0] == "key" {
owner, ok = store.LimitOwner{Scope: store.ScopeKey, ID: which}, true
owner, ok = store.LimitOwner{Scope: store.ScopeKey, ID: which}, m.mcp.keys[which]
}
if !ok {
return nil, fmt.Errorf("no %s %q", v[0], which)