Complete architecture for a ClickUp/Notion/Miro-class project management app: - Turborepo monorepo with Next.js 15, TypeScript, PostgreSQL (Drizzle ORM) - Object-centered database schema (everything is an Object: tasks, projects, docs, whiteboards) - NextAuth v5 authentication with credentials + OAuth providers - tRPC v11 API layer with full CRUD for objects, properties, relations, templates, search - Three-panel UI: collapsible sidebar, center content area, push-in right panel - Purple/teal theme with light/dark mode via Shadcn/ui + Tailwind CSS - Multiple views: List, Kanban board (dnd-kit), Table (spreadsheet), Embedded iframe - TipTap rich text editor with slash commands, custom blocks (callout, toggle, mention, embed, divider), AI block - Real-time collaboration via Yjs + Hocuspocus with presence/cursors - tldraw whiteboard with custom shape cards (task, document, project) - MCP server exposing all app data/tools for AI agents - AI chat panel, editor AI slash commands, Cmd+K command palette - Template system with built-in templates (Bug Report, Meeting Notes, Sprint) - Full-text search with result highlighting - Docker Compose for full-stack deployment (web + collab + postgres + redis) Made-with: Cursor
125 lines
4 KiB
TypeScript
125 lines
4 KiB
TypeScript
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
import { and, eq } from "../drizzle.js";
|
|
import { z } from "zod";
|
|
import { db } from "../db.js";
|
|
import { objectAssignees, objects, views } from "../schema.js";
|
|
import { viewTypes } from "../shared-types.js";
|
|
import { toolCatch, toolErr, toolOk } from "./tool-result.js";
|
|
|
|
const viewTypeSchema = z.enum(viewTypes as unknown as [string, ...string[]]);
|
|
|
|
const manageObjectInputSchema = z.discriminatedUnion("operation", [
|
|
z.object({
|
|
operation: z.literal("move_object"),
|
|
id: z.string().uuid(),
|
|
newParentId: z.string().uuid().nullable(),
|
|
}),
|
|
z.object({
|
|
operation: z.literal("assign_object"),
|
|
objectId: z.string().uuid(),
|
|
userId: z.string().uuid(),
|
|
role: z.string().optional(),
|
|
action: z.enum(["add", "remove"]),
|
|
}),
|
|
z.object({
|
|
operation: z.literal("create_view"),
|
|
objectId: z.string().uuid(),
|
|
viewType: viewTypeSchema,
|
|
name: z.string().min(1).max(255),
|
|
config: z.record(z.unknown()).optional(),
|
|
}),
|
|
z.object({
|
|
operation: z.literal("apply_template"),
|
|
objectId: z.string().uuid(),
|
|
templateId: z.string().uuid(),
|
|
}),
|
|
]);
|
|
|
|
export function registerManageObjectTool(mcp: McpServer): void {
|
|
mcp.registerTool(
|
|
"manage_object",
|
|
{
|
|
description:
|
|
"Manage objects: move_object (change parent), assign_object (add/remove assignee), create_view, or apply_template (set template on object).",
|
|
inputSchema: manageObjectInputSchema,
|
|
},
|
|
async (args) => {
|
|
try {
|
|
const input = manageObjectInputSchema.parse(args);
|
|
|
|
if (input.operation === "move_object") {
|
|
const [updated] = await db
|
|
.update(objects)
|
|
.set({ parentId: input.newParentId, updatedAt: new Date() })
|
|
.where(eq(objects.id, input.id))
|
|
.returning();
|
|
if (!updated) {
|
|
return toolErr(`Object not found: ${input.id}`);
|
|
}
|
|
return toolOk({ operation: input.operation, object: updated });
|
|
}
|
|
|
|
if (input.operation === "assign_object") {
|
|
if (input.action === "add") {
|
|
const role = input.role ?? "assignee";
|
|
await db
|
|
.insert(objectAssignees)
|
|
.values({
|
|
objectId: input.objectId,
|
|
userId: input.userId,
|
|
role,
|
|
})
|
|
.onConflictDoUpdate({
|
|
target: [objectAssignees.objectId, objectAssignees.userId],
|
|
set: { role },
|
|
});
|
|
return toolOk({ operation: input.operation, action: input.action, ok: true });
|
|
}
|
|
|
|
const deleted = await db
|
|
.delete(objectAssignees)
|
|
.where(
|
|
and(
|
|
eq(objectAssignees.objectId, input.objectId),
|
|
eq(objectAssignees.userId, input.userId),
|
|
),
|
|
)
|
|
.returning();
|
|
return toolOk({
|
|
operation: input.operation,
|
|
action: input.action,
|
|
removed: deleted[0] ?? null,
|
|
});
|
|
}
|
|
|
|
if (input.operation === "create_view") {
|
|
const [created] = await db
|
|
.insert(views)
|
|
.values({
|
|
objectId: input.objectId,
|
|
viewType: input.viewType,
|
|
name: input.name,
|
|
config: input.config ?? null,
|
|
})
|
|
.returning();
|
|
if (!created) {
|
|
return toolErr("Failed to create view");
|
|
}
|
|
return toolOk({ operation: input.operation, view: created });
|
|
}
|
|
|
|
const [updated] = await db
|
|
.update(objects)
|
|
.set({ templateId: input.templateId, updatedAt: new Date() })
|
|
.where(eq(objects.id, input.objectId))
|
|
.returning();
|
|
if (!updated) {
|
|
return toolErr(`Object not found: ${input.objectId}`);
|
|
}
|
|
return toolOk({ operation: input.operation, object: updated });
|
|
} catch (e) {
|
|
return toolCatch(e);
|
|
}
|
|
},
|
|
);
|
|
}
|