Conversation
Add the ability to serve any CDF data model as an MCP (Model Context Protocol) server, enabling LLMs like Claude to interact with Cognite Data Fusion directly. Features: - New `pygen mcp-serve` CLI command - Interactive OAuth 2.0 PKCE browser authentication (zero config) - Automatic SDK generation in memory from data model ID - Exposes list, retrieve, and graphql_query tools for each view Usage: pygen mcp-serve mySpace/MyModel@v1 --cluster api --project my-project Install with: pip install cognite-pygen[mcp]
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. |
☂️ Python Coverage
Overall Coverage
New Files
Modified Files
|
Switch from requests to httpx for OAuth HTTP calls since httpx is already a transitive dependency of mcp and has proper type stubs. Also includes ruff formatting fixes.
- Change --graphql to opt-in (default off) instead of --no-graphql - Add --write flag to enable delete operations (default off) - Add _make_delete_tool helper for delete functionality This gives users explicit control over which capabilities to expose.
- Introspect SDK list method signatures to expose all filter parameters
- Support datetime filters (ISO 8601 strings converted to datetime)
- Support node reference filters ({"space": str, "externalId": str})
- Support array of node refs for edge list filters
- Handle Python 3.10+ UnionType (X | Y) syntax
- Add search, aggregate, and histogram tools for all view APIs - Extract parameter descriptions from SDK docstrings - Refactor to use generic _make_dynamic_tool helper - Fix histogram result serialization (access .buckets attribute) - Force-include method-specific params (aggregate, group_by, property, interval)
Parameters without defaults (required) were incorrectly being marked as optional with default=None. This caused MCP tools like aggregate to not enforce required parameters. Now: - Required params: no default, non-nullable type annotation - Optional params: has default, nullable type annotation (type | None)
Allows filtering which views and operations are exposed: - --views: comma-separated list of view external IDs to include - --operations/--ops: comma-separated operations (list, retrieve, search, aggregate, histogram) This helps reduce tool count for MCP clients with limits. Examples: pygen mcp-serve model -c api -p proj --views Asset,Equipment pygen mcp-serve model -c api -p proj --ops list,search
Summary
Adds MCP (Model Context Protocol) server support to pygen, enabling LLMs to interact with CDF data models through dynamically generated tools.
Features
aggregatein aggregate tools) are properly enforced--viewsto include only specific views (reduces tool count)--operationsto enable only specific operations (list, search, etc.)Supported Operations
listretrievesearchaggregatehistogramdelete--writeflag)graphql_query--graphqlflag)Type Support
datetime.datetime{"space": str, "externalId": str}objectsCLI Usage
Installation
Cursor IDE Setup
Example Cursor MCP config (
~/.cursor/mcp.json):{ "mcpServers": { "cognite": { "command": "pygen", "args": ["mcp-serve", "space/dataModel/version", "-c", "greenfield", "-p", "myproject", "--org", "myorg"] } } }Claude Desktop Setup
Example Claude Desktop config (
~/Library/Application Support/Claude/claude_desktop_config.json):{ "mcpServers": { "cognite": { "command": "/Users/yourname/.local/bin/pygen", "args": [ "mcp-serve", "sp_enterprise_process_industry/RigsbergProcessIndustries@v1", "-c", "greenfield", "-p", "eos-greenfield", "--org", "cog-ai", "--views", "RigsbergAsset,RigsbergFile,RigsbergMaintenanceOrder", "--ops", "list,search" ] } } }Note: Claude Desktop requires the full path to
pygensince~/.local/binis not in its PATH.Authentication
Uses interactive OAuth 2.0 Authorization Code Flow with PKCE (same as
@cognite/dune):.envfiles or client secrets requiredTest Plan
aggregate) are properly enforced, optional params have defaults--viewsflag filters to specified view external IDs--operationsflag enables only specified operationsBump
Changelog
Added
pygen mcp-serveto launch MCP server from a data model ID--graphqland--writeflags for GraphQL queries and delete operations--viewsflag to filter which views are exposed as MCP tools--operationsflag to control which operations are enabled (list, retrieve, search, aggregate, histogram)Fixed
aggregate) are now properly enforced in MCP tool schemas