File size: 2,341 Bytes
4e7644b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { describe, expect, it, vi, afterEach } from "vitest";
import { mcpApi } from "./mcp";
import { request } from "../request";

vi.mock("../request", () => ({ request: vi.fn() }));

describe("mcpApi policy endpoints", () => {
  afterEach(() => vi.clearAllMocks());

  it("gets MCP policy from the policy endpoint", async () => {
    vi.mocked(request).mockResolvedValue({
      default_effect: "ask",
      client_overrides: [],
      tool_defaults: [],
      tool_overrides: [],
      unmanaged_rules_count: 0,
    });

    await mcpApi.getMCPPolicy("local_stdio_echo");

    expect(request).toHaveBeenCalledWith("/mcp/policy/local_stdio_echo");
  });

  it("updates MCP policy through the policy endpoint", async () => {
    vi.mocked(request).mockResolvedValue({
      default_effect: "ask",
      client_overrides: [],
      tool_defaults: [],
      tool_overrides: [],
      unmanaged_rules_count: 0,
    });

    await mcpApi.updateMCPPolicy("local_stdio_echo", {
      default_effect: "ask",
      client_overrides: [
        {
          source_type: "channel",
          source_value: "console",
          subject_type: "all",
          subject_value: "",
          effect: "allow",
        },
      ],
      tool_defaults: [{ tool_name: "echo", effect: "ask" }],
      tool_overrides: [
        {
          tool_name: "echo",
          source_type: "channel",
          source_value: "dingtalk",
          subject_type: "user",
          subject_value: "alice",
          effect: "allow",
        },
      ],
      unmanaged_rules_count: 0,
    });

    expect(request).toHaveBeenCalledWith("/mcp/policy/local_stdio_echo", {
      method: "PUT",
      body: JSON.stringify({
        default_effect: "ask",
        client_overrides: [
          {
            source_type: "channel",
            source_value: "console",
            subject_type: "all",
            subject_value: "",
            effect: "allow",
          },
        ],
        tool_defaults: [{ tool_name: "echo", effect: "ask" }],
        tool_overrides: [
          {
            tool_name: "echo",
            source_type: "channel",
            source_value: "dingtalk",
            subject_type: "user",
            subject_value: "alice",
            effect: "allow",
          },
        ],
        unmanaged_rules_count: 0,
      }),
    });
  });
});