The Easiest Way to Use MCP Servers in Laravel

Laravel| 00:08:41|Jun 9, 2026
Chapters5
Introduces MCP servers and how they provide external tools and data to AI agents, upgrading before with a smoother, built-in workflow.

Integrate MCP servers directly into Laravel AI SDK agents to query external tools like Nightwatch without glue code or manual mappings.

Summary

Laravel creator walks through adding MCP servers to the Laravel AI SDK agent, turning external tools into first-class tools inside your dashboard agent. The talk demonstrates wiring an MCP client for Nightwatch, registering it in the app service provider, and enabling OAuth-based authentication so the agent can call Nightwatch’s MCP tools seamlessly. You’ll see how a dashboard agent can query Nightwatch for issues and performance data, with tokens cached for smooth operation. The presenter also shows practical gotchas, such as avoiding production-only functions that exist only in local packages, and confirms that adding MCP servers to the agent’s tools is the simplest way to expose external capabilities. The result is a more powerful, plug-and-play integration where MCP servers behave like any built-in tool your AI SDK uses. The video closes by inviting viewer feedback on which MCP servers they want to wire up next and encouraging experimentation with Nightwatch in Laravel Boost for local development. Overall, it’s a hands-on guide to turning external data sources into effortlessly accessible AI tools within Laravel.

Key Takeaways

  • Register an MCP client in the service provider to avoid duplicating tool definitions in the agent’s tools method.
  • Use OAuth to authorize Nightwatch’s MCP server and define routes for connect and callback in the MCP package.
  • Connect Nightwatch MCP server to your Laravel app by providing the MCP server URL and enabling token-based access from cache.
  • Expose Nightwatch’s tools directly in the dashboard agent so the AI can call them as if they were native tools.
  • Verify Nightwatch data (e.g., latest issue) through the agent to confirm the MCP integration is functioning end-to-end.

Who Is This For?

Laravel developers who want to extend their AI agents with external data sources via MCP servers, especially those using Laravel AI SDK and Nightwatch for project data and performance insights.

Notable Quotes

""MCP servers make it possible for your AI applications to connect to external tools like data and context in a standard way.""
Introducing the core purpose of MCP servers in the video.
""register client night watch here""
Demonstrates registering a Nightwatch MCP client in the service provider.
""we can also provide MCP servers here directly inside our tools method here""
Shows adding MCP servers to the agent’s tools method.
""This MCP server gives us access to our projects inside Nightwatch""
Describes what Nightwatch MCP server exposes.
""the only thing that I had to do is add the all of routes here""
Highlights the OAuth routes setup for MCP connection.

Questions This Video Answers

  • how do I connect an MCP server to a Laravel AI SDK agent?
  • can I use Nightwatch MCP servers with Laravel Boost for local development?
  • what are the steps to authorize an MCP client with OAuth in Laravel?
Laravel AI SDKMCP serversNightwatchOAuthLaravel service providerDashboard agentGitHub MCP serverCodexCursorLaravel Boost
Full Transcript
What if you could use any MCP server in your AI SDK agent? MCP is everywhere right now. MCP servers make it possible for your AI applications to connect to external tools like data and context in a standard way. So, for example, a Night Watch MCP server could expose context about your Laravel application like errors, performance issues, and effective routes. So, if you're already building agents with the Laravel AI SDK, using those MCP servers was not very easy to use. You could make it work, but you had to glue a few things together and map those MCP tools into something your agent could call. Now, this has changed. We are going to work here again with this beautiful The Artisan Supply Shop for every artisan fan. You have these wonderful products here like the Qworker Lunchbox or the Migration Time Machine. Okay, and what we also have here is a dashboard. We have assets manager, we have some customer supports, we have a knowledge base. So, a few things here that we have to handle. And what I've already implemented here is a little helper here, which we can ask about some of our inventories. So, for example, how many products um do we have here? Two typos, that's a must for every talk to your AI. And yeah, you can see we get four products back. Okay, pretty cool. The way that this works is with an dashboard agent here. So, this is a PHP class created with the Laravel AI SDK. So, this is an agent, it's a PHP class that is very specific, that provides specific instruction to the AI. So, yeah, like a specific agent just for our um backend here, providing us with some data information. And we have here some instructions here. And what we also have here provided is tools so that it can check our database as well. So, this is a shop metrics tool. And basically, what we're doing here in the handle method, we're just providing a bunch of numbers here to the AI and if we're asking the AI something where it feels like one of the tools that we provide could help here, then it's going to use those and that's how we got our result back. Okay, so far so good. Um we have seen and done this already a bunch of times, but now we're talking about MCP servers today. And the cool thing about MCP servers is um that they provide you um information and data from specific external tools. So, what this means here is what was a little bit tricky before, but is now way better here with the latest release of the Laravel AI SDK that we can also provide MCP servers here directly inside our tools method here. And for this, we have um our MCP package here and we're just creating a new client uh for example, GitHub and then you can just create it here, provide the URL to the MCP server and just work with it directly here from within your tools, which is pretty cool. We are today also going to work with an MCP server, but we're going to work with the one from Laravel Nightwatch. So, this MCP server gives us access to our projects inside Nightwatch and we can, for example, get the latest issue, see performance um um problems and so on. So, this as an example this MCP server, you can also use it with Laravel Boost for local development or you can also install it with one of your favorite agents like Cloud Code, Codex, Cursor. So, I've been using it with Codex already and then you would install it like this and then you connect it to your application, to your account on Nightwatch and then um Codex has access to it if you need some information about Nightwatch. Now, if you want to do something similar, you want to integrate this inside our shop so that we can also ask here questions about our Nightwatch project on yeah, on Laravel night watch. Okay, how can we do this? Um this needs a little bit more work because we need to work here with OAuth. But we're going to start here in the app service provider. So instead of just um creating a new client inside your tools of the agent, you can also register it first. What I'm doing here. So I'm using the MCP package again, register client night watch here. And then I'm providing here the URL MCP server, which you will also find on the documentation of the night watch MCP server. And I'm also telling here that I want to use OAuth. And the nice thing about registering here in the service provider is first that we don't have to provide everything again inside um the tools here. So we don't need to provide again that we're using OAuth, for example. Okay, so that's the one thing. The other thing, since we're using OAuth, we also need to define some routes here. And from the MCP package, we have this night OAuth routes for method, where we define for which client it is. In this case, it's for night watch. And this method basically creates two routes. The first one is which you can use for a button to click in order to connect it. And the second one is then a callback, which is going to provide this callback here, this closure here. Where we're basically saying Basically, we're doing this. We're putting the access token, which we get here from the OAuth connection, we're um storing this in the cache for specific time. And then I'm returning here back to one of my dashboard pages here. Okay, so these are two things that we need. Here we can use the token um from the cache then in order to connect this, which we then have to do inside our agent here. So I'm bringing this in. [clears throat] All right. So what are we doing here? We are um using our night watch client, which we have already defined. But now we're saying we want to use it with a token. And here we're getting the token from the cache if it is set. And by default, we also say that this should be an array because we are extracting now all the tools here from this um MCP client here so that we can provide all the given tools from Nightwatch here inside our dashboard agent. Okay, of course, I have already in my environment file provided an API key for the Level AI SDK to work. But basically, this should be it. So, let's give this a try. On the admin page, I have this button which I told you about, which is connected to the route which we have defined with the What was it called? OAuth routes form method. So, when we click this now, we go directly to Nightwatch here, and here we have the OAuth workflow here. We can say, "Okay, we want to authorize this." All right, we are back here. We also see this nice little connected button here. And this now means that we're connected to the Nightwatch MCP server, and this means we should also be able to Mhm, show me the latest issue on the Artisan Supply project in Nightwatch. And with a little bit of luck, if we set up everything correctly, we should see something here in just a couple of seconds. Bop bop bop bop bop bop bam. And here we have it. Call to undefined um undefined function. Fake, yeah, where That was where I was trying to see the database, and I was using the fake um global method here, which was not provided on the production environment because this package is only being added to local to um to the local packages. But yeah, if you can as you can see, it's been working. It knows about my Artisan Supply project on Nightwatch. It knows what the issue is, and it can just provide this information to me. Yeah, here where it makes sense in my dashboard agent where I can directly ask about specific things and the only thing that I had to do is add the all of routes here. I had to define and register my MCP server and then bring it just to my cool tools which I think is just the coolest thing that you can just add MCP servers and their tools directly into your Laravel agents, which is just so cool. And this is how it's done. You connect MCP server and its tools to your agent and your Laravel AI SDK agent can use them like any other tool. I really hope you can see how useful this is. Please let me know which MCP servers you're already using or which one you would like to integrate into your Laravel AI SDK agents. Thanks for watching. Hit the like and subscribe button somewhere here as always and see you the next time. Thank you. Bye.

Get daily recaps from
Laravel

AI-powered summaries delivered to your inbox. Save hours every week while staying fully informed.