Skip to content

feat(mcp): shared limits, truncation, list coercion and ToolError mapping - #21342

Merged
nwadams merged 16 commits into
na--mcp-execution-helpersfrom
na--mcp-data-helpers
Nov 23, 2026
Merged

nwadams merged 16 commits into
na--mcp-execution-helpersfrom
na--mcp-data-helpers

Conversation

@nwadams

@nwadams nwadams commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Stack. This is one PR in a series that adds a built-in MCP server to DataHub Core. It is based on na--mcp-execution-helpers (the previous PR in the stack); review only its own commit. It changes only the shared datahub-core-mcp-tools package and datahub-ai-service. Everything user-facing is behind a GMS feature flag, MCP_SERVER_ENABLED, off by default (added in #21349).

Stack so far:

  1. feat(mcp): add DataHub's built-in MCP server, off by default #21332
  2. feat(mcp): read GMS version and deployment from /config #21333
  3. feat(ai): scaffold the datahub-ai-service with /health #21334
  4. feat(ai): serve MCP at /mcp with caller-scoped DataHub clients #21335
  5. build(ai): add PyPI release scripts for datahub-core-mcp-tools and datahub-ai-service #21336
  6. feat(mcp): filter tools by the connected GMS version #21337
  7. feat(mcp): compile GraphQL for the exact GMS version with #[since] markers #21338
  8. test(mcp): validate packaged GraphQL against pinned GMS schemas #21339
  9. feat(mcp): tool groups and tool-aware server instructions #21340
  10. feat(mcp): deliver tool cancellation safely and report progress on slow tools #21341
  11. feat(mcp): shared limits, truncation, list coercion and ToolError mapping #21342 ← this PR
  12. feat(mcp): ReadBackend and ResultPolicy retrieval seams #21343
  13. feat(ai): bound GMS requests and never replay one GMS may have run #21344
  14. feat(gms): report whether authentication is enabled in /config #21345
  15. feat(ai): follow GMS's auth mode on /mcp #21346
  16. feat(ai): refuse DNS-rebinding requests to /mcp while GMS auth is off #21347
  17. feat(ai): datahub-ai-service docker image and locked dependencies #21348
  18. feat(mcp): keep the MCP server off until MCP_SERVER_ENABLED is set #21349
  19. feat(frontend): proxy /mcp to the datahub-ai-service #21350
  20. ci(ai): build the datahub-ai-service image on every relevant PR #21351
  21. feat(docker): run datahub-ai-service in quickstart and datahub-dev #21352
  22. test(smoke): MCP through the frontend's /mcp route #21353
  23. feat(mcp): port the read tools to DataHub Core's MCP server #21435
  24. feat(mcp): port the get_entities tool #21436
  25. feat(mcp): port the list_schema_fields tool #21437
  26. feat(mcp): port the search_documents tool #21438
  27. feat(mcp): port the grep_documents tool #21439
  28. feat(mcp): port the grep_entities tool #21440
  29. feat(mcp): port the get_lineage tool #21441
  30. feat(mcp): port the get_lineage_paths_between tool #21442
  31. feat(mcp): port the get_dataset_queries tool #21443
  32. feat(mcp): port the get_dataset_usage_history tool #21444
  33. feat(mcp): port the get_aspect_history tool #21445
  34. feat(mcp): port the glossary term version read tools #21447
  35. feat(mcp): port the write tools to DataHub Core's MCP server #21501
  36. feat(mcp): add the create_tag tool #21502
  37. feat(mcp): port add_terms and remove_terms #21503
  38. feat(mcp): port create_glossary_term and add_related_terms #21504
  39. feat(mcp): port the create_glossary_term_version tool #21505
  40. feat(mcp): port set_domains and remove_domains #21506
  41. feat(mcp): add the create_domain tool #21507
  42. feat(mcp): port add_owners and remove_owners #21508
  43. feat(mcp): port the update_description tool #21509
  44. feat(mcp): port add_structured_properties and remove_structured_properties #21510
  45. feat(mcp): port the save_document tool #21511
  46. feat(mcp): port the update_document tool #21512

What this does

Add the data helpers the tool ports build on.

  • Size limits for tool output, overridable with the same environment
    variables as mcp-server-datahub (DESCRIPTION_LENGTH_LIMIT,
    QUERY_LENGTH_LIMIT, DOCUMENT_CONTENT_CHAR_LIMIT,
    FIELD_DESCRIPTION_LENGTH_LIMIT, ...). A non-numeric or non-positive value
    fails at startup with the variable's name.
  • truncate_with_ellipsis, including limits shorter than the suffix and a
    "[+N chars]" marker.
  • arg_validation: StrList and friends accept a list that a client sent as
    a JSON string or a bare value, while the published schema stays a single
    array type ("" and "null" count as omitted). coerce_keyword_list also
    splits comma-joined keywords.
  • execute_graphql raises ToolError with a message the model can act on
    (rejected token, GMS unreachable, GraphQL errors); format_exception=False
    keeps the SDK's raw GraphError for callers that act on error types.
    datahub-ai-service's token check reuses its HTTP status helper.

Testing

Unit tests incl. published schema shape.

Checklist

  • The PR conforms to DataHub's Contributing Guideline (particularly PR Title Format)
  • Tests for the changes have been added/updated (if applicable)
  • Docs related to the changes have been added/updated (if applicable). The MCP docs come later in the stack.
  • For any breaking change/potential downtime/deprecation/big changes an entry has been made in Breaking Changes. The release notes come later in the stack.

🤖 Generated with Claude Code

@nwadams
nwadams requested a review from lakshay-nasa November 16, 2026 23:30
@cursor

cursor Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

PR Summary

Overview
Adds shared infrastructure in datahub-core-mcp-tools for upcoming MCP tool ports, plus a small dedup in datahub-ai-service.

Configurable response sizing — graphql_helpers now defines env-overridable limits (descriptions, queries, documents, grep budgets, etc.) and a truncate_with_ellipsis helper so tool output can stay within LLM/MCP client bounds.

LLM-friendly tool parameters — New arg_validation (StrList, OptionalStrList, coerce_keyword_list, etc.) coerces list args that clients send as JSON strings or scalars while keeping the published JSON Schema as a plain array (avoiding anyOf that breaks strict function-calling APIs).

Unified GraphQL failures — execute_graphql maps DataHub/SDK failures to ToolError messages via describe_datahub_error, with optional format_exception=False for callers that need raw GraphError. http_status is centralized there; get_me drops its local try/except and auth.py reuses the shared helper instead of a duplicate _http_status.

Deps/tests — Adds pydantic to datahub-core-mcp-tools and test_data_helpers.py covering truncation, env limits, error mapping, and schema shape for list coercion.

Reviewed by Cursor Bugbot for commit 13529b9. Bugbot is set up for automated code reviews on this repo. Configure here.

This was referenced Nov 16, 2026

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 66ac9c1. Configure here.

@lakshay-nasa

Copy link
Copy Markdown
Contributor

lgtm. tiny nit: arg_validation.py cites #98 and #173. those are mcp-server-datahub numbers, so in this repo they link to unrelated items. maybe acryldata/mcp-server-datahub#98 / #173

@nwadams
nwadams force-pushed the na--mcp-data-helpers branch from 66ac9c1 to 9ada623 Compare November 19, 2026 00:10
@nwadams
nwadams force-pushed the na--mcp-execution-helpers branch from 4f50cf0 to 87d71cc Compare November 19, 2026 00:10
…ping

Add the data helpers the tool ports build on.

- Size limits for tool output, overridable with the same environment
  variables as mcp-server-datahub (DESCRIPTION_LENGTH_LIMIT,
  QUERY_LENGTH_LIMIT, DOCUMENT_CONTENT_CHAR_LIMIT,
  FIELD_DESCRIPTION_LENGTH_LIMIT, ...). A non-numeric or non-positive value
  fails at startup with the variable's name.
- truncate_with_ellipsis, including limits shorter than the suffix and a
  "[+N chars]" marker.
- arg_validation: StrList and friends accept a list that a client sent as
  a JSON string or a bare value, while the published schema stays a single
  array type ("" and "null" count as omitted). coerce_keyword_list also
  splits comma-joined keywords.
- execute_graphql raises ToolError with a message the model can act on
  (rejected token, GMS unreachable, GraphQL errors); format_exception=False
  keeps the SDK's raw GraphError for callers that act on error types.
  datahub-ai-service's token check reuses its HTTP status helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nwadams and others added 4 commits November 23, 2026 14:53
CI's package check compares find_packages with find_namespace_packages, and the
gql directory had no __init__.py. Make it a package and declare its .gql files
as its own package data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Installing metadata-ingestion and the two packages from source resolves their
build requirements from the configured index. In CI that index needs the netrc
secret, which only the lock install step mounted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FastMCP 4.2.5 serves subscriptions/listen, and on the 2026-07-28 protocol the
SDK advertises listChanged whenever that handler is registered, overriding the
notification options. Drop the handler: the server never sends change
notifications, and an in-process bus can't reach clients on another replica.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
master now adds its own placeholder right after __SYSTEM_CLIENT_SECRET__.
Keeping ours one line further down lets both changes merge without a
conflict. The replacements are independent, so their order doesn't matter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

2 active deployments
datahub-project-web-react (Preview) — 66f97775 Deployed Nov 23, 2026 by github-actions[bot]
Preview — 66f97775 Deployed Nov 23, 2026 by vercel[bot]
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