Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 10 additions & 9 deletions apps/app/src/app/lib/openwork-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export type OpenworkMcpItem = {
name: string;
config: Record<string, unknown>;
source: "config.project" | "config.global" | "config.remote";
inherited?: boolean;
disabledByTools?: boolean;
};

Expand Down Expand Up @@ -1036,23 +1037,23 @@ export function createOpenworkServerClient(options: { baseUrl: string; token?: s
method: "POST",
body: payload,
}),
removeMcp: (workspaceId: string, name: string) =>
requestJson<{ items: OpenworkMcpItem[] }>(baseUrl, `/workspace/${workspaceId}/mcp/${encodeURIComponent(name)}`, {
token,
hostToken,
method: "DELETE",
}),
setMcpEnabled: (workspaceId: string, name: string, enabled: boolean) =>
requestJson<{ items: OpenworkMcpItem[] }>(
requestJson<{ items: OpenworkMcpItem[]; enabled: boolean; changed: boolean }>(
baseUrl,
`/workspace/${workspaceId}/mcp/${encodeURIComponent(name)}/enabled`,
`/workspace/${workspaceId}/mcp/${encodeURIComponent(name)}`,
{
token,
hostToken,
method: "POST",
method: "PATCH",
body: { enabled },
},
),
removeMcp: (workspaceId: string, name: string) =>
requestJson<{ items: OpenworkMcpItem[] }>(baseUrl, `/workspace/${workspaceId}/mcp/${encodeURIComponent(name)}`, {
token,
hostToken,
method: "DELETE",
}),

logoutMcpAuth: (workspaceId: string, name: string) =>
requestJson<{ ok: true }>(baseUrl, `/workspace/${workspaceId}/mcp/${encodeURIComponent(name)}/auth`, {
Expand Down
189 changes: 189 additions & 0 deletions apps/app/src/app/mcp.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
import { describe, expect, test } from "bun:test";
import { parse } from "jsonc-parser";

import {
parseEffectiveMcpServersFromContent,
parseMcpServersFromContent,
updateMcpEnabledInConfigContent,
} from "./mcp";

describe("mcp config helpers", () => {
test("updates enabled without changing the MCP config shape", () => {
const updated = updateMcpEnabledInConfigContent(
`{
// keep workspace comments
"mcp": {
"stripe": {
"type": "remote",
"url": "https://example.com/mcp",
"headers": {
"x-team": "payments"
}
}
}
}
`,
"stripe",
false,
);

expect(updated).toContain("// keep workspace comments");
const parsed = parse(updated) as {
mcp: { stripe: { type: string; url: string; enabled: boolean; headers: Record<string, string> } };
};
expect(parsed.mcp.stripe).toEqual({
type: "remote",
url: "https://example.com/mcp",
headers: { "x-team": "payments" },
enabled: false,
});
});

test("parses paused MCP apps as configured entries", () => {
const entries = parseMcpServersFromContent(
JSON.stringify({
mcp: {
stripe: {
type: "remote",
url: "https://example.com/mcp",
enabled: false,
},
},
}),
);

expect(entries).toEqual([
{
name: "stripe",
source: "config.project",
config: {
type: "remote",
url: "https://example.com/mcp",
enabled: false,
},
},
]);
});

test("rejects unknown MCP app names", () => {
expect(() =>
updateMcpEnabledInConfigContent(
JSON.stringify({
mcp: {
stripe: { type: "remote", url: "https://example.com/mcp" },
},
}),
"linear",
false,
),
).toThrow("MCP server not found");
});

test("pauses an inherited global MCP with a minimal workspace override", () => {
const updated = updateMcpEnabledInConfigContent(
"{}\n",
"linear",
false,
{
inheritedMcpServers: [
{
name: "linear",
config: {
type: "remote",
url: "https://example.com/linear",
headers: { Authorization: "Bearer secret" },
},
},
],
},
);

const parsed = parse(updated) as { mcp: { linear: Record<string, unknown> } };
expect(parsed.mcp.linear).toEqual({ enabled: false });
expect(updated).not.toContain("example.com/linear");
expect(updated).not.toContain("secret");
});

test("resumes an inherited global MCP by removing the workspace override", () => {
const updated = updateMcpEnabledInConfigContent(
JSON.stringify({
mcp: {
linear: { enabled: false },
stripe: { type: "remote", url: "https://example.com/stripe" },
},
}),
"linear",
true,
{
inheritedMcpServers: [
{
name: "linear",
config: {
type: "remote",
url: "https://example.com/linear",
},
},
],
},
);

const parsed = parse(updated) as { mcp: Record<string, unknown> };
expect(parsed.mcp.linear).toBeUndefined();
expect(parsed.mcp.stripe).toEqual({ type: "remote", url: "https://example.com/stripe" });
});

test("does not write an override when inherited global MCP is already disabled", () => {
const source = "{}\n";
const updated = updateMcpEnabledInConfigContent(source, "linear", false, {
inheritedMcpServers: [
{
name: "linear",
config: {
type: "remote",
url: "https://example.com/linear",
enabled: false,
},
},
],
});

expect(updated).toBe(source);
});

test("lists inherited global MCPs with workspace pause overrides", () => {
const entries = parseEffectiveMcpServersFromContent(
JSON.stringify({
mcp: {
linear: { enabled: false },
stripe: { type: "remote", url: "https://example.com/stripe" },
},
}),
JSON.stringify({
mcp: {
linear: { type: "remote", url: "https://example.com/linear" },
github: { type: "remote", url: "https://example.com/github" },
},
}),
);

expect(entries).toEqual([
{
name: "linear",
config: { type: "remote", url: "https://example.com/linear", enabled: false },
source: "config.project",
inherited: true,
},
{
name: "github",
config: { type: "remote", url: "https://example.com/github" },
source: "config.global",
inherited: true,
},
{
name: "stripe",
config: { type: "remote", url: "https://example.com/stripe" },
source: "config.project",
},
]);
});
});
Loading
Loading