Skip to main content
Glama

MCP Server on Cloudflare Workers

Cloudflare Workers 上的 MCP 服务器采用 Bearer Auth

该存储库演示了在 Cloudflare Workers 上运行的模型上下文协议 (MCP) 服务器的概念验证实现,并带有简单的承载令牌身份验证。

概述

该项目展示了如何:

  • 在 Cloudflare 的边缘网络上部署 MCP 服务器
  • 实施基本承载令牌认证
  • 通过无服务器架构创建和公开 MCP 工具

本地开发

# Install dependencies npm install # Run the server locally npm run dev

启动服务器后,即可通过http://localhost:8787访问

验证

此实现使用简单的 Bearer Token 身份验证方案。客户端必须在其请求中提供 Authorization 标头。服务器将此令牌传递给 MCP 工具,允许工具根据已验证的用户执行操作。

使用 MCP Inspector 进行测试

您可以使用MCP 检查器来测试您的 MCP 服务器:

  1. 安装并启动检查器:
    npx @modelcontextprotocol/inspector
  2. 配置检查器:
    • 将传输类型切换为SSE
    • 输入您的 MCP 服务器的 URL(本地: http://localhost:8787/sse或已部署: https://your-worker.workers.dev/sse ://your-worker.workers.dev/sse )
    • 在授权字段中添加承载令牌
    • 点击“连接”
  3. 测试功能:
    • 单击“列出工具”查看可用工具
    • 尝试运行“getToken”工具,它将返回您的授权标头
    • 尝试使用两个数字的“添加”工具来测试基本功能

部署到 Cloudflare

将您的 MCP 服务器部署到 Cloudflare Workers:

npm run deploy

部署后,您的服务器将通过https://your-worker.workers.dev访问

项目结构

  • src/index.ts - 使用 MCP 工具定义的主服务器实现
  • src/utils.ts - 用于渲染 Web 界面的辅助实用程序
  • wrangler.jsonc - Cloudflare Workers 配置

重要提示

这是一个概念验证的实现,旨在演示如何在无服务器环境中运行 MCP。在生产环境中,您需要实现:

  • 更强大的身份验证(OAuth、令牌验证等)
  • 速率限制和额外的安全措施
  • 正确的错误处理和监控

故障排除

如果您遇到问题:

  1. 确保您的持有者令牌在授权标头中格式正确
  2. 检查 Cloudflare 仪表板中的工作日志
  3. 尝试重启本地开发服务器

对于持续存在的身份验证问题,您可能需要清除所有缓存的凭据:

rm -rf ~/.mcp-auth
-
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.

在 Cloudflare 的边缘网络上运行的模型上下文协议服务器的概念验证实现,具有承载令牌身份验证,允许部署的 AI 模型通过无服务器架构访问工具。

  1. 概述
    1. 本地开发
      1. 验证
        1. 使用 MCP Inspector 进行测试
          1. 部署到 Cloudflare
            1. 项目结构
              1. 重要提示
                1. 故障排除

                  Related MCP Servers

                  • A
                    security
                    F
                    license
                    A
                    quality
                    A tool for deploying an authentication-free Model Context Protocol server on Cloudflare Workers that can be connected to AI clients like Claude Desktop or the Cloudflare AI Playground.
                    Last updated -
                    2
                    TypeScript
                  • -
                    security
                    F
                    license
                    -
                    quality
                    A deployable Model Context Protocol server for Cloudflare Workers that enables AI models to use custom tools without requiring authentication.
                    Last updated -
                    TypeScript
                  • -
                    security
                    F
                    license
                    -
                    quality
                    A deployable Model Context Protocol server for Cloudflare Workers that allows running custom AI tools without authentication requirements.
                    Last updated -
                    TypeScript
                  • -
                    security
                    F
                    license
                    -
                    quality
                    A serverless implementation of Model Context Protocol server on Cloudflare Workers that allows users to deploy and customize AI tools without authentication requirements.
                    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/Pedropfuenmayor/mcp-cloudflare'

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