mcp-server

prvnheritk/mcp-server

3.1

If you are the rightful owner of mcp-server 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.

A Model Context Protocol (MCP) server built with Node.js that provides tools, resources, and prompts for AI applications.

Tools
3
Resources
0
Prompts
0

MCP Server

A Model Context Protocol (MCP) server built with Node.js that provides tools, resources, and prompts for AI applications.

Features

  • Tools: Calculator, Weather lookup, File reading
  • Resources: System file access (hosts, kernel version)
  • Prompts: Code review and concept explanation templates
  • Type Safety: Built with Zod for runtime validation
  • Modern JavaScript: ES modules and async/await

Prerequisites

  • Node.js 18.0.0 or higher
  • npm or yarn package manager

Installation

  1. Clone or download this project

  2. Navigate to the project directory:

    cd mcp-server
    
  3. Install dependencies:

    npm install
    

Usage

Development Mode

npm run dev

Production Mode

npm start

Testing

npm test

Linting

npm run lint

Formatting

npm run format

Available Tools

1. Calculator

Performs basic arithmetic operations.

Parameters:

  • operation: "add", "subtract", "multiply", or "divide"
  • a: First number
  • b: Second number

Example:

{
  "name": "calculator",
  "arguments": {
    "operation": "add",
    "a": 5,
    "b": 3
  }
}

2. Weather

Gets weather information for a location (mock data).

Parameters:

  • location: City name or location (required)
  • unit: "celsius" or "fahrenheit" (optional, default: "celsius")

Example:

{
  "name": "weather",
  "arguments": {
    "location": "New York",
    "unit": "fahrenheit"
  }
}

3. Read File

Reads the contents of a file.

Parameters:

  • path: Path to the file to read

Example:

{
  "name": "read_file",
  "arguments": {
    "path": "/etc/hosts"
  }
}

Available Resources

  • file:///etc/hosts - System hosts file
  • file:///proc/version - Linux kernel version information

Available Prompts

1. Code Review

Generates a code review prompt for given code.

Arguments:

  • code: The code to review (required)
  • language: Programming language (optional)

2. Explain Concept

Creates a prompt to explain a technical concept.

Arguments:

  • concept: The concept to explain (required)
  • audience: Target audience level (optional)

Configuration

The server can be configured through environment variables:

  • NODE_ENV: Environment (development/production)
  • PORT: Server port (default: 3000)
  • WEATHER_API_KEY: Weather API key (optional)
  • OPENAI_API_KEY: OpenAI API key (optional)

Project Structure

mcp-server/
├── src/
│   └── index.js          # Main server implementation
├── config.js             # Configuration file
├── package.json          # Dependencies and scripts
└── README.md            # This file

Development

Adding New Tools

  1. Define the tool schema using Zod
  2. Add the tool to the ListToolsRequestSchema handler
  3. Implement the tool handler in the CallToolRequestSchema handler
  4. Add validation and error handling

Adding New Resources

  1. Add the resource to the ListResourcesRequestSchema handler
  2. Implement resource reading in the ReadResourceRequestSchema handler

Adding New Prompts

  1. Add the prompt to the ListPromptsRequestSchema handler
  2. Implement prompt generation in the GetPromptRequestSchema handler

Error Handling

The server includes comprehensive error handling:

  • Input validation using Zod schemas
  • Graceful error responses
  • Detailed error messages for debugging

License

MIT License - see LICENSE file for details

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Support

For issues and questions, please create an issue in the repository.