How Headless Gives You an AI Head-Start

🔗 **Source:** [How Headless Gives You an AI Head-Start](https://www.youtube.com/watch?v=QfbJ9h2O_GU)
Howdy y'all. I'm Fran and I work in developer relations here at WP Engine with a focus on headless WordPress AI and MCP development. A lot of what I do here is build technical demos, create documentation, and make developer
content that helps people build modern apps and sites. So, I spend a lot of time working across APIs, content systems, agentic workflows, MCPs, and I what I really actually do is enjoy making complex technical ideas easier to understand and actually useful in the real world. But more than anything, this is my mantra, y'all. I'm super stoked about making headless WordPress more powerful, more flexible, and more connected to growing world of AI and
developer tools. Now, I'm going to pass it along to my cohort and one of my favorite people in the world and developers, uh, Terry Goble. >> Thanks, Fran. I'm Teresa, a software engineer at WP Engine, building better business solutions. And my experience includes optimizing backend efficiency, scaling infrastructure, building WordPress plugins, and integrating front-end tools with headless WordPress. Um, I enjoy streamlining systems to bridge gaps between legacy data and modern automated workflows. And when I'm
not uh organizing hackathons and exploring WordPress features, um, I love writing science fiction and bird watching. So, but we're not going to talk about those two things today. We're going to get into how Headless gives you an AI head start. So, why is Headless the prerequisite for modern AI integration? >> Well, Terry, you've asked the correct question to the right guy, and I have the right answer for you. Boy, do I. So,
headless is the prerequisite for modern AI integration because AI systems need structured content and reliable API access. So as you all know in a traditional CMS content is it's often tightly bound right to theme logic page rendering and it makes it harder to retrieve transform and reuse it programmatically. Now trust me when I was in boot camp in a young dev I had the hardest time doing this programmatically but y'all headless. It
solves that by decoupling the content management from presentation and exposing through APIs like REST and love of my life, Terry, GraphQL. You know, I love a good GraphQL API. So, that gives developers a really clean way to feed into LLMs. They'll feed their data into LLMs, vector search, agents, recommendation systems, and multi-channel apps. So if you think about it really the value ad
is not just architectural flexibility but Terry it's a content layer that is usable by the AI systems today and that everchanging ecosystem. So that's that's why >> thanks Fran. It sounds to me like the key point here is data transformation. So let's go ahead and dig into that a little bit further. So as Fran said there is a shift happening. Content is data not pages. So in a traditional monolithic WordPress setup, we have the
content and the layout and the functionality all locked together. But in a headless environment or decoupled architecture, we separate the content management from the display layer. So why does AI care? Well, going back to Fran's point, it's because this turns those pages into modular structured data. So that core shift that Fran was talking about is an adoption of headless WordPress architecture where
organizations convert their content library into a structured reusable content data set instead. Headless WordPress doesn't just manage your content, it provides the content to be actioned by the next generation of uh incredible intelligent systems that are on their way to us. So let's touch base briefly on what trends are shaping the AI tooling landscape. Now I know y'all have gone to uh some of the keynote speakers who have talked at length about
this but a couple of key points to take away from our talk is there's a rise of agentic workflows. The defining shift of 2026 is agentic workflows. Users can now deploy those workers, agentic workers that collaborate in multi- aent systems to solve end-to-end business problems. You'll also see a lot of context engineering versus prompt engineering. This year, the goal has moved away from
writing the perfect prompt to curating the perfect data set for the AI to analyze. We're also touching base on model decentralization. So enterprises are beginning to move away from a one model strategy instead using AI gateways to route tasks to the most effective model per nature of the task. And then of course um sovereign and
vertical AI uh which is the rise of the small language models uh which are trained on proprietary industry data. So uh those of you here who are working on legal or healthcare or finance related um endeavors, you're going to see a lot of those small language models to ensure uh data privacy and high precision. So essentially 2026 um is AI as electricity. So it's
invisible. It's everywhere and it's a fundamental utility upon which all modern business is built. So let's take a look at this infographic which shows us traditional monolithic WordPress compared to headless WordPress and how AI can make a better product and workflow for your team. So this first row we have strategic drivers. So traditional WordPress um has to parse uh AI has to parse the
entire page to find relevant data. In headless WordPress, that same content is structured JSON or GraphQL data, so blocks or custom fields. And the way that AI can make this better is that AI models actually ingest labeled semantic data way better, increasing accuracy and understanding of user intent. We also have a huge one that many of you
are already familiar with, which is that delivery speed. So pages in monolithic traditional WordPress are typically rendered by the server on demand. when we go into headless WordPress territory, the front end is pre-built um or renders client side. And then with that change, APIdriven headless sites can provide substantial increases in speed um especially if they're static. Of course,
we also have multi-channel context um which is consumed by AI um much better in headless. So publishing to apps or assistants in traditional WordPress is difficult. We all know that the API delivers the content anywhere in headless WordPress. the front end adapts the view and so with AI and headless a single piece of content feeds to a retrieval augmented generation for
example and that system then can power multiple types of contexts simultaneously which opens up your options and lastly we have security and scale which is going to be huge coming up over the next several years traditional WordPress the single server handles everything, login, content, traffic spikes, making it a target for DDOS and injection attacks. But headless all by itself, that backend uh the database is
hidden behind other things, the API gateway, a CDN. So that by itself increases security and scale um exponentially. If you deploy an AI agent that, for example, generates thousands of landing pages an hour based on a single WordPress entry, a headless setup can more easily handle that load uh without crashing and can keep you uh at scale and secure. So, that's just a
really general walkthrough of some of the things that um will help you with starting off with AI if you move to a headless structure. Let's talk a little bit about what Fran is about to demo. Now, uh for his demo, there is a core application architecture that includes WordPress admin copilot, WP engines smart search AI, an MCP, which is a smart searched managed content platform server, and then we also have Nex.js uh
API backend in use um coupled with Open AI. >> Thank you so much for handing that off to me, y'all. I'm super stoked. We're going to get into the demo and all those pieces that Terry mentioned, you're going to see it and you're gonna I'm gonna deep dive into the files here. And I have a surprise for y'all. I'm going to drop the bomb today in the session chat description. And as collateral, this demo that I'm doing is an actual howto guide that has been published by
yours truly. So throughout this demo, as you're following along, if you want to follow along, deep dive into the article, you can. So let's get right to it, y'all. So we're in WP Admin now, and let me start this off by showing how this works. Once the plugin is downloaded, this renders a custom chatbot, as you can see here, and then it has an input box. And I'm going to ask about index content right now. So, let's ask about Star
Wars, which I know is in here. So, down here, it's giving you a chat AI chat experience, and it's saying it's sending this response back and this is done through server sent events. And here is the response back
with the data that matches and tracks on what you asked for. It asked for I asked for Star Wars content and it gave me the Mandalorian, a Return of the Jedi movie review and then a uh the Return of the Jedi um triumph scene. So now following up, let me ask it a followup uh query here. Second result.
Awesome. And so it summarized the second result. Uh, as you can see, the document is a review of the MU Return of the Jedi, which tracks on the second result. All right, let's dive into the text stack and see how this works. The first thing is this WP admin copilot right here. This is a custom plugin that I've created. It uh uses PHP and JavaScript and it's just a regular uh custom plugin uh for WordPress.
When you download this plugin, it's going to render this and then it's going to give you an option here on the left hand side menu that says WP Copilot. We click on that and we have our settings and variables that we need in here. The first thing is that agent endpoint URL and I'll show you where that's coming from at the end of this demo. And then we have a shared secret token which is a randomized string that you can make up for your own secret authentication. So
once we have these in place, the other thing that we're going that we need to make this work is the smart search AI MCP server. And within that um the plug-in credentials when you get a smart search AI license you will have that MCP access with the O token right here um next to this GraphQL endpoint and this GraphQL access token. And just for full disclosure at the time I did this demo
the Smart Search AIM MCP was in closed beta. This is why you're not seeing it, but it is an open beta now for everybody to consume. So, you will see that uh on the uh user interface in the WP admin when you do get a smart search license. Next, let's go ahead and go to Visual Studio Code. So, I can discuss the files that are necessary in the next.js application, which acts as the orchestration layer to this AI chatbot
um text stack and how this works. and I'm going to go through three main files here. So, let's dive into Visual Studio Code. I'm going to open my code editor here. There's going to be three main files that I want to go over. The first one is going to live in the lib folder. And this is the mcp.ts file. Let me scroll all the way up to the top here. And this file is the integration layer between our app and the smart search MCP server. So I'm going to go over a couple
of important things in this file. At the top we define TypeScript types for JSON RPC payloads right here and tool arguments search args and fetch args. The main class is smart search MCP client. It stores the MCP URL bearer token and session ID for stateful communication. The key method is called tool which executes MCP tools either search or
fetch. The critical reliability feature here is session recovery. If errors suggest a stale or missing session, it automatically reinitializes and retries once. search wraps call tool and returns both raw payload and normalized results through a defensive parser that handles multiple MCP response formats. Fetch retrieves full documents by ID. So
this file you can think of as the transport and parsing backbone for MCP communication. The next file I want to go over is in the same folder and it's the tools.ts file. Let me click on that. And we're at the top of the file. You can think of this as the bridge um which bridges OpenAI tool calling and our MCP client. So let's go over the most important things in this one.
So here it exports open AI tools. This is the canonical tool list exposed to the model. Smart search search for semantic search with query optional filter and pageionation. Smart search fetch for full document retrieval by ID. Each has strict JSON schema with required fields.
The central function is execute tool. Now this routes by tool name, normalizes arguments, calls the MCP client and updates last search state which is critical for supporting follow-ups like pageionation or summarizing prior results. This file is intentionally thin. It decouples input validation and tool execution from the API route.
If tool interfaces change later, updates happen here without having to rewrite the whole controller. The next file I want to go over is the route.ts file. This is the endpoint uh that is the Nex.js application and we're going to go over to that exact file. Uh this lives in the API folder. Within its subfolder is the chat folder and then it's the route.ts file. So let's break
this down with the most important things within this file. So this file this handles off cores and streams responses over server sent events also known as SSC. The post handler validates origin and token then opens a server sent events stream. Now inside there are three guarded paths. The first one is non-indexed
queries about users, roles or plugins. This gets an immediate limitation message. Second guarded path pageionation requests like show more or use prior query and offset deterministically. And the third guarded path is summarize the nth result which fetches that document and runs a focused open AI call. Now for all other requests it runs
iterative open AAI tool calling as follows. Sends messages to open AAI execute requested tools via execute tool. append tool outputs back into conversation. Repeat up to five rounds and then stream the final answer. So this is the control plane. This secures O takes smart shortcuts and executes a gentic orchestration over SSE.
The last file that I want to show you is the&env.example file. And if you're going to run this locally, you would uh add this into the env.local file. But just for the example, these are the environment variables that you're going to want to keep and copy and paste into your WP Engine headless platform account. These are what make the Nex.js route and the
orchestration layer connect all together with these environments. Now, if you run this locally on Nex.js, JS as you guys know it'll spin up on port 3000 on localhost. So if you were running lo this locally you could copy this endpoint in with the slappi/ chat path into that WPadmin copilot settings and it would run. However you would want this to sustain over a hosted platform
like the headless platform that WP Engine has. And that is the endpoint that I have in uh my WP admin right here. Now if I replace that with localhost 3000/ API/ chat, it'll work as long as that Nex.js local server is running. Now this is the endpoint that's provisioned by the WP Engine headless platform. And let me show you where that
is. So, I'm going to go over to my user portal account here at the WP Engine platform, headless. And this is the first application uh site here. And that is it. That's the endpoint that I pasted into the WP admin to connect the co-pilot. Now, what this is is a git based workflow. um you get commit and push and it updates the WP Engine platform once it's connected to whatever remote repository you have.
Now, just wanted to show you exactly where this is. If I click on main and I go to variables, everything in that environment variable file that's necessary for this application to connect and run via Nex.js and WP admin is in this environment variable um settings input box page. So, that's pretty handy here and it's very easy to use. The other thing, too, is it has other things like a main overview
dashboard of your site's statistics and your last commit, the details. You've got build logs in there, and you've got runtime logs as well. All right, y'all. And that concludes the demo. >> Thank you for that demo, Fran. We hope you've learned something new today. >> Absolutely, Terry. You all are welcome. Don't forget to check out the article. And until then, I'll see you all next time. >> Thank you for watching., How Headless Gives You an AI Head-Start, YouTube, 01kr1g68f8nw8v2m28202v173b.