
在云运行中托管模型上下文协议SSE部署,使用IAM认证。
概览
目前(2024年3月4日),MCP仍在处理认证和授权问题。他们计划在2025年上半年完成这项工作。问题是,我想现在就和团队共享我的MCP服务器。所以我们现在就在这里。目前唯一直接的解决方案是使用基于网络层的解决方案(例如代理)。基本认证、API密钥,别想了。 利用 GCP 云运行和基于用户的 IAM 认证,我创建了一种简单且安全的方式,允许客户端通过互联网访问自定义 MCP 服务器。 MCP服务器托管在Google Cloud Run上。利用Cloud Run IAM Authentication,我们可以通过Google Cloud SDK创建代理连接,安全地从互联网连接到服务器。 如果你已经有docker,并且本地设置了gcloud的CLI就只能做最简单的配置。 更新 deploy.sh 你的项目ID、服务账户邮箱等信息。 部署成功后,获取提供的云运行URL,添加到mcp_proxy。
概述(AI 翻译)
目前(2024年3月4日),MCP仍在处理认证和授权问题。他们计划在2025年上半年完成这项工作。问题是,我想现在就和团队共享我的MCP服务器。所以我们现在就在这里。目前唯一直接的解决方案是使用基于网络层的解决方案(例如代理)。基本认证、API密钥,别想了。
利用 GCP 云运行和基于用户的 IAM 认证,我创建了一种简单且安全的方式,允许客户端通过互联网访问自定义 MCP 服务器。
MCP路线图
它是如何运作的
MCP服务器托管在Google Cloud Run上。利用Cloud Run IAM Authentication,我们可以通过Google Cloud SDK创建代理连接,安全地从互联网连接到服务器。
简要说明
如果你已经有docker和本地设置了gcloud CLI,这**应该开箱即用,只需最小配置即可。
步骤1: 更新deploy.sh,包含你的项目ID、服务账户邮箱等。
步骤2: 部署成功后,获取提供的云运行URL,并将其与项目ID一起添加到mcp_proxy.ts。
步骤3: 运行代理 npx ts-node mcp_proxy.ts
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
Host MCP SSE Server on Google Cloud Run
At the moment (03/04/2024) MCP is still addressing Authentication and Authorization. They plan to complete this in H1 2025. The issue is, I want to share my MCP server with my team NOW. So here we are. The only immediate answer to use a SSE MCP server in Cursor, etc… right now is a network layer based solution (e.g., a proxy). Basic auth, api keys, forget about it.
Utilizing GCP Cloud Run and User Based IAM Authentication, I have created a simple, secure way to allow clients to access a custom MCP server over the internet.
How it works
The MCP server is hosted on Google Cloud Run. Utilizing Cloud Run IAM Authentication, we can securely connect to the server from the internet by utilizing the Google Cloud SDK to create a proxy connection.
TLDR README
This should work out of the box with minimal config if you already have docker and the gcloud CLI set up locally.
Step 1: Update deploy.sh with your project id, service account email, etc.
Step 2: On deploy success, grab the cloud run URL that was provided, and add it to mcp_proxy.ts along with your project id.
Step 3: Run the proxy npx ts-node mcp_proxy.ts
Step 3: Access your MCP server using http://localhost:3030 - Add it to Cursor under Settings > Features > MCP Servers (make sure you select SSE not command)
LONG BORING README
Deployment Steps
- Clone the repository
- Run
npm installto install the dependencies - Run
npm run devto start the server locally
Deployment to Google Cloud Run
To deploy your MCP server to Google Cloud Run:
- Make sure you have the Google Cloud SDK installed
- Update the
deploy.shscript with your project details:PROJECT_ID: Your Google Cloud project IDREGION: Your preferred GCP regionSERVICE_ACCOUNT_EMAIL: The service account email with appropriate permissions
- Run the deployment script:
chmod +x deploy.sh ./deploy.sh
The deployment script will:
- Build a Docker container for your MCP server
- Push it to Google Container Registry
- Deploy it to Cloud Run with authentication enabled
Connecting to your deployed MCP server
To connect to your deployed MCP server:
-
Run the MCP proxy locally:
npx ts-node mcp_proxy.ts -
The proxy will:
- Check if you’re authenticated with Google Cloud
- Obtain authentication tokens automatically
- Create a local proxy server (default: http://localhost:3030)
- Forward authenticated requests to your Cloud Run service
-
Configure your MCP client to connect to the local proxy URL
Use the MCP server in Cursor
安装
npx ts-node mcp_proxy.ts