@@ -35,8 +35,26 @@ Install the Google Cloud SDK:
35
35
36
36
* ** Debian/Ubuntu:**
37
37
38
+ > These steps also apply to WSL2 running Ubuntu.
39
+
38
40
``` bash
39
- sudo apt-get install google-cloud-cli
41
+ # Update package lists and install necessary utilities
42
+ sudo apt-get update
43
+ sudo apt-get install -y apt-transport-https ca-certificates gnupg curl
44
+
45
+ # Import the Google Cloud public key securely
46
+ # This is for newer distributions (Debian 9+ or Ubuntu 18.04+).
47
+ curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg
48
+
49
+ # Add the Google Cloud SDK distribution URI as a package source
50
+ # This is for newer distributions, ensuring packages are signed by the key we just added.
51
+ echo " deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
52
+
53
+ # Update your package lists again to recognize the new repository
54
+ sudo apt-get update
55
+
56
+ # Install the Google Cloud CLI
57
+ sudo apt-get install -y google-cloud-cli
40
58
```
41
59
42
60
* ** Windows (PowerShell):**
@@ -57,11 +75,18 @@ Authenticate with your Google Cloud account:
57
75
gcloud auth login
58
76
```
59
77
78
+ Set a project ID:
79
+
80
+ ``` bash
81
+ gcloud config set project PROJECT_ID
82
+ ```
83
+
60
84
### 2. Enable Required APIs
61
85
62
86
Enable the necessary Google Cloud APIs:
63
87
64
88
``` bash
89
+ # This might take a minute..
65
90
gcloud services enable \
66
91
run.googleapis.com \
67
92
sqladmin.googleapis.com \
@@ -87,6 +112,35 @@ Prepare the following environment variables:
87
112
| ` CACHE_TYPE ` | Set to ` redis ` for production environments |
88
113
| ` PORT ` | Port number the application listens on (e.g., ` 4444 ` ) |
89
114
115
+ Consider creating a ` .env.gcr ` file where you will record the various settings used during deployment.
116
+
117
+ ``` bash
118
+ # ─── Google Cloud project ───────────────────────────────────
119
+ PROJECT_ID=
120
+ REGION=us-central1
121
+ SERVICE_NAME=mcpgateway
122
+
123
+ # ─── Authentication ─────────────────────────────────────────
124
+ JWT_SECRET_KEY=
125
+ BASIC_AUTH_USER=
126
+ BASIC_AUTH_PASSWORD=
127
+ AUTH_REQUIRED=true
128
+
129
+ # ─── Cloud SQL (PostgreSQL) ─────────────────────────────────
130
+ SQL_INSTANCE=mcpgw-db
131
+ SQL_REGION=us-central1
132
+ DATABASE_URL=postgresql://postgres:< PASSWORD> @< SQL_IP> :5432/mcpgw
133
+
134
+ # ─── Memorystore (Redis) ────────────────────────────────────
135
+ REDIS_INSTANCE=mcpgw-redis
136
+ REDIS_REGION=us-central1
137
+ REDIS_URL=redis://< REDIS_IP> :6379/0
138
+ CACHE_TYPE=redis
139
+
140
+ # ─── Application ────────────────────────────────────────────
141
+ PORT=4444
142
+ ```
143
+
90
144
---
91
145
92
146
## ⚙️ Setup Steps
@@ -96,8 +150,10 @@ Prepare the following environment variables:
96
150
Create a PostgreSQL instance using the ` db-f1-micro ` tier for cost efficiency:
97
151
98
152
``` bash
153
+ # POSTGRES_16 and POSTGRES_17 default to Enterprise Plus; adding --edition=ENTERPRISE lets you pick db-f1-micro
99
154
gcloud sql instances create mcpgw-db \
100
155
--database-version=POSTGRES_17 \
156
+ --edition=ENTERPRISE \
101
157
--tier=db-f1-micro \
102
158
--region=us-central1
103
159
```
@@ -148,32 +204,131 @@ gcloud redis instances describe mcpgw-redis \
148
204
149
205
### 3. Deploy to Google Cloud Run
150
206
151
- Deploy the MCP Gateway container with minimal resource allocation:
207
+ Cloud Run only accepts container images that live in Artifact Registry or the older Container Registry endpoints; anything pulled from the public internet (for example ghcr.io) must first be proxied or copied into Artifact Registry.
208
+
209
+
210
+ #### Set Your Project ID
211
+
212
+ Begin by setting your Google Cloud project ID as an environment variable:
213
+
214
+ ``` bash
215
+ export PROJECT_ID=" your-project-id"
216
+ ```
217
+
218
+ Replace ` "your-project-id" ` with your actual Google Cloud project ID.
219
+
220
+ #### Enable Required APIs
221
+
222
+ Ensure that the necessary Google Cloud APIs are enabled:
223
+
224
+ ``` bash
225
+ gcloud services enable artifactregistry.googleapis.com
226
+ ```
227
+
228
+ #### Create a Remote Repository
229
+
230
+ Set up a remote repository in Artifact Registry that proxies GitHub Container Registry (GHCR):
231
+
232
+ ``` bash
233
+ gcloud artifacts repositories create ghcr-remote \
234
+ --project=$PROJECT_ID \
235
+ --repository-format=docker \
236
+ --location=us-central1 \
237
+ --description=" Proxy for GitHub Container Registry" \
238
+ --mode=remote-repository \
239
+ --remote-docker-repo=https://ghcr.io
240
+ ```
241
+
242
+ #### Retrieve Cloud SQL Instance Connection Name
243
+
244
+ ``` bash
245
+ gcloud sql instances describe mcpgw-db \
246
+ --format=" value(connectionName)"
247
+ ```
248
+
249
+ It will output something like this:
250
+
251
+ ```
252
+ your-project-id:us-central1:mcpgw-db
253
+ ```
254
+
255
+
256
+ #### Allow ingress to your database.
257
+
258
+ Consider only allowing the Cloud Run IP range.
259
+
260
+ ``` bash
261
+ gcloud sql instances patch mcpgw-db \
262
+ --authorized-networks=0.0.0.0/0
263
+ ```
264
+
265
+ #### Deploy the MCP Gateway container with minimal resource allocation:
152
266
153
267
``` bash
154
268
gcloud run deploy mcpgateway \
155
- --image=ghcr.io/ ibm/mcp-context-forge:latest \
269
+ --image=us-central1-docker.pkg.dev/ $PROJECT_ID /ghcr-remote/ ibm/mcp-context-forge:latest
156
270
--region=us-central1 \
157
271
--platform=managed \
158
272
--allow-unauthenticated \
159
273
--port=4444 \
160
274
--cpu=1 \
161
- --memory=256Mi \
275
+ --memory=512i \
162
276
--max-instances=1 \
163
277
--set-env-vars=\
164
- JWT_SECRET_KEY=your -secret,\
278
+ JWT_SECRET_KEY=jwt -secret-key ,\
165
279
BASIC_AUTH_USER=admin,\
166
280
BASIC_AUTH_PASSWORD=changeme,\
167
281
AUTH_REQUIRED=true,\
168
282
DATABASE_URL=postgresql://postgres:mysecretpassword@< SQL_IP> :5432/mcpgw,\
169
283
REDIS_URL=redis://< REDIS_IP> :6379/0,\
170
- CACHE_TYPE=redis
284
+ CACHE_TYPE=redis,\
285
+ HOST=0.0.0.0,\
286
+ GUNICORN_WORKERS=1
171
287
```
172
288
173
289
> ** Replace ` <SQL_IP> ` and ` <REDIS_IP> ` ** with the actual IP addresses obtained from the previous steps.
290
+ > Do not leave out the HOST=0.0.0.0 to ensure the container listens on all ports, or the container engine won't be able to reach the container.
291
+ > Setting the number of GUNICORN_WORKERS lets you control how much memory the service consumes.
292
+
293
+ #### Check the logs
174
294
295
+ ``` bash
296
+ gcloud run services logs read mcpgateway --region=us-central1
297
+ ```
175
298
---
176
299
300
+ #### Check that the database is created:
301
+
302
+ You can use any PostgreSQL client, such as ` psql ` . You should see the list of tables when using ` dt; `
303
+
304
+ ``` bash
305
+ psql postgresql://postgres:mysecretpassword@< SQL_IP> :5432/mcpgw
306
+
307
+ mcpgw=> \d t;
308
+ List of relations
309
+ Schema | Name | Type | Owner
310
+ --------+------------------------------+-------+----------
311
+ public | gateways | table | postgres
312
+ public | mcp_messages | table | postgres
313
+ public | mcp_sessions | table | postgres
314
+ public | prompt_gateway_association | table | postgres
315
+ public | prompt_metrics | table | postgres
316
+ public | prompts | table | postgres
317
+ public | resource_gateway_association | table | postgres
318
+ public | resource_metrics | table | postgres
319
+ public | resource_subscriptions | table | postgres
320
+ public | resources | table | postgres
321
+ public | server_metrics | table | postgres
322
+ public | server_prompt_association | table | postgres
323
+ public | server_resource_association | table | postgres
324
+ public | server_tool_association | table | postgres
325
+ public | servers | table | postgres
326
+ public | tool_gateway_association | table | postgres
327
+ public | tool_metrics | table | postgres
328
+ public | tools | table | postgres
329
+ (18 rows)
330
+ ```
331
+
177
332
## 🔒 Authentication and Access
178
333
179
334
### Generate a JWT Bearer Token
@@ -182,7 +337,7 @@ Use the MCP Gateway container to generate a JWT token:
182
337
183
338
``` bash
184
339
docker run -it --rm ghcr.io/ibm/mcp-context-forge:latest \
185
- python3 -m mcpgateway.utils.create_jwt_token -u admin
340
+ python3 -m mcpgateway.utils.create_jwt_token -u admin --secret jwt-secret-key
186
341
```
187
342
188
343
Export the token as an environment variable:
@@ -193,12 +348,18 @@ export MCPGATEWAY_BEARER_TOKEN=<paste-token-here>
193
348
194
349
### Perform Smoke Tests
195
350
196
- Test the ` /health ` and ` /tools ` endpoints:
351
+ Test the ` /health ` , ` /version ` , and ` /tools ` endpoints:
197
352
198
353
``` bash
354
+ # Check that the service is healthy
199
355
curl -H " Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN " \
200
356
https://< your-cloud-run-url> /health
201
357
358
+ # Check that version reports the version and show Postgres/Redis as connected
359
+ curl -H " Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN " \
360
+ https://< your-cloud-run-url> /health
361
+
362
+ # Check that tools return an empty list []
202
363
curl -H " Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN " \
203
364
https://< your-cloud-run-url> /tools
204
365
```
@@ -211,24 +372,11 @@ curl -H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" \
211
372
212
373
### View Logs via CLI
213
374
214
- Tail real-time logs:
375
+ Tailing real-time logs requires ` google-cloud-cli-log-streaming ` . Ex: ` sudo apt-get install google-cloud-cli-log-streaming ` :
215
376
216
377
``` bash
217
- gcloud run services logs tail mcpgateway --region us-central1
378
+ gcloud beta run services logs tail mcpgateway --region= us-central1
218
379
```
219
-
220
- Read recent logs:
221
-
222
- ``` bash
223
- gcloud run services logs read mcpgateway --limit 50
224
- ```
225
-
226
- Filter logs by severity:
227
-
228
- ``` bash
229
- gcloud run services logs read mcpgateway --severity=ERROR
230
- ```
231
-
232
380
### Access Logs via Console
233
381
234
382
Navigate to the [ Cloud Run Console] ( https://console.cloud.google.com/run ) and select your service to view logs and metrics.
0 commit comments