MCP採用の拡大:よりシンプルで安全、かつコスト効率の良い企業向けMCP導入のためのリファレンスアーキテクチャ
Cloudflareは、Model Context Protocol(MCP)の企業規模での安全かつ低コストな導入を実現するため、リモートサーバー分離と専用ゲートウェイを組み合わせた参考アーキテクチャを公開した。
キーポイント
MCPクライアントとサーバーの分離設計
エージェントの自律性と企業リソースへのアクセス権限を物理的に分離し、セキュリティ境界を明確化する。
Cloudflareプラットフォームとの統合管理
Cloudflare OneとDeveloperプラットフォームを連携させ、認可スプレッドやプロンプトインジェクションなどのリスクを一元制御する。
コスト削減と不正利用検知の新機能
Code Modeによるトークン効率化と、Cloudflare Gatewayを活用したShadow MCPサーバーの自動検出を実装する。
ローカル展開のセキュリティリスクと集中管理
ローカルMCPサーバーは未検証ソースによるサプライチェーン攻撃やツールインジェクションのリスクがあり、IT管理者による統制が不可能であるため、Cloudflareは社内チームによる集中管理プラットフォームを採用してインフラとガバナンスを標準化している。
テンプレート駆動の自動ガバナンスと迅速な展開
従業員はAIガバナンスの承認後、テンプレートをコピーして展開するだけで、監査ログやシークレット管理、自動CI/CDパイプラインなどのガバナンス機能を自動的に継承でき、展開に要する時間を数分に短縮している。
Cloudflare Accessを活用した認証とグローバル展開
プライベートMCPサーバーにはOAuthプロバイダーとしてCloudflare Accessを統合しSSOやMFA、コンテキスト属性を検証する一方、Cloudflareのグローバルネットワークへ自動展開することで低レイテンシと可視性・制御性を両立させている。
MCPサーバーポータルによる一元化管理とアクセス制御
発見機能、ログ管理、DLPガードレールを一元化し、ロールや環境に応じたツール公開とポリシー適用を実現する。
影響分析・編集コメントを表示
影響分析
MCP標準の普及に伴い、企業はセキュリティリスクを無視したローカル展開から、クラウドプロバイダーが提供する一元管理型リモートアーキテクチャへ移行する必要がある。本記事は、具体的な実装パターンと制御ポイントを提示することで、企業向けAIセキュリティの実践基準を定義するきっかけとなる。
編集コメント
自社プラットフォームの販促色が強いものの、MCP標準化に伴う「認可スプレッド」や「サプライチェーン攻撃」といった実務上の課題に対し、具体的なアーキテクチャパターンを示している点は評価できる。企業はベンダーロックインを避けつつ、同様の分離設計とゲートウェイ制御を導入するべきだろう。
Cloudflareでは、Model Context Protocol(MCP)をAI戦略の中核として積極的に採用しています。この取り組みはエンジニアリング組織の枠を超え、製品、営業、マーケティング、財務などの各部門の従業員が、日々の業務効率化のためにエージェント型ワークフローを活用するまでに広がっています。しかし、MCPを用いたエージェント型ワークフローの導入には、セキュリティリスクが伴います。これには権限管理の散逸(authorization sprawl)、プロンプトインジェクション、サプライチェーンリスクなどが含まれます。社全体でのこの広範な採用を安全なものとするため、Cloudflare One(SASE)プラットフォームとCloudflare Developerプラットフォームの両方から一連のセキュリティ制御を統合し、業務速度を落とすことなくMCPによるAI利用をガバナンスできるようにしました。
このブログ記事では、自律型AI時代の統一されたセキュリティアーキテクチャを構築するためにプラットフォームの異なる要素を組み合わせて、MCPワークフローを保護するための当社のベストプラクティスをご紹介します。また、エンタープライズ向けMCP導入を支える2つの新しい概念についても共有します。
MCPサーバーポータルとCode Modeをリリースし、MCP利用に関連するトークンコストを大幅に削減します。
Cloudflare Gatewayを使用してShadow MCPを検出する方法について説明し、認可されていないリモートMCPサーバーの使用状況を把握します。
さらに、当組織がMCPの導入にどのように取り組み、Cloudflare製品(リモートMCPサーバー、Cloudflare Access、MCPサーバーポータル、AI Gatewayなど)を使用してMCPセキュリティアーキテクチャを構築したかについても言及します。
リモートMCPサーバーは、より優れた可視性と制御性を提供します
MCPは、開発者がAIアプリケーションとアクセスが必要なデータソースの間に双方向接続を構築できるようにするオープン標準です。このアーキテクチャでは、MCPクライアントはLLM(大規模言語モデル)やその他のAIエージェントとの統合ポイントであり、MCPサーバーはMCPクライアントと企業リソースの間に位置します。
image
MCPクライアントとMCPサーバーの分離により、エージェントは自律的に目標を追求し行動を取ることができます。同時に、AI(MCPクライアントで統合)と企業リソースの資格情報およびAPI(MCPサーバーで統合)の間には明確な境界が維持されます。
Cloudflareの従業員は、プロジェクト管理プラットフォーム、社内Wiki、ドキュメントおよびコード管理プラットフォームなど、さまざまな内部リソースへのアクセスにMCPサーバーを絶えず使用しています。
非常に初期の段階で、ローカルホスト型のMCPサーバーはセキュリティ上のリスクであることに気づきました。ローカルのMCPサーバー導入では、審査されていないソフトウェアソースやバージョンに依存する可能性があり、サプライチェーン攻撃やツールインジェクション攻撃のリスクが高まります。また、ITおよびセキュリティ管理者がこれらのサーバーを管理できず、どのMCPサーバーを実行し、どのように最新状態を維持するかを個々の従業員や開発者に委ねることになります。これは勝算のないゲームです。

その代わりに、Cloudflareでは社内チームが企業全体のMCPサーバー導入を一元管理しています。このチームは、モノレポ内に標準でガバナンスされたインフラストラクチャを提供する共有MCPプラットフォームを構築しました。従業員が内部リソースをMCP経由で公開したい場合、まずAIガバナンスチームからの承認を得てから、テンプレートをコピーし、ツールの定義を記述してデプロイします。その間、監査ログ付きのデフォルト拒否書き込み制御、自動生成されたCI/CDパイプライン、シークレット管理を無償で継承します。つまり、新しいガバナンス付きMCPサーバーの構築には、スキャフォールディング(骨組み作成)に数分を要するだけです。ガバナンスはプラットフォーム自体に組み込まれており、これにより採用が急速に拡大することが可能になりました。
当社のCI/CDパイプラインは、これらをCloudflareのデベロッパープラットフォーム上のカスタムドメインにあるリモートMCPサーバーとしてデプロイします。これにより、従業員がどのMCPサーバーを使用しているかを可視化しつつ、ソフトウェアのソースに対する制御を維持できます。さらに利点として、Cloudflareデベロッパープラットフォーム上のすべてのリモートMCPサーバーは、当社のグローバルなデータセンターネットワーク全体に自動的にデプロイされるため、世界中のどこにいても低レイテンシでMCPサーバーにアクセスできます。
Cloudflare Accessによる認証
当社の一部のMCPサーバーは、Cloudflareドキュメント用MCPサーバーやCloudflare Radar用MCPサーバーなど、パブリックなリソースの前に配置されているため、誰でもアクセスできるようにしたいと考えています。しかし、従業員が使用する多くのMCPサーバーは、プライベートな企業リソースの前に配置されています。これらのMCPサーバーにはユーザー認証が必要であり、権限のあるCloudflare従業員以外は一切アクセスできないようにします。これを実現するため、当社のMCPサーバー用モノレポテンプレートには、OAuthプロバイダーとしてCloudflare Accessが統合されています。Cloudflare Accessはログインフローを保護し、リソースへのアクセストークンを発行するとともに、ID集約体として機能し、エンドユーザーのシングルサインオン(SSO)、マルチファクター認証(MFA)、およびIPアドレス、場所、デバイス証明書などのさまざまなコンテキスト属性を検証します。
MCPサーバーポータルによる発見とガバナンスの一元化

MCPサーバーポータルは、すべてのAIアクティビティに対するガバナンスと制御を一元化します。
リモートMCPサーバーの数が増加するにつれ、私たちは新たな壁に直面しました:それは「発見(ディスカバリー)」の問題です。私たちは、すべての従業員(特にMCPに慣れていない新規社員)が、利用可能なすべてのMCPサーバーを簡単に見つけ、活用できるようにしたかったのです。私たちの「MCPサーバーポータル」製品が、このための便利なソリューションを提供しました。従業員は単に自身のMCPクライアントをMCPサーバーポータルに接続するだけで、ポータルが直ちに、彼らがアクセス権を持つ内部およびサードパーティのMCPサーバーをすべて表示します。
さらに、私たちのMCPサーバーポータルは、集中型ログ管理、一貫したポリシーの適用、およびデータ損失防止(DLPガードレール)を提供します。管理者は、誰がどのMCPポータルにログインしたかを確認でき、個人識別情報(PII)などの特定のデータが特定のMCPサーバーと共有されないようにするDLPルールを作成することができます。
また、ポータル自体へのアクセス権限を持つユーザーを制御し、各MCPサーバーからどのツールを公開するかを管理するポリシーを作成することもできます。例えば、社内コードリポジトリの背後にあるMCPサーバーの読み取り専用ツールのみを公開するポータルを、財務グループに所属する従業員のみがアクセスできるように設定できます。一方、エンジニアリングチームの社員が社用ラップトップからアクセスできる別のMCPサーバーポータルでは、コードリポジトリ用のMCPサーバーに対してより強力な読み書きツールを公開することも可能です。
上記は当社のMCPサーバーポータルのアーキテクチャの概要です。このポータルは、Cloudflare上でホストされるリモートMCPサーバーと、その他の場所にあるサードパーティのMCPサーバーの両方をサポートしています。このアーキテクチャが独自に高いパフォーマンスを発揮する理由は、すべてのセキュリティおよびネットワークコンポーネントが、当社のグローバルネットワーク内にある同一の物理マシン上で動作している点にあります。従業員の要求がMCPサーバーポータル、Cloudflareホスト型リモートMCPサーバー、そしてCloudflare Accessを通過する際、そのトラフィックは同一の物理マシンから外に出る必要がありません。
MCPサーバーポータルを使用したコードモードによるコスト削減
高ボリュームのMCPデプロイメントを数ヶ月にわたって実施した結果、私たちは当然のごとく多くのトークンを消費しました。さらに、多くの人がMCPの使い方を誤っていることに気づき始めています。
MCP の標準的なアプローチでは、MCP サーバーを介して公開されるすべての API 操作に対して個別のツールを定義する必要があります。しかし、この静的で網羅的なアプローチは、特にエンドポイントが数千ある大規模なプラットフォームでは、エージェントのコンテキストウィンドウをすぐに枯渇させてしまいます。
以前の記事で、Cloudflare の MCP サーバーを動かすためにサーバーサイドの Code Mode をどのように使用したかについて解説しました。これにより、Cloudflare API の数千のエンドポイントを公開しつつ、トークン使用量を 99.9% 削減することが可能になりました。Cloudflare の MCP サーバーは、わずか 2 つのツールだけを公開しています。検索ツールではモデルが JavaScript を記述して利用可能なリソースを探索でき、実行ツールでは見つけたツールを呼び出すための JavaScript を記述できます。モデルは事前にすべてを受け取るのではなく、必要に応じて必要なものを発見します。
このパターンを非常に気に入ったため、誰もが利用できるようにしました。そこで現在、「Code Mode」パターンを MCP サーバーポータルで使用する機能をリリースしました。これにより、すべての MCP サーバーを中央のポータルでフロントエンド化でき、監査制御と段階的なツール公開を行うことで、トークンコストを削減できます。
動作原理は以下の通りです。すべてのツール定義をクライアントに公開するのではなく、基盤となるMCPサーバーは2つのMCPポータルツール(portal_codemode_search および portal_codemode_execute)に集約されます。検索ツールは、接続されているすべての上位MCPサーバーから取得したツール定義を返す codemode.tools() 関数へのモデルのアクセスを提供します。その後、モデルはJavaScriptを記述してこれらの定義をフィルタリングおよび探索し、コンテキストにすべてのスキーマを読み込むことなく、必要なツールを正確に見つけ出します。実行ツールは、各上位ツールが呼び出し可能な関数として利用可能な codemode プロキシオブジェクトを提供します。モデルはこれらのツールを直接呼び出すJavaScriptを記述し、複数の操作をチェーンしたり、結果をフィルタリングしたり、コード内でエラー処理を行います。これらすべての処理は、Dynamic Workers によって駆動されるMCPサーバーポータル上のサンドボックス環境で実行されます。
Jiraのチケットを検索し、Google Driveからの情報でそれを更新する必要があるエージェントの例を示します。まず、適切なツールを検索します:
// portal_codemode_search
async () => {
const tools = await codemode.tools();
return tools
.filter(t => t.name.includes("jira") || t.name.includes("drive"))
.map(t => ({ name: t.name, params: Object.keys(t.inputSchema.properties || {}) }));
}
モデルは、ツールの完全なスキーマがコンテキストに入る必要なく、必要な正確なツール名とパラメータを把握します。その後、操作をチェーンする単一のexecute呼び出しを記述します:
// portal_codemode_execute
async () => {
const tickets = await codemode.jira_search_jira_with_jql({
jql: ‘project = BLOG AND status = “In Progress”’,
fields: [“summary”, “description”]
});
const doc = await codemode.google_workspace_drive_get_content({
fileId: “1aBcDeFgHiJk”
});
await codemode.jira_update_jira_ticket({
issueKey: tickets[0].key,
fields: { description: tickets[0].description + “\n\n” + doc.content }
});
return { updated: tickets[0].key };
}
これは単なる2つのツール呼び出しに過ぎません。最初の呼び出しは利用可能なリソースの発見を行い、2番目の呼び出しが実際の作業を行います。Code Mode(コードモード)を使用しない場合、同じワークフローを実行するには、モデルが両方のMCPサーバー(Model Context Protocolサーバー)から提供されるすべてのツールの完全なスキーマを事前に受け取り、その後3回の別々のツール呼び出しを行う必要がありました。
節約効果を数字で見てみましょう。内部のMCPサーバーポータルが、単に4つの社内MCPサーバーと接続されているだけで、52個のツールを公開しており、それらの定義だけで約9,400トークンのコンテキスト(文脈)を消費します。Code Modeを有効にすると、これら52個のツールは約600トークンを消費する2つのポータルツールに圧縮され、94%の削減となります。さらに重要なのは、このコストが固定されることです。ポータルに接続するMCPサーバーが増加しても、Code Modeのトークンコストは増大しません。
Code Mode は、MCP サーバーポータルの URL にクエリパラメータを追加することで有効化できます。通常の URL(例:https://myportal.example.com/mcp)経由でポータルに接続する代わりに、URL に ?codemode=search_and_execute を付加します(例:https://myportal.example.com/mcp?codemode=search_and_execute)。
AI Gateway は拡張性とコスト制御を提供します
私たちの取り組みはここで終わりではありません。MCP クライアントと LLM(大規模言語モデル)の接続間に AI Gateway を配置することで、アーキテクチャに組み込みます。これにより、ベンダーロックインを防ぐためにさまざまな LLM プロバイダ間で迅速に切り替えることができ、また各従業員が消費できるトークン数を制限することでコスト制御を適用できます。完全なアーキテクチャは以下に示されています。
image
Cloudflare Gateway はシャドウ MCP を発見してブロックします
許可された MCP サーバーへの管理されたアクセスを提供したところで、次に認可されていない MCP サーバーへの対処について見ていきましょう。Cloudflare Gateway を使用してシャドウ MCP の検出を行うことができます。Cloudflare Gateway は包括的なセキュア Web ゲートウェイであり、エンタープライズセキュリティチームに対して従業員のインターネットトラフィックに関する可視性と制御を提供します。
Cloudflare Gateway API を使用して、MCP サーバー ポータル経由でアクセスされていないリモート MCP サーバーを検出するための多層スキャンを実行できます。これには、以下の既存の Gateway および Data Loss Prevention (DLP) セレクターを組み合わせて使用することが可能です:
Gateway の httpHost セレクターを使用して、既知の MCP サーバー ホスト名(mcp.stripe.com など)や、ワイルドカード ホスト名パターンによる mcp.* サブドメインを検出します。
Gateway の httpRequestURI セレクターを使用して、/mcp や /mcp/sse といった MCP 固有の URL パスを検出します。
DLP ベースの本文検査を使用して、URI に「mcp」や「sse」といった明らかなキーワードが含まれていない場合でも MCP トラフィックを検出します。具体的には、MCP が HTTP 上で JSON-RPC を使用するという特性を利用し、すべてのリクエストに「tools/call」、「prompts/get」、または「initialize」などの値を持つ「method」フィールドが含まれる点を利用します。以下は、HTTP 本文内の MCP トラフィックを検出するために使用できる正規表現ルールです:
const DLP_REGEX_PATTERNS = [
{
name: "MCP Initialize Method",
regex: '"method"\\s{0,5}:\\s{0,5}"initialize"',
},
{
name: "MCP Tools Call",
regex: '"method"\\s{0,5}:\\s{0,5}"tools/call"',
},
{
name: "MCP Tools List",
regex: '"method"\\s{0,5}:\\s{0,5}"tools/list"',
},
{
name: "MCP Resources Read",
regex: '"method"\\s{0,5}:\\s{0,5}"resources/read"',
},
{
name: "MCP Resources List",
regex: '"method"\\s{0,5}:\\s{0,5}"resources/list"',
},
{
name: "MCP Prompts List",
regex: '"method"\\s{0,5}:\\s{0,5}"prompts/(list|get)"',
},
{
name: "MCP Sampling Create Message",
regex: '"method"\\s{0,5}:\\s{0,5}"sampling/createMessage"',
},
{
name: "MCP Protocol Version",
regex: '"protocolVersion"\\s{0,5}:\\s{0,5}"202[4-9]',
},
{
name: "MCP Notifications Initialized",
regex: '"method"\\s{0,5}:\\s{0,5}"notifications/initialized"',
},
{
name: "MCP Roots List",
regex: '"method"\\s{0,5}:\\s{0,5}"roots/list"',
},
];
The Gateway API supports additional automation. For example, one can use the custom DLP profile we defined above to block traffic, or redirect it, or just to log and inspect MCP payloads. Put this together, and Gateway can be used to provide comprehensive detection of unauthorized remote MCP servers accessed via an enterprise network.
For more information on how to build this out, see this tutorial.
パブリック向けMCPサーバーは、アプリ用AIセキュリティで保護されています
これまで私たちは、社内MCPサーバーへの従業員のアクセスを保護することに注力してきました。しかし、多くの他の組織と同様に、当社の顧客がエージェントを通じてCloudflare製品を管理・運用するために利用する、パブリック向けのMCPサーバーも保有しています。これらのMCPサーバーは、Cloudflareのデベロッパープラットフォーム上にホストされています。(特定の製品用の個別MCPの一覧はここでご覧いただけます。また、Code Modeを使用してCloudflare API全体へのより効率的なアクセスを提供する私たちの新しいアプローチについてもご参照ください。)
私たちは、すべての組織が自社の製品に対して公式かつファーストパーティのMCPサーバーを公開すべきだと考えています。その代替案として、顧客がパブリックリポジトリから審査されていないサーバーを取得するケースがあります。そのようなパッケージには、危険な信頼関係の前提、非開示のデータ収集、およびあらゆる種類の認可されていない動作が含まれている可能性があります。独自のMCPサーバーを公開することで、顧客が使用するツールのコード、更新頻度、セキュリティ姿勢を制御できます。
すべてのリモートMCPサーバーはHTTPエンドポイントであるため、Cloudflare Web Application Firewall (WAF) の背後に配置することができます。顧客はWAF内で「アプリ用AIセキュリティ」機能を有効化し、プロンプトインジェクションの試行、機密データの漏洩、およびトピック分類について、受信MCPトラフィックを自動的に検査することができます。パブリック向けのMCPは、他のWeb APIと同様に保護されます。
エンタープライズにおけるMCPの未来
私たちの経験、製品、および参照アーキテクチャが、MCP の広範な企業全体への導入に向けた独自の取り組みを続ける他の組織にとって有用であることを願っています。
私たちは以下の方法で、自社内の MCP ワークフローを安全に確保しました:
Cloudflare Access を認証手段として使用し、開発者プラットフォーム上でリモート MCP サーバーの構築とデプロイを行うためのテンプレート化されたフレームワークを開発者に提供すること
組織全体の従業員を MCP サーバーポータルに接続することで、認可された MCP サーバーへの安全なアイデンティティベースのアクセスを確保すること
AI Gateway を使用して、従業員の MCP クライアントを動かす大規模言語モデル(LLM)へのアクセスを仲介し、MCP サーバーポータルの Code Mode を使用してトークン消費とコンテキストの肥大化を削減することで、コストを管理すること
Cloudflare Gateway によってシャドウ MCP の使用を発見すること
独自の企業向け MCP 導入を進めている組織に対しては、既存のリモートおよびサードパーティ製 MCP サーバーを Cloudflare MCP サーバーポータルの背後に配置し、Code Mode を有効化して、より安価で安全かつ簡素な MCP の企業向けデプロイメントの恩恵を受けることから始めることを推奨します。
謝辞:
この参照アーキテクチャおよびブログ記事は、Cloudflare 内の多くの異なる役割やビジネスユニットにまたがる多くの人々の作業の成果を表しています。貢献者の一部を以下に列挙します:Ann Ming Samborski、Kate Reznykova、Mike Nomitch、James Royal、Liam Reese、Yumna Moazzam、Simon Thorpe、Rian van der Merwe、Rajesh Bhatia、Ayush Thakur、Gonzalo Chavarri、Maddy Onyehara、および Haley Campbell。
Cloudflare TV で視聴
MCP(Model Context Protocol)の採用を拡大するための当社の参照アーキテクチャは、よりシンプルで安全かつ低コストなエンタープライズ(企業向け)デプロイメントを実現することを目的としています。このアーキテクチャは、大規模な組織が AI モデルと外部データソースやツールを安全かつ効率的に統合するためのベストプラクティスを定義しています。
原文を表示
We at Cloudflare have aggressively adopted Model Context Protocol (MCP) as a core part of our AI strategy. This shift has moved well beyond our engineering organization, with employees across product, sales, marketing, and finance teams now using agentic workflows to drive efficiency in their daily tasks. But the adoption of agentic workflow with MCP is not without its security risks. These range from authorization sprawl, prompt injection, and supply chain risks. To secure this broad company-wide adoption, we have integrated a suite of security controls from both our Cloudflare One (SASE) platform and our Cloudflare Developer platform, allowing us to govern AI usage with MCP without slowing down our workforce.
In this blog we’ll walk through our own best practices for securing MCP workflows, by putting different parts of our platform together to create a unified security architecture for the era of autonomous AI. We’ll also share two new concepts that support enterprise MCP deployments:
We are launching Code Mode with MCP server portals, to drastically reduce token costs associated with MCP usage;
We describe how to use Cloudflare Gateway for Shadow MCP detection, to discover use of unauthorized remote MCP servers.
We also talk about how our organization approached deploying MCP, and how we built out our MCP security architecture using Cloudflare products including remote MCP servers, Cloudflare Access, MCP server portals and AI Gateway.
Remote MCP servers provide better visibility and control
MCP is an open standard that enables developers to build a two-way connection between AI applications and the data sources they need to access. In this architecture, the MCP client is the integration point with the LLM or other AI agent, and the MCP server sits between the MCP client and the corporate resources.
image
The separation between MCP clients and MCP servers allows agents to autonomously pursue goals and take actions while maintaining a clear boundary between the AI (integrated at the MCP client) and the credentials and APIs of the corporate resource (integrated at the MCP server).
Our workforce at Cloudflare is constantly using MCP servers to access information in various internal resources, including our project management platform, our internal wiki, documentation and code management platforms, and more.
Very early on, we realized that locally-hosted MCP servers were a security liability. Local MCP server deployments may rely on unvetted software sources and versions, which increases the risk of supply chain attacks or tool injection attacks. They prevent IT and security administrators from administrating these servers, leaving it up to individual employees and developers to choose which MCP servers they want to run and how they want to keep them up to date. This is a losing game.
image
Instead, we have a centralized team at Cloudflare that manages our MCP server deployment across the enterprise. This team built a shared MCP platform inside our monorepo that provides governed infrastructure out of the box. When an employee wants to expose an internal resource via MCP, they first get approval from our AI governance team, and then they copy a template, write their tool definitions, and deploy, all the while inheriting default-deny write controls with audit logging, auto-generated CI/CD pipelines, and secrets management for free. This means standing up a new governed MCP server is minutes of scaffolding. The governance is baked into the platform itself, which is what allowed adoption to spread so quickly.
Our CI/CD pipeline deploys them as remote MCP servers on custom domains on Cloudflare’s developer platform. This gives us visibility into which MCPs servers are being used by our employees, while maintaining control over software sources. As an added bonus, every remote MCP server on the Cloudflare developer platform is automatically deployed across our global network of data centers, so MCP servers can be accessed by our employees with low latency, regardless of where they might be in the world.
Cloudflare Access provides authentication
Some of our MCP servers sit in front of public resources, like our Cloudflare documentation MCP server or Cloudflare Radar MCP server, and thus we want them to be accessible to anyone. But many of the MCP servers used by our workforce are sitting in front of our private corporate resources. These MCP servers require user authentication to ensure that they are off limits to everyone but authorized Cloudflare employees. To achieve this, our monorepo template for MCP servers integrates Cloudflare Access as the OAuth provider. Cloudflare Access secures login flows and issues access tokens to resources, while acting as an identity aggregator that verifies end user single-sign on (SSO), multifactor authentication (MFA), and a variety of contextual attributes such as IP addresses, location, or device certificates.
MCP server portals centralize discovery and governance
image
MCP server portals unify governance and control for all AI activity.
As the number of our remote MCP servers grew, we hit a new wall: discovery. We wanted to make it easy for every employee (especially those that are new to MCP) to find and work with all the MCP servers that are available to them. Our MCP server portals product provided a convenient solution. The employee simply connects their MCP client to the MCP server portal, and the portal immediately reveals every internal and third-party MCP servers they are authorized to use.
Beyond this, our MCP server portals provide centralized logging, consistent policy enforcement and data loss prevention (DLP guardrails). Our administrators can see who logged into what MCP portal and create DLP rules that prevent certain data, like personally identifiable data (PII), from being shared with certain MCP servers.
We can also create policies that control who has access to the portal itself, and what tools from each MCP server should be exposed. For example, we could set up one MCP server portal that is only accessible to employees that are part of our finance group that exposes just the read-only tools for the MCP server in front of our internal code repository. Meanwhile, a different MCP server portal, accessible only to employees on their corporate laptops that are in our engineering team, could expose more powerful read/write tools to our code repository MCP server.
An overview of our MCP server portal architecture is shown above. The portal supports both remote MCP servers hosted on Cloudflare, and third-party MCP servers hosted anywhere else. What makes this architecture uniquely performant is that all these security and networking components run on the same physical machine within our global network. When an employee's request moves through the MCP server portal, a Cloudflare-hosted remote MCP server, and Cloudflare Access, their traffic never needs to leave the same physical machine.
Code Mode with MCP server portals reduces costs
After months of high-volume MCP deployments, we’ve paid out our fair share of tokens. We’ve also started to think most people are doing MCP wrong.
The standard approach to MCP requires defining a separate tool for every API operation that is exposed via an MCP server. But this static and exhaustive approach quickly exhausts an agent’s context window, especially for large platforms with thousands of endpoints.
We previously wrote about how we used server-side Code Mode to power Cloudflare’s MCP server, allowing us to expose the thousands of end-points in Cloudflare API while reducing token use by 99.9%. The Cloudflare MCP server exposes just two tools: a search tool lets the model write JavaScript to explore what’s available, and an execute tool lets it write JavaScript to call the tools it finds. The model discovers what it needs on demand, rather than receiving everything upfront.
We like this pattern so much, we had to make it available for everyone. So we have now launched the ability to use the “Code Mode” pattern with MCP server portals. Now you can front all of your MCP servers with a centralized portal that performs audit controls and progressive tool disclosure, in order to reduce token costs.
Here is how it works. Instead of exposing every tool definition to a client, all of your underlying MCP servers collapse into just two MCP portal tools: portal_codemode_search and portal_codemode_execute. The search tool gives the model access to a codemode.tools() function that returns all the tool definitions from every connected upstream MCP server. The model then writes JavaScript to filter and explore these definitions, finding exactly the tools it needs without every schema being loaded into context. The execute tool provides a codemode proxy object where each upstream tool is available as a callable function. The model writes JavaScript that calls these tools directly, chaining multiple operations, filtering results, and handling errors in code. All of this runs in a sandboxed environment on the MCP server portal powered by Dynamic Workers.
Here is an example of an agent that needs to find a Jira ticket and update it with information from Google Drive. It first searches for the right tools:
// portal_codemode_search
async () => {
const tools = await codemode.tools();
return tools
.filter(t => t.name.includes("jira") || t.name.includes("drive"))
.map(t => ({ name: t.name, params: Object.keys(t.inputSchema.properties || {}) }));
}
The model now knows the exact tool names and parameters it needs, without the full schemas of tools ever entering its context. It then writes a single execute call to chain the operations together:
// portal_codemode_execute
async () => {
const tickets = await codemode.jira_search_jira_with_jql({
jql: ‘project = BLOG AND status = “In Progress”’,
fields: [“summary”, “description”]
});
const doc = await codemode.google_workspace_drive_get_content({
fileId: “1aBcDeFgHiJk”
});
await codemode.jira_update_jira_ticket({
issueKey: tickets[0].key,
fields: { description: tickets[0].description + “\n\n” + doc.content }
});
return { updated: tickets[0].key };
}
This is just two tool calls. The first discovers what's available, the second does the work. Without Code Mode, this same workflow would have required the model to receive the full schemas of every tool from both MCP servers upfront, and then make three separate tool invocations.
Let’s put the savings in perspective: when our internal MCP server portal is connected to just four of our internal MCP servers, it exposes 52 tools that consume approximately 9,400 tokens of context just for their definitions. With Code Mode enabled, those 52 tools collapse into 2 portal tools consuming roughly 600 tokens, a 94% reduction. And critically, this cost stays fixed. As we connect more MCP servers to the portal, the token cost of Code Mode doesn’t grow.
Code Mode can be activated on an MCP server portal by adding a query parameter to the URL. Instead of connecting to your portal over its usual URL (e.g. https://myportal.example.com/mcp), you attach ?codemode=search_and_execute to the URL (e.g. https://myportal.example.com/mcp?codemode=search_and_execute).
AI Gateway provides extensibility and cost controls
We aren’t done yet. We plug AI Gateway into our architecture by positioning it on the connection between the MCP client and the LLM. This allows us to quickly switch between various LLM providers (to prevent vendor lock-in) and to enforce cost controls (by limiting the number of tokens each employee can burn through). The full architecture is shown below.
image
Cloudflare Gateway discovers and blocks shadow MCP
Now that we’ve provided governed access to authorized MCP servers, let’s look into dealing with unauthorized MCP servers. We can perform shadow MCP discovery using Cloudflare Gateway. Cloudflare Gateway is our comprehensive secure web gateway that provides enterprise security teams with visibility and control over their employees’ Internet traffic.
We can use the Cloudflare Gateway API to perform a multi-layer scan to find remote MCP servers that are not being accessed via an MCP server portal. This is possible using a variety of existing Gateway and Data Loss Prevention (DLP) selectors, including:
Using the Gateway httpHost selector to scan for
known MCP server hostnames using (like mcp.stripe.com)
mcp.* subdomains using wildcard hostname patterns
Using the Gateway httpRequestURI selector to scan for MCP-specific URL paths like /mcp and /mcp/sse
Using DLP-based body inspection to find MCP traffic, even if that traffic uses URI that do not contain the telltale mentions of mcp or sse. Specifically, we use the fact that MCP uses JSON-RPC over HTTP, which means every request contains a "method" field with values like "tools/call", "prompts/get", or "initialize." Here are some regex rules that can be used to detect MCP traffic in the HTTP body:
const DLP_REGEX_PATTERNS = [
{
name: "MCP Initialize Method",
regex: '"method"\\s{0,5}:\\s{0,5}"initialize"',
},
{
name: "MCP Tools Call",
regex: '"method"\\s{0,5}:\\s{0,5}"tools/call"',
},
{
name: "MCP Tools List",
regex: '"method"\\s{0,5}:\\s{0,5}"tools/list"',
},
{
name: "MCP Resources Read",
regex: '"method"\\s{0,5}:\\s{0,5}"resources/read"',
},
{
name: "MCP Resources List",
regex: '"method"\\s{0,5}:\\s{0,5}"resources/list"',
},
{
name: "MCP Prompts List",
regex: '"method"\\s{0,5}:\\s{0,5}"prompts/(list|get)"',
},
{
name: "MCP Sampling Create Message",
regex: '"method"\\s{0,5}:\\s{0,5}"sampling/createMessage"',
},
{
name: "MCP Protocol Version",
regex: '"protocolVersion"\\s{0,5}:\\s{0,5}"202[4-9]',
},
{
name: "MCP Notifications Initialized",
regex: '"method"\\s{0,5}:\\s{0,5}"notifications/initialized"',
},
{
name: "MCP Roots List",
regex: '"method"\\s{0,5}:\\s{0,5}"roots/list"',
},
];
The Gateway API supports additional automation. For example, one can use the custom DLP profile we defined above to block traffic, or redirect it, or just to log and inspect MCP payloads. Put this together, and Gateway can be used to provide comprehensive detection of unauthorized remote MCP servers accessed via an enterprise network.
For more information on how to build this out, see this tutorial.
Public-facing MCP Servers are protected with AI Security for Apps
So far, we’ve been focused on protecting our workforce’s access to our internal MCP servers. But, like many other organizations, we also have public-facing MCP servers that our customers can use to agentically administer and operate Cloudflare products. These MCP servers are hosted on Cloudflare’s developer platform. (You can find a list of individual MCPs for specific products here, or refer back to our new approach for providing more efficient access to the entire Cloudflare API using Code Mode.)
We believe that every organization should publish official, first-party MCP servers for their products. The alternative is that your customers source unvetted servers from public repositories where packages may contain dangerous trust assumptions, undisclosed data collection, and any range of unsanctioned behaviors. By publishing your own MCP servers, you control the code, update cadence, and security posture of the tools your customers use.
Since every remote MCP server is an HTTP endpoint, we can put it behind the Cloudflare Web Application Firewall (WAF). Customers can enable the AI Security for Apps feature within the WAF to automatically inspect inbound MCP traffic for prompt injection attempts, sensitive data leakage, and topic classification. Public facing MCPs are protected just as any other web API.
The future of MCP in the enterprise
We hope our experience, products, and reference architectures will be useful to other organizations as they continue along their own journey towards broad enterprise-wide adoption of MCP.
We’ve secured our own MCP workflows by:
Offering our developers a templated framework for building and deploying remote MCP servers on our developer platform using Cloudflare Access for authentication
Ensuring secure, identity-based access to authorized MCP servers by connecting our entire workforce to MCP server portals
Controlling costs using AI Gateway to mediate access to the LLMs powering our workforce’s MCP clients, and using Code Mode in MCP server portals to reduce token consumption and context bloat
Discovering shadow MCP usage by Cloudflare Gateway
For organizations advancing on their own enterprise MCP journeys, we recommend starting by putting your existing remote and third-party MCP servers behind Cloudflare MCP server portals and enabling Code Mode to start benefitting for cheaper, safer and simpler enterprise deployments of MCP.
Acknowledgements: This reference architecture and blog represents this work of many people across many different roles and business units at Cloudflare. This is just a partial list of contributors: Ann Ming Samborski, Kate Reznykova, Mike Nomitch, James Royal, Liam Reese, Yumna Moazzam, Simon Thorpe, Rian van der Merwe, Rajesh Bhatia, Ayush Thakur, Gonzalo Chavarri, Maddy Onyehara, and Haley Campbell.
Watch on Cloudflare TV
関連記事
AgentCore Gateway を用いた MCP クライアント向けの安全な認証コードフロー構築
AWS は、Kiro などのエージェント型コーディングアシスタントと企業システム間での安全なアクセスを実現するため、AgentCore Gateway を活用した認証コードフローの構築方法を公開しました。
Amazon Bedrock AgentCore Gateway の MCP サポート拡張
AWS は、企業向けに Amazon Bedrock AgentCore Gateway で Model Context Protocol(MCP)サーバーの運用を支援する機能を強化しました。これにより、大規模環境での細粒度アクセス制御、ツール利用状況の可視化、データ漏洩防止、および集中型認証管理が可能になります。
MCP を活用した時系列データベースとの Amazon Quick 統合による市場インテリジェンスの強化
Amazon は、Model Context Protocol(MCP)を Amazon Quick に統合し、金融アナリストが複雑なデータベースクエリを実行せずに時系列市場データにアクセスできる機能を追加しました。これにより、高頻度取引パターンの分析効率が向上します。