Skip to content
Merged
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ Agent products that act in your tools share three problems: approvals that live
- Built-in Google Sheets: read any sheet by link, add rows, update cells and create spreadsheets, each write shown as a table on the approval card ("save the invoice from that email and add its total to my Expenses sheet")
- Automations triggered by a cron schedule, new Gmail messages matching a search, or a secret webhook URL
- Reminders and follow-ups from chat: "remind me Friday at 9 to send the report" notifies you by push, Slack or email at that time; "in 3 days, check whether Sam replied and nudge him if not" brings the agent back to the same conversation, with its context, to do it. One-off or repeating, in your time zone, listed (and cancellable) under Automations. Scheduling from a task that read an email or web page always asks first, so outside content can't plant a scheduled instruction ([how it works](docs/api.md#scheduled-from-chat))
- MCP connections over Streamable HTTP with OAuth 2.1 + PKCE, or bearer tokens; presets for GitHub, Linear, Notion, Atlassian, Sentry
- An app directory of 41 remote MCP servers that connect in one click (Notion, Jira and Confluence, Asana, Stripe, Intercom, Granola, Supabase, Sentry and more), each with starter asks; sign-in happens on the app's own site and its tools fall under your approval rules
- Any other MCP server over Streamable HTTP, with OAuth 2.1 + PKCE or a bearer token
- Approval inbox, editable approvals, deny-with-reason, cancel now / after this step
- Approve a plan, not every step: the agent proposes the exact actions it will take, you untick what you don't want, and the kept actions run without asking again (even after the task read outside content, because you saw each one, unless a step names a recipient that first appeared in that content)
- Several pending actions from one step can be ticked and signed off together
Expand Down
114 changes: 114 additions & 0 deletions apps/server/src/catalog.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { afterAll, beforeAll, expect, test } from "bun:test";
import { schema } from "@synapse/db";
import { createApp } from "./app";
import { APP_CATEGORIES, CATALOG, catalogAppFor, sameServer } from "./catalog";
import { loadConfig } from "./config";
import { createServices, type Services } from "./services";

let services: Services;
let app: ReturnType<typeof createApp>;
const ORIGIN = "http://localhost:3000";

beforeAll(async () => {
services = await createServices(
loadConfig({
NODE_ENV: "test",
DATABASE_URL: "pglite://memory",
SYNAPSE_SECRET: "t".repeat(40),
PUBLIC_URL: ORIGIN,
}),
);
app = createApp(services);
});
afterAll(() => services.close());

async function signUp(email: string) {
const res = await app.request("/api/auth/sign-up/email", {
method: "POST",
headers: { "content-type": "application/json", origin: ORIGIN },
body: JSON.stringify({ email, password: "correct horse battery", name: "Ada" }),
});
expect(res.status).toBe(200);
const cookie = res.headers
.getSetCookie()
.map((c) => c.split(";")[0])
.join("; ");
const userId = ((await res.json()) as { user: { id: string } }).user.id;
const call = async (path: string, method = "GET") => {
const r = await app.request(path, { method, headers: { cookie, origin: ORIGIN } });
const text = await r.text();
// biome-ignore lint/suspicious/noExplicitAny: test responses are loosely typed JSON
return { status: r.status, json: text ? (JSON.parse(text) as Record<string, any>) : null };
};
return { userId, call };
}

test("every directory entry is connectable as listed", () => {
const ids = new Set<string>();
for (const a of CATALOG) {
// The id becomes the connection name: the same rule POST /api/connections enforces.
expect(a.id).toMatch(/^[a-z0-9][a-z0-9-]*$/);
expect(ids.has(a.id)).toBe(false);
ids.add(a.id);
expect(new URL(a.url).protocol).toBe("https:");
expect(APP_CATEGORIES).toContain(a.category);
expect(a.examples.length).toBeGreaterThan(0);
expect(CATALOG.filter((b) => sameServer(a.url, b.url))).toHaveLength(1);
}
for (const c of APP_CATEGORIES) expect(CATALOG.some((a) => a.category === c)).toBe(true);
});

test("sameServer ignores host case and trailing slashes, nothing else", () => {
expect(sameServer("https://mcp.notion.com/mcp", "https://MCP.notion.com/mcp/")).toBe(true);
expect(sameServer("https://mcp.stripe.com", "https://mcp.stripe.com/")).toBe(true);
expect(sameServer("https://mcp.notion.com/mcp", "https://mcp.notion.com/sse")).toBe(false);
expect(sameServer("https://mcp.notion.com/mcp", "http://mcp.notion.com/mcp")).toBe(false);
expect(catalogAppFor("https://mcp.notion.com/mcp/")?.id).toBe("notion");
});

test("directory marks what you've connected; connecting twice or unknown apps is refused", async () => {
const ada = await signUp("ada-directory@example.com");
const bob = await signUp("bob-directory@example.com");

const before = await ada.call("/api/connections/catalog");
expect(before.status).toBe(200);
expect(before.json!.categories).toEqual(APP_CATEGORIES);
expect(before.json!.apps).toHaveLength(CATALOG.length);
expect(before.json!.apps.every((a: { connectionId: unknown }) => a.connectionId === null)).toBe(
true,
);

// Connected earlier by hand, under another name and a slightly different URL.
const [row] = await services.database.db
.insert(schema.connections)
.values({
userId: ada.userId,
name: "my notes",
url: "https://MCP.notion.com/mcp/",
status: "disabled",
auth: { type: "none" },
})
.returning();

const after = await ada.call("/api/connections/catalog");
const notion = after.json!.apps.find((a: { id: string }) => a.id === "notion");
expect(notion.connectionId).toBe(row!.id);
// Someone else's connections don't count.
const theirs = await bob.call("/api/connections/catalog");
expect(theirs.json!.apps.find((a: { id: string }) => a.id === "notion").connectionId).toBe(null);

const again = await ada.call("/api/connections/catalog/notion", "POST");
expect(again.status).toBe(409);
expect(again.json!.error.message).toContain("Notion is already connected");

const unknown = await ada.call("/api/connections/catalog/not-an-app", "POST");
expect(unknown.status).toBe(404);

// The connection list names it the way the directory does and carries its starter asks.
const list = await ada.call("/api/connections");
expect(list.json!.connections[0]).toMatchObject({
name: "my notes",
title: "Notion",
examples: CATALOG.find((a) => a.id === "notion")!.examples,
});
});
Loading
Loading