Skip to content

Commit 3f72447

Browse files
kmoscoeclincoln8
andauthored
Migrate MCP docs from Github repo to Docsite (#650)
* remove references to dataclass objects * Fix a copy-paste error. * remove extra file * Create placeholders for LLM pages * rename to MCP * complete rename * remove old file * Changes from Keyur * Add target tag * Rewording suggested by Keyur * Remove extraneous text * Fix a copy-paste error. * Migrate MCP docs to docsite * Restructuring * Remove unused file * Add TOCs etc. * Update var formatting * comments from Keyur * another change from Keyur * Update mcp/index.md Co-authored-by: Christie Ellks <[email protected]> * Changes from Christie * Apply suggestion from @clincoln8 Co-authored-by: Christie Ellks <[email protected]> * More changes from Christie * Changes from Dan * Link fixes * Remove MCP inspector info * Add more context to agent dev doc * fix formatting * Create placeholders for LLM pages * merge * Slight rewording based on comment from Christie --------- Co-authored-by: Christie Ellks <[email protected]>
1 parent c772181 commit 3f72447

File tree

5 files changed

+283
-4
lines changed

5 files changed

+283
-4
lines changed

assets/images/mcp.png

43 KB
Loading

llm/index.md

Whitespace-only changes.

mcp/develop_agent.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
layout: default
3+
title: Develop an ADK agent
4+
nav_order: 3
5+
parent: MCP - Query data interactively with an AI agent
6+
---
7+
8+
# Develop your own ADK agent
9+
10+
We provide two sample Google Agent Development Kit-based agents you can use as inspiration for building your own agent:
11+
12+
- [Try Data Commons MCP Tools with a Custom Agent](https://github.com/datacommonsorg/agent-toolkit/blob/main/notebooks/datacommons_mcp_tools_with_custom_agent.ipynb) is a Google Colab tutorial that shows how to build an ADK Python agent step by step.
13+
- The sample [basic agent](https://github.com/datacommonsorg/agent-toolkit/tree/main/packages/datacommons-mcp/examples/sample_agents/basic_agent) is a simple Python [Google ADK](https://google.github.io/adk-docs/) agent you can use to develop locally.
14+
15+
## Customize the sample agent
16+
17+
You can make changes directly to the Python files in <https://github.com/datacommonsorg/agent-toolkit/blob/main/packages/datacommons-mcp/examples/sample_agents/basic_agent/>. You'll need to [restart the agent](/mcp/run_tools.html#use-the-sample-agent) any time you make changes.
18+
19+
> Tip: You do not need to install the Google ADK; when you use the [command we provide](run_tools.md#use-the-sample-agent) to start the agent, it downloads the ADK dependencies at run time.
20+
21+
### Customize the model
22+
23+
To change to a different LLM, edit the `AGENT_MODEL` constant in [packages/datacommons-mcp/examples/sample_agents/basic_agent/agent.py](https://github.com/datacommonsorg/agent-toolkit/blob/main/packages/datacommons-mcp/examples/sample_agents/basic_agent/agent.py#L23){: target="_blank"}.
24+
25+
### Customize agent behavior
26+
27+
The agent's behavior is determined by prompts provided in the `AGENT_INSTRUCTIONS` in [packages/datacommons-mcp/examples/sample_agents/basic_agent/instructions.py](https://github.com/datacommonsorg/agent-toolkit/blob/main/packages/datacommons-mcp/examples/sample_agents/basic_agent/instructions.py){: target="_blank"}.
28+
29+
You can add your own prompts to modify how the agent handles tool results. For example, you might want to give a prompt to "build a report for every response" or "always save tabular results to a CSV file". See the Google ADK page on [LLM agent instructions](https://google.github.io/adk-docs/agents/llm-agents/#guiding-the-agent-instructions-instruction){: target="_blank"} for tips on how to write good prompts.
30+

mcp/index.md

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,48 @@ nav_order: 20
55
has_children: true
66
---
77

8-
# MCP overview
8+
{:.no_toc}
9+
# Query data interactively with an AI agent
910

10-
Data Commons has recently launched a [Model Context Protocol](https://github.com/datacommonsorg/agent-toolkit){: target="_blank"} server. This allows you to use any MCP-enabled agent, powered by a Large Language Model (LLM) like Google Gemini, to interactively query Data Commons data. See the following pages for details:
11+
* TOC
12+
{:toc}
1113

12-
- [Quickstart: Use the Data Commons MCP Server with Gemini CLI](https://github.com/datacommonsorg/agent-toolkit/blob/main/docs/quickstart.md){: target="_blank"}
13-
- [User Guide](https://github.com/datacommonsorg/agent-toolkit/blob/main/docs/user_guide.md){: target="_blank"}
14+
## Overview
1415

16+
The Data Commons [Model Context Protocol (MCP)](https://modelcontextprotocol.io/docs/getting-started/intro) service gives AI agents access to the Data Commons knowledge graph and returns data related to statistical variables, topics, and observations. It allows end users to formulate complex natural-language queries interactively, get data in textual, structured or unstructured formats, and download the data as desired. For example, depending on the agent, a user can answer high-level questions such as "give me the economic indicators of the BRICS countries", view simple tables, and download a CSV file of the data in tabular format.
17+
18+
The MCP server returns data from datacommons.org by default or can be configured for a Custom Data Commons instance.
19+
20+
The server is a Python binary based on the [FastMCP 2.0 framework](https://gofastmcp.com). A prebuilt package is available at <https://pypi.org/project/datacommons-mcp/>.
21+
22+
At this time, there is no centrally deployed server; you run your own server, and any client you want to connect to it.
23+
24+
![alt text](/assets/images/mcp.png)
25+
26+
## Tools
27+
28+
The server currently supports the following tools:
29+
30+
- `search_indicators`: Searches for available variables and/or topics (a hierarchy of sub-topics and member variables) for a given place or metric.
31+
- `get_observations`: Fetches statistical data for a given variable and place.
32+
33+
## Clients
34+
35+
To connect to the Data Commons MCP Server, you can use any available AI application that supports MCP, or your own custom agent.
36+
37+
The server supports both standard MCP [transport protocols](https://modelcontextprotocol.io/docs/learn/architecture#transport-layer):
38+
- Stdio: For clients that connect directly using local processes
39+
- Streamable HTTP: For clients that connect remotely or otherwise require HTTP (e.g. Typescript)
40+
41+
See [Run and connect to the server](run_tools.md) for procedures for using [Gemini CLI](https://github.com/google-gemini/gemini-cli).
42+
43+
## Unsupported features
44+
45+
At the current time, the following are not supported:
46+
- Non-geographical ("custom") entities
47+
- Events
48+
- Exploring nodes and relationships in the graph
49+
50+
## Disclaimer
51+
52+
AI applications using the MCP server can make mistakes, so please double-check responses.

mcp/run_tools.md

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
---
2+
layout: default
3+
title: Run MCP tools
4+
nav_order: 2
5+
parent: MCP - Query data interactively with an AI agent
6+
---
7+
8+
{:.no_toc}
9+
# Run and connect to the server
10+
11+
This page shows you how to run a local agent and connect to a Data Commons MCP server running locally or remotely.
12+
13+
* TOC
14+
{:toc}
15+
16+
17+
We provide specific instructions for the following agents:
18+
19+
- [Gemini CLI](https://github.com/google-gemini/gemini-cli)
20+
- Can be used for datacommons.org or a Custom Data Commons instance
21+
- Requires minimal setup
22+
23+
See [Use Gemini CLI](#use-gemini-cli) for this option.
24+
- A sample basic agent based on the Google [Agent Development Kit](https://google.github.io/adk-docs/) and [Gemini Flash 2.5](https://deepmind.google/models/gemini/flash/)
25+
- Best for interacting with a Web UI
26+
- Can be used for datacommons.org or a Custom Data Commons instance
27+
- Can be customized to run other LLMs
28+
- Requires some additional setup
29+
30+
See [Use the sample agent](#use-the-sample-agent) for this option.
31+
32+
For an end-to-end tutorial using a server and agent over HTTP, see the sample Data Commons Colab notebook, [Try Data Commons MCP Tools with a Custom Agent](https://github.com/datacommonsorg/agent-toolkit/blob/main/notebooks/datacommons_mcp_tools_with_custom_agent.ipynb).
33+
34+
For other clients/agents, see the relevant documentation; you should be able to reuse the commands and arguments detailed below.
35+
36+
## Prerequisites
37+
38+
- A (free) Data Commons API key. To obtain an API key, go to <https://apikeys.datacommons.org> and request a key for the `api.datacommons.org` domain.
39+
- Install `uv` for managing and installing Python packages; see the instructions at <https://docs.astral.sh/uv/getting-started/installation/>.
40+
- For running the sample agent or the Colab notebook, a GCP project and a Google AI API key. For details on supported keys, see <https://google.github.io/adk-docs/get-started/quickstart/#set-up-the-model>.
41+
- For running the sample agent locally, install [Git](https://git-scm.com/).
42+
43+
> **Important**: Additionally, for custom Data Commons instances:
44+
> If you have not rebuilt your Data Commons image since the stable release of 2025-09-08, you must [sync to the latest stable release](/custom_dc/build_image.html#sync-code-to-the-stable-branch), [rebuild your image](/custom_dc/build_image.html#build-package) and [redeploy](/custom_dc/deploy_cloud.html#manage-your-service).
45+
46+
47+
## Configure environment variables
48+
49+
### Base Data Commons (datacommons.org)
50+
51+
For basic usage against datacommons.org, set the required `DC_API_KEY` in your shell/startup script (e.g. `.bashrc`).
52+
<pre>
53+
export DC_API_KEY=<var>YOUR API KEY</var>
54+
</pre>
55+
56+
### Custom Data Commons
57+
58+
If you're running a against a custom Data Commons instance, we recommend using a `.env` file, which the server locates automatically, to keep all the settings in one place. All supported options are documented in <https://github.com/datacommonsorg/agent-toolkit/blob/main/packages/datacommons-mcp/.env.sample>.
59+
60+
To set variables using a `.env` file:
61+
62+
1. From Github, download the file [`.env.sample`](https://github.com/datacommonsorg/agent-toolkit/blob/main/packages/datacommons-mcp/.env.sample) to the desired directory. Or, if you plan to run the sample agent, clone the repo <https://github.com/datacommonsorg/agent-toolkit/>.
63+
64+
1. From the directory where you saved the sample file, copy it to a new file called `.env`. For example:
65+
```bash
66+
cd ~/agent-toolkit/packages/datacommons-mcp
67+
cp .env.sample .env
68+
```
69+
1. Set the following variables:
70+
- `DC_API_KEY`: Set to your Data Commons API key
71+
- `DC_TYPE`: Set to `custom`.
72+
- `CUSTOM_DC_URL`: Uncomment and set to the URL of your instance.
73+
1. Optionally, set other variables.
74+
1. Save the file.
75+
76+
## Use Gemini CLI
77+
78+
1. Install Gemini CLI: see instructions at <https://github.com/google-gemini/gemini-cli#quick-install>.
79+
2. To configure Gemini CLI to recognize the Data Commons server, edit your `~/.gemini/settings.json` file to add the following:
80+
81+
<pre>
82+
{
83+
// ...
84+
"mcpServers": {
85+
"datacommons-mcp": {
86+
"command": "uvx",
87+
"args": [
88+
"datacommons-mcp@latest",
89+
"serve",
90+
"stdio"
91+
],
92+
"env": {
93+
"DC_API_KEY": "<var>YOUR DATA COMMONS API KEY</var>"
94+
},
95+
"trust": true
96+
}
97+
}
98+
// ...
99+
}
100+
</pre>
101+
1. From any directory, run `gemini`.
102+
1. To see the Data Commons tools, use `/mcp tools`.
103+
1. Start sending [natural-language queries](#sample-queries).
104+
105+
> **Tip**: To ensure that Gemini CLI uses the Data Commons MCP tools, and not its own `GoogleSearch` tool, include a prompt to use Data Commons in your query. For example, use a query like "Use Data Commons tools to answer the following: ..." You can also add such a prompt to a [`GEMINI.md` file](https://codelabs.developers.google.com/gemini-cli-hands-on#9) so that it's persisted across sessions.
106+
107+
## Use the sample agent
108+
109+
We provide a basic agent for interacting with the MCP Server in [packages/datacommons-mcp/examples/sample_agents/basic_agent](https://github.com/datacommonsorg/agent-toolkit/tree/main/packages/datacommons-mcp/examples/sample_agents/basic_agent). To run the agent locally:
110+
111+
1. If not already installed, install `uv` for managing and installing Python packages; see the instructions at <https://docs.astral.sh/uv/getting-started/installation/>.
112+
1. From the desired directory, clone the `agent-toolkit` repo:
113+
```bash
114+
git clone https://github.com/datacommonsorg/agent-toolkit.git
115+
```
116+
1. Set the following environment variables in your shell or startup script:
117+
<pre>
118+
export DC_API_KEY=<var>YOUR DATA COMMONS API KEY</var>
119+
export GEMINI_API_KEY=<var>YOUR GOOGLE AI API KEY</var>
120+
</pre>
121+
1. Go to the root directory of the repo:
122+
```bash
123+
cd agent-toolkit
124+
```
125+
1. Run the agent using one of the following methods.
126+
127+
### Web UI (recommended)
128+
129+
1. Run the following command:
130+
```bash
131+
uvx --from google-adk adk web ./packages/datacommons-mcp/examples/sample_agents/
132+
```
133+
1. Point your browser to the address and port displayed on the screen (e.g. `http://127.0.0.1:8000/`). The Agent Development Kit Dev UI is displayed.
134+
1. From the **Type a message** box, type your [query for Data Commons](#sample-queries) or select another action.
135+
136+
### Command line interface
137+
138+
1. Run the following command:
139+
```bash
140+
uvx --from google-adk adk run ./packages/datacommons-mcp/examples/sample_agents/basic_agent
141+
```
142+
1. Enter your [queries](#sample-queries) at the `User` prompt in the terminal.
143+
144+
## Sample queries
145+
146+
The Data Commons MCP tools excel at natural-language queries that involve:
147+
- Comparisons between two or more entities, such as countries or metrics
148+
- Exploring data available for a given topic
149+
150+
Here are some examples of such queries:
151+
152+
- "What health data do you have for Africa?"
153+
- "What data do you have on water quality in Zimbabwe?"
154+
- "Compare the life expectancy, economic inequality, and GDP growth for BRICS nations."
155+
- "Generate a concise report on income vs diabetes in US counties."
156+
157+
## Use a remote server/client
158+
159+
### Run a standalone server
160+
161+
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.
162+
1. Run:
163+
<pre>
164+
uvx datacommons-mcp serve http [--port <var>PORT</var>]
165+
</pre>
166+
By default, the port is 8080 if you don't set it explicitly.
167+
168+
The server is addressable with the endpoint `mcp`. For example, `http://my-mcp-server:8080/mcp`.
169+
170+
### Connect to an already-running server from a remote client
171+
172+
Below we provide instructions for Gemini CLI and a sample ADK agent. If you're using a different client, consult its documentation to determine how to specify an HTTP URL.
173+
174+
#### Gemini CLI
175+
176+
To configure Gemini CLI to connect to a remote Data Commons server over HTTP, replace the `mcpServers` section in `~/.gemini/settings.json` (or other `settings.json` file) with the following:
177+
178+
<pre>
179+
{
180+
// ... (additional configuration)
181+
"mcpServers": {
182+
"datacommons-mcp": {
183+
"httpUrl": "http://<var>HOST</var>:<var>PORT</var>/mcp"
184+
}
185+
// ... (other mcpServers entries)
186+
}
187+
}
188+
</pre>
189+
190+
#### Sample agent
191+
192+
To configure the sample agent to connect to a remote Data Commons MCP server over HTTP, you need to modify the code in [`basic_agent/agent.py`](https://github.com/datacommonsorg/agent-toolkit/blob/main/packages/datacommons-mcp/examples/sample_agents/basic_agent/agent.py). Set import modules and agent initialization parameters as follows:
193+
194+
```python
195+
from google.adk.tools.mcp_tool.mcp_toolset import (
196+
MCPToolset,
197+
StreamableHTTPConnectionParams
198+
)
199+
200+
root_agent = LlmAgent(
201+
# ...
202+
tools=[McpToolset(
203+
connection_params=StreamableHTTPConnectionParams(
204+
url=f"http://<host>:<port>/mcp"
205+
)
206+
)],
207+
)
208+
```
209+
Run the agent as described in [Use the sample agent](#use-the-sample-agent) above.
210+
211+

0 commit comments

Comments
 (0)