Build a minimal MCP server in TypeScript
Build a local TypeScript MCP server with one read-only tool, validated input and stdio transport.

Put it into practice
What you will produce
A server with one narrowly scoped tool, input validation, a predictable response and a smoke-test request.
- 01
Define the example contract
Choose one harmless capability, such as returning a fixed project note; specify its input shape, expected response and what it must never access or change.
Expected result: A tiny example with a testable boundary and no implied production authority.
- 02
Build the smallest typed tool
Use the SDK version pinned by the example's project, validate the input at the tool boundary and return a deterministic response; check API names in that version's official documentation.
Expected result: One locally inspectable tool with an explicit schema and predictable output.
- 03
Exercise valid and invalid requests
Send a valid sample request, then malformed and out-of-range inputs; verify each invalid case is rejected without touching external files or services.
Expected result: A smoke-test record showing the documented response and safe failure behavior.
- 04
Explain how to adapt it
Document startup, required configuration, exposed capability, test invocation and the extra review needed before adding credentials, network access or writes.
Expected result: An example a developer can run and extend without mistaking it for a production-ready server.
A local MCP server with one read-only tool
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
const server = new McpServer({ name: "project-notes", version: "1.0.0" });
server.registerTool(
"read_workflow_note",
{
description: "Return the public workflow note when topic is workflow.",
inputSchema: { topic: z.string().min(1).max(40) },
},
async ({ topic }) => ({
content: [{
type: "text",
text: topic === "workflow"
? "The workflow note is: scope, inspect, change, verify, review."
: "No note is available for that topic.",
}],
})
);
await server.connect(new StdioServerTransport());Complete example for the MCP TypeScript SDK v1 local stdio transport. Install @modelcontextprotocol/sdk and zod in a compatible Node.js project, then run this file with your chosen TypeScript runtime. The tool reads and writes no files and makes no network calls. Check versions and execution commands in the linked official guide before adapting it.
Acceptance checks
- The example exposes exactly one narrowly scoped capability.
- The SDK version and corresponding API documentation are identified.
- Valid input returns the documented value and malformed input is rejected.
- No credentials, external writes or unreviewed file access are required to run the sample.
Limits and trade-offs
MCP SDK APIs evolve. Pin the SDK version used by your example and verify method names against current official docs.
Official sources
Map useful MCP servers
Related guides
Claude Code MCP: Connect Servers & Tools
Claude Code MCP (Model Context Protocol) lets you plug external tools and data into Claude. Full guide: how to add an MCP server, list available ones, and the patterns that work.
A Claude Code conversation can only do so much with the tools shipped in the box. The moment you want Claude to touch Notion, Stripe, your AWS account, a specific database you need MCP. MCP (Model Context Protocol) is the standard that connects Claude to external tools. Here's what it is, how to add servers, and the patterns that don't waste your time. What MCP actually is MCP is an open protocol. A small server process (the "MCP server") exposes a set of tools. Claude Code (the "MCP client") talks to it over stdio or HTTP. When Claude needs to call one of those tools, it sends a JSON RPC request; the server runs the function and returns the result. Three pieces: MCP server the process that exposes tools. Usually npx installable. Examples: filesystem, GitHub, Notion, Stripe, Postgres. MCP client Claude Code itself. It manages connections, surfaces tools to the…
Read the guideConnect Claude to Notion, Gmail & Drive
Claude Code MCP servers let Claude read and write Notion, Gmail, and Google Drive. Step-by-step setup guide for the three most useful ones.
An MCP server exposes external tools to Claude Code. Depending on the server, it can run locally or remotely. Retrieved data may be sent to the model provider, the connected service and, for a hosted server, its operator. Check their policies and your authorization before connecting sensitive data. Choose a connection For Notion, Gmail and Google Drive, start with the provider's documentation and the MCP server maintainer's current instructions. Check its maintainer, available tools, authentication and requested permissions. Capabilities vary: do not assume a Gmail server is limited to drafts. Register the server with the maintainer's command and choose its scope. Shared project configuration lives in .mcp.json at the repository root; never put tokens in it. The Claude Code MCP documentation covers local and HTTP servers and their scopes. Connect Notion to Claude Code Notion documents a remote MCP server. After installing Claude Code, register it from the project where…
Read the guideBuilding AI agents that actually work
Most 'agents' are brittle pipelines dressed up with AI. Here's the anatomy of a reliable agent, three patterns that hold up in production, and when to use n8n vs code.
Everyone is building agents. Most of them break on the third run. One common failure mode is asking the model to handle too many responsibilities without clear checks. Architecture, model behavior and external dependencies can all contribute to failures. Here's what I've learned building agents that actually run week after week. The anatomy of a reliable agent Every agent that works has three parts, and only one of them should involve AI. Trigger something deterministic starts the agent. A schedule, a webhook, a file drop, a form submission. Not "whenever the AI decides it's time." Context the agent gathers what it needs before calling the AI. The document, the data, the user preferences, the constraints. The AI call happens with full context, not halfway through discovery. Action after the AI produces output, something deterministic happens with it. It gets saved, sent, logged, or published. The action step doesn't retry or…
Read the guide