Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions src/mcp/server/mcpserver/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
TextContent,
TextResourceContents,
ToolAnnotations,
ToolExecution,
)
from mcp.types import Prompt as MCPPrompt
from mcp.types import PromptArgument as MCPPromptArgument
Expand Down Expand Up @@ -383,6 +384,7 @@ async def list_tools(self) -> list[MCPTool]:
annotations=info.annotations,
icons=info.icons,
_meta=info.meta,
execution=info.execution,
)
for info in tools
]
Expand Down Expand Up @@ -465,6 +467,7 @@ def add_tool(
icons: list[Icon] | None = None,
meta: dict[str, Any] | None = None,
structured_output: bool | None = None,
execution: ToolExecution | None = None,
) -> None:
"""Add a tool to the server.

Expand All @@ -483,6 +486,8 @@ def add_tool(
- If None, auto-detects based on the function's return type annotation
- If True, creates a structured tool (return type annotation permitting)
- If False, unconditionally creates an unstructured tool
execution: Optional ToolExecution for declaring task support per MCP spec
(e.g. ToolExecution(taskSupport="optional"))
"""
self._tool_manager.add_tool(
fn,
Expand All @@ -493,6 +498,7 @@ def add_tool(
icons=icons,
meta=meta,
structured_output=structured_output,
execution=execution,
)

def remove_tool(self, name: str) -> None:
Expand Down
5 changes: 4 additions & 1 deletion src/mcp/server/mcpserver/tools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from mcp.server.mcpserver.utilities.func_metadata import FuncMetadata, func_metadata
from mcp.shared.exceptions import UrlElicitationRequiredError
from mcp.shared.tool_name_validation import validate_and_warn_tool_name
from mcp.types import Icon, ToolAnnotations
from mcp.types import Icon, ToolAnnotations, ToolExecution

if TYPE_CHECKING:
from mcp.server.context import LifespanContextT, RequestT
Expand All @@ -36,6 +36,7 @@ class Tool(BaseModel):
annotations: ToolAnnotations | None = Field(None, description="Optional annotations for the tool")
icons: list[Icon] | None = Field(default=None, description="Optional list of icons for this tool")
meta: dict[str, Any] | None = Field(default=None, description="Optional metadata for this tool")
execution: ToolExecution | None = Field(default=None, description="Optional execution properties for task support")

@cached_property
def output_schema(self) -> dict[str, Any] | None:
Expand All @@ -53,6 +54,7 @@ def from_function(
icons: list[Icon] | None = None,
meta: dict[str, Any] | None = None,
structured_output: bool | None = None,
execution: ToolExecution | None = None,
) -> Tool:
"""Create a Tool from a function."""
func_name = name or fn.__name__
Expand Down Expand Up @@ -87,6 +89,7 @@ def from_function(
annotations=annotations,
icons=icons,
meta=meta,
execution=execution,
)

async def run(
Expand Down
4 changes: 3 additions & 1 deletion src/mcp/server/mcpserver/tools/tool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from mcp.server.mcpserver.exceptions import ToolError
from mcp.server.mcpserver.tools.base import Tool
from mcp.server.mcpserver.utilities.logging import get_logger
from mcp.types import Icon, ToolAnnotations
from mcp.types import Icon, ToolAnnotations, ToolExecution

if TYPE_CHECKING:
from mcp.server.context import LifespanContextT, RequestT
Expand Down Expand Up @@ -51,6 +51,7 @@ def add_tool(
icons: list[Icon] | None = None,
meta: dict[str, Any] | None = None,
structured_output: bool | None = None,
execution: ToolExecution | None = None,
) -> Tool:
"""Add a tool to the server."""
tool = Tool.from_function(
Expand All @@ -62,6 +63,7 @@ def add_tool(
icons=icons,
meta=meta,
structured_output=structured_output,
execution=execution,
)
existing = self._tools.get(tool.name)
if existing:
Expand Down