prvnheritk/mcp-server
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.
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
-
Clone or download this project
-
Navigate to the project directory:
cd mcp-server -
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 numberb: 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 filefile:///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
- Define the tool schema using Zod
- Add the tool to the
ListToolsRequestSchemahandler - Implement the tool handler in the
CallToolRequestSchemahandler - Add validation and error handling
Adding New Resources
- Add the resource to the
ListResourcesRequestSchemahandler - Implement resource reading in the
ReadResourceRequestSchemahandler
Adding New Prompts
- Add the prompt to the
ListPromptsRequestSchemahandler - Implement prompt generation in the
GetPromptRequestSchemahandler
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
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Support
For issues and questions, please create an issue in the repository.