A full-featured CRM built with React, shadcn/ui, and Supabase.
Add MCP server URL to profile
fzaninotto8115c54706f9
diff --git a/src/components/atomic-crm/providers/commons/englishCrmMessages.ts b/src/components/atomic-crm/providers/commons/englishCrmMessages.tsindex 71904a42..2b42a059 100644--- a/src/components/atomic-crm/providers/commons/englishCrmMessages.ts+++ b/src/components/atomic-crm/providers/commons/englishCrmMessages.ts@@ -522,6 +522,11 @@ export const englishCrmMessages = {"You can start sending emails to your server's inbound email address, e.g. by adding it to the %{field} field. Atomic CRM will process the emails and add notes to the corresponding contacts.",title: "Inbound email",},+ mcp: {+ title: "MCP Server",+ description:+ "Use this URL to connect your AI assistant to your CRM data via the Model Context Protocol (MCP).",+ },password: {change: "Change password",},diff --git a/src/components/atomic-crm/providers/commons/frenchCrmMessages.ts b/src/components/atomic-crm/providers/commons/frenchCrmMessages.tsindex 26b16fc8..a0f41891 100644--- a/src/components/atomic-crm/providers/commons/frenchCrmMessages.ts+++ b/src/components/atomic-crm/providers/commons/frenchCrmMessages.ts@@ -529,6 +529,11 @@ export const frenchCrmMessages = {"Vous pouvez commencer à envoyer des e-mails vers l'adresse de réception de votre serveur, par exemple en l'ajoutant au champ %{field}. Atomic CRM traitera les e-mails et ajoutera des notes aux contacts correspondants.",title: "E-mail entrant",},+ mcp: {+ title: "Serveur MCP",+ description:+ "Utilisez cette URL pour connecter votre assistant IA aux données de votre CRM via le Model Context Protocol (MCP).",+ },password: {change: "Changer le mot de passe",},diff --git a/src/components/atomic-crm/settings/ProfilePage.tsx b/src/components/atomic-crm/settings/ProfilePage.tsxindex c045a314..4aae578d 100644--- a/src/components/atomic-crm/settings/ProfilePage.tsx+++ b/src/components/atomic-crm/settings/ProfilePage.tsx@@ -1,5 +1,5 @@import { useMutation } from "@tanstack/react-query";-import { CircleX, Copy, Pencil, Save } from "lucide-react";+import { Check, CircleX, Copy, Pencil, Save } from "lucide-react";import {Form,useDataProvider,@@ -243,11 +243,30 @@ const ProfileForm = ({field: "Cc:",})}</p>- <CopyPaste />+ <CopyPaste value={import.meta.env.VITE_INBOUND_EMAIL} /></div></CardContent></Card>)}+ <Card>+ <CardContent>+ <div className="space-y-4 justify-between">+ <h2 className="text-xl font-semibold text-muted-foreground">+ {translate("crm.profile.mcp.title", {+ _: "MCP Server",+ })}+ </h2>+ <p className="text-sm text-muted-foreground">+ {translate("crm.profile.mcp.description", {+ _: "Use this URL to connect your AI assistant to your CRM data via the Model Context Protocol (MCP).",+ })}+ </p>+ <CopyPaste+ value={`${import.meta.env.VITE_SUPABASE_URL}/functions/v1/mcp`}+ />+ </div>+ </CardContent>+ </Card></div>);};@@ -309,12 +328,12 @@ const TextRender = ({);};-const CopyPaste = () => {+const CopyPaste = ({ value }: { value: string }) => {const translate = useTranslate();const [copied, setCopied] = useState(false);const handleCopy = () => {setCopied(true);- navigator.clipboard.writeText(import.meta.env.VITE_INBOUND_EMAIL);+ navigator.clipboard.writeText(value);setTimeout(() => {setCopied(false);}, 1500);@@ -329,10 +348,12 @@ const CopyPaste = () => {variant="ghost"className="normal-case justify-between w-full">- <span className="overflow-hidden text-ellipsis">- {import.meta.env.VITE_INBOUND_EMAIL}- </span>- <Copy className="h-4 w-4 ml-2" />+ <span className="overflow-hidden text-ellipsis">{value}</span>+ {copied ? (+ <Check className="h-4 w-4 ml-2" />+ ) : (+ <Copy className="h-4 w-4 ml-2" />+ )}</Button></TooltipTrigger><TooltipContent>diff --git a/src/components/atomic-crm/settings/SettingsPageMobile.tsx b/src/components/atomic-crm/settings/SettingsPageMobile.tsxindex 7f92addc..b2a6769a 100644--- a/src/components/atomic-crm/settings/SettingsPageMobile.tsx+++ b/src/components/atomic-crm/settings/SettingsPageMobile.tsx@@ -18,7 +18,7 @@ import {SelectValue,} from "@/components/ui/select";import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";-import { Copy, LogOut, Moon, Smartphone, Sun } from "lucide-react";+import { Check, Copy, LogOut, Moon, Smartphone, Sun } from "lucide-react";import {Form,Translate,@@ -108,6 +108,7 @@ export const SettingsPageMobile = () => {<ProfileSection /><PreferencesSection /><InboundEmailSection />+ <McpServerSection /></div><div className="mt-auto pt-6 space-y-3">@@ -464,18 +465,40 @@ const InboundEmailSection = () => {})}</p><ItemGroup className="rounded-lg border overflow-hidden">- <CopyPasteRow />+ <CopyPasteRow value={import.meta.env.VITE_INBOUND_EMAIL} /></ItemGroup></div>);};-const CopyPasteRow = () => {+const McpServerSection = () => {+ const translate = useTranslate();++ return (+ <div>+ <SectionLabel>+ {translate("crm.profile.mcp.title", { _: "MCP Server" })}+ </SectionLabel>+ <p className="text-sm text-muted-foreground mb-2 px-1">+ {translate("crm.profile.mcp.description", {+ _: "Use this URL to connect your AI assistant to your CRM data via the Model Context Protocol (MCP).",+ })}+ </p>+ <ItemGroup className="rounded-lg border overflow-hidden">+ <CopyPasteRow+ value={`${import.meta.env.VITE_SUPABASE_URL}/functions/v1/mcp`}+ />+ </ItemGroup>+ </div>+ );+};++const CopyPasteRow = ({ value }: { value: string }) => {const translate = useTranslate();const [copied, setCopied] = useState(false);const handleCopy = () => {setCopied(true);- navigator.clipboard.writeText(import.meta.env.VITE_INBOUND_EMAIL);+ navigator.clipboard.writeText(value);setTimeout(() => {setCopied(false);}, 1500);@@ -491,12 +514,14 @@ const CopyPasteRow = () => {onClick={handleCopy}><ItemContent className="overflow-hidden">- <ItemTitle className="font-normal truncate">- {import.meta.env.VITE_INBOUND_EMAIL}- </ItemTitle>+ <ItemTitle className="font-normal truncate">{value}</ItemTitle></ItemContent><ItemActions className="shrink-0">- <Copy className="size-4 text-muted-foreground" />+ {copied ? (+ <Check className="size-4 text-muted-foreground" />+ ) : (+ <Copy className="size-4 text-muted-foreground" />+ )}</ItemActions></Item></TooltipTrigger>diff --git a/supabase/functions/mcp/index.ts b/supabase/functions/mcp/index.tsindex 9259a0c0..2e76f8f1 100644--- a/supabase/functions/mcp/index.ts+++ b/supabase/functions/mcp/index.ts@@ -278,7 +278,7 @@ function createMcpServer(authInfo: AuthInfo): McpServer {server.tool("get_schema",- "Retrieve the database schema including all tables, views, columns, types, and foreign key relationships. Views (like contacts_summary, companies_summary) are read-only and provide pre-joined/aggregated data. Use them for search and list queries.",+ "Retrieve the database schema for the user's Atomic CRM instance including all tables, views, columns, types, and foreign key relationships. Views (like contacts_summary, companies_summary) are read-only and provide pre-joined/aggregated data. Use them for search and list queries.",{},async () => {const schema = await getSchemaData();@@ -288,9 +288,31 @@ function createMcpServer(authInfo: AuthInfo): McpServer {server.tool("query",- "Execute a SQL query against the CRM database. The query runs with Row Level Security (RLS) enforced for the authenticated user. Supports SELECT, INSERT, UPDATE, DELETE. Use *_summary views for aggregated/search data. IMPORTANT: Never specify sales_id in INSERT or UPDATE statements — it is automatically set to the authenticated user by a database trigger. Examples: SELECT id, first_name, last_name FROM contacts_summary WHERE email_fts LIKE '%@company.com%'; INSERT INTO contact_notes (contact_id, text, date, status) VALUES (1, 'Called client', NOW(), 'cold')",+ `Query data from the user's CRM instance using SQL.++IMPORTANT: Before using this tool, you MUST call the get_schema tool first to understand what tables and columns are available in the database.++Use this tool when the user asks about their CRM data such as:+- Contacts, companies, and deals+- Sales pipeline and forecasting data+- Customer interactions and notes+- Tasks and follow-ups+- Custom fields and metadata++Row Level Security (RLS) is enforced - queries automatically return only data the authenticated user has permission to access.++Note: Use the *_summary views (contacts_summary, companies_summary) for queries that need aggregated data or search capabilities.++IMPORTANT: Never specify sales_id in INSERT or UPDATE statements — it is automatically set to the authenticated user by a database trigger.++Examples:+- "SELECT id, first_name, last_name, email_fts FROM contacts_summary WHERE email_fts LIKE '%@company.com%'"+- "SELECT name, stage, amount FROM deals WHERE created_at > NOW() - INTERVAL '30 days' ORDER BY amount DESC"+- "SELECT COUNT(*) as total_tasks, type FROM tasks WHERE done_date IS NULL GROUP BY type"+- "SELECT c.first_name, c.last_name, co.name as company_name FROM contacts c JOIN companies co ON c.company_id = co.id WHERE co.sector = 'Technology'"`,{ sql: z.string().describe("The SQL query to execute") },- async ({ sql }) => {+ async ({ sql }: { sql: string }) => {+ // eslint-disable-next-line no-consoleconsole.log(`[MCP query] user=${authInfo.userId} sql=${sql}`);const result = await executeQueryWithRLS(sql, authInfo.token);if (result.success) {