MCP Server in Node.js

by lucianoayres

75 stars
448 downloads
Not rated
GitHub

About

MCP Server implemented in JavaScript using Node.js that demonstrates how to build an MCP server with a custom prompt and custom tools, including one that loads an environment variable from a configuration file, to integrate seamlessly with AI-assisted environments like Cursor IDE

Details

Author
lucianoayres
GitHub stars
75
Downloads
448
Categories
Developer Tools, AI

- MCP Integration exposes tool functionality to LLM-based IDEs.
- Addition Tool accepts two numeric parameters and returns their sum.
- MCP Prompt (“add_numbers”) helps AI models infer tool usage.
- Environment variable retrieval via the getApiKey tool.
- Input validation uses Zod for schema checking.
- Standard I/O transport via StdioServerTransport.

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name MCP Server in Node.js
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

Clone the repository, install dependencies with npm install, then test via the MCP Inspector using npm run inspector or npx @modelcontextprotocol/inspector node ./mcp-server.js. To integrate with Cursor IDE, add the server configuration in Cursor’s Settings → Tools & Integrations using the sample JSON provided in the README.

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "mcp server in node.js": {
            "mcp-server-node": {
                "command": "npx",
                "args": [
                    "@modelcontextprotocol/inspector",
                    "node",
                    "./mcp-server.js"
                ]
            }
        }
    }
}

McpServers

{
    "mcp-server-node": {
        "command": "npx",
        "args": [
            "@modelcontextprotocol/inspector",
            "node",
            "./mcp-server.js"
        ]
    }
}

🟢 MCP Server in Node.js

MCP Server in Node.js banner

Build and run a custom MCP Server in Node.js in just 2 minutes ⏱️

Overview · Features · Installation · Testing with MCP Inspector · Setting Environment Variables for Testing · Integrating with Cursor AI · Using the MCP Tool in Cursor (Agent Mode) · Code Overview · References & Resources · License

Overview

MCP (Model Context Protocol) is a framework that allows you to integrate custom tools into AI-assisted development environments—such as Cursor AI. MCP servers expose functionality (like data retrieval or code analysis) so that an LLM-based IDE can call these tools on demand. Learn more about MCP in the Model Context Protocol Introduction.

This project demonstrates an MCP server implemented in JavaScript using Node.js. It defines two tools: add, which takes two numeric inputs and returns their sum, and getApiKey, which retrieves the API key from the API_KEY environment variable. It also provides a predefined prompt add_numbers that allows AI models to infer the usage of the addition tool.

Requirements

- Node.js: Version 20 or higher is required.

Features

- MCP Integration: Exposes tool functionality to LLM-based IDEs.
- Addition Tool: Accepts two numeric parameters and returns their sum.
- MCP Prompt: Provides a predefined prompt ("add_numbers") that allow AI models to infer tool usage.
- Env Var Retrieval: Demonstrates how to load an example environment variable from the configuration file.
- Input Validation: Uses Zod for schema validation.
- Standard I/O Transport: Connects via StdioServerTransport for integration with development environments.

Installation

1. Clone the Repository

   git clone <repository_url>
   cd <repository_directory>
   

2. Install Dependencies

You can install the project dependencies in one of two ways:

Option 1: Install using the existing package.json

Simply run:

   npm install
   

Option 2: Install dependencies manually

If you prefer, delete the existing package.json and install the required packages manually:

   npm install @modelcontextprotocol/sdk zod
   

Then, update the newly generated package.json file to include the following lines, which enables ES Modules and adds the mcp inspector command:

   "type": "module",
   "scripts": {
    "inspector": "npx @modelcontextprotocol/inspector node ./mcp-server.js"
   }
   

Testing with MCP Inspector

The MCP Inspector is a debugging tool that lets you test your server's tools interactively before integrating with an IDE.

Option 1: Run directly with npx

npx @modelcontextprotocol/inspector node ./mcp-server.js

Option 2: Use the npm script

npm run inspector

This will:

1. Start the MCP inspector server
2. Open your browser to the inspector interface
3. Allow you to test tools, resources, and prompts

Open the MCP Server Inspector on the browser:
http://localhost:6274/

Setting Environment Variables for Testing

To test the getApiKey tool with different API keys, you can set environment variables before running the inspector:

Linux/macOS (Bash/Zsh):

```bash

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.