Blog

Browse by Category

* controller.abort(), { once: true }); // ── Tool 1: Get practice information ──────────────────────────────────── navigator.modelContext.registerTool({ name: "get_practice_info", description: "Get information about Dr. Peter H. Addy's psychedelic-informed psychotherapy practice, including bio, credentials (LPC, PhD), specializations, and how to get in touch.", inputSchema: { type: "object", properties: {}, required: [], }, signal, execute: async () => { try { const [aboutPages, contactPages] = await Promise.all([ fetch("/wp-json/wp/v2/pages?slug=about&_fields=title,content,excerpt,link") .then((r) => r.json()) .catch(() => []), fetch("/wp-json/wp/v2/pages?slug=contact&_fields=title,content,link") .then((r) => r.json()) .catch(() => []), ]); return { name: "Dr. Peter H. Addy, LPC, PhD", specialization: "Psychedelic-Informed Psychotherapy", site: "https://peterhaddy.com", about: aboutPages[0] ? { title: stripHtml(aboutPages[0].title?.rendered), excerpt: stripHtml(aboutPages[0].excerpt?.rendered), url: aboutPages[0].link, } : null, contact: contactPages[0] ? { url: contactPages[0].link } : { url: "https://peterhaddy.com/contact/" }, }; } catch (err) { return { error: err.message }; } }, }); // ── Tool 2: Search site content ────────────────────────────────────────── navigator.modelContext.registerTool({ name: "search_content", description: "Search Dr. Addy's published articles and pages about psychedelic therapy, MDMA, psilocybin, ketamine, mental health, trauma, PTSD, and related topics.", inputSchema: { type: "object", properties: { query: { type: "string", description: 'Search terms, e.g. "MDMA therapy", "psilocybin depression", "ketamine"', }, limit: { type: "number", description: "Max results to return (default: 5, max: 20)", }, }, required: ["query"], }, signal, execute: async ({ query, limit = 5 }) => { const n = Math.min(Number(limit) || 5, 20); const q = encodeURIComponent(query); const fields = "_fields=id,title,excerpt,link,type,date"; try { const [posts, pages] = await Promise.all([ fetch(`/wp-json/wp/v2/posts?search=${q}&per_page=${n}&${fields}`) .then((r) => r.json()) .catch(() => []), fetch(`/wp-json/wp/v2/pages?search=${q}&per_page=${n}&${fields}`) .then((r) => r.json()) .catch(() => []), ]); const results = [...posts, ...pages] .slice(0, n) .map((item) => ({ title: stripHtml(item.title?.rendered), excerpt: stripHtml(item.excerpt?.rendered), url: item.link, type: item.type, date: item.date, })); return { query, count: results.length, results }; } catch (err) { return { query, error: err.message, results: [] }; } }, }); // ── Tool 3: Get recent articles ────────────────────────────────────────── navigator.modelContext.registerTool({ name: "get_recent_articles", description: "Get the most recent articles and blog posts from Dr. Addy about psychedelic therapy and mental health.", inputSchema: { type: "object", properties: { count: { type: "number", description: "Number of articles to return (default: 5, max: 20)", }, }, required: [], }, signal, execute: async ({ count = 5 }) => { const n = Math.min(Number(count) || 5, 20); try { const posts = await fetch( `/wp-json/wp/v2/posts?per_page=${n}&_fields=title,excerpt,link,date,categories` ) .then((r) => r.json()) .catch(() => []); return posts.map((p) => ({ title: stripHtml(p.title?.rendered), excerpt: stripHtml(p.excerpt?.rendered), url: p.link, date: p.date, })); } catch (err) { return { error: err.message }; } }, }); // ── Helper ─────────────────────────────────────────────────────────────── function stripHtml(html) { if (!html) return ""; return html .replace(/<[^>]+>/g, " ") .replace(/\s+/g, " ") .trim(); } })();