Skip to main content
Glama

MCP Server with Cloudflare Workers

by sivakumarl

Cloudflare Workersを使用したMCPサーバー

導入

モデルコンテキストプロトコル(MCP)は、AIエージェントとアシスタントがサービスとやり取りできるようにするオープンスタンダードです。MCPサーバーを設定することで、AIアシスタントがAPIに直接アクセスできるようになります。

Cloudflare Workers は、 workers-mcpパッケージと組み合わせることで、MCP サーバーを構築するための強力でスケーラブルなソリューションを提供します。

前提条件

始める前に、次のものを用意してください。

  • Cloudflareアカウント
  • Node.jsがインストールされている
  • Wrangler CLI がインストールされている ( npm install -g wrangler )

はじめる

ステップ1: 新しいCloudflareワーカーを作成する

まず、新しい Cloudflare Worker プロジェクトを初期化します。

npx create-cloudflare@latest my-mcp-worker cd my-mcp-worker

次に、Cloudflare アカウントを認証します。

wrangler login

ステップ2: Wranglerを構成する

正しいアカウント詳細でwrangler.tomlファイルを更新します。

name = "my-mcp-worker" main = "src/index.ts" compatibility_date = "2025-03-03" account_id = "your-account-id"

MCPツールのインストール

MCP サポートを有効にするには、 workers-mcpパッケージをインストールします。

npm install workers-mcp

MCP を構成するには、セットアップ コマンドを実行します。

npx workers-mcp setup

これにより、次のようになります。

  • 必要な依存関係を追加する
  • テスト用にローカルプロキシを設定する
  • MCPコンプライアンスのためにWorkerを構成する

MCP サーバーコードの作成

src/index.tsを更新して MCP サーバーを定義します。

import { WorkerEntrypoint } from 'cloudflare:workers'; import { ProxyToSelf } from 'workers-mcp'; export default class MyWorker extends WorkerEntrypoint<Env> { /** * A friendly greeting from your MCP server. * @param name {string} The name of the user. * @return {string} A personalized greeting. */ sayHello(name: string) { return `Hello from an MCP Worker, ${name}!`; } /** * @ignore */ async fetch(request: Request): Promise<Response> { return new ProxyToSelf(this).fetch(request); } }

主要コンポーネント:

  • WorkerEntrypoint : 受信リクエストとメソッドの公開を管理します。
  • ProxyToSelf : MCP プロトコルの準拠を保証します。
  • sayHello メソッド: AI アシスタントが呼び出すことができる MCP 関数の例。

API呼び出しの追加

外部APIを統合することで、MCPサーバーを拡張できます。以下は天気データを取得する例です。

export default class WeatherWorker extends WorkerEntrypoint<Env> { /** * Fetch weather data for a given location. * @param location {string} The city or ZIP code. * @return {object} Weather details. */ async getWeather(location: string) { const response = await fetch(`https://api.weather.example/v1/${location}`); const data = await response.json(); return { temperature: data.temp, conditions: data.conditions, forecast: data.forecast }; } async fetch(request: Request): Promise<Response> { return new ProxyToSelf(this).fetch(request); } }

MCPサーバーの展開

Worker をセットアップしたら、Cloudflare にデプロイします。

npx wrangler deploy

展開後、Worker が稼働し、AI アシスタントが MCP ツールを検出して使用できるようになります。

MCP サーバーを更新するには、次のコマンドで再デプロイします。

npm run deploy

MCPサーバーのテスト

MCP セットアップをローカルでテストするには:

npx workers-mcp proxy

このコマンドは、MCP クライアント (Claude Desktop など) が接続できるようにローカル プロキシを起動します。


安全

MCP サーバーを保護するには、Wrangler Secrets を使用します。

npx wrangler secret put MCP_SECRET

これにより、不正アクセスを防ぐための共有秘密認証メカニズムが追加されます。


結論

おめでとうございます!Cloudflare Workersを使用してMCPサーバーを構築し、デプロイしました。これで、さらに多くの機能を追加して拡張し、AIアシスタント用の新しいツールを公開できるようになりました。

詳細については、 Cloudflare MCP ドキュメントを参照してください。


-
security - not tested
-
license - not tested
-
quality - not tested

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

スケーラビリティのために Cloudflare Workers を使用して構築された、モデル コンテキスト プロトコルを通じて AI アシスタントが API やサービスに直接アクセスできるようにするオープン スタンダードのサーバー実装です。

  1. 導入
    1. 前提条件
      1. はじめる
        1. ステップ1: 新しいCloudflareワーカーを作成する
        2. ステップ2: Wranglerを構成する
      2. MCPツールのインストール
        1. MCP サーバーコードの作成
          1. 主要コンポーネント:
        2. API呼び出しの追加
          1. MCPサーバーの展開
            1. MCPサーバーのテスト
              1. 安全
                1. 結論

                  Related MCP Servers

                  • -
                    security
                    F
                    license
                    -
                    quality
                    A Model Context Protocol server that runs on Cloudflare Workers with OAuth login, allowing AI assistants like Claude to execute tools remotely through HTTP connections.
                    Last updated -
                    TypeScript
                  • -
                    security
                    F
                    license
                    -
                    quality
                    A Cloudflare Workers-based implementation of Model Context Protocol (MCP) server that enables AI assistants like Claude to access external tools and capabilities through a standardized interface with OAuth authentication.
                    Last updated -
                    14
                    TypeScript
                  • -
                    security
                    F
                    license
                    -
                    quality
                    A Model Context Protocol server implementation that runs on Cloudflare Workers, providing tool integration for AI assistants like Claude with OAuth login capability.
                    Last updated -
                    14
                    TypeScript
                  • -
                    security
                    F
                    license
                    -
                    quality
                    A Cloudflare Workers-based server implementing the Model Context Protocol that enables AI assistants like Claude to securely access external tools through OAuth authentication.
                    Last updated -
                    14
                    TypeScript

                  View all related MCP servers

                  MCP directory API

                  We provide all the information about MCP servers via our MCP API.

                  curl -X GET 'https://glama.ai/api/mcp/v1/servers/sivakumarl/my-mcp-worker'

                  If you have feedback or need assistance with the MCP directory API, please join our Discord server