Join My Newsletter for Regular AI Updates 👇🏼
https://forwardfuture.ai
My Links 🔗
👉🏻 Subscribe:...
Video Transcript:
let me show you how to set up a simple mCP server with a tool and get it running in Claude desktop if you're not familiar with what an mCP server is you can think of it like exposing a tool or set of tools to your AI assistant or agent so I created a tool that counts the number of RS in a given word and so here in Claude desktop I say use the count R tool to count the RS in Strawberry here it says I'll use the count R tool to count the number of R letters in the word straw strawberry there it is the word strawberry contains three letter RS very simple but it should give you the basis to build any tool that you want let me show you how I did it now so the first thing you're going to do is open up your IDE of preference today I'm going to be using wind surf then you're going to open up the terminal so the first thing you're going to do is create a new folder so you can create it anywhere and you just type mkdir and then the folder name so count our server from there hit enter I already have that folder created so then I'm just going to CD into it so count our server then the next thing you're going to do is spin up a new environment so to do that you type Python dmvm dovm and then hit enter Then you activate the environment and if you're on Windows this is how you do itvm back SL scripts back SL activate hit enter and you can see it is activated right there now if you're on a Mac this is how you do it source. vm/ bin SL activate but now you can see there is our environment and there we are in the right folder the next thing you're going to do is install the mCP Library so pip install mCP and then hit enter and then it should install everything you need and now you're ready to write your actual Server create a new file server. py and it's going to be a python file obviously now this is a slightly more complex version of an mCP server than what is absolutely necessary I just put some error handling around it and just a little bit more robustness so let me walk you through what it is the first thing you're going to do is import so from mCP dos server.
fast mCP import fast mCP I also decided to make it a little bit more robust import time import signal import cyst the number of lines you really need to get an mCP server up and running is pretty minimal probably about less than a dozen but again I decided to make it a little bit more robust here we have the signal Handler just giving us some nice out output and handling the control C gracefully this is where the mCP server starts so you want to declare a new variable and it equals fast mCP and here are the parameters you need first you need a name we're going to count it the count R this is what you're going to reference when you're calling the tool so you can in a prompt explicitly say use the count R tool to do this then you're going to give it the host URL so if you're hosting this on a server somewhere this would be different but since I'm running everything locally I'm giving it our local host address 1 12 7001 and I'm going to specify the port at 5,000 I'm also going to give it a 30-second timeout again you probably don't need that but I was running into a lot of issues setting this up so I wanted to really make it resilient then we Define our actual tool and that starts with at mCP do tool open and close parentheses so we have a definition count we're going to be passing in a word that's a string and we're going to Output an integer a little brief definition of what it is and then we're going to do try so if not is instance of a word so just catching if we don't pass in a word then return the word lower count R so it counts the number of letters in the word and returns it as an integer this can be any tool you want you can check the weather using a weather server you can wrap basically any API in this nice template that mCP provides you so any single tool that you want to build this is how you do it and don't forget there are already servers full of mCP tools I found this really nice GitHub repo it's called awesome mCP servers and it's by app Cipher I'll drop this down in the description below and it basically lists a bunch of awesome mCP servers exactly what it sounds like tells you what they do the documentation for it how to use it how to plug it in everything so back to the code if we have an exception we return it then at the end you say if name is equal to Main and then we give it some output so print starting the mCP server and then you do mCP do run and that spins up the server all right so once we have this all written out we can start our server and we do that by typing Python server. py and we see it right here starting SCP starting mCP server count r on and then Local Host 8080 but that's not it we actually have to tell Claude desktop where to find our mCP server and so then we get the Claude desktop config.