Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

Add link to the contact

fzaninottoacbc06bda2a2
diff --git a/supabase/functions/.env b/supabase/functions/.env
index 6148b846..175d9891 100644
--- a/supabase/functions/.env
+++ b/supabase/functions/.env
@@ -9,3 +9,7 @@ POSTMARK_WEBHOOK_AUTHORIZED_IPS=3.134.147.250,50.31.156.6,50.31.156.77,18.217.20
SB_JWT_ISSUER=http://127.0.0.1:54321/auth/v1
SB_PUBLISHABLE_KEY=sb_publishable_ACJWlzQHlZjBrEguHvfOxg_3BJgxAaH
+
+# Public URL of the CRM app — used by the task-list MCP App to link
+# contact names back to the CRM. Leave empty to render names as plain text.
+CRM_BASE_URL=http://localhost:5173
diff --git a/supabase/functions/mcp/index.ts b/supabase/functions/mcp/index.ts
index d5ac59fc..90addcce 100644
--- a/supabase/functions/mcp/index.ts
+++ b/supabase/functions/mcp/index.ts
@@ -13,6 +13,7 @@ import { corsHeaders } from "../_shared/cors.ts";
const SUPABASE_URL = Deno.env.get("SUPABASE_URL")!;
const SUPABASE_JWT_ISSUER =
Deno.env.get("SB_JWT_ISSUER") ?? `${SUPABASE_URL}/auth/v1`;
+const CRM_BASE_URL = (Deno.env.get("CRM_BASE_URL") ?? "").replace(/\/$/, "");
const JWKS = createRemoteJWKSet(
new URL(`${SUPABASE_URL}/auth/v1/.well-known/jwks.json`),
@@ -398,6 +399,13 @@ Examples:
// --- UI resource for the task-list MCP App ---
+ // Inject the CRM base URL into the task-list guest HTML
+ // so contact names can link back to the CRM
+ const taskListHtml = TASK_LIST_HTML.replace(
+ /__CRM_BASE_URL__/g,
+ CRM_BASE_URL,
+ );
+
server.registerResource(
"task-list-ui",
TASK_LIST_UI_URI,
@@ -411,7 +419,7 @@ Examples:
{
uri: uri.href,
mimeType: "text/html;profile=mcp-app",
- text: TASK_LIST_HTML,
+ text: taskListHtml,
},
],
}),
@@ -439,6 +447,14 @@ Examples:
.nullable()
.optional()
.describe("Full name of the linked contact, if any"),
+ contact_id: z
+ .number()
+ .int()
+ .nullable()
+ .optional()
+ .describe(
+ "Id of the linked contact — used to render the contact name as a link to the CRM contact page",
+ ),
});
type Task = z.infer<typeof taskSchema>;
@@ -450,7 +466,7 @@ Examples:
This tool is presentational: it does not query the database. Fetch the rows yourself via the query tool (joining contacts for contact_name when useful), then pass them here. Prefer this over replying with a bulleted list of tasks.
-Each task should include at least: id (required, used for the mark-as-done action), text, type, due_date, done_date, and optionally contact_name.`,
+Each task should include at least: id (required, used for the mark-as-done action), text, type, due_date, done_date, and optionally contact_name + contact_id (the UI renders the name as a link to the CRM contact page when contact_id is provided).`,
inputSchema: {
tasks: z.array(taskSchema).describe("Array of task objects to render"),
},
diff --git a/supabase/functions/mcp/taskListUi.ts b/supabase/functions/mcp/taskListUi.ts
index 0a74a89b..897737c5 100644
--- a/supabase/functions/mcp/taskListUi.ts
+++ b/supabase/functions/mcp/taskListUi.ts
@@ -31,6 +31,8 @@ export const TASK_LIST_HTML = /*html*/ `
.task-meta { margin-top:3px; font-size:12px; color:#6b7280; display:flex; flex-wrap:wrap; gap:10px; }
.pill { display:inline-block; padding:1px 6px; border-radius:4px; background:rgba(128,128,128,0.22); color:#374151; }
.contact { color:#2563eb; font-weight:500; }
+ a.contact { text-decoration:none; }
+ a.contact:hover { text-decoration:underline; }
.empty { text-align:center; color:#6b7280; padding:16px 8px; }
.error { padding:8px 10px; border-radius:6px; border:1px solid rgba(220,38,38,0.4); background:rgba(220,38,38,0.08); color:#dc2626; font-size:12px; margin-bottom:8px; }
html.dark body { color:#f5f5f5; }
@@ -75,7 +77,14 @@ export const TASK_LIST_HTML = /*html*/ `
<div class="task-content">
<div class="task-text">{{ t.text || '(no description)' }}</div>
<div v-if="t.contact_name || t.type || t.due_date" class="task-meta">
- <span v-if="t.contact_name" class="contact">{{ t.contact_name }}</span>
+ <a
+ v-if="t.contact_name && t.contact_id && contactUrl(t.contact_id)"
+ class="contact"
+ :href="contactUrl(t.contact_id)"
+ target="_blank"
+ rel="noopener noreferrer"
+ >{{ t.contact_name }}</a>
+ <span v-else-if="t.contact_name" class="contact">{{ t.contact_name }}</span>
<span v-if="t.type" class="pill">{{ t.type }}</span>
<span v-if="t.due_date">Due {{ formatDate(t.due_date) }}</span>
</div>
@@ -116,6 +125,11 @@ export const TASK_LIST_HTML = /*html*/ `
const ready = ref(false);
const updating = reactive({});
+ // CRM base URL is injected server-side (empty string when not configured,
+ // in which case contact names render as plain text).
+ const CRM_BASE_URL = '__CRM_BASE_URL__';
+ const contactUrl = (id) => CRM_BASE_URL ? CRM_BASE_URL + '/#/contacts/' + id + '/show' : '';
+
const formatDate = (value) => {
const d = new Date(value);
if (isNaN(d.getTime())) return String(value);
@@ -193,7 +207,7 @@ export const TASK_LIST_HTML = /*html*/ `
post({ jsonrpc: '2.0', method: 'ui/ready' });
});
- return { tasks, error, ready, updating, formatDate, complete };
+ return { tasks, error, ready, updating, formatDate, contactUrl, complete };
},
}).mount('#app');
})();