Skip to main content
Glama
RianHarahap

my-mcp-server

by RianHarahap

My MCP Server (für Anfänger)

Eigener MCP (Model Context Protocol) Server mit:

  • Eigenes API-Key- und URL-Modul über die Datei .env

  • Beispiel-Tools: echo und call_my_api

  • Bereit zum Testen mit MCP Inspector

  • Bereit zur direkten Verwendung in VS Code (GitHub Copilot Chat)

1. Abhängigkeiten installieren

npm install

Related MCP server: mcp-server-demo

2. Datei .env erstellen

Kopiere .env.example zu .env und fülle sie mit deinem API-Key und deiner URL:

Copy-Item .env.example .env

Inhalt der .env:

MY_API_KEY=api-key-asli-kamu
MY_API_BASE_URL=https://api.contohkamu.com
MCP_SERVER_NAME=my-mcp-server

⚠️ Committe die Datei .env niemals in git. Diese Datei wird automatisch über .gitignore ignoriert.

3. Projekt bauen

npm run build

Dieser Befehl kompiliert TypeScript in src/ zu JavaScript in build/.

4. Mit MCP Inspector testen

MCP Inspector ist ein visuelles Tool (Browser), um deine MCP-Tools ohne weiteren Client auszuprobieren.

npm run inspector

Dies führt npx @modelcontextprotocol/inspector node build/index.js aus und öffnet den Inspector im Browser. Von dort kannst du:

  1. Klicke auf den Tab Tools

  2. Wähle das Tool echo oder call_my_api

  3. Fülle die Parameter aus, klicke auf Run Tool und sieh dir das Ergebnis an

5. Direkt in VS Code verwenden

Die Datei .vscode/mcp.json ist bereits vorbereitet. Öffne die Command Palette → MCP: List Servers → wähle my-mcp-server → Start Server. Dieser Server liest .env automatisch über envFile.

Projektstruktur

├── .env                  # rahasia kamu (tidak di-commit)
├── .env.example          # contoh isi .env
├── .vscode/mcp.json      # konfigurasi MCP untuk VS Code
├── src/
│   ├── config.ts         # loader environment variable
│   ├── apiClient.ts      # modul pemanggilan API eksternal (pakai API key & URL)
│   └── index.ts          # server MCP utama + daftar tool
├── package.json
└── tsconfig.json

Neues Tool hinzufügen

Füge einen neuen Block server.registerTool("nama_tool", { ... }, async (input) => { ... }) in src/index.ts hinzu und führe dann npm run build erneut aus.

Fehlerbehebung

  • Fehler „Umgebungsvariable ... nicht ausgefüllt" → stelle sicher, dass .env vorhanden und ausgefüllt ist.

  • Tool call_my_api schlägt fehl → prüfe, ob MY_API_BASE_URL und MY_API_KEY korrekt sind und ob der API-Endpunkt den Header Authorization: Bearer <key> unterstützt.

  • Inspector öffnet nicht → stelle sicher, dass zuerst npm run build ausgeführt wurde.

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables users to expose arbitrary HTTP APIs as configurable MCP tools by defining tool specifications in a JSON configuration file.
    2,323 npm
    3
    -
  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables AI clients to connect to example tools, resources, and prompts over MCP, demonstrating integration with IDEs, chatbots, and agent frameworks.
    -
  • A
    license
    Not graded
    quality
    C
    maintenance
    Enables interaction with Infor systems by exposing verified HTTP/SOAP requests as MCP tools, supporting multiple services, configurable authentication, and extensible request definitions.
    Apache 2.0