Skip to content

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

Fix MCP App for Chagpt

fzaninottob458fb44e6ff
diff --git a/supabase/functions/mcp/index.ts b/supabase/functions/mcp/index.ts
index 90addcce..6f1f2b78 100644
--- a/supabase/functions/mcp/index.ts
+++ b/supabase/functions/mcp/index.ts
@@ -483,8 +483,12 @@ Each task should include at least: id (required, used for the mark-as-done actio
console.log(
`[MCP display_task_list] user=${authInfo.userId} count=${tasks.length}`,
);
+ // content carries the display text (used by Claude's guest HTML);
+ // structuredContent carries the typed data (used by ChatGPT's Apps SDK
+ // convention). Supplying both keeps the guest host-agnostic.
return {
content: [{ type: "text" as const, text: JSON.stringify(tasks) }],
+ structuredContent: { tasks },
};
},
);
diff --git a/supabase/functions/mcp/taskListUi.ts b/supabase/functions/mcp/taskListUi.ts
index 1955b099..5f5294eb 100644
--- a/supabase/functions/mcp/taskListUi.ts
+++ b/supabase/functions/mcp/taskListUi.ts
@@ -210,23 +210,55 @@ export const TASK_LIST_HTML = /*html*/ `
});
};
+ // Extract an array of tasks from a tool result, handling the multiple
+ // shapes hosts use. Claude sends the JSON-stringified array in
+ // content[0].text. ChatGPT (OpenAI Apps SDK convention) instead populates
+ // structuredContent with typed data — either the array directly or a
+ // wrapper object like { tasks: [...] }.
+ const extractTasks = (result) => {
+ if (!result) return null;
+ const sc = result.structuredContent;
+ if (Array.isArray(sc)) return sc;
+ if (sc && Array.isArray(sc.tasks)) return sc.tasks;
+ const text = result.content && result.content[0] && result.content[0].text;
+ if (typeof text === 'string' && text.length > 0) {
+ try {
+ const parsed = JSON.parse(text);
+ if (Array.isArray(parsed)) return parsed;
+ if (parsed && Array.isArray(parsed.tasks)) return parsed.tasks;
+ } catch (_) {
+ // fall through
+ }
+ }
+ return null;
+ };
+
const applyToolResult = (result) => {
LOG('applyToolResult', result);
- const text = result && result.content && result.content[0] && result.content[0].text;
- try {
- const parsed = JSON.parse(text || '[]');
- tasks = Array.isArray(parsed) ? parsed : [];
+ const extracted = extractTasks(result);
+ if (extracted) {
+ tasks = extracted;
errorMsg = '';
LOG('parsed tasks', { count: tasks.length });
- } catch (e) {
+ } else {
tasks = [];
- errorMsg = 'Could not parse task list: ' + ((e && e.message) || e);
- LOG('parse error', errorMsg);
+ errorMsg = 'Could not extract task list from tool result';
+ LOG('extract failed', { hasStructured: !!result && !!result.structuredContent });
}
ready = true;
render();
};
+ const applyToolInput = (input) => {
+ const args = input && input.arguments;
+ if (args && Array.isArray(args.tasks)) {
+ tasks = args.tasks;
+ errorMsg = '';
+ ready = true;
+ render();
+ }
+ };
+
// -------- Bootstrap --------
window.addEventListener('message', (event) => {
LOG('message <-', {
@@ -258,18 +290,14 @@ export const TASK_LIST_HTML = /*html*/ `
if (m.method === 'ui/notifications/tool-result') {
LOG('handling tool-result');
applyToolResult(m.params);
- } else if (m.method === 'ui/notifications/tool-input-partial') {
- // Stream partial tool arguments: render progressively so the user sees
- // tasks appear as the model generates them instead of a 10s blank wait.
- const partialTasks = m.params && m.params.arguments && m.params.arguments.tasks;
- if (Array.isArray(partialTasks)) {
- tasks = partialTasks;
- errorMsg = '';
- ready = true;
- render();
- }
- } else if (m.method === 'ui/notifications/tool-input') {
- // Final resolved tool-input arrives just before tool-result; ignore here.
+ } else if (
+ m.method === 'ui/notifications/tool-input-partial' ||
+ m.method === 'ui/notifications/tool-input'
+ ) {
+ // Render progressively from streamed tool arguments so the user sees
+ // tasks appear as the model generates them instead of a blank wait.
+ // Claude uses tool-input-partial; ChatGPT streams via tool-input.
+ applyToolInput(m.params);
} else if (m.method === 'ui/notifications/host-context-changed') {
LOG('host-context-changed', m.params);
const theme = m.params && m.params.theme;