Open History to see the last commit
1import {
2 AuthProvidersManageScope,
3 AuthSettingsWriteScope,
4 DEFAULT_SERVER_SETTINGS,
5 ProjectId,
6 requiredScopesForServerSettingsPatch,
7 ServerSettings,
8 type McpServerConfig,
9} from "@t3tools/contracts";
10import * as Schema from "effect/Schema";
11import { describe, expect, it } from "vite-plus/test";
12
13import { applyThreadToolOverrides, withThreadToolOverride } from "./agentTools.ts";
14import { resolveProjectSettings } from "./projectSettings.ts";
15import { applyServerSettingsPatch } from "./serverSettings.ts";
16
17const projectId = ProjectId.make("project-a");
18
19const linear: McpServerConfig = {
20 enabled: true,
21 transport: { type: "http", url: "https://mcp.linear.app/mcp", headers: [] },
22};
23const supabase: McpServerConfig = {
24 enabled: true,
25 transport: {
26 type: "stdio",
27 command: "npx",
28 args: ["-y", "@supabase/mcp-server-supabase"],
29 env: [{ name: "SUPABASE_ACCESS_TOKEN", value: "env-token", sensitive: true }],
30 },
31};
32
33describe("project tools overrides", () => {
34 it("merges servers per name so environment servers still reach the project", () => {
35 const projectSupabase: McpServerConfig = {
36 enabled: true,
37 transport: { ...supabase.transport, args: ["--project-ref", "project-db"] } as never,
38 };
39 const settings = {
40 ...DEFAULT_SERVER_SETTINGS,
41 mcpServers: { linear, supabase, sentry: linear },
42 projectSettingsOverrides: {
43 [projectId]: {
44 mcpServers: {
45 // Replaces the environment's server of the same name.
46 supabase: projectSupabase,
47 // Switches an inherited server off without restating it.
48 sentry: { enabled: false },
49 // A switch for a server the environment no longer has is ignored,
50 // including names an object inherits.
51 removed: { enabled: true },
52 constructor: { enabled: true },
53 playwright: {
54 enabled: true,
55 transport: { type: "stdio", command: "npx", args: ["@playwright/mcp"], env: [] },
56 },
57 },
58 },
59 },
60 } satisfies ServerSettings;
61
62 const resolved = resolveProjectSettings(settings, projectId);
63
64 expect(resolved.sources.mcpServers).toBe("project");
65 expect(resolved.settings.mcpServers).toEqual({
66 linear,
67 supabase: projectSupabase,
68 sentry: { ...linear, enabled: false },
69 playwright: {
70 enabled: true,
71 transport: { type: "stdio", command: "npx", args: ["@playwright/mcp"], env: [] },
72 },
73 });
74 });
75
76 it("turns skills off and back on per project over the environment list", () => {
77 const settings = {
78 ...DEFAULT_SERVER_SETTINGS,
79 disabledSkills: ["grill-me", "prepare-pr"],
80 projectSettingsOverrides: {
81 [projectId]: { disabledSkills: { "prepare-pr": false, "expo-deployment": true } },
82 },
83 } satisfies ServerSettings;
84
85 expect(resolveProjectSettings(settings, projectId).settings.disabledSkills).toEqual([
86 "expo-deployment",
87 "grill-me",
88 ]);
89 expect(resolveProjectSettings(settings, null).settings.disabledSkills).toEqual([
90 "grill-me",
91 "prepare-pr",
92 ]);
93 });
94});
95
96describe("thread tool overrides", () => {
97 const effective = {
98 disabledSkills: ["Playwright"],
99 mcpServers: { linear: { ...linear, enabled: false }, supabase },
100 };
101
102 it("lets a thread switch servers and skills either way, skipping servers settings lack", () => {
103 expect(
104 applyThreadToolOverrides(effective, {
105 mcpServers: { linear: true, supabase: false, missing: true },
106 skills: { playwright: true, "grill-me": false },
107 }),
108 ).toEqual({
109 disabledSkills: ["grill-me"],
110 mcpServers: { linear, supabase: { ...supabase, enabled: false } },
111 });
112 });
113
114 it("drops a switch that matches settings, so the thread follows settings again", () => {
115 expect(
116 withThreadToolOverride(
117 { skills: { "grill-me": false } },
118 "mcpServers",
119 "linear",
120 true,
121 false,
122 ),
123 ).toEqual({ skills: { "grill-me": false }, mcpServers: { linear: true } });
124 expect(
125 withThreadToolOverride(
126 { mcpServers: { linear: true } },
127 "mcpServers",
128 "linear",
129 false,
130 false,
131 ),
132 ).toEqual({});
133 // Skill names ignore case, as the sessions read them.
134 expect(
135 withThreadToolOverride({ skills: { Playwright: false } }, "skills", "playwright", true, true),
136 ).toEqual({});
137 });
138});
139
140describe("mcpServers patches", () => {
141 it("replaces one server at a time and removes it with null", () => {
142 const current = { ...DEFAULT_SERVER_SETTINGS, mcpServers: { linear, supabase } };
143 const switched: McpServerConfig = {
144 enabled: true,
145 transport: { type: "http", url: "https://example.com/mcp", headers: [] },
146 };
147
148 const next = applyServerSettingsPatch(current, {
149 mcpServers: { supabase: switched, linear: null },
150 });
151
152 // A stdio server edited into an http one keeps no stdio fields.
153 expect(next.mcpServers).toEqual({ supabase: switched });
154 });
155
156 it("needs provider management to define a server, not to switch one for a project", () => {
157 expect(requiredScopesForServerSettingsPatch({ mcpServers: { linear } })).toEqual([
158 AuthProvidersManageScope,
159 ]);
160 expect(
161 requiredScopesForServerSettingsPatch({
162 projectSettingsOverrides: { [projectId]: { mcpServers: { linear } } },
163 }),
164 ).toEqual([AuthSettingsWriteScope, AuthProvidersManageScope]);
165 expect(
166 requiredScopesForServerSettingsPatch({
167 projectSettingsOverrides: { [projectId]: { mcpServers: { linear: { enabled: false } } } },
168 }),
169 ).toEqual([AuthSettingsWriteScope]);
170 expect(requiredScopesForServerSettingsPatch({ disabledSkills: ["grill-me"] })).toEqual([
171 AuthSettingsWriteScope,
172 ]);
173 });
174
175 it("rejects T3's own server name", () => {
176 const decode = Schema.decodeUnknownExit(ServerSettings);
177 expect(decode({ mcpServers: { "t3-code": linear } })._tag).toBe("Failure");
178 expect(decode({ mcpServers: { linear } })._tag).toBe("Success");
179 });
180});