Skip to content

Remove legacy local mode and standardize on Agent API - #216

Merged
keyurva merged 4 commits into
datacommonsorg:mainfrom
keyurva:remove-local-mode
Aug 31, 2026
Merged

Remove legacy local mode and standardize on Agent API#216
keyurva merged 4 commits into
datacommonsorg:mainfrom
keyurva:remove-local-mode

Conversation

@keyurva

@keyurva keyurva commented Aug 28, 2026

Copy link
Copy Markdown
Contributor
  • Removed legacy local graph traversal, topic caches, and datacommons-client dependency.
  • Simplified settings into a single DCSettings model configured via DC_AGENT_API_ROOT.
  • Standardized MCP tools and services to call Data Commons Agent API endpoints.
  • Added request-scoped API key propagation via context variables in APIKeyMiddleware.
  • Flattened the instructions directory structure and configured native FastMCP skills.
  • Updated Cloud Run deployment manifests across autopush, staging, and release environments to remove obsolete environment variables (DC_USE_AGENT_API, DC_API_ROOT).

@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 simplifies the Data Commons MCP server by removing the local processing mode and migrating entirely to the Agent API client, which includes removing the datacommons-client dependency and refactoring tools, services, and settings. The review identified two critical issues: a potential security vulnerability where agent_api_root is not validated or normalized, and a runtime NameError in utils.py due to storage being used in _get_gcs_client() while only imported under TYPE_CHECKING.

Comment thread packages/datacommons-mcp/datacommons_mcp/app.py
Comment thread packages/datacommons-mcp/datacommons_mcp/utils.py
@keyurva

keyurva commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 migrate fully to the Agent API, removing local processing, custom Data Commons configurations, and the datacommons-client dependency. The initialization process, settings, services, and tools are simplified to directly call the Agent API endpoints, and a context-based API key override mechanism is introduced. The review feedback recommends two improvements: refactoring APIKeyMiddleware to a pure ASGI middleware to prevent contextvars propagation issues associated with BaseHTTPMiddleware, and defaulting the date parameter in get_observations to a safe, defensive value ('latest') to handle cases where the caller fails to provide a value.

Comment thread packages/datacommons-mcp/datacommons_mcp/middleware.py
child_place_type: str | None = None,
source_override: str | None = None,
date: str = ObservationDateType.LATEST.value,
date: str | None = None,

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.

medium

To align with the general rule of defaulting tool parameters to safe, defensive values (like 'latest') rather than None, and to maintain consistency with get_multi_entity_observations (which defaults date to ObservationDateType.LATEST.value), we should default date to ObservationDateType.LATEST.value here as well. This protects against cases where the caller or agent fails to provide a value.

Suggested change
date: str | None = None,
date: str | None = ObservationDateType.LATEST.value,
References
  1. When defining tool parameters (such as date filters) for LLM agents, default to a safe, defensive value (e.g., 'latest') rather than None to protect against the agent failing to provide a value.

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.

No we want latest to be the default.

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.

why not set default to latest here?

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.

Sorry, I had read this backward. Updated now so latest is default. Thanks for the catch!

@keyurva
keyurva requested a review from clincoln8 August 28, 2026 19:24

@clincoln8 clincoln8 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.

Thanks Keyur!

@keyurva
keyurva merged commit caf446b into datacommonsorg:main Aug 31, 2026
13 of 14 checks passed
@keyurva
keyurva deleted the remove-local-mode branch August 31, 2026 20:29
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