TRANSKRYPCJA VIDEO
A step-by-step guide was provided on setting up an MCP server using a single TypeScript file without a build step. The process involved initializing the server, adding a tool named getWeather with a Zod schema for city input, and connecting the server to Claude code through standard I/O. By running the necessary commands, the server was successfully added to the global configuration, allowing communication with Claude. This setup enables running scripts locally and expanding the toolset seamlessly within the local Claude instance.
I'm going to show you the simplest way you can set up an MCP server. We're going to create an MCP server, connect it to Claude code, and then we can use our server to run any script we want. And we're going to do this all with a single TypeScript file and no build step. We're going to start by creating a main. ts file. And inside here, we're going to initialize an MCP server. We're getting this MCP server from the model context protocol SDK package. We're now going to add a tool to our server. We're going to give the tool a name, in this case. getWeather. Next, we're going to describe the arguments that the tool receives.
In this case, it's going to be a city, which we're describing with a Zod schema. Finally, we add a callback function here that runs when the tool is actually called. We receive the city as a string, and then we return an array of content where we have type text.
and the weather in city is sunny if we were implementing this for real this would be an async function so we could call an actual weather api in here and just like that our server is complete a server with a name and a single tool called get weather but we need some way for claude code to actually communicate with our server it's going to do the communication through standard i o so we're going to import standard i o server transport then we initialize the transport down here and connect the server to the transport to add our new mcp server to Claude, we're going to run claude mcp add. We'll enter through this. Then our server name is going to be called weather example here.
I'm going to make it available globally. Why not? And the command I'm going to run here is npx. npx lets me run any terminal command from npm. Then using npx, I'm going to use tsx here. And as my second argument, I'm going to pass in the entire path of the file. And as we can see, our server weather example has been added to the global configuration. Let's now try running claude. We can see that Claude has connected to the WeatherExample MCP server. I'll ask it, get the weather in Oxford. And as we can see, it says, WeatherExample, get weather, the weather in Oxford is sunny.
So amazingly, just with this simple text input, it knew which tool to call, and it returned the output from our function. This is so exciting because it means we can continue adding tools into our local setup, and our local Claude instance will just immediately know about them. So if you have anything you need to run locally, like Docker setup or Git commands, or database migrations, then you can just tell Claude Code about them and it can run them for you. If you want the code for all this stuff, then it's on AIhero. dev and I will link it down below. I'm going to be coming out with more MCP content as well as some proper courses soon. So I'll see you very soon. .
Informujemy, że odwiedzając lub korzystając z naszego serwisu, wyrażasz zgodę aby nasz serwis lub serwisy naszych partnerów używały plików cookies do przechowywania informacji w celu dostarczenie lepszych, szybszych i bezpieczniejszych usług oraz w celach marketingowych.