pvakati-tech.ai
MCP Integration Guide

Connecting to MCP Servers

This example shows how to register an MCP server, expose a tool, and verify the connection from your client runtime.

← Back to topics
Transport: stdioLanguage: Node.jsCapability: tools

1) Minimal MCP server

Create a local server that exposes one tool called hello_mcp. Your client should discover this tool when the server starts successfully.

#!/usr/bin/env node
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";

const server = new Server(
  { name: "demo-mcp-server", version: "1.0.0" },
  { capabilities: { tools: {} } }
);

server.tool(
  "hello_mcp",
  "Returns a greeting from the MCP server",
  { name: z.string().default("developer") },
  async ({ name }) => ({
    content: [{ type: "text", text: `Hello ${name}, MCP server is connected.` }]
  })
);

const transport = new StdioServerTransport();
await server.connect(transport);

Verification Checklist

1. Server starts with no runtime errors.

2. Client lists MCP server as connected.

3. Tool hello_mcp appears in the available tools list.

4. Tool invocation returns expected greeting text.

2) Client MCP config

Add the server to your MCP client configuration. Use an absolute path so the process can be launched reliably.

{
  "mcpServers": {
    "demo": {
      "command": "node",
      "args": ["/absolute/path/demo-mcp-server/index.js"],
      "env": {
        "NODE_ENV": "production"
      }
    }
  }
}

3) Common issues

Server not detected: confirm command and file path in config.

Tool list empty: verify server capabilities include tools.

Process exits immediately: check Node version and package install.

Timeouts: inspect stderr logs and avoid long startup work in server boot.