Home›MCP / Tooling›MCP 2026-07-28対応のMCPサーバーをTypeScript SDK v2で作ってみた(実装編)
MCP 2026-07-28対応のMCPサーバーをTypeScript SDK v2で作ってみた(実装編)

MCP 2026-07-28対応のMCPサーバーをTypeScript SDK v2で作ってみた(実装編)This article walks through building a working MCP server compliant with the…

元記事を読むRead original articleqiita.com(新しいタブで開きます)(opens in a new tab)
AI要点サマリSummary highlight

MCP 2026-07-28仕様に準拠したMCPサーバーをTypeScript SDK v2で実際に構築する手順を解説しており、前回の仕様整理編に続く実装編として具体的なコード例を提供している。

This article walks through building a working MCP server compliant with the 2026-07-28 spec using TypeScript SDK v2, serving as the hands-on implementation follow-up to a prior spec-overview post.

本ページの本文と要約は AI による自動生成です。日本語版と英語版は言語ごとに独立して生成されるため、表現や詳しさが異なる場合があります。正確性は元記事 (qiita.com) をご確認ください。The body and summaries are AI-generated independently for each language, so wording and detail may differ. Verify accuracy at the original source (qiita.com).

要約と収集メタデータに基づく AI 解説。元記事全文の転載・翻訳ではありません。AI explainer based on the summaries and collected metadata, not a copy or translation of the full source article.

MCPサーバー

MCP 2026-07-28仕様に準拠したMCPサーバーを、TypeScript SDK v2で実際に構築する実装例だ。仕様をコードへ落とし込み、新しい通信モデルを手元で再現することに重点を置いている。

実際のAWSやKubernetesには接続せず、デプロイ処理はシミュレーションする。動作するサーバーを作りながら、仕様を読むだけでは把握しにくい実装方法を確認する構成となっている。

Requestの橋渡し

コア部分の@modelcontextprotocol/serverは、Web標準のRequestを扱う。一方、@modelcontextprotocol/nodeは、Node.jsのnode:httpとの橋渡しを担う。この分割により、Cloudflare WorkersやDenoにも載せ替えやすいと説明されている。

また、ESMのimportを通すため、最初にnpm pkg set type=moduleを実行する必要がある。

ファクトリー関数

createMcpHandlerへ渡すのは、サーバーインスタンスではなくファクトリー関数だ。この関数はHTTPリクエストごとに実行され、そのたびに新しいMcpServerが作られる。

手元の1プロセスでは、不適切な実装でも動いてしまう場合がある。しかし、ECSタスクを複数立てると壊れるため、リクエスト単位でサーバーを生成するモデルに合わせる必要がある。

HMAC署名とMRTR

セッションがなくなったことで、prepare_deploymentで作成した計画をexecute_deploymentへ渡す手段が必要になる。実装例では、計画をJSON文字列化したペイロードに署名を加え、HMAC署名付きトークンとして受け渡している。

MRTRで承認を求める際はinputRequired()を返す。ユーザーの回答が付いた状態で同じハンドラーが再実行されるため、この再実行を前提に処理を組み立てる。

TypeScript SDK v2

This implementation builds a working MCP server compliant with the MCP 2026-07-28 specification using TypeScript SDK v2. It follows an earlier review of the specification changes and focuses on showing how the revised communication model works in code.

The server does not connect to real AWS or Kubernetes environments. Deployment operations are simulated so that the new communication model can be reproduced locally without performing an actual deployment.

Request and node:http

The implementation separates the core server behavior from the Node.js HTTP integration. The @modelcontextprotocol/server package handles the web-standard Request object, while @modelcontextprotocol/node provides the bridge to Node.js node:http.

This division makes the server easier to move to Cloudflare Workers or Deno. The project must also be configured as an ESM package. Running npm pkg set type=module at the beginning prevents ESM import statements from failing.

createMcpHandler factory function

createMcpHandler receives a factory function rather than a server instance. That function runs for every HTTP request and creates a new McpServer each time.

This request-level lifecycle affects how state can be handled. Code that relies on reusing a single server instance may appear to work while testing within one local process, but it breaks when multiple ECS tasks are started.

Because there is no session, a separate mechanism is required to pass the plan created by prepare_deployment to execute_deployment. The implementation uses an HMAC-signed token for that purpose. The plan is serialized as JSON, converted to a UTF-8 payload, and combined with a signature generated from that payload.

MRTR approval handling

Under MRTR, a handler returns inputRequired() when it needs approval from the user. After the user’s response is attached, the same handler runs again.

The implementation therefore demonstrates both parts of the revised flow: preserving deployment-plan information without a session and resuming the same handler after required user input has been provided.

ポコとTECHガイドPoko & TECH Guide

ポコと当サイトのTECHガイドが、記事の要約と収集した情報から読みどころを語るAI生成の対話です。Poko and TECH Dashboard's own TECH Guide discuss the article's highlights in an AI-generated conversation based on its summary and collected source details.

  1. ポコPokoHTTPリクエストのたびに新しいMcpServerを作るって、かなり大きな変化? 1個を使い回すんじゃないんだ!A new McpServer for every HTTP request—is that a major change? I thought you’d just reuse one!
  2. TECHガイドTECH Guideこの記事では、使い回す実装は1プロセスだと動いても、ECSタスクを複数にすると壊れるとしておる。新しい通信モデルを再現する重要な点じゃな。The article warns that reuse may work in one process but break with multiple ECS tasks. So creating a server per request is an important part of reproducing the new communication model.
  3. ポコPokoセッションがないからHMAC署名付きトークンで計画を渡すって、つまりどういうこと?With no session, the plan is passed in an HMAC-signed token. What does that actually mean?
  4. TECHガイドTECH Guide本文の実装では、準備した計画を署名付きの札にして次の処理へ渡すんじゃ。HMACは、共有した秘密を使って改変を確かめる署名じゃよ。In this implementation, the prepared plan becomes a signed tag passed to the next step. HMAC is a signature made with a shared secret, letting the system check for tampering.
  5. ポコPoko僕なら、承認を挟むデプロイ手順を手元で試す練習用サーバーにしてみたいな。I’d use it as a practice server for testing a deployment flow that pauses for approval.
  6. TECHガイドTECH Guideこの作例も承認後に同じハンドラーを再実行する形じゃ。ただしAWSやKubernetesには接続せず、デプロイはシミュレーションじゃよ。That matches the example: after approval, the same handler runs again. Just remember, it doesn’t connect to AWS or Kubernetes—the deployment itself is simulated.
記事情報・収集記録Article details & collection record
出典Source
Qiita MCPコミュニティCommunity
公開日時 (JST)Published (JST)
収集日時 (JST)Collected (JST)
配信形式Format
ブログBlog
原文言語Source language
JA
重要度の位置づけImportance in this lane
MediumMedium priority(MCP / Tooling 122件中、同等以上 112件)(112 of 122 MCP / Tooling entries are equal or higher)
出典の平均重要度(掲載直近 30 件・最大 30 件)Source average (last 30 listed, up to 30)
2.1 / 31=情報 · 2=中 · 3=高1=Info · 2=Medium · 3=High
情報の寿命Half-life
中期 (チュートリアル)Medium-term (tutorial)

🔗MCP / Tooling の他の記事More from MCP / Toolingもっと見る →View more →

ページ上部へScroll to top