Run and connect to the server
This page shows you how to run a local agent and connect to a Data Commons MCP server running locally or remotely.
- Prerequisites
- Configure environment variables
- Use Gemini CLI
- Use the sample agent
- Sample queries
- Use a remote server/client
We provide specific instructions for the following agents:
- Gemini CLI
- Can be used for datacommons.org or a Custom Data Commons instance
- Requires minimal setup
See Use Gemini CLI for this option.
- A sample basic agent based on the Google Agent Development Kit and Gemini Flash 2.5
- Best for interacting with a Web UI
- Can be used for datacommons.org or a Custom Data Commons instance
- Can be customized to run other LLMs
- Requires some additional setup
See Use the sample agent for this option.
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.
For other clients/agents, see the relevant documentation; you should be able to reuse the commands and arguments detailed below.
Prerequisites
- 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.orgdomain. - Install
uvfor managing and installing Python packages; see the instructions at https://docs.astral.sh/uv/getting-started/installation/. - 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.
- For running the sample agent locally, install Git.
Important: Additionally, for custom Data Commons instances: 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, rebuild your image and redeploy.
Configure environment variables
Base Data Commons (datacommons.org)
For basic usage against datacommons.org, set the required DC_API_KEY in your shell/startup script (e.g. .bashrc).
export DC_API_KEY=YOUR API KEY
Custom Data Commons
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.
To set variables using a .env file:
-
From Github, download the file
.env.sampleto the desired directory. Or, if you plan to run the sample agent, clone the repo https://github.com/datacommonsorg/agent-toolkit/. - From the directory where you saved the sample file, copy it to a new file called
.env. For example:cd ~/agent-toolkit/packages/datacommons-mcp cp .env.sample .env - Set the following variables:
DC_API_KEY: Set to your Data Commons API keyDC_TYPE: Set tocustom.CUSTOM_DC_URL: Uncomment and set to the URL of your instance.
- Optionally, set other variables.
- Save the file.
Use Gemini CLI
- Install Gemini CLI: see instructions at https://github.com/google-gemini/gemini-cli#quick-install.
- To configure Gemini CLI to recognize the Data Commons server, edit your
~/.gemini/settings.jsonfile to add the following:
{
// ...
"mcpServers": {
"datacommons-mcp": {
"command": "uvx",
"args": [
"datacommons-mcp@latest",
"serve",
"stdio"
],
"env": {
"DC_API_KEY": "YOUR DATA COMMONS API KEY"
},
"trust": true
}
}
// ...
}
- From any directory, run
gemini. - To see the Data Commons tools, use
/mcp tools. - Start sending natural-language queries.
Tip: To ensure that Gemini CLI uses the Data Commons MCP tools, and not its own
GoogleSearchtool, 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 aGEMINI.mdfile so that it’s persisted across sessions.
Use the sample agent
We provide a basic agent for interacting with the MCP Server in packages/datacommons-mcp/examples/sample_agents/basic_agent. To run the agent locally:
- If not already installed, install
uvfor managing and installing Python packages; see the instructions at https://docs.astral.sh/uv/getting-started/installation/. - From the desired directory, clone the
agent-toolkitrepo:git clone https://github.com/datacommonsorg/agent-toolkit.git - Set the following environment variables in your shell or startup script:
export DC_API_KEY=YOUR DATA COMMONS API KEY export GEMINI_API_KEY=YOUR GOOGLE AI API KEY
- Go to the root directory of the repo:
cd agent-toolkit - Run the agent using one of the following methods.
Web UI (recommended)
- Run the following command:
uvx --from google-adk adk web ./packages/datacommons-mcp/examples/sample_agents/ - 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. - From the Type a message box, type your query for Data Commons or select another action.
Command line interface
- Run the following command:
uvx --from google-adk adk run ./packages/datacommons-mcp/examples/sample_agents/basic_agent - Enter your queries at the
Userprompt in the terminal.
Sample queries
The Data Commons MCP tools excel at natural-language queries that involve:
- Comparisons between two or more entities, such as countries or metrics
- Exploring data available for a given topic
Here are some examples of such queries:
- “What health data do you have for Africa?”
- “What data do you have on water quality in Zimbabwe?”
- “Compare the life expectancy, economic inequality, and GDP growth for BRICS nations.”
- “Generate a concise report on income vs diabetes in US counties.”
Use a remote server/client
Run a standalone server
- Ensure you’ve set up the relevant server environment variables. If you’re using a
.envfile, go to the directory where the file is stored. - Run:
uvx datacommons-mcp serve http [--port PORT]
By default, the port is 8080 if you don’t set it explicitly.
The server is addressable with the endpoint mcp. For example, http://my-mcp-server:8080/mcp.
Connect to an already-running server from a remote client
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.
Gemini CLI
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:
{
// ... (additional configuration)
"mcpServers": {
"datacommons-mcp": {
"httpUrl": "http://HOST:PORT/mcp"
}
// ... (other mcpServers entries)
}
}
Sample agent
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. Set import modules and agent initialization parameters as follows:
from google.adk.tools.mcp_tool.mcp_toolset import (
MCPToolset,
StreamableHTTPConnectionParams
)
root_agent = LlmAgent(
# ...
tools=[McpToolset(
connection_params=StreamableHTTPConnectionParams(
url=f"http://<host>:<port>/mcp"
)
)],
)
Run the agent as described in Use the sample agent above.
Page last updated: October 24, 2025 • Send feedback about this page