first-mcp-server
first-mcp-server
Projektübersicht
Ein minimaler MCP-Server (Model Context Protocol), der ein einzelnes Tool namens
addbereitstellt, das zwei Zahlen add iert und das Ergebnis als Text zurückgibt.Erstellt mit den @modelcontextprotocol-Paketen und zod für die Eingabevalidierung.
Wichtige Dateien
index.js – die zentrale Server-Datei, die das Tool
addregistiert und den Server startet.
Voraussetzungen
Node.js 16+ (empfohlene LTS)
npm oder yarn
Installation
Klone das Repositorium und wechsle in das Projektverzeichnis:
git clone && cd /Users/sagar/Documents/Learning/MCP-Server
Installiere die Abhängigkeiten (Beispiel mit npm):
npm install
Verwendete Abhängigkeiten in dasen Projekt (hier Beispiele aus dem Code):
@modelcontextprotocol/server (server)
@modelcontextprotocol/server/stdio (STDIO-Transport)
@modelcontextprotocol/express (Express-Hilfer)
@modelcontextprotocol/node (Node HTTP-Transport)
zod (Validierung)
Ausführen:
Standard-HTTP-Transport (so wie das Projekt der zezeit startet):
node index.js
Der Server lauscht auf Port 3001 und stellt den MCP-Endpunktepunkt über /mcp bereit (siehe index.js).
STDO-Transport (nützlich für lokale CLI-artige Integrations):
Komentrieen Sie ie Aufruf aus
gg? Tie. Enkomentieren Sie den Aufruf vonrunServerOnSTDIOTransport()in index.js und führen Sie aus:node index.js
Verwendungsbeispiele
HTTP-Beispiel (mit curl)
Anforderungs-Ppayload (JSON):
{ "tool": "add", "input": { "num1": 10, "num2": 20 } }
Beispiel-Aufruf mit curl (Host/port bei Bedarf anpassen):
curl -X POST http://localhost:3001/mcp
-H "Content-Type: application/json"
-d '{"tool":"add","input":{"num1":10,"num2":20}}'
Erwartete Antwort (das Tool des Servers gibt ein content-Array mit Text -Blöcken zuruck):
{ "content": [ { "type": "text", "text": "30" } ] }
Hinweis: index.js nutzt für den HTTP-Transport NodeStreamableHTTPServerTransport and ruft transport.handleRequest(req, res, req.body) auf (siehe index.js). Das genaue Format, das der Transport erwartet, hängt von der Implementierung des @modelcontextprotocol/node-Transports ab; das obige Beispiel folgt der einfachen Form, die in this'en project used (tool + input).
STDO-Beispiel (lokale CLI-Integration)
Das Projekt enthält eine Hilfsfunktion zur Ausführung des Servers üßber STDO mit
StdioServerTransport. Im STDO-Betrieb erwartet der Server JSON-Anfragen auf stdin und antwortet auf stdout. Das in index.js registierte Tool validiert die Eingaben mit zod und gibt die Suche als Text.
Tool-Details () Beim Code)
Tool-Name:
addBeschreibung: „Add two numbers"
E ingabeschema (zod):
num1: number
num2: number
Implementierung snippet (from [index.js]...:11-33):
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}` }],
}),
);Hinweise:
Validierung: zod validiert die Eingaben bereits. Stellen Sie sicher, dass aufrufer numerische Werte senden und validierungsfehler:
Fehlerbehandlung: Fügen Sie try/catc around
transport.handleRequestand the Tool-Handler hinzu, um konsistente Fehler-Payloads and HTTP-Statuscodes (4xx bei Clientfehler, 5xx bei Serverfehler) zurückgegeben.Logging & Monititoring: Führe Sie strukturertes Local, Request-Ids and grundlegende Metriken ein, um Nutzung und Fehler zu überwachen.
Sicherheit: Falls öffentlich erreichbar, schützen Sie den /mcp-Endkpkt (Authentifizierung, Rate-Limiting) and( die abiaufen)h zu: ** related
Tests: Führen Sie eine Einheit-Tests für of the Tool Handler and integration tests für die Transports (HTTP and STDO) hin zu.
Mitwirken
Öffnen Sie Issues oder Pull Requests for Feature-Anfragen oder Fehlerbehehinzusen.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
No tool schema history has been recorded yet.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Add two numbers instantly and generate friendly greetings on demand. Speed up quick math and perso…
Create friendly greetings and add two numbers instantly. Speed up simple tasks and streamline ligh…
This MCP server enables users to perform scientific computations regarding linear algebra and vect…
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceA simple MCP server that provides integer addition functionality. Enables users to perform basic arithmetic operations by adding two integers together through natural language interactions.-
- AlicenseNot gradedqualityDmaintenanceA simple demonstration MCP server that provides a basic arithmetic tool for adding two numbers together, showcasing how to build custom MCP servers with input validation.15ISC
- AlicenseNot gradedqualityDmaintenanceEnables AI applications to perform basic mathematical operations like addition and subtraction through MCP tools. Also provides REST API endpoints for the same operations.MIT
- FlicenseNot gradedqualityDmaintenanceA simple MCP server that provides a tool for adding two numbers, designed for testing MCP integration with Claude.-
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/Sagar06/MCP-Server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server