In this tutorial, you will expose the functions of a weather API as tools that AI agents can discover and use through the Model Context Protocol (MCP) by:
- Creating an Express API using Vercel's CLI and adding an endpoint that returns real time weather data.
- Build an MCP server with four specialized tools
- Test your MCP server with the MCP Inspector and the Cursor IDE
You will re-use the code from How to Build a Weather API with Express and Vercel.
The complete code for this guide is available in this Github repository. You can deploy it with one click on Vercel.
Before you begin, ensure you have:
- Node.js 20 or later installed
- Vercel CLI (
npm install -g vercel) - Basic knowledge of Express and TypeScript
Adding MCP to Express creates two layers:
- Express REST API: Your endpoints work as normal HTTP routes. They handle business logic, fetch data, process requests, and return JSON.
- MCP Tools: MCP tools wrap your Express endpoints. When an AI agent calls a tool, the tool requests your Express endpoint and formats the response.
The mcp-handler package handles MCP protocol details. Because it expects Web API Request/Response objects, you will add a small adapter to convert Express req/res.
Create a new Express project with the Vercel CLI inside a folder called express-mcp-weather:
Update your package.json with the following dependencies:
These provide:
mcp-handler: Vercel's MCP adapterzod: Schema validation (version 3.23.8 required)
Replace src/index.ts with a weather endpoint:
This endpoint geocodes city names and fetches weather from the Open-Meteo API.
Test the endpoint with the vercel CLI. You will be asked to link your code with an existing or new project on your Vercel account:
In another terminal:
You should see weather data in JSON format.
Add MCP tools to src/index.ts after the weather endpoint:
Each tool follows this pattern:
- Define name and description
- Specify parameters with Zod schemas
- Call the Express endpoint with
fetch() - Format the response for MCP
- Handle errors with clear messages
The mcp-handler expects Web API Request/Response objects. Since Express uses its own req/res format, add this adapter after your MCP handler to handle this transformation.
The adapter:
- Converts Express
reqto Web APIRequest - Calls MCP handler
- Converts Web API
Responseto Expressres
Your server is already running at http://localhost:3000 using vercel dev.
Test the MCP Server:
You should see all four tools listed.
The MCP Inspector provides a visual interface for testing any MCP server. Start it in a new terminal:
The inspector runs at http://localhost:6274. Check your terminal for the URL.
Connect to your MCP server:
- Open
http://localhost:6274 - Select "Streamable HTTP"
- In the URL field, enter:
http://localhost:3001/api/mcp - Make sure that Authentication is not enabled
- Click Connect
Test your tools:
- Click List Tools - see all four weather tools
- Select "get_temperature"
- Type a city like "London"
- Click Run Tool
- See the result:
Test each tool:
get_temperature: Paris (metric), New York (imperial)get_humidity: Tokyoget_wind_speed: Berlinget_full_weather: London
In a sample folder that you open in your Cursor IDE, create a mcp.json file in the .cursor folder and paste:
Cursor shows a dialog to enable the MCP server. Restart Cursor if needed.
Ask the following example questions in Cursor Chat:
- "What's the temperature in Paris?"
- "Give me complete weather for Tokyo"
- "Compare humidity in London and Berlin"
- "What's the wind speed in San Francisco in mph?"
Cursor detects when to use tools. It shows a dialog like "Run get_temperature" with extracted parameters like "London". Choose "allowlist" or "run" to proceed.
For the question about comparison, Cursor runs "get_humidity" twice (once per city) and returns the comparison.
To deploy your project to production, run vercel --prod in your project folder. Update .cursor/mcp.json with the deployed production URL:
In this tutorial, you enabled MCP with your Express API in a single Express project that you deployed to Vercel that can be used by an AI agent that supports MCP.
- Add tools for more endpoints
- Implement OAuth authentication for security
- Create tools that combine API calls