This commit is contained in:
zhangguoyun committed 2025-11-14 15:10:16 +08:00
commit 227d77f586
5 files changed
+1179

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
# Qwen Code Context: Node.js MCP Server
## Project Overview
This is a Node.js-based Model Context Protocol (MCP) server implementation that provides tools for external clients to interact with. The server uses the `@modelcontextprotocol/sdk` to implement the MCP specification and offers tools like greeting and weather information retrieval.
## Project Structure
- `index.js`: Main server implementation containing tool registrations and server startup logic
- `package.json`: Project metadata and dependencies
- `package-lock.json`: Dependency lock file
- `node_modules/`: Project dependencies
## Key Dependencies
- `@modelcontextprotocol/sdk`: Core SDK for MCP implementation
- `zod`: For runtime type checking and validation of tool parameters
## Architecture
The server implements the Model Context Protocol and registers two tools:
1. `say_hello`: A simple greeting tool that takes a name and returns a personalized greeting
2. `get_weather`: A weather information tool that fetches current weather data for a given city using WeatherAPI
## Building and Running
- To run the server: `node index.js`
- The server uses stdio transport for communication with clients
- For the weather tool to work, a `WEATHER_API_KEY` environment variable must be set
## Development Conventions
- Uses ES modules (indicated by "type": "module" in package.json)
- Implements async/await for handling asynchronous operations
- Uses Zod for parameter validation
- Includes proper error handling for robust operation
- Logs important messages to stderr to separate them from data output
- Follows MCP specification for return value formatting
## Configuration
The weather tool requires a `WEATHER_API_KEY` environment variable to be set to access the weather API service.
## Purpose
This project serves as an example MCP server implementation that demonstrates how to register and implement tools that can be called by MCP-compatible clients. It's designed to be extensible for adding more tools as needed.
Always respond in 中文