Logo van MCP Server Node

MCP Server Node

Community
lucianoayres

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.

Uitgeverlucianoayres
Repositorymcp-server-node
TaalJavaScript
Forks
19
Sterren
75
Beschikbare tools
0
Transporttypestdio
LicentieMIT
Links
  • Koppel tools aan AI-workflows

    MCP Server Node biedt MCP-functionaliteit die compatibele AI-clients en agenten kunnen gebruiken.

  • 0 beschikbare tools

    Bekijk hieronder de aanroepbare acties, inclusief namen en beschrijvingen als de server die beschikbaar stelt.

  • Configuratie om direct te kopiëren

    Gebruik de installatievoorbeelden om deze server in je favoriete MCP-client te configureren.

  • Indicatoren van opensource-interesse

    75 sterren en 19 forks in de gekoppelde repository.

🟢 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

    bash
    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:

    bash
    npm install

    Option 2: Install dependencies manually

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

    bash
    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:

    json
    "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

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

Option 2: Use the npm script

bash
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
# Temporary (current session only)
export API_KEY="your-test-key"
npm run inspector

# Or set for single command
API_KEY="your-test-key" npm run inspector

Windows (Command Prompt):

cmd
# Set for current session
set API_KEY=your-test-key
npm run inspector

Windows (PowerShell):

powershell
# Set for current session
$env:API_KEY="your-test-key"
npm run inspector

# Or set for single command
$env:API_KEY="your-test-key"; npm run inspector

Integrating with Cursor AI

To integrate this MCP server with Cursor IDE, you need to add the configuration through Cursor's settings interface:

  1. Open Cursor IDE
  2. Go to Settings → Tools & Integrations
  3. Click on Add Custom MCP Server
  4. Add the configuration below

Important: If you already have other MCP servers configured, don't overwrite the entire configuration. Instead, add the "MCP Server Boilerplate" object to the existing "mcpServers" object.

Sample Configuration File: This project includes a sample configuration file at ./cursor/mcp.json that you can reference or copy from.

Configuration Structure

Below is the configuration you need to add:

Linux/macOS example:

json
{
  "MCP Server Boilerplate": {
    "command": "node",
    "args": ["/home/john/mcp-server-node/mcp-server.js"],
    "env": {
      "API_KEY": "abc-1234567890"
    }
  }
}

Windows example:

json
{
  "MCP Server Boilerplate": {
    "command": "node",
    "args": ["C:\\Users\\john\\mcp-server-node\\mcp-server.js"],
    "env": {
      "API_KEY": "abc-1234567890"
    }
  }
}

If you have existing MCP servers configured, your full configuration might look like this:

json
{
  "mcpServers": {
    "existing-server": {
      "command": "python",
      "args": ["/path/to/existing/server.py"]
    },
    "MCP Server Boilerplate": {
      "command": "node",
      "args": ["/home/john/mcp-server-node/mcp-server.js"],
      "env": {
        "API_KEY": "abc-1234567890"
      }
    }
  }
}

Configuration Parameters

  • MCP Server Boilerplate:
    This is the key for your server configuration. You can name it as you like.

  • command:
    The Node.js executable to run your server. You can use either:

    • "node" (if Node.js is in your PATH)
    • The full path to your Node.js executable (if needed)

    Finding your Node.js path:

    Linux/macOS:

    bash
    which node
    # Example output: /home/john/.nvm/versions/node/v20.13.1/bin/node

    Windows (Command Prompt):

    cmd
    where node
    # Example output: C:\Program Files\nodejs\node.exe

    Windows (PowerShell):

    powershell
    Get-Command node
    # Example output: C:\Program Files\nodejs\node.exe
  • args:
    An array containing the absolute path to your MCP server file.

    Linux/macOS examples:

    json
    ["/home/john/mcp-server-node/mcp-server.js"]

    Windows examples:

    json
    ["C:\\Users\\john\\mcp-server-node\\mcp-server.js"]
  • env: (Optional)
    Defines environment variables for your MCP server process. In this example, the API_KEY is set to "abc-1234567890". Adjust this value as needed for your environment.

Code Overview

The project comprises the following key parts:

  • MCP Server Initialization:
    The MCP server is instantiated using McpServer from the MCP SDK and connected via StdioServerTransport.

  • Tool Definitions:

    • add:
      Defined with a Zod schema that accepts two numbers (a and b) and returns their sum as text.
    • getApiKey:
      Retrieves the API key from the environment variable API_KEY and returns it as text.
  • Prompt Definition:

    • add_numbers:
      A predefined prompt that allows AI models to infer the usage of the addition tool.

Important Note: It's not required to have a prompt defined for a tool. This example just demonstrates one of the capabilities of prompts, allowing the AI model to infer which tool to use based on your input. The AI can also use tools directly when it determines they're needed for a task.

Using the MCP Tool in Cursor (Agent Mode)

With the MCP server integrated into Cursor IDE and with Agent mode enabled, you can use the tools in several ways:

Addition Tool Usage

Method 1: Natural Language Prompt Simply use a natural language prompt like:

add 3 and 5

or

what is 7 plus 12?

Method 2: Prompt-Based Tool Invocation Type the following prompt in the chat:

/add_numbers

When you press Enter after typing this prompt, Cursor will automatically:

  1. Recognize that you want to use the add tool from the Node Server
  2. Display a GUI prompt asking for the two number parameters
  3. The AI model will infer that it needs to use the add tool to calculate the result

Parameters for the Addition Tool:

  • Parameter a: First number to add
  • Parameter b: Second number to add
  • Returns: The sum of the two numbers as text

API Key Tool Usage

For the getApiKey tool, you can use:

what is my API key?

or

get my API key

The AI agent will automatically infer the appropriate tool to use based on your request.

References & Resources

License

This project is licensed under the MIT License.

Gebruik MCP Server Node MCP met meerdere AI-modellen

TypingMind koppelt MCP-tools aan de werkruimte. Zodra MCP Server Node is verbonden, kun je deze dus met verschillende AI-modellen in TypingMind gebruiken, zonder de verbinding voor elk model apart in te stellen. Deze MCP-integratie draait lokaal via de TypingMind MCP-connector op je apparaat.

Installatiehandleiding voor de lokale connector

Gebruik dit als de MCP-server toegang nodig heeft tot lokale bestanden, apps of privébronnen op je computer.

1

Open de MCP-instellingen

Ga in TypingMind naar Instellingen, Geavanceerde instellingen en vervolgens Model Context Protocol. Kies daar Connector instellen.

  1. Open TypingMind in je browser.
  2. Klik op het pictogram Instellingen.
  3. Ga naar Geavanceerde instellingen.
  4. Open het gedeelte Model Context Protocol.
  5. Klik op Connector instellen en kies Dit apparaat.
Instelscherm voor de TypingMind MCP-connector met Dit apparaat geselecteerd
2

Voer de connectoropdracht uit

Kies Dit apparaat, kopieer de opdracht uit TypingMind en voer deze uit in Terminal. Laat het proces draaien zolang je MCP gebruikt.

  1. Kopieer de installatieopdracht die TypingMind toont.
  2. Open Terminal op macOS of Windows Terminal op Windows.
  3. Plak de opdracht en voer deze uit.
  4. Keur de pakketinstallatie goed als Terminal vraagt of je wilt doorgaan.
  5. Laat het proces in het Terminal-venster draaien zolang je MCP-tools gebruikt.
3

Voeg MCP Server Node toe als server

Klik op Servers bewerken zodra de connectorstatus Gereed is en plak de MCP-serverconfiguratie.

  1. Wacht tot de connectorstatus Gereed aangeeft.
  2. Klik op Servers bewerken.
  3. Plak de MCP-serverconfiguratie van MCP Server Node.
  4. Sla de serverlijst op.
  5. Vernieuw om te controleren of de connector nog steeds klaar is voor gebruik.
MCP-instellingen van TypingMind met een actieve server en de knop Servers bewerken
{
  "mcpServers": {
    "mcp-server-node": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

Gebruik de verbinding met verschillende modellen

Sla de serverlijst op, open Plug-ins en schakel de MCP-tools van MCP Server Node in. Selecteer vervolgens een ondersteund AI-model in TypingMind en gebruik de tools in de chat of wijs ze toe aan een AI-agent.

  1. Open de pagina Plug-ins in TypingMind.
  2. Schakel de MCP-tools van MCP Server Node in.
  3. Start een chat en kies het AI-model dat je wilt gebruiken.
  4. Gebruik de MCP-tools in een chat of wijs ze toe aan een AI-agent.
  5. Schakel wanneer nodig over naar een ander AI-model zonder opnieuw verbinding te maken met MCP.
TypingMind-chat met ingeschakelde MCP-tools en een geselecteerd AI-model
Kun je MCP Server Node gebruiken om me hiermee te helpen?
MCP Server Node
Zeker. Ik heb het gelezen.
Dit vond ik met MCP Server Node.

Veelgestelde vragen

Waarvoor wordt de MCP-server MCP Server Node gebruikt?

MCP Server Node is een MCP-server waarmee compatibele AI-clients verbinding kunnen maken met externe tools en context. In TypingMind hoef je deze MCP-server maar één keer toe te voegen om de tools beschikbaar te maken in je AI-werkruimte.

Kan ik MCP Server Node MCP met meerdere AI-modellen in TypingMind gebruiken?

Ja. TypingMind verbindt MCP-tools op werkruimteniveau. Daardoor kun je MCP Server Node gebruiken met verschillende AI-modellen, zoals Claude, ChatGPT, Gemini of andere modellen die je in TypingMind hebt ingesteld, zonder de MCP-server voor elk model afzonderlijk in te stellen.

Waarom MCP Server Node MCP gebruiken met TypingMind?

TypingMind is een van de beste interfaces voor chats met LLM's, omdat het meerdere AI-modellen, prompts, plug-ins, AI-agenten, API-sleutels en MCP-tools samenbrengt in één werkruimte. Als MCP Server Node verbonden is, kun je de MCP-tools ervan gebruiken met je favoriete modellen en je chatworkflow overzichtelijk houden in TypingMind.

Hoe verbind ik MCP Server Node MCP met TypingMind?

MCP Server Node werkt via de lokale MCP-connector van TypingMind. Dit is de beste optie als de MCP-server toegang nodig heeft tot lokale bestanden, desktopapps, opdrachtregeltools of privébronnen op je computer.

Welke tools biedt MCP Server Node MCP in TypingMind?

MCP Server Node biedt MCP-functies die je kunt inschakelen via de pagina Plug-ins in TypingMind. Je kunt ze gebruiken in chats of toewijzen aan AI-agenten.

Moet ik mijn API-sleutels delen met TypingMind om MCP Server Node MCP te gebruiken?

Nee. TypingMind werkt in de eerste plaats lokaal en laat je de controle houden over je modelaanbieders, API-sleutels, prompts en MCP-configuratie. Als MCP Server Node authenticatie vereist, voeg je bij het maken van de verbinding de vereiste headers, OAuth-instellingen of lokale configuratie voor die MCP-server toe.

Gerelateerde MCP-servers

Toon alles

Maak nu je eigen AI-werkruimte

Schrijf je in voor onze nieuwsbrief en blijf op de hoogte van nieuwe functies en toekomstige weggeefacties 👇