Skip to content

Commit d80ed79

Browse files
committed
2 parents 85d15a4 + 3e7aea5 commit d80ed79

4 files changed

Lines changed: 137 additions & 25 deletions

File tree

custom_dc/build_image.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ While you are just testing out data changes, you don't need to build the website
1717

1818
Data Commons provides two prebuilt images in the Google Artifact Registry that you can download to run in a Docker container:
1919

20-
- `gcr.io/datcom-ci/datacommons-data:stable` and `gcr.io/datcom-ci/datacommons-services:stable`. These are tested, stable versions but may be several weeks old.
20+
- `gcr.io/datcom-ci/datacommons-data:stable` and `gcr.io/datcom-ci/datacommons-services:stable`. These are tested, stable versions but may be several weeks old.
2121
- `gcr.io/datcom-ci/datacommons-data:latest` and `gcr.io/datcom-ci/datacommons-services:latest`. These are the latest versions built from head.
2222

23+
You can see the images with their tags at <https://console.cloud.google.com/artifacts/docker/datcom-ci/us/gcr.io/datacommons-data> and <https://console.cloud.google.com/artifacts/docker/datcom-ci/us/gcr.io/datacommons-services>.
24+
2325
If you want to pick up the latest prebuilt version, do the following:
2426

2527
1. From the root directory (e.g. `website`), run the following command:

custom_dc/deploy_cloud.md

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ The first time you run it, may be prompted to specify a quota project for billin
5151
<pre>
5252
gcloud auth application-default set-quota-project <var>PROJECT_ID</var></pre>
5353

54-
## One-time setup: Create service accounts and enable all APIs
54+
## One-time setup: Enable APIs
5555

56-
`website/deploy/terraform-custom-datacommons/setup.sh` is a convenience script to set up service account roles and all necessary Cloud APIs. To run it:
56+
`website/deploy/terraform-custom-datacommons/setup.sh` is a convenience script to set up all necessary Cloud APIs. To run it:
5757

5858
<pre>
5959
cd website/deploy/terraform-custom-datacommons
@@ -80,6 +80,7 @@ We recommend using the Data Commons Terraform scripts to greatly simplify and au
8080

8181
Terraform provisions and runs all the necessary Cloud Platform services:
8282

83+
- Creates a service account for your project and namespace and assigns it various permissions ([IAM roles](https://docs.cloud.google.com/iam/docs/roles-overview){: target="_blank}).
8384
- Creates a Cloud Storage bucket and top-level folder, which will store your data files. You will upload your input data in the subsequent steps.
8485
- Creates a Cloud SQL MySQL instance, with basic resources, a default database user and a random password.
8586
- Creates the Data Commons data management container as a Cloud Run job, with basic resources.
@@ -262,7 +263,7 @@ To view the tables:
262263
1. In the left panel, select **Cloud SQL Studio**.
263264
1. In the **Sign in to SQL Studio** page, from the **Database** field, select the database created by the Terraform script.
264265
1. In the **User** field, select the user created by the Terraform script.
265-
1. In the **Password** field, enter the password you have retrieved from the Cloud Secret Manager
266+
1. In the **Password** field, enter the password you have retrieved from the Cloud Secret Manager.
266267
1. In the left Explorer pane that appears, expand the **Databases** icon, your database name, and **Tables**. The table of interest is **observations**. You can see column names and other metadata.
267268
1. To view the actual data, in the main window, click **New SQL Editor tab**. This opens an environment in which you can enter and run SQL queries.
268269
1. Enter a query and click **Run**. For example, for the sample OECD data, if you do `select * from observations limit 10;`, you should see output like this:
@@ -294,20 +295,19 @@ Any time you make changes to the website and want to deploy your changes to the
294295
If you don't specify the <code>--package</code> option, the package name and tag will be the same as the source image.
295296
</div>
296297
<div><ol><li>Build a local version of the Docker image, following the procedure in <a href="/custom_dc/build_image.html#build-repo">Build a local image</a>.</li>
297-
<li>Generate credentials for the Docker package.
298+
<li>Generate credentials for the Docker package:
298299
<pre>gcloud auth configure-docker <var>REGION</var>-docker.pkg.dev</pre></li>
299300
<li>Create a package from the source image you created in step 1:
300301
<pre>docker tag <var>SOURCE_IMAGE_NAME</var>:<var>SOURCE_IMAGE_TAG</var> \
301302
<var>REGION</var>-docker.pkg.dev/<var>PROJECT_ID</var>/<var>ARTIFACT_REPO</var>/<var>TARGET_IMAGE_NAME</var>:<var>TARGET_IMAGE_TAG</var></pre>
302303
The artifact repo is <code><var>PROJECT_ID</var>-artifacts</code>.</li>
303304
<li>Push the image to the registry:
304305
<pre>docker push <var>CONTAINER_IMAGE_URL</var></pre>
305-
The container image URL is the full name of the package you created in the previous step, including the tag.</li>
306+
The container image URL is the full name of the package you created in the previous step, including the tag. For example: `us-central1-docker-pkg.dev/myproject/myrepo/datacommons:latest`.</li>
306307
</ol>
307308
</div>
308309
</div>
309310
</div>
310-
311311
- The target image name and tag can be the same as the source or different.
312312
- Docker package names must be in the format <code><var>REGION</var>-docker-pkg.dev</code>. The default region in the Terraform scripts is `us-central1`.
313313

@@ -346,29 +346,22 @@ You need to restart the services container every time you make changes to the co
346346
<div class="active">
347347
<ol>
348348
<li>Go to the <a href="https://console.cloud.google.com/run/services" target="_blank">https://console.cloud.google.com/run/services</a> page for your project.</li>
349-
<li>From the list of services, click the link of the service created by the Terraform scripts</li>
350-
<li>click <b>Edit & Deploy Revision</b>.</li>
349+
<li>From the list of services, click the link of the service created by the Terraform scripts.</li>
350+
<li>Click <b>Edit & Deploy Revision</b>.</li>
351351
<li>Under <b>Container image URL</b>, click <b>Select</b>.</li>
352352
<li>Expand the package name you created in the previous step.</li>
353353
<li>Expand the image name of the container, and select the tag you created in the previous step.</li>
354354
<li>Click <b>Deploy</b>. It will take several minutes for the service to start. You can click the <b>Logs</b> tab to view the progress.</li>
355355
</ol>
356356
</div>
357-
<div>
358-
<li>From any local directory, run the following command:
359-
<pre>gcloud run deploy <var>SERVICE_NAME</var> --image <var>CONTAINER_IMAGE_URL</var></pre></li>
360-
<li>To view the startup status, run the following command:
357+
<div><p>From any local directory, run the following command:
358+
<pre>gcloud run deploy <var>SERVICE_NAME</var> --image <var>CONTAINER_IMAGE_URL</var></pre></p>
359+
<p> To view the startup status, run the following command:
361360
<pre>gcloud beta run jobs logs tail <var>SERVICE_NAME</var></pre>
362-
</li>
363-
The service name is <code><var>NAMESPACE</var>-datacommons-web-service</code>.
364-
The container image URL is the name of the package you created in the previous step.
365-
</ol>
361+
</p>
366362
</div>
367-
<div>
368-
</div>
363+
</div>
369364
</div>
370-
</div>
371-
372365

373366
### View your running application {#view-app}
374367

@@ -403,6 +396,7 @@ To create additional deployments:
403396
cp terraform.tfvars terraform_prod.tfvars
404397
```
405398
> Tip: You may wish to rename the original `terraform.tfvars` to something more descriptive as well.
399+
406400
1. Do any of the following:
407401
- If you intend to run the new deployment in a different GCP project, edit the `project_id` variable and specify the project ID.
408402
- If you intend to run the new deployment in the same GCP project, edit the `namespace` variable to name it according to the environment you are creating, e.g. `-prod`. When you run the deployment, all created services will use the new namespace.

custom_dc/deploy_mcp_cloud.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
---
2+
layout: default
3+
title: Run an MCP server in Google Cloud
4+
nav_order: 9
5+
parent: Build your own Data Commons
6+
---
7+
8+
{:.no_toc}
9+
# Run an MCP server in Google Cloud
10+
11+
If you have built a custom agent or Gemini CLI extension which you want to make publicly available, this page describes how to run the [Data Commons MCP server](https://pypi.org/project/datacommons-mcp/) in the cloud, using Google Cloud Run.
12+
13+
Since setting up an MCP server is a simple, one-time setup, there's no need to use Terraform to manage it. Data Commons provides a prebuilt Docker image in the Artifact Registry, so you only need to set up a new Cloud Run service to point to it.
14+
15+
## Prebuilt images
16+
17+
There are several versions of the image available, viewable at <https://console.cloud.google.com/artifacts/docker/datcom-ci/us/gcr.io/datacommons-mcp-server>. We recommend that you choose a production version with a specific version number, to ensure that changes introduced by the Data Commons team don't break your application.
18+
19+
## Before you start: decide on a hosting model
20+
21+
There are several ways you can host the MCP server in Cloud Run, namely:
22+
23+
- As a standalone service. In this case, any client simply connects to it over HTTP, including your own MCP agent running as a separate Cloud Run service or locally. You can choose whether to make the internal Cloud Run app URL publicly available, or whether to put a load balancer in front of the service and map a domain name.
24+
- As a ["sidecar"](https://docs.cloud.google.com/run/docs/deploying#sidecars){: target="_blank"} to an MCP client. If you are hosting your own MCP client in Cloud Run as well, this may be a useful option. In this case, the MCP server is not directly addressable; all external connections are managed by the client.
25+
26+
In this page, we provide steps for running the Data Commons MCP server as a standalone container. If you want to go with the sidecar option, please see [Deploying multiple containers to a service (sidecars)](https://docs.cloud.google.com/run/docs/deploying#sidecars){: target="_blank"} for additional requirements and setup procedures.
27+
28+
## Prerequisites
29+
30+
The following procedures assume that you have set up the following Google Cloud Platform services, using the [Terraform scripts](deploy_cloud.md#terraform):
31+
- A service account and roles.
32+
- A Google Cloud Secret Manager secret for storing your Data Commons API key.
33+
34+
## Create a Cloud Run Service for the MCP server
35+
36+
The following procedure sets up a bare-bones container service. To set additional options, such as request timeouts, instance replication, etc., please see [Configure Cloud Run services](https://docs.cloud.google.com/run/docs/configuring){: target="_blank"} for details.
37+
38+
<div class="gcp-tab-group">
39+
<ul class="gcp-tab-headers">
40+
<li class="active">Cloud Console</li>
41+
<li>gcloud CLI</li>
42+
</ul>
43+
<div class="gcp-tab-content">
44+
<div class="active">
45+
<ol>
46+
<li>Go to the <a href="https://console.cloud.google.com/run/services" target="_blank">https://console.cloud.google.com/run/services</a> page for your project.</li>
47+
<li>Click <b>Deploy container</b>.</li>
48+
<li>In the <b>Container image URL</b> field, click <b>Select</b>.</li>
49+
<li>In the Artifact Registry panel that appears in the right side of the window, that appears, click <b>Change</b>.</li>
50+
<li>In the project search bar, enter <code>datcom-ci</code> and click on the link that appears.</li>
51+
<li>Expand <b>gcr.io/datcom-ci</b> and expand <b>datacommons-mcp-server</b>.</li>
52+
<li>From the list of images, select a production image, e.g. <code>production-v1.1.4</code>.</li>
53+
<li>Under <b>Configure</b>, select the desired region for the service, e.g. <code>us-central1</code>.</li>
54+
<li>Expand <b>Containers, Networking, Security</b>.</li>
55+
<li>Click the <b>Variables & secrets</b> tab.</li>
56+
<li>Under <b>Environment variables</b>, click <b>Add variable</b> and set the following variables:
57+
<ul>
58+
<li>name: <code>DC_TYPE</code>, value: <code>custom</code></li>
59+
<li>name: <code>CUSTOM_DC_URL</code>, value: <code><var>YOUR_INSTANCE_URL</var></code></li>
60+
</ul></li>
61+
<li>Under <b>Secrets exposed as environment variables</b>, click <b>Reference a secret</b>.</li>
62+
<li>In the <b>Name</b> field, enter <code>DC_API_KEY</code>, and from the <b>Secret</b> field, select the secret previously created by the Terraform scripts. It is in the form <code><var>NAMESPACE</var>-datacommons-dc-api-key-<var>FINGERPRINT</var></code>.</li>
63+
<li>In the <b>Version</b> field, select the desired version, e.g. <b>latest</b>.</li>
64+
<li>Click <b>Done</b>.</li>
65+
<li>Click the <b>Security</b> tab. From the <b>Service account</b> field, select the service account for your namespace and project, previously created by the Terraform scripts.</li>
66+
<li>Click <b>Create</b>. If correctly configured, the service will deploy automatically. It may take several minutes to start up.</li></ol>
67+
</div>
68+
<div>
69+
<ol>
70+
<li>If you haven't recently refreshed your Google Cloud credentials, run <code>gcloud auth application-default login</code> and authenticate.</li>
71+
<li>From any local directory, run the following command:
72+
<pre>gcloud run deploy datacommons-mcp-server --image <var>CONTAINER_IMAGE_URL</var> \
73+
--service-account <var>SERVICE_ACCOUNT</var> --region <var>REGION</var> \
74+
--allow-unauthenticated \
75+
--set-secrets="DC_API_KEY=<var>SECRET_NAME</var>:latest" \
76+
--set-env-vars="DC_TYPE=custom" --set-env-vars="CUSTOM_DC_URL=<var>INSTANCE_URL</var>"</pre></li>
77+
</ol>
78+
<ul>
79+
<li>The container image URL is <code>gcr.io/datcom-ci/datacommons-mcp-server:<var>TAG</var></code>. The tag should be a production image with a version number, e.g. <code>production-v1.1.4</code>.</li>
80+
<li>The service account was created when you ran Terraform. It is in the form <code><var>NAMESPACE</var>-datacommons-sa@<var>PROJECT_ID</var>.iam.gserviceaccount.com</code>.</li>
81+
<li>The region is the Cloud region where you want to run the service, e.g. <code>us-central1</code>.</li>
82+
<li>The secret name is the one created when you ran the Terraform scripts, in the form <code><var>NAMESPACE</var>-datacommons-dc-api-key-<var>FINGERPRINT</var></code>. If you're not sure about the name or fingerprint, go to <a href="https://console.cloud.google.com/security/secret-manager" target="_blank">https://console.cloud.google.com/security/secret-manager</a> for your project and look it up.</li>
83+
</ul>
84+
To view the startup status, run the following command:
85+
<pre>gcloud run services logs tail datacommons-mcp-server --region <var>REGION</var></pre>
86+
</div>
87+
</div>
88+
</div>
89+
90+
<script src="/assets/js/customdc-doc-tabs.js"></script>
91+
92+
## Connect to the server from a remote client
93+
94+
For details, see the following pages:
95+
- [Connect to the server from a local Gemini CLI client](/mcp/run_tools.html#gemini-cli-remote)
96+
- [Connect to the server from a local agent](/mcp/run_tools.html#remote)
97+
98+
The HTTP URL parameter is the Cloud Run App URL, if you are exposing the service directly, or a custom domain URL if you are using a load balancer and domain mapping.
99+
100+
## Troubleshoot deployment issues
101+
102+
### Container fails to start
103+
104+
If you see this error message:
105+
106+
```
107+
The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable within the allocated timeout...
108+
```
109+
This is a generic message that could indicate a number of configuration problems. Check all of these:
110+
- Be sure you have specified the `DC_API_KEY` environment variable.
111+
- Be sure you have specified the correct service account.
112+
- Try increasing the health check timeout.
113+
114+
115+

mcp/run_tools.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This page shows you how to run a local agent and connect to a Data Commons MCP s
1515

1616
We provide specific instructions for the following agents. All may be used to query datacommons.org or a [Custom Data Commons instance](/custom_dc).
1717

18-
- [Gemini CLI extension](#use-the-gemini-cli-extension)
18+
- [Gemini CLI extension](#extension)
1919
- Best for querying datacommons.org
2020
- Provides a built-in "agent" and context file for Data Commons
2121
- Downloads extension files locally
@@ -222,7 +222,7 @@ To configure Gemini CLI to recognize the Data Commons server, edit the relevant
222222
</pre>
223223

224224
{:.no_toc}
225-
### Configure to connect to a remote server
225+
### Configure to connect to a remote server {#gemini-cli-remote}
226226

227227
1. Start up the MCP server in standalone mode, as described in [Run a standalone server](#run-a-standalone-server).
228228
1. In the `settings.json` file, replace the `datacommons-mcp` specification as follows:
@@ -298,9 +298,8 @@ By default, the agent will spawn a local server and connect to it over Stdio. If
298298
```
299299
1. Enter your [queries](#sample-queries) at the `User` prompt in the terminal.
300300

301-
{: #remote}
302301
{:.no_toc}
303-
### Configure to connect to a remote server
302+
### Configure to connect to a remote server {#remote}
304303

305304
If you want to connect to a remote MCP server, follow this procedure before starting the agent:
306305

@@ -343,6 +342,8 @@ Here are some examples of such queries:
343342

344343
## Run a standalone server
345344

345+
The following procedure starts the MCP server in a local environment. To run the server in Google Cloud against a Custom Data Commons instance, see [Run an MCP server in Google Cloud](/custom_dc/deploy_mcp_cloud.html)
346+
346347
1. Ensure you've set up the relevant server [environment variables](#configure-environment-variables). If you're using a `.env` file, go to the directory where the file is stored.
347348
1. Run:
348349
<pre>

0 commit comments

Comments
 (0)