mirror of
https://github.com/PerpetualSoftware/pad.git
synced 2026-10-26 22:37:03 +00:00
e43bd7b858
* feat: the console MCP section, and Connected Apps follows OAuth (TASK-3303, PLAN-2310 U5) The admin Settings page gains "MCP for agents": the toggle (saved on click; disabled with "set by environment (PAD_MCP_ENABLED)" or "managed by the operator" when locked) and the GET /api/v1/admin/mcp readout: state (on, off, or blocked with the reason), public origin and where it came from, MCP URL, https, how agents sign in, and while off, what would resume (nothing was revoked). The session, setup and admin stats payloads carry mcp_available and oauth_available (per request). Connected Apps keys on oauthAvailable instead of cloud mode, and the admin MCP Audit tab is always shown to admins, with "No MCP activity recorded" as its empty state. Claude-Session: https://claude.ai/code/session_01NidgPePY7UvHcEJCMkD2Qz * fix(web): the MCP Off state no longer overstates what the routes answer (TASK-3303, codex r1) Claude-Session: https://claude.ai/code/session_01NidgPePY7UvHcEJCMkD2Qz * feat(web): the MCP toggle saves with an explicit Save, like the page's other sections (TASK-3303, lead ruling) Claude-Session: https://claude.ai/code/session_01NidgPePY7UvHcEJCMkD2Qz * fix(web): 'off by default' is a self-host fact (TASK-3303, codex r3 nit) Claude-Session: https://claude.ai/code/session_01NidgPePY7UvHcEJCMkD2Qz
64 lines
1.9 KiB
Go
64 lines
1.9 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/PerpetualSoftware/pad/internal/config"
|
|
)
|
|
|
|
// PLAN-2310 DR-7 (TASK-3303): the session payload and the admin stats carry
|
|
// mcp_available and oauth_available, evaluated per request, so the console can
|
|
// key Connected Apps on the OAuth path rather than on cloud mode.
|
|
func TestMCPAvailabilityInPayloads(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
url string
|
|
on bool
|
|
withOAuth bool
|
|
mcp, oauth bool
|
|
}{
|
|
{"off", "https://pad.example.com", false, true, false, false},
|
|
{"on, https, OAuth built", "https://pad.example.com", true, true, true, true},
|
|
{"on, http", "http://10.0.0.5:7777", true, false, true, false},
|
|
{"on, no origin", "", true, false, false, false},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
srv, token := mcpServer(t, config.Config{URL: c.url}, nil)
|
|
if c.withOAuth {
|
|
o, err := newTestOAuthServer(t, srv)
|
|
if err != nil {
|
|
t.Fatalf("oauth: %v", err)
|
|
}
|
|
srv.oauthServer = o
|
|
}
|
|
if c.on {
|
|
if err := srv.store.SetPlatformSetting(settingMCPEnabled, "true"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
for _, path := range []string{"/api/v1/auth/session", "/api/v1/admin/stats"} {
|
|
rr := doRequestWithCookie(srv, "GET", path, nil, token)
|
|
if rr.Code != http.StatusOK {
|
|
t.Fatalf("%s: %d %s", path, rr.Code, rr.Body.String())
|
|
}
|
|
var got struct {
|
|
MCP *bool `json:"mcp_available"`
|
|
OAuth *bool `json:"oauth_available"`
|
|
}
|
|
if err := json.Unmarshal(rr.Body.Bytes(), &got); err != nil {
|
|
t.Fatalf("%s: %v", path, err)
|
|
}
|
|
if got.MCP == nil || got.OAuth == nil {
|
|
t.Fatalf("%s: fields missing: %s", path, rr.Body.String())
|
|
}
|
|
if *got.MCP != c.mcp || *got.OAuth != c.oauth {
|
|
t.Errorf("%s: mcp=%v oauth=%v, want %v %v", path, *got.MCP, *got.OAuth, c.mcp, c.oauth)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|