Skip to main content
Glama
my-mcp-server

my-mcp-server

by RianHarahap

My MCP Server (for Beginners)

A self-made MCP (Model Context Protocol) Server with:

  • Your own API key & URL module via the .env file

  • Example tools: echo and call_my_api

  • Ready to test with MCP Inspector

  • Ready to use directly in VS Code (GitHub Copilot Chat)

1. Install dependencies

npm install

Related MCP server: mcp-server-demo

2. Create the .env file

Copy .env.example to .env, then fill it in with your own API key and URL:

Copy-Item .env.example .env

Fill in .env:

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

⚠️ Never commit the .env file to git. This file is already automatically ignored via .gitignore.

3. Build the project

npm run build

This command compiles the TypeScript in src/ into JavaScript in build/.

4. Test with MCP Inspector

MCP Inspector is a visual (browser) tool for trying out your MCP tools without needing another client.

npm run inspector

This will run npx @modelcontextprotocol/inspector node build/index.js and open the Inspector in the browser. From there you can:

  1. Click the Tools tab

  2. Select the echo or call_my_api tool

  3. Fill in the parameters, click Run Tool, and see the results

5. Use directly in VS Code

The .vscode/mcp.json file is already prepared. Open the Command Palette → MCP: List Servers → select my-mcp-server → Start Server. This server automatically reads .env via envFile.

Project Structure

├── .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

Adding a new tool

Add a new server.registerTool("nama_tool", { ... }, async (input) => { ... }) block in src/index.ts, then run npm run build again.

Troubleshooting

  • Error "Environment variable ... not set yet" → make sure .env exists and is filled in.

  • Tool call_my_api fails → check whether MY_API_BASE_URL and MY_API_KEY are correct, and that the API endpoint supports the Authorization: Bearer <key> header.

  • Inspector does not open → make sure you have run npm run build first.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    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.
      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.
      -