mcp-server-sample

qiaoleiatms/mcp-server-sample

3.1

If you are the rightful owner of mcp-server-sample and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

This project demonstrates how to create an MCP server for retrieving weather data using TypeScript.

Weather Data Retrieval Mcp Server Sample

This is a sample project demonstrating how to create an MCP (Model Context Protocol) server that retrieves weather data for a given location using TypeScript. The server uses the MCP framework to define a tool for fetching weather information.

Getting Started

Prerequisites

  • Node.js (version 18 or higher)

Installation

  1. Clone the repository:
    git clone https://github.com/qiaoleiatms/mcp-server-sample.git
    
  2. Navigate to the project directory:
    cd mcp-server-sample
    
  3. Install the dependencies:
    npm install
    
  4. Build the project:
    npm run build
    

Running the Server

To start the MCP server, run the following command:

npm start

The server will start and listen for incoming requests to fetch weather data.

Running with Inspector

To run the MCP server with the inspector tool, use the following command:

npm run inspector

This will launch the server along with the MCP inspector for debugging and monitoring.

Usage

You can configure this MCP server to any MCP-compatible client to request weather data for a specific location. The server will respond with the current temperature and weather description.

A sample mcp.json configuration for connecting to this server is as follows:

{
    "servers": {
        "mcp-server-sample": {
            "type": "stdio",
            "command": "node",
            "args": [
                "absolute/path/to/your/dist/index.js",
                // any additional arguments if needed
            ],
            "env": {
                // any environment variables if needed
            }
        }
    }
}