A practical guide to MCP servers and integrations for marketing, design, and content workflows.

Building a Custom MCP Server With the TypeScript SDK

Three decisions turn your application logic into a tool any MCP agent can call.

· 8 min read
Cover illustration for “Building a Custom MCP Server With the TypeScript SDK”
MCP Tool Development · November 13, 2026 · 8 min read · 1,897 words

Building a custom MCP server with the TypeScript SDK is a tractable engineering task. The work is easier to manage when it is split into three choices: the tool contract, the transport, and the deployment pattern. Together, those decisions turn application logic into a service that MCP-compatible agents can call without a separate integration for each client.

What MCP is and why the TypeScript SDK is the right tool for building a server today

MCP is a JSON-RPC 2.0 protocol that gives AI agents a standard way to call external tools, read data, and use prompt templates. Its three primitives divide those capabilities clearly. Tools are callable functions, resources are data addressed by URI, and prompts are reusable message templates. Native support across Claude, ChatGPT, Gemini, Microsoft Copilot, Visual Studio Code, and Cursor makes that shared interface useful across the major clients.

The TypeScript SDK handles the JSON-RPC layer entirely. A working server is roughly 40 lines, leaving the builder to design its capabilities. The version landscape still requires attention, however. The SDK’s v2 stable line uses separate @modelcontextprotocol/server and @modelcontextprotocol/client packages and implements the date-versioned 2026-07-28 specification. That revision removes the initialize handshake and protocol-level session, so tutorials targeting 2024 or 2025 revisions retain conceptual value but contain outdated wire details.

The three layers every custom MCP server depends on — tool contracts, transport, and deployment shape

The tool contract defines what the agent sees. Its name, description, and Zod-typed input schema explain what the tool does and how to call it, while the implementation remains behind that interface. Transport then determines how a client reaches the server. Stdio connects a client to a subprocess on the same machine, whereas Streamable HTTP makes the server accessible over a network.

Deployment gives those choices an operating environment. A local binary, containerized HTTP service, and serverless function have different requirements for packaging, authentication, state, and scaling. These concerns are separable, but their order is consequential because each decision constrains the next. Even a correct handler is of little use if the contract is vague or the intended client cannot reach the transport.

Defining tool contracts — schema, description, and the mistakes that break agent behavior

The contract is the agent’s entire user manual. The model does not read the handler’s source code to discover what inputs it accepts or when it should be used. Instead, it chooses tools through the descriptions and schemas exposed by the server. Contract design therefore precedes handler refinement. Even correct application logic is of limited use when the agent cannot distinguish its purpose from that of a related tool.

For the v2 SDK, project setup begins with mkdir orders-mcp && cd orders-mcp, followed by npm init -y && npm pkg set type=module. Install the runtime dependencies with npm install @modelcontextprotocol/server zod and the development dependencies with npm install --save-dev tsx typescript @types/node. Module resolution needs explicit configuration. Set both module and moduleResolution to Node16 in the TypeScript configuration because the older node resolution cannot resolve the SDK’s .js extension imports.

Server construction uses McpServer from @modelcontextprotocol/server, with a name such as orders and version 1.0.0. Registration uses server.registerToolRegistration uses server.registerTool, the successor to the older server.tool method.tool method. Its arguments are a name string, a configuration object, and an asynchronous handler. The configuration supplies the title, description, Zod input schema, and optional annotations. The handler returns a content array, where a text result is an object whose type is text and whose text` holds the serialized result.

The description is a routing instruction. It should explain what the tool returns and how it differs from related tools, using the precision appropriate for a smart junior developer. Error responses need an equally deliberate contract. Return content with isError set to true rather than throwing an application error across the protocol boundary, where it becomes an unstructured failure. For HTTP, a factory function builds the server separately so that each independent request can get its own server object.

Resources are read-only, application-controlled data addressed by URI, suitable for a product catalog, brand guidelines, or today’s error logs. Prompts are user-controlled, parameterized templates for workflows a user deliberately invokes. When resources have side effects or tools only return static data, those boundaries become hard to predict. Output has a boundary too. Stdio reserves stdout for JSON-RPC, so debugging belongs in console.error() or a log file.

Choosing between stdio and Streamable HTTP — what each transport actually determines

Stdio limits the server to processes that the host client launches directly. The client starts the server as a subprocess and communicates through its stdin and stdout. This works well for local developer tools, internal scripts, Claude Desktop, and Cursor on the same machine. No network listener or port management is required. Connecting a StdioServerTransport to the server is thus the easiest way to get it working.

The Claude Desktop configuration has the path to the compiled entry point and any environment variables the server needs. That arrangement suits tools that depend on the developer’s local environment, but it does not make the server available to remote agents. Streamable HTTP serves that different client population. It is the appropriate transport when other developers, teams, or tenants need network access.

The SDK provides NodeStreamableHTTPServerTransport through @modelcontextprotocol/node and WebStandardStreamableHTTPServerTransport through @modelcontextprotocol/server. Express and Hono adapters are also available through @modelcontextprotocol/express and @modelcontextprotocol/hono. The versions must match before the code that connects them can be copied. Under the 2026-07-28 revision, requests are stateless, and older examples built around protocol sessions, the Mcp-Session-Id header, or an HTTP GET stream are outdated. The factory pattern remains useful for request-scoped server objects.

Treat the server as an OAuth 2.1 resource server, validate bearer tokens with requireBearerAuth, and advertise the authorization server through protected resource metadata. Authentication failures return 401 with WWW-Authenticate. To keep those concerns out of initial debugging, build and test over stdio first. Move to HTTP when remote access is required.

Testing a server before wiring it to a live client

The MCP Inspector is the main tool for testing a server before it connects to a live client. It separates server behavior from client configuration, avoiding a debugging process in which either could explain every failure. Before client testing starts, npx tsc should finish without output and with exit code 0, and dist/index.js should exist.

The test should inspect the tool list returned by tools/list, the response shape for a valid call, and the isError response for an invalid input. It should also confirm that stdout contains no output other than protocol messages. Where a graphical testing tool is unavailable, raw JSON-RPC provides a secondary route. Piping a tools/call request directly to the server’s stdin and inspecting the response tests the protocol path without involving a client UI.

Deployment patterns — local binary, containerized HTTP service, and serverless function

A local binary is a natural fit for stdio transport. Build it with tsc, ship the dist/ directory, and include a package.json whose bin field points to the entry point. Publishing to npm allows clients to install it globally with npm install -g or invoke it through npx. The client manages the process lifecycle. This pattern needs no server infrastructure or network authentication and works well for utilities that read local files or call APIs with credentials passed through environment variables.

A containerized HTTP service lets clients share access over a network. The container exposes a single POST endpoint for MCP requests, with OAuth 2.1 bearer-token validation applied before requests reach the MCP handler. Under the 2026-07-28 specification, requests are stateless, so there is no need for session affinity and load balancing is simpler. This pattern works well for servers shared by a team and for access to private network resources. It also works well for servers that need rate-limiting or audit-logging.

Serverless deployment uses the same independent-request model. Stateless HTTP maps cleanly to a function. Cold starts are the main tradeoff. They can be acceptable for moderate call frequency but problematic for latency-sensitive interactive tools, making this pattern a fit for low-traffic servers where infrastructure management should remain minimal.

Before shipping, the deployment review should cover packaging, state, authentication, and client compatibility. The transport implementation must also match the revision used by the clients. When both sides target 2026-07-28, the v2 migration guide is the authoritative reference before adopting HTTP code from an older tutorial.

Applying the same pattern to brand context — what a brand MCP server exposes and why it works

Every agent working on a brand needs structured information that is up to date, without a separate copy pasted into each prompt. A brand MCP server applies the same contracts, transport, and deployment choices to that requirement. The distinction lies in what it exposes. Its resources contain read-only information such as color tokens, typography, logo references, voice rules, approved asset lists, and naming guidelines that include retired names.

Tools provide access shaped around the current task. They can retrieve visual rules, voice rules, or full guidelines, find approved assets, or review generated content against the brand. Prompts serve a different purpose by defining review workflows that a user deliberately invokes. A review might examine copy first from the target reader’s perspective and then for brand voice and naming compliance.

Pulumi Brand MCP Server exposes Pulumi’s guidelines as structured resources, tools, and prompts over Streamable HTTP at brand.pulumi.com. Its review_copy prompt starts with the target reader’s point of view. It then reviews brand voice, tone, writing style, and naming, including every product and feature name against the retired-names list. Frontify’s MCP server provides another application of shared brand access. Connected tools such as Claude or ChatGPT can find approved assets, check guidelines, and generate on-brand creative from editable templates, with context updating as guidelines and assets change.

The @brandsystem/mcp package takes a compilation approach. It extracts brand identity from sources including websites, PDF guides, Figma libraries, and local files, then compiles a .brand/ directory containing DTCG tokens, brand-runtime.json, and interaction-policy.json. Its brand_runtime tool supports full, visual, voice, and minimal slices for different token budgets. A separate brand_context tool selects task-scoped context through task_type and standard or compact budget modes. Host-native exports include AGENTS.md, Cursor rules, CSS variables, a Tailwind v4 theme, a shadcn/ui theme, and a Claude skill.

Current data is essential to this design. A shared server containing stale token values or retired product names would distribute the wrong guidance through the same interface intended to prevent inconsistency. The deployment pattern should therefore version brand data as code is versioned, allowing connected agents to receive updates without reconfiguration. This makes the server more than a convenient retrieval endpoint. It becomes the source of brand context that compatible clients share.

What to build next once the first server is running

Add one tool at a time, test it with the Inspector before connecting a live client, and keep its description precise and schema narrow. The same approach works for multi-tool servers, multi-brand configurations, and agent workflows that share one source of context. The work can grow more complex while the architectural model stays the same.

Portability is the durable return on that work. MCP’s move to the Linux Foundation reinforces the protocol’s role as vendor-independent infrastructure. A server built against the specification can serve Claude and other compatible clients without duplicating its application logic for each. As additional agents support the protocol, the reusable asset remains the server and its contracts.

More in MCP Tool Development