Skip to content
All posts

How to build an MCP server for your team's internal tools

Build an MCP server in TypeScript that lets Claude Code, Cursor and Codex read and update your issue tracker, with safe write tools and shared HTTP auth.

Polin Khan

9 min read

Every team has a handful of internal tools that everyone opens twenty times a day: the issue tracker, the HR portal, an admin dashboard. AI coding assistants are now where many of us spend the day too, and copying text between the two gets old fast.

The Model Context Protocol (MCP) fixes that. You write one small server that exposes your tool's actions, and any MCP client can use them: Claude Code, Cursor, Codex, Claude Desktop and others. At work I built MCP servers for our issue tracker and our HR system, and the whole team now asks things like "what's assigned to me this sprint?" or "add a comment to #1423 with the fix" without leaving the editor.

This guide walks through the same approach with a Redmine-style issue tracker as the example. It uses the v2 TypeScript SDK.

What an MCP server actually is

An MCP server is a small program that tells an AI client three kinds of things:

  • Tools: actions the model can call, with a name, a description and an input schema. This is what you'll use most.
  • Resources: read-only data the client can load, such as a document or a config file.
  • Prompts: reusable prompt templates.

The client lists your tools, shows them to the model, and calls them when the model decides they help. Your server does the real work, usually by calling an API you already have, and returns text.

Servers talk to clients over one of two transports:

TransportHow it runsUse it when
stdioThe client starts your server as a child process on the same machineEach developer runs it locally with their own API key
Streamable HTTPYour server runs once, somewhere, and clients connect over HTTPYou want one shared server for the team, with central auth and logging

Start with stdio. It's the simplest to build and debug, and moving to HTTP later reuses all of your tool code.

Set up the project

TerminalBash
mkdir tracker-mcp && cd tracker-mcp
npm init -y
npm pkg set type=module
npm install @modelcontextprotocol/server zod tsx
mkdir src

A small API client

Keep the HTTP calls to your tool in one place. Redmine's REST API takes the key in an X-Redmine-API-Key header; your tool will have its own equivalent.

src/tracker.tsTypeScript
const BASE_URL = process.env.TRACKER_URL;
const API_KEY = process.env.TRACKER_API_KEY;
 
if (!BASE_URL || !API_KEY) {
  throw new Error("Set TRACKER_URL and TRACKER_API_KEY");
}
 
export async function tracker<T>(path: string, init: RequestInit = {}): Promise<T> {
  const response = await fetch(new URL(path, BASE_URL), {
    ...init,
    headers: {
      "Content-Type": "application/json",
      "X-Redmine-API-Key": API_KEY!,
      ...init.headers,
    },
  });
  if (!response.ok) {
    throw new Error(`Tracker API error: HTTP ${response.status}`);
  }
  // Updates return 204 No Content
  return (response.status === 204 ? null : await response.json()) as T;
}
 
export type Issue = {
  id: number;
  subject: string;
  status: { name: string };
  assigned_to?: { name: string };
  description?: string;
  journals?: { user: { name: string }; notes: string; created_on: string }[];
};

Read-only tools first

Start with tools that can't change anything. They're safe to let the model call freely, and they cover most of what people actually ask.

src/server.tsTypeScript
import { McpServer } from "@modelcontextprotocol/server";
import * as z from "zod/v4";
import { tracker, type Issue } from "./tracker.js";
 
const text = (value: string) => ({ content: [{ type: "text" as const, text: value }] });
 
export function createServer(): McpServer {
  const server = new McpServer({ name: "tracker", version: "1.0.0" });
 
  server.registerTool(
    "search-issues",
    {
      title: "Search issues",
      description:
        "List open issues in a project. Use assignee 'me' for the current user's issues. Returns id, status, assignee and subject.",
      inputSchema: z.object({
        project: z.string().describe("Project identifier, e.g. 'web-portal'"),
        assignee: z.string().optional().describe("'me' or a user id"),
        limit: z.number().int().min(1).max(50).default(20),
      }),
      annotations: { readOnlyHint: true },
    },
    async ({ project, assignee, limit }) => {
      const params = new URLSearchParams({ project_id: project, status_id: "open", limit: String(limit) });
      if (assignee) params.set("assigned_to_id", assignee);
      const { issues } = await tracker<{ issues: Issue[] }>(`/issues.json?${params}`);
      if (issues.length === 0) return text("No open issues found.");
      return text(
        issues
          .map((i) => `#${i.id} [${i.status.name}] ${i.assigned_to?.name ?? "unassigned"}: ${i.subject}`)
          .join("\n"),
      );
    },
  );
 
  server.registerTool(
    "get-issue",
    {
      title: "Get issue",
      description: "Get one issue with its description and comment history.",
      inputSchema: z.object({ id: z.number().int().describe("Issue number, without the #") }),
      annotations: { readOnlyHint: true },
    },
    async ({ id }) => {
      const { issue } = await tracker<{ issue: Issue }>(`/issues/${id}.json?include=journals`);
      const comments = (issue.journals ?? [])
        .filter((j) => j.notes)
        .map((j) => `- ${j.user.name} (${j.created_on}): ${j.notes}`)
        .join("\n");
      return text(
        `#${issue.id}: ${issue.subject}\nStatus: ${issue.status.name}\n\n${issue.description ?? ""}\n\nComments:\n${comments || "none"}`,
      );
    },
  );
 
  return server;
}

A few things here matter more than they look:

  • Descriptions are prompts. The model decides when to call a tool from its description alone. Say what it returns and when to use it, and describe every parameter with .describe().
  • Return compact text. Don't dump raw JSON with fifty fields. Every token you return fills the model's context; give it what it needs to answer.
  • Cap list sizes. A limit with a sensible maximum stops one call from returning 2,000 issues.

Write tools, carefully

Now the useful but risky part: letting the model change things. Make write tools narrow, and mark them so clients ask before running them.

src/server.ts (inside createServer)TypeScript
server.registerTool(
  "add-comment",
  {
    title: "Add a comment to an issue",
    description: "Post a comment on an issue. Only call this when the user asked to comment.",
    inputSchema: z.object({
      id: z.number().int(),
      comment: z.string().min(1).max(5000),
    }),
    annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
  },
  async ({ id, comment }) => {
    await tracker(`/issues/${id}.json`, {
      method: "PUT",
      body: JSON.stringify({ issue: { notes: comment } }),
    });
    return text(`Comment added to #${id}.`);
  },
);

How I keep write tools safe:

  • Add actions, not raw access. add-comment and set-status are fine. A generic update-issue that takes any field is not, and delete-issue doesn't belong in an MCP server at all.
  • Use annotations honestly. readOnlyHint and destructiveHint are hints clients use to decide when to ask for confirmation. They don't enforce anything, so your API key's permissions are the real limit.
  • Use each person's own key. With stdio, every developer runs the server with their own API key, so actions show up under their name and they can't do anything they couldn't already do in the web UI.

Run it over stdio

src/index.tsTypeScript
import { serveStdio } from "@modelcontextprotocol/server/stdio";
import { createServer } from "./server.js";
 
void serveStdio(createServer);
console.error("tracker MCP server running on stdio");

Log with console.error, never console.log. On stdio, standard output is the protocol channel, and a stray log line corrupts it.

Before wiring it into an editor, poke at it with the MCP Inspector. It lists your tools, lets you call them with test input and shows the raw messages:

TerminalBash
TRACKER_URL=https://tracker.example.com TRACKER_API_KEY=... \
  npx @modelcontextprotocol/inspector npx tsx src/index.ts

Connect it to Claude Code, Cursor and Codex

Claude Code. Add it from the command line. --scope project writes it to .mcp.json so the whole team gets it from the repository:

TerminalBash
claude mcp add tracker --scope project \
  --env TRACKER_URL=https://tracker.example.com \
  --env TRACKER_API_KEY=your-key \
  -- npx tsx /path/to/tracker-mcp/src/index.ts

If you commit .mcp.json, replace the real key with ${TRACKER_API_KEY} so each person's key comes from their own environment.

Cursor. Add it to .cursor/mcp.json in the project, or ~/.cursor/mcp.json for every project:

.cursor/mcp.jsonJSON
{
  "mcpServers": {
    "tracker": {
      "type": "stdio",
      "command": "npx",
      "args": ["tsx", "/path/to/tracker-mcp/src/index.ts"],
      "env": {
        "TRACKER_URL": "https://tracker.example.com",
        "TRACKER_API_KEY": "${env:TRACKER_API_KEY}"
      }
    }
  }
}

Codex. Use the CLI, or add the same thing to ~/.codex/config.toml:

TerminalBash
codex mcp add tracker --env TRACKER_URL=https://tracker.example.com \
  --env TRACKER_API_KEY=your-key -- npx tsx /path/to/tracker-mcp/src/index.ts
~/.codex/config.tomltoml
[mcp_servers.tracker]
command = "npx"
args = ["tsx", "/path/to/tracker-mcp/src/index.ts"]
 
[mcp_servers.tracker.env]
TRACKER_URL = "https://tracker.example.com"
TRACKER_API_KEY = "your-key"

Restart the client, then ask it something like "What issues are assigned to me in web-portal?"

One shared server over HTTP

Once a few people use it, a shared HTTP server is easier to maintain: one deployment, one place for logs, and nobody has to install Node.js tools locally. The tool code stays exactly the same; only the entry point changes.

TerminalBash
npm install @modelcontextprotocol/express @modelcontextprotocol/node express
src/http.tsTypeScript
import { createMcpExpressApp, requireBearerAuth } from "@modelcontextprotocol/express";
import { toNodeHandler } from "@modelcontextprotocol/node";
import { createMcpHandler } from "@modelcontextprotocol/server";
import { createServer } from "./server.js";
 
const handler = createMcpHandler(() => createServer());
const node = toNodeHandler(handler);
 
const app = createMcpExpressApp({ host: "0.0.0.0", allowedHosts: ["mcp.internal.example.com"] });
const auth = requireBearerAuth({ verifier });
 
app.all("/mcp", auth, (req, res) => void node(req, res, req.body));
app.listen(3000);

verifier is your own function that checks the bearer token and returns who the caller is. That's where you plug in your SSO or a table of personal tokens. Inside a tool, the verified identity is available as ctx.http.authInfo, which lets you call the tracker as that user instead of with one shared admin key.

Clients then connect by URL:

TerminalBash
claude mcp add --transport http tracker https://mcp.internal.example.com/mcp \
  --header "Authorization: Bearer your-token"

What I learned running these at work

  • Fewer, sharper tools win. Six well-described tools beat twenty overlapping ones. When tools overlap, the model picks the wrong one.
  • Write the error for the model. "Project 'web' not found. Valid projects: web-portal, mobile-app" lets the model fix its own call. "HTTP 404" doesn't. Return errors with isError: true in the result.
  • Paginate and summarise on the server. If an answer needs 500 records, do the counting in your code and return the summary.
  • Start read-only. Ship the read tools, watch how people use them for a week, then add the two or three write actions they actually ask for.

FAQ

What is an MCP server?

A small program that exposes tools, data or prompts to AI clients through the Model Context Protocol. The client, such as Claude Code or Cursor, discovers its tools and calls them when they help answer a request.

Should I use stdio or Streamable HTTP?

Use stdio for a server each developer runs locally with their own credentials. Use Streamable HTTP when you want one shared server for a team, with central authentication, logging and updates.

Can one MCP server work with Claude, Cursor and Codex?

Yes. That's the point of the protocol. The server code is the same; each client only needs a few lines of configuration pointing at it.

How do I stop the AI from making changes I didn't ask for?

Keep write tools narrow, mark them with readOnlyHint: false so clients ask for confirmation, run the server with each user's own permissions, and leave destructive actions such as deletes out entirely.

Why does my stdio server break when I add logging?

On stdio, standard output carries the protocol messages. Anything printed with console.log corrupts them. Log to standard error with console.error instead.