Guide · AI agents & MCP

Build an MCP server in Node.js for your internal tools

The Model Context Protocol (MCP) lets AI assistants like Claude use your company's tools and data through one standard interface. Here's how I build MCP servers in Node.js that stay small, secure, and work with self-hosted models too.

Why MCP for internal tools

Every company has the same problem: useful data and actions are spread across an admin panel, a CRM, a database and a few internal APIs. Wiring each of them into each AI tool doesn't scale. MCP solves that with one server per system that any MCP-compatible client can use.

Build the integration once, and it works in Claude Desktop, Claude Code, and the agents you build yourself, including ones running on self-hosted models.

Architecture

MCP server architectureAn AI client such as Claude or an agent on Ollama connects to a Node.js MCP server, which calls internal APIs and databases with least-privilege access.Your infrastructureAI clientClaude · agentMCP serverNode.jsAuth & auditper-tool scopesInternal APIsCRM · adminDatabaseread-only
The MCP server is the only path from the AI to your systems, which makes it the right place for security.
  • Transport: stdio for a local, single-user tool. HTTP for a shared server next to your systems.
  • Tools, not access: expose narrow actions (find_customer, create_ticket), never a generic query endpoint.
  • One server per domain: small servers are easier to secure, test and reason about than one giant gateway.

A minimal MCP server in Node.js

The official TypeScript/JavaScript SDK keeps it short. This exposes a single read-only tool with validated input:

JavaScript · server.js
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
import { findCustomerByEmail } from "./db.js";

const server = new McpServer({ name: "internal-tools", version: "1.0.0" });

server.tool(
  "find_customer",
  { email: z.string().email() },
  async ({ email }) => {
    const customer = await findCustomerByEmail(email); // read-only query
    return { content: [{ type: "text", text: JSON.stringify(customer ?? null) }] };
  }
);

await server.connect(new StdioServerTransport());

Two dependencies: the SDK and a schema validator. That's in keeping with how I build everything: fewer dependencies, less to audit.

Security checklist

  • Least privilege per tool. Read-only by default, and write tools scoped to exactly one action.
  • Validate every input. Schemas on every tool, so the model can't pass anything unexpected downstream.
  • Authenticate the human, not just the app. On HTTP transport, act with the calling user's permissions.
  • Audit log everything. Who asked, which tool, which arguments, what came back.
  • Confirm destructive actions. Deletes, payments and emails need explicit human approval.

Claude or a self-hosted model?

The same MCP server works with both. I typically use Claude for agents that need strong reasoning across many tools, and a self-hosted model on Ollama or llama.cpp when the data involved must stay in-house. See the private AI case study for how that side is built.

FAQ

What is an MCP server?

An MCP server exposes tools (actions), resources (data) and prompts to AI applications through the open Model Context Protocol. Any MCP-compatible client, such as Claude Desktop, Claude Code or your own agent, can discover and call them without custom integration code for each one.

Should I use stdio or HTTP transport?

Use stdio when the server runs on the same machine as a single user's AI client, for example a developer tool. Use the HTTP transport when the server is shared by a team or runs next to your internal systems, and put authentication in front of it.

Can I use MCP with Ollama or llama.cpp?

Yes. The MCP server doesn't care which model calls it. With a self-hosted model that supports tool calling, your own agent loop (or an MCP-capable client) passes the tool definitions to the model and executes the calls it makes, so sensitive data never leaves your infrastructure.

Is it safe to give an AI agent access to internal systems?

It is when access is designed like any other integration: least-privilege tools, read-only by default, validated inputs, per-user authentication, audit logs, and human confirmation for anything destructive. Never expose a raw SQL or shell tool.