feat: add mcp abstractions to core (#36151)

This commit is contained in:
Ville Brofeldt
2025-11-25 08:23:59 -10:00
committed by GitHub
parent bae716fa83
commit a4860075d2
37 changed files with 1044 additions and 151 deletions

View File

@@ -566,8 +566,8 @@ class TestDashboardSortableColumns:
SORTABLE_DASHBOARD_COLUMNS,
)
# Check list_dashboards docstring (stored in description after @mcp.tool)
assert hasattr(list_dashboards, "description")
assert "Sortable columns for order_column:" in list_dashboards.description
# Check list_dashboards docstring for sortable columns documentation
assert list_dashboards.__doc__ is not None
assert "Sortable columns for order_column:" in list_dashboards.__doc__
for col in SORTABLE_DASHBOARD_COLUMNS:
assert col in list_dashboards.description
assert col in list_dashboards.__doc__

View File

@@ -1199,11 +1199,11 @@ class TestDatasetSortableColumns:
SORTABLE_DATASET_COLUMNS,
)
# Check list_datasets docstring (stored in description after @mcp.tool)
assert hasattr(list_datasets, "description")
assert "Sortable columns for order_column:" in list_datasets.description
# Check list_datasets docstring for sortable columns documentation
assert list_datasets.__doc__ is not None
assert "Sortable columns for order_column:" in list_datasets.__doc__
for col in SORTABLE_DATASET_COLUMNS:
assert col in list_datasets.description
assert col in list_datasets.__doc__
@pytest.mark.asyncio
async def test_default_ordering(self):

View File

@@ -0,0 +1,51 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""Test MCP tool registration through superset-core dependency injection."""
import sys
from unittest.mock import MagicMock, patch
from superset.core.mcp.core_mcp_injection import initialize_core_mcp_dependencies
def test_initialize_core_mcp_dependencies_replaces_decorator():
"""Test that initialize_core_mcp_dependencies replaces the abstract tool
decorator."""
# Mock the superset_core.mcp module
mock_mcp_module = MagicMock()
with patch.dict(sys.modules, {"superset_core.mcp": mock_mcp_module}):
initialize_core_mcp_dependencies()
# Verify the abstract decorator was replaced
assert hasattr(mock_mcp_module, "tool")
assert callable(mock_mcp_module.tool)
def test_tool_import_works():
"""Test that tool can be imported from superset_core.mcp after
initialization."""
# This test verifies the basic import works (dependency injection has happened)
from superset_core.mcp import tool
# Should be callable
assert callable(tool)
# Should return a decorator function
decorator = tool(name="test", description="test")
assert callable(decorator)