Skip to content

Overhaul MCP tools, add metadata tool, and introduce skills#209

Merged
keyurva merged 4 commits into
datacommonsorg:mainfrom
keyurva:metadata-tool
Jun 24, 2026
Merged

Overhaul MCP tools, add metadata tool, and introduce skills#209
keyurva merged 4 commits into
datacommonsorg:mainfrom
keyurva:metadata-tool

Conversation

@keyurva

@keyurva keyurva commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Overview

This PR overhauls the Data Commons MCP server to simplify tool definitions, reduce errors, and introduce native skills.

Key Changes

  • Tool Refactoring: Simplified tool definitions to reduce AI errors by splitting complex, multi-mode legacy tools into 5 single-purpose tools.
  • Metadata Integration: Added a dedicated metadata tool to support thorough variable discovery.
  • Native MCP Skills: Introduced the FastMCP skills provider to expose a structured agent playbook (researcher skill).
  • Path Isolation: Separated legacy local instructions from the modernized agent API instructions.
  • Draft Staging Instructions: Provided draft staging templates for the tools and skills; Caro is currently iterating on them, and we will submit final versions in a subsequent PR.
  • GCS Path Warning: Added a warning log for GCS-hosted instructions and a TODO to implement the GCS-to-local bootstrap cache in a follow-up PR.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the Data Commons MCP server to support distinct 'agent_api' and 'local' modes, organizing tool instructions and introducing native FastMCP skills via the SkillsDirectoryProvider. It also adds new tools and service endpoints for retrieving variable metadata and child observations. The review feedback highlights critical improvements: defaulting the date parameter to None in get_observations and get_child_observations to ensure range queries are not inadvertently overridden, and upgrading the root fastmcp dependency to >=3.0.0 to match the package's requirement and prevent runtime import errors.

Comment thread packages/datacommons-mcp/datacommons_mcp/agent_api_tools.py
Comment thread packages/datacommons-mcp/datacommons_mcp/agent_api_tools.py
Comment thread pyproject.toml Outdated
@keyurva keyurva marked this pull request as ready for review June 24, 2026 04:37
@keyurva keyurva requested a review from rohitkumarbhagat June 24, 2026 04:40
@keyurva

keyurva commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

FYI - @carojahn

@rohitkumarbhagat rohitkumarbhagat left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks Keyur!

server_params=StdioServerParameters(
command="uv",
args=["run", "datacommons-mcp", "serve", "stdio"],
env={"DC_API_KEY": dc_api_key},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now conflicts with the updated eval fixtures. The fixtures expect agent API tools like get_child_observations, but this server is still launched without DC_USE_AGENT_API=true, so it exposes only the local tools (get_observations, search_indicators). Please add DC_USE_AGENT_API: "true" here or keep the fixtures on the local tool surface.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Reverted the evals for now. We need a larger overhaul of evals, something that's on @shixiao-coder's radar in the medium term.


Data Commons organizes data into two main structural hierarchies. Understanding these is key to choosing your place names and variables:

1. **Topics (Variable Hierarchy)**: A taxonomy of categories (e.g., `Health` -> `Clinical Data` -> `Medical Conditions`). Topics contain sub-topics and individual variables.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also explain what is the relationship between variables, topics, and indicators because they are used across the skills.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a starter template. @carojahn is actually working / testing the skill + server and tool instructions. We'll then use those prompts here.

Caro - pl consider Rohit's comments on this PR when finalizing the prompts.

When researching statistics, always separate your work into three distinct phases to avoid context bloat:

1. **Discovery (`search_indicators` or `search_child_indicators`)**: Use this to find candidate variables matching the user's concept.
2. **Assessment (`get_variable_metadata`)**: Pass candidate variables and target locations to retrieve structural metadata, ensuring the dataset matches the required temporal range, granularity, and source trust.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this for variable or indicator? If only for variable, how will agent distinguish between them?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only for variable. search_indicators returns the typeOf property which the agent uses to distinguish.


1. **Discovery (`search_indicators` or `search_child_indicators`)**: Use this to find candidate variables matching the user's concept.
2. **Assessment (`get_variable_metadata`)**: Pass candidate variables and target locations to retrieve structural metadata, ensuring the dataset matches the required temporal range, granularity, and source trust.
3. **Retrieval (`get_observations` or `get_child_observations`)**: Fetch the actual timeseries arrays once the variables and facets have been qualified.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we explain what facet and child observation is? Does paent-child refer to place hierarchy or soemthing else too, better to call out.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment as earlier - Caro is working on this.

@@ -0,0 +1,141 @@
---
name: data-commons-researcher

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this skill file be always loaded in mcp client context, whether it uses dc mpc or not?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just like any other skill, the frontmatter is always loaded, the content only when needed.

@keyurva keyurva left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review!

@@ -0,0 +1,141 @@
---
name: data-commons-researcher

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just like any other skill, the frontmatter is always loaded, the content only when needed.


Data Commons organizes data into two main structural hierarchies. Understanding these is key to choosing your place names and variables:

1. **Topics (Variable Hierarchy)**: A taxonomy of categories (e.g., `Health` -> `Clinical Data` -> `Medical Conditions`). Topics contain sub-topics and individual variables.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a starter template. @carojahn is actually working / testing the skill + server and tool instructions. We'll then use those prompts here.

Caro - pl consider Rohit's comments on this PR when finalizing the prompts.

When researching statistics, always separate your work into three distinct phases to avoid context bloat:

1. **Discovery (`search_indicators` or `search_child_indicators`)**: Use this to find candidate variables matching the user's concept.
2. **Assessment (`get_variable_metadata`)**: Pass candidate variables and target locations to retrieve structural metadata, ensuring the dataset matches the required temporal range, granularity, and source trust.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only for variable. search_indicators returns the typeOf property which the agent uses to distinguish.


1. **Discovery (`search_indicators` or `search_child_indicators`)**: Use this to find candidate variables matching the user's concept.
2. **Assessment (`get_variable_metadata`)**: Pass candidate variables and target locations to retrieve structural metadata, ensuring the dataset matches the required temporal range, granularity, and source trust.
3. **Retrieval (`get_observations` or `get_child_observations`)**: Fetch the actual timeseries arrays once the variables and facets have been qualified.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment as earlier - Caro is working on this.

server_params=StdioServerParameters(
command="uv",
args=["run", "datacommons-mcp", "serve", "stdio"],
env={"DC_API_KEY": dc_api_key},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Reverted the evals for now. We need a larger overhaul of evals, something that's on @shixiao-coder's radar in the medium term.

@keyurva keyurva merged commit 7972107 into datacommonsorg:main Jun 24, 2026
13 of 14 checks passed
@keyurva keyurva deleted the metadata-tool branch June 24, 2026 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants