MCP servers: fields that can be emptied, addresses without passwords
CI / test (push) Failing after 6m34s

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

+20 -6
View File
@@ -34,6 +34,7 @@ type MCPAdmin interface {
PutLimits(ctx context.Context, l store.Limits) error
GrantTools(ctx context.Context, scope store.Scope, id, server string, tools []string) (store.ToolGrant, error)
RevokeTools(ctx context.Context, scope store.Scope, id, server string) error
KeyByID(ctx context.Context, id string) (store.Key, error)
Tree(ctx context.Context) ([]store.TreeOrg, error)
Users(ctx context.Context, state store.UserState) ([]store.User, error)
}
@@ -193,12 +194,20 @@ func (p *AccountPages) RegisterAdminMCP(mux *http.ServeMux, s MCPAdmin, local fu
mux.HandleFunc("POST /admin/mcp/{name}/edit", adminsOnly(func(w http.ResponseWriter, r *http.Request, admin store.User) {
l, name := langOf(r), r.PathValue("name")
timeout, rate, err := mcpBounds(l, r.FormValue("timeout"), r.FormValue("rate"))
if err == nil && rate == 0 {
rate = -1 // an empty rate takes the bound away
}
if err == nil {
err = put(r, admin, name, adminapi.MCPServerRequest{URL: strings.TrimSpace(r.FormValue("url")),
Description: strings.TrimSpace(r.FormValue("description")), TimeoutSeconds: timeout, RatePerMinute: rate})
req := adminapi.MCPServerRequest{URL: strings.TrimSpace(r.FormValue("url")),
Description: strings.TrimSpace(r.FormValue("description")), TimeoutSeconds: timeout, RatePerMinute: rate}
// An emptied field empties it, rather than leaving it as it was.
if req.Description == "" {
req.Clear = append(req.Clear, "description")
}
if timeout == 0 {
req.Clear = append(req.Clear, "timeout")
}
if rate == 0 {
req.Clear = append(req.Clear, "rate")
}
err = put(r, admin, name, req)
}
done(w, r, admin, "mcp server "+name, l.T("mcp.changed", name), err)
}))
@@ -357,7 +366,12 @@ func mcpResolve(ctx context.Context, s MCPAdmin, l *Lang, scope store.Scope, whi
}
switch scope {
case store.ScopeKey:
return which, which, nil
// A key that is not there would be granted nothing, and said granted.
k, err := s.KeyByID(ctx, which)
if err != nil {
return "", "", errors.New(l.T("mcp.err.no_such", which))
}
return k.ID, k.Name + " (" + k.Prefix + "…)", nil
case store.ScopeUser:
users, err := s.Users(ctx, "")
if err != nil {
+24
View File
@@ -12,6 +12,7 @@ import (
"slices"
"strings"
"testing"
"time"
"gitea.mynodes.xyz/ilker/llmgw/internal/mcpclient/mcptest"
"gitea.mynodes.xyz/ilker/llmgw/internal/secrets"
@@ -183,3 +184,26 @@ func TestAGrantBelowALevelThatNamesOtherToolsSaysSoAndKeepsWhatItHad(t *testing.
t.Errorf("the team's list is %v; it should keep hr's, which it saw from its organization", l.AllowedTools)
}
}
func TestAnMCPServersFieldsCanBeEmptiedAndItsAddressHoldsNoPassword(t *testing.T) {
mux, st, _ := mcpPage(t, mcpAdmin)
ctx := context.Background()
_ = st.PutMCPServer(ctx, store.MCPServer{Name: "hr", URL: "https://hr/mcp", Description: "people", Enabled: true,
Timeout: 30 * time.Second, RatePerMinute: 10})
mirrorPost(t, mux, "/admin/mcp/hr/edit", url.Values{"csrf": {"tok"}, "url": {"https://hr/mcp"}, "description": {""},
"timeout": {""}, "rate": {""}})
if m, _ := st.MCPServer(ctx, "hr"); m.Description != "" || m.Timeout != 0 || m.RatePerMinute != 0 {
t.Errorf("emptied fields kept: %+v", m)
}
body := mirrorPost(t, mux, "/admin/mcp/add", url.Values{"csrf": {"tok"}, "name": {"db"},
"url": {"https://admin:hunter2@db.internal/mcp"}, "auth": {"none"}}).Body.String()
if _, err := st.MCPServer(ctx, "db"); err == nil || !strings.Contains(body, "user and password in it") {
t.Errorf("an address with a password was kept: %s", body)
}
// A grant to a key that is not there is refused, not said done.
body = mirrorPost(t, mux, "/admin/mcp/hr/grant", url.Values{"csrf": {"tok"}, "scope": {"key"}, "which": {"key-nope"},
"tools": {"hr.*"}}).Body.String()
if !strings.Contains(body, "There is no key-nope") {
t.Errorf("a grant to no key: %s", body)
}
}
+2 -2
View File
@@ -57,16 +57,16 @@
<button type="submit">{{t "mcp.revoke" .Label}}</button></form>
{{end}}{{end}}
{{if not .Local}}
<h3>{{t "mcp.change"}}</h3>
<form method="post" action="/admin/mcp/{{.Name}}/edit">
<input type="hidden" name="csrf" value="{{$.CSRF}}">
<label>{{t "mcp.address"}} <input type="text" inputmode="url" name="url" value="{{.URL}}" required></label>
<label>{{t "mcp.address"}} <input type="text" inputmode="url" name="url" value="{{.URL}}" required{{if .Local}} readonly{{end}}></label>
<label>{{t "mcp.about"}} <input type="text" name="description" value="{{.Description}}"></label>
<label>{{t "mcp.timeout"}} <input type="number" name="timeout" min="0" value="{{if .TimeoutSeconds}}{{.TimeoutSeconds}}{{end}}"></label>
<label>{{t "mcp.rate"}} <input type="number" name="rate" min="0" value="{{if .RatePerMinute}}{{.RatePerMinute}}{{end}}"></label>
<button type="submit">{{t "mcp.save"}}</button>
</form>
{{if not .Local}}
<h3>{{t "mcp.credential"}}</h3>
<form method="post" action="/admin/mcp/{{.Name}}/credential">
<input type="hidden" name="csrf" value="{{$.CSRF}}">