# Add MCP Server to Any FastAPI App in 5 Minutes

## Метаданные

- **Канал:** Travis Media
- **YouTube:** https://www.youtube.com/watch?v=1GshZTn_6qE

## Содержание

### [0:00](https://www.youtube.com/watch?v=1GshZTn_6qE) Segment 1 (00:00 - 04:00)

Hey everyone. In this short video, I'm going to share how to take your fast API app and easily expose some or all of your endpoints as MCP tools. And you don't have to change anything. You can actually add this MCP capability on top of your API. And if you're like, what's Fast API? I have a video that I'll link to below. It's been a very popular tutorial. Go and check that out as I'll assume you're familiar with it in this video. So, I have this really basic fast API to-do app. There's the traditional get all to-dos route, specific to-dos route, a post, a put, and a delete. And I have a SQL database with like 20 to-dos in it. And what's available now is a package called fast API MCP, which is fast API native, not another open API to MCP converter. And while again, you can create it as an MCP server on its own, a more interesting use case is to add an MCP server to your already existing API and then choose which routes to expose. So, in being able to add this functionality, you can keep your same documentation and schemas, and you essentially just mount your MCP server to the same app, though you can do it separately. Check this out. Here's the documentation, but we'll actually start out in the GitHub repo. First, install the package with pip or UV. I'll run it here. And then, we'll need to import fast API MCP. So, I'll just put that under this. We'll instantiate the fast API MCP. and we'll do an MCP mount. And I'm actually going to do that after we declare all the routes. This is very important. So go all the way down here. And I'm just going to put it here MCP mount. And that's all you have to do to add this MCP package to your FAST API API. Now we'll jump over to the documentation and we'll go to tool naming. And you'll see here that fast API MCP uses the operation ID from your routes as the MCP tool names. If you don't specify one, it autogenerates one, which we don't want. So let's do an operation ID for our gettodos route. That's the only one I want to expose. So I'll just add a comma and add it here. And we'll call it gettodos. Why not? And then if we go to customization, you can see that we can include or exclude endpoints. So I only want that one endpoint. So where I instantiate fast API MCP, I'm going to include only that one operation. So let's go down to that section where it says app, I'll just put a comma and I'll include get to-dos. And that's it, guys. That's all you have to do. So import fast API MCP. Find the route that you want to expose. So for me, that's the to-dos route. And by the way, just to show you that this works, I have the root route, which is welcome to the to-do API. And then I can do /todos. I should get all my to-dos. So the API does have to-dos in the database. It does populate and all of that. And if you need me to upload this to GitHub for any reason, just let me know down in the comments and I'll do that. But yeah, you just add the operation ID to the routes that you want to expose. And then so that all routes are not exposed, include or exclude them here in your instantiation. And then if you go to quick start, you'll notice that your MCP server is at localhost8000/MCB. And then down here, it shows you how to connect to clients that support MCP. So what we're going to do is we're going to take this, we're going to open up Windf, click on the hammer, go to configure, view raw config, and paste that in. And actually, it's not URL, it's server URL. So the docs are wrong, I think. Anyway, save that. Do a refresh and you'll see you have fast API MCP with one tool, which is get to-dos. That's the only one you allowed. So, I can come up here to chat and I can say, "Hey, can you check my to-dos and see if I booked an appointment with my dentist? " Because I can't remember. My to-dos have a completed field, so it should be able to tell. And it says, "Great news. I found your dentist appointment in the to-dos. You've already taken care of it. Completed on May 22nd, 2025. " So, yeah, yesterday. And if I try to do something like, "Can you set this to not completed? " It shouldn't be able to do it. I don't have the ability to update to-dos because I didn't give it that route or didn't expose that route to the MCP server. So, anyway, I thought that was kind of neat. If you have a fast API app and want to add on this MCP server functionality to a route or two, pretty easy to do. If you found this video helpful, let me know. If you like these short kind of here's something I learned videos, let me know down below. If you haven't subscribed to the channel, consider doing so. And I'll see you in the next video.

---
*Источник: https://ekstraktznaniy.ru/video/32658*