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 Worker 만들기

먼저, 새로운 Cloudflare Worker 프로젝트를 초기화합니다.

지엑스피1

그런 다음 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
F
license - not found
-
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.

AI 어시스턴트가 모델 컨텍스트 프로토콜을 통해 API와 서비스에 직접 액세스할 수 있도록 하는 개방형 표준 서버 구현으로, 확장성을 위해 Cloudflare Workers를 사용하여 구축되었습니다.

  1. 소개
    1. 필수 조건
      1. 시작하기
        1. 1단계: 새로운 Cloudflare Worker 만들기
        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 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
                  • -
                    security
                    F
                    license
                    -
                    quality
                    A Cloudflare Workers-based Model Context Protocol server that enables AI assistants like Claude to access external tools via OAuth authentication.
                    Last updated -
                    14
                    TypeScript
                  • -
                    security
                    F
                    license
                    -
                    quality
                    A Cloudflare Workers implementation of a Model Context Protocol server with OAuth login that enables AI assistants like Claude to access external tools.
                    Last updated -
                    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