Getting started
JavaScript (Node)
Want to teach an AI how to check the weather? You're in the right place. This guide walks you through building a simple tool using the Model Context Protocol (MCP), which lets your code talk directly to AI assistants.
We'll use Claude Desktop as an example AI client in this guide because it has built-in support for MCP — but the tool you build can work with any AI that understands MCP, like ChatGPT Desktop or Raycast AI, for example.
You'll need to use Hackatime to track your coding time. Hackatime works on all major code editors.
Set it up with the instructions here: https://hackatime.hackclub.com
In short, MCP (Model Context Protocol) servers allow AI to connect to real tools. Think of it as USB ports for AI apps.
Here's how it works:
We'll be writing this in JavaScript with NodeJS. You can install NodeJS from https://nodejs.org/
I'm going to call my project mcp-weather-server
.
In a new folder called your project name, let's initialize a project.
Install the MCP SDK:
If you're on an older Node version (<18.0.0), run npm install node-fetch
as well.
Create a file called index.js
. We'll build this step-by-step.
At the very top of your index.js
file, add this line:
This tells the system how to run your script and makes it executable on all platforms.
The input schema defines what the AI should input to your tool.
In this case: a city name.
Side note: You can make fields optional in the schema by using .optional()
in Zod. For example: z.string().optional()
would make that input not required. This can be useful if your tool supports multiple input paths or you want to provide fallback behavior.
If you need to add additional fields, just expand the parameters of the function. For example: getWeather({ city, isMetric })
.
Now connect the schema and the function together and register it to our server so it can be accessed.
There are multiple transport methods for MCP servers (how your AI connects to the MCP server).
We'll be using StdioServerTransport, which works great locally.
MCP comes with a really cool inspector. To run it, simply enter the following command:
You'll get a URL in the console that you can open. Simply click the connect button on the bottom left!
For local development testing, if you're using Claude Desktop:
Replace /full/path/to/mcp-weather-server/
with the actual path to your project folder
If you need environment variables (for API keys, configs, etc.), you can define them in the config like this
If all goes well, Claude should show the result returned by your tool. Other AI clients that support MCP may offer similar functionality.
We need to package and publish our MCP server to make it easy for others to use.
bin
entry pointIn your package.json
, add this line:
This tells npm to treat index.js
as a command-line app called mcp-weather-server
.
Note: We already added the shebang #!/usr/bin/env node
at the beginning of our file in step 1, so our script is ready to run on all systems!
This is just a tutorial — don't actually run the publish command unless you're shipping your own version. But if you were building your own app, you would run these to publish to npm.
First, make sure you're logged in:
And then publish it:
Anyone can now run your server with your config file!
Once your package is published to npm, others (and you) can use it with a simpler config:
This approach uses npx
to automatically download and run your published package, making it much easier for others to use your tool!
Now that you've got the basics, try branching out. Your AI client can use any tool — as long as you define inputs and return something usable.
Here are some inspiration, but you should come up with something else!
To submit you must:
If you need any help, reach out in the #toolsmith Slack channel!
Once you've built your MCP tool and tested it, you can submit it to earn your $10 in AI credits!
Submit Your Tool