Skip to content

feat(mcp): add list and get tools for annotation layers and annotations#40303

Closed
aminghadersohi wants to merge 3 commits into
masterfrom
mcp-annotations-99978
Closed

feat(mcp): add list and get tools for annotation layers and annotations#40303
aminghadersohi wants to merge 3 commits into
masterfrom
mcp-annotations-99978

Conversation

@aminghadersohi
Copy link
Copy Markdown
Contributor

SUMMARY

Adds 4 new MCP tools in a new superset/mcp_service/annotation_layer/ domain:

  • list_annotation_layers — list annotation layers with filtering, search, and 1-based pagination
  • get_annotation_layer_info — get annotation layer details by ID
  • list_layer_annotations — list annotations within a layer (requires layer_id to scope results)
  • get_layer_annotation_info — get a single annotation by layer_id + annotation_id, with layer-membership verification

The annotation tools mirror the pattern used by database/, dashboard/, and dataset/ domains: Pydantic request/response schemas, ModelListCore for listings, DAO-based lookups, ToolAnnotations, and event_logger instrumentation.

For annotations, layer_id is a required parameter that scopes all results to the parent layer — mirroring the Superset REST API structure (GET /annotation_layer/{layer_pk}/annotation/).

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A (backend-only MCP tool additions)

TESTING INSTRUCTIONS

  1. Run unit tests:
    pytest tests/unit_tests/mcp_service/annotation_layer/
    
  2. Connect an MCP client and call:
    • list_annotation_layers({}) — lists all annotation layers
    • get_annotation_layer_info({"id": <id>}) — retrieves a specific layer
    • list_layer_annotations({"layer_id": <id>}) — lists annotations in a layer
    • get_layer_annotation_info({"layer_id": <id>, "annotation_id": <id>}) — retrieves a specific annotation

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration
  • Introduces new feature or API
  • Removes existing feature or API

@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

❌ Patch coverage is 65.62500% with 88 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.83%. Comparing base (73f66e4) to head (6e71872).
⚠️ Report is 11 commits behind head on master.

Files with missing lines Patch % Lines
...annotation_layer/tool/get_layer_annotation_info.py 29.03% 22 Missing ⚠️
...ce/annotation_layer/tool/list_layer_annotations.py 39.39% 20 Missing ⚠️
superset/mcp_service/annotation_layer/schemas.py 87.31% 16 Missing and 1 partial ⚠️
...ce/annotation_layer/tool/list_annotation_layers.py 42.85% 16 Missing ⚠️
...annotation_layer/tool/get_annotation_layer_info.py 43.47% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40303      +/-   ##
==========================================
- Coverage   64.14%   63.83%   -0.32%     
==========================================
  Files        2592     2598       +6     
  Lines      138846   140183    +1337     
  Branches    32201    32492     +291     
==========================================
+ Hits        89069    89488     +419     
- Misses      48245    49131     +886     
- Partials     1532     1564      +32     
Flag Coverage Δ
hive 39.15% <65.62%> (-0.18%) ⬇️
mysql 58.28% <65.62%> (-0.58%) ⬇️
postgres 58.36% <65.62%> (-0.58%) ⬇️
presto 40.79% <65.62%> (-0.21%) ⬇️
python 59.89% <65.62%> (-0.62%) ⬇️
sqlite 58.01% <65.62%> (-0.58%) ⬇️
unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aminghadersohi aminghadersohi force-pushed the mcp-annotations-99978 branch 4 times, most recently from 32ffe2c to 7df5804 Compare May 21, 2026 18:04
aminghadersohi and others added 3 commits May 21, 2026 20:10
- Use ModelGetInfoCore in get_annotation_layer_info (DRY, matches other get_info tools)
- Expand search_columns to include descr and long_descr (align with docstrings)
- Simplify layer_id assignment in list_layer_annotations (direct attribute set vs rebuild)
- Fix AnnotationList.layer_id default to 0 (ModelListCore cannot inject domain fields)

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- AnnotationList.filters_applied used list[AnnotationFilter] which only
  allows col="short_descr", but ModelListCore injects a col="layer_id"
  ColumnOperator that fails Pydantic validation, causing KeyError on
  layer_id in the JSON response. Changed to list[ColumnOperator].
- test_get_annotation_layer_info_found: ModelGetInfoCore._find_object
  calls find_by_id(id, query_options=None), not find_by_id(id); updated
  assertion to assert_called_once_with(5, query_options=None).
@aminghadersohi aminghadersohi force-pushed the mcp-annotations-99978 branch from 7df5804 to 6e71872 Compare May 21, 2026 20:10
@aminghadersohi aminghadersohi marked this pull request as ready for review May 22, 2026 02:46
@aminghadersohi aminghadersohi requested a review from geido May 22, 2026 02:48
@aminghadersohi
Copy link
Copy Markdown
Contributor Author

Superseded by #40342 (branch renamed to follow amin/ convention).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant