Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1e63247
feat: add mcp tool abstractions to core
villebro Nov 18, 2025
bcf6495
rename decorator and add test
villebro Nov 18, 2025
62a7fc5
remove MCPToolDefinition
villebro Nov 18, 2025
eeddc74
fix test
villebro Nov 18, 2025
69f78ab
fix missing license
villebro Nov 18, 2025
ec68e4e
flaky test
villebro Nov 18, 2025
4bc516d
set name and description correctly
villebro Nov 18, 2025
375f25e
migrate to shared decorator
villebro Nov 18, 2025
980a115
update tests
villebro Nov 18, 2025
0c1d027
cleanup
villebro Nov 18, 2025
402d3aa
rename auth to secure in mcp_tool decorator
villebro Nov 19, 2025
61d3d39
update decorator signatures
villebro Nov 19, 2025
6c52879
fix tests
villebro Nov 19, 2025
29ca521
simplify mcp singleton
villebro Nov 19, 2025
ed69867
rename secure to protect
villebro Nov 19, 2025
dcb47ed
clean up wording here and there
villebro Nov 19, 2025
8c02caa
migrate mcp.prompt to mcp_prompt
villebro Nov 19, 2025
48b08ee
rename mcp_tool and mcp_prompt to tool and prompt respectively
villebro Nov 19, 2025
50a2ae8
generalized docs
villebro Nov 19, 2025
035ab55
fix claude typo
villebro Nov 19, 2025
0cad510
remove trailing spaces
villebro Nov 19, 2025
3a67242
Merge branch 'master' into villebro/mcp-extensions
villebro Nov 19, 2025
19a89e0
update deps
villebro Nov 19, 2025
3eb8500
fix tool() vs tool references
villebro Nov 19, 2025
b39a534
revert the current_app to Flask change
villebro Nov 20, 2025
d61cee0
fix docstring
villebro Nov 21, 2025
8a9f83d
Merge branch 'master' into villebro/mcp-extensions
villebro Nov 21, 2025
80dd0b7
Merge branch 'master' into villebro/mcp-extensions
villebro Nov 25, 2025
229bd5f
fix doc
villebro Nov 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
460 changes: 460 additions & 0 deletions docs/developer_portal/extensions/mcp.md

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ pyasn1-modules==0.4.2
pycparser==2.22
# via cffi
pydantic==2.11.7
# via apache-superset (pyproject.toml)
# via
# apache-superset (pyproject.toml)
# apache-superset-core
pydantic-core==2.33.2
# via pydantic
pygments==2.19.1
Expand Down
1 change: 1 addition & 0 deletions requirements/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ pydantic==2.11.7
# via
# -c requirements/base-constraint.txt
# apache-superset
# apache-superset-core
# fastmcp
# mcp
# openapi-pydantic
Expand Down
1 change: 1 addition & 0 deletions superset-core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ classifiers = [
]
dependencies = [
"flask-appbuilder>=5.0.2,<6",
"pydantic>=2.8.0",
"sqlalchemy>=1.4.0,<2.0",
"sqlalchemy-utils>=0.38.0",
"sqlglot>=27.15.2, <28",
Expand Down
161 changes: 161 additions & 0 deletions superset-core/src/superset_core/mcp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# 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.

"""
MCP (Model Context Protocol) tool registration for Superset MCP server.
This module provides a decorator interface to register MCP tools with the
host application.
Usage:
from superset_core.mcp import tool
@tool(name="my_tool", description="Custom business logic", tags=["extension"])
def my_extension_tool(param: str) -> dict:
return {"message": f"Hello {param}!"}
# Or use function name and docstring:
@tool
def another_tool(value: int) -> str:
'''Tool description from docstring'''
return str(value * 2)
"""

from typing import Any, Callable, TypeVar

# Type variable for decorated functions
F = TypeVar("F", bound=Callable[..., Any])


def tool(
func_or_name: str | Callable[..., Any] | None = None,
*,
name: str | None = None,
description: str | None = None,
tags: list[str] | None = None,
protect: bool = True,
) -> Any: # Use Any to avoid mypy issues with dependency injection
"""
Decorator to register an MCP tool with optional authentication.
This decorator combines FastMCP tool registration with optional authentication.
Can be used as:
@tool
def my_tool(): ...
Or:
@tool(name="custom_name", protect=False)
def my_tool(): ...
Args:
func_or_name: When used as @tool, this will be the function.
When used as @tool("name"), this will be the name.
name: Tool name (defaults to function name, prefixed with extension ID)
description: Tool description (defaults to function docstring)
tags: List of tags for categorizing the tool (defaults to empty list)
protect: Whether to require Superset authentication (defaults to True)
Returns:
Decorator function that registers and wraps the tool, or the wrapped function
Raises:
NotImplementedError: If called before host implementation is initialized
Example:
@tool(name="my_tool", description="Does something useful", tags=["utility"])
def my_custom_tool(param: str) -> dict:
return {"result": param}
@tool # Uses function name and docstring with auth
def simple_tool(value: int) -> str:
'''Doubles the input value'''
return str(value * 2)
@tool(protect=False) # No authentication required
def public_tool() -> str:
'''Public tool accessible without auth'''
return "Hello world"
"""
raise NotImplementedError(
"MCP tool decorator not initialized. "
"This decorator should be replaced during Superset startup."
)


def prompt(
func_or_name: str | Callable[..., Any] | None = None,
*,
name: str | None = None,
title: str | None = None,
description: str | None = None,
tags: set[str] | None = None,
protect: bool = True,
) -> Any: # Use Any to avoid mypy issues with dependency injection
"""
Decorator to register an MCP prompt with optional authentication.
This decorator combines FastMCP prompt registration with optional authentication.
Can be used as:
@prompt
async def my_prompt_handler(): ...
Or:
@prompt("my_prompt")
async def my_prompt_handler(): ...
Or:
@prompt("my_prompt", protected=False, title="Custom Title")
async def my_prompt_handler(): ...
Args:
func_or_name: When used as @prompt, this will be the function.
When used as @prompt("name"), this will be the name.
name: Prompt name (defaults to function name if not provided)
title: Prompt title (defaults to function name)
description: Prompt description (defaults to function docstring)
tags: Set of tags for categorizing the prompt
protect: Whether to require Superset authentication (defaults to True)
Returns:
Decorator function that registers and wraps the prompt, or the wrapped function
Raises:
NotImplementedError: If called before host implementation is initialized
Example:
@prompt
async def my_prompt_handler(ctx: Context) -> str:
'''Interactive prompt for doing something.'''
return "Prompt instructions here..."
@prompt("custom_prompt", protect=False, title="Custom Title")
async def public_prompt_handler(ctx: Context) -> str:
'''Public prompt accessible without auth'''
return "Public prompt accessible without auth"
"""
raise NotImplementedError(
"MCP prompt decorator not initialized. "
"This decorator should be replaced during Superset startup."
)


__all__ = [
"tool",
"prompt",
]
Loading
Loading