first-mcp-server

first-mcp-server

Enables adding two numbers through a single MCP tool and returns the sum as text.

Category
Visit Server

README

first-mcp-server

Project summary

  • A minimal MCP (Model Context Protocol) server exposing a single tool named add that adds two numbers and returns the result as text.
  • Built with @modelcontextprotocol packages and zod for input validation.

Key files

  • index.js — main server file that registers the add tool and starts the server.

Requirements

  • Node.js 16+ (recommend LTS)
  • npm or yarn

Install

  1. Clone the repository and change into the project directory:

    git clone <repo-url> && cd /Users/sagar/Documents/Learning/MCP-Server

  2. Install dependencies (example with npm):

    npm install

Dependencies used in this project (examples from code):

  • @modelcontextprotocol/server
  • @modelcontextprotocol/server/stdio (stdio transport)
  • @modelcontextprotocol/express (express helper)
  • @modelcontextprotocol/node (Node HTTP transport)
  • zod (validation)

Run

  • Default HTTP transport (as the project currently starts):

    node index.js

    The server listens on port 3001 and mounts the MCP endpoint at /mcp (see index.js).

  • STDIO transport (useful for local CLI-style integrations):

    Uncomment the call to runServeronSTDIOTransport() in index.js and run:

    node index.js

Usage examples

  1. HTTP example (curl)
  • Request payload (JSON):

    { "tool": "add", "input": { "num1": 10, "num2": 20 } }

  • Example curl call (adjust hostname/port if needed):

    curl -X POST http://localhost:3001/mcp
    -H "Content-Type: application/json"
    -d '{"tool":"add","input":{"num1":10,"num2":20}}'

  • Expected response (the server's tool returns a content array of text blocks):

    { "content": [ { "type": "text", "text": "30" } ] }

Notes: index.js wires the HTTP transport using NodeStreamableHTTPServerTransport and calls transport.handleRequest(req, res, req.body) (see index.js). The exact envelope the transport expects depends on the @modelcontextprotocol/node transport implementation; the example above follows the simple shape used in this project (tool + input).

  1. STDIO example (local CLI integration)
  • The project contains a helper to run the server over STDIO using StdioServerTransport. If started in STDIO mode, the server expects JSON requests on stdin and replies on stdout. The tool registered in index.js validates inputs with zod and returns the sum as text.

Tool details (from code)

  • Tool name: "add"
  • Description: "Add two numbers"
  • Input schema (zod):
    • num1: number
    • num2: number

Implementation snippet (from index.js):

server.registerTool(
  "add",
  {
    title: "add",
    description: "Add two numbers",
    inputSchema: z.object({ num1: z.number(), num2: z.number() }),
  },
  async (ctx) => ({
    content: [{ type: "text", text: `${ctx.num1 + ctx.num2}` }],
  }),
);

Notes:

  • Validation: zod already validates the inputs. Ensure callers send numeric values and handle validation errors gracefully.
  • Error handling: Add try/catch around transport.handleRequest and tool handlers to return consistent error payloads and HTTP status codes (4xx for client errors, 5xx for server errors).
  • Logging & monitoring: Add structured logging, request IDs, and basic metrics to monitor usage and errors.
  • Security: If exposed publicly, protect the /mcp endpoint (authentication, rate-limiting) and run behind a reverse proxy.
  • Tests: Add unit tests for tool handlers and integration tests for transports (HTTP and STDIO).

Contributing

  • Open issues or PRs for feature requests or fixes.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured