Skip to content

Accept callables in Tool.from_tool()#3235

Merged
jlowin merged 3 commits intomainfrom
fix/from-tool-accept-callables
Feb 19, 2026
Merged

Accept callables in Tool.from_tool()#3235
jlowin merged 3 commits intomainfrom
fix/from-tool-accept-callables

Conversation

@jlowin
Copy link
Copy Markdown
Member

@jlowin jlowin commented Feb 19, 2026

Tool.from_tool() previously required a Tool object as its first argument, but the @tool decorator (since v3.0) returns the original function with metadata attached rather than a Tool object. This meant the documented workflow of decorating a function and then transforming it before registration would crash with AttributeError: 'function' object has no attribute 'parameters'.

Now from_tool accepts either a Tool or a callable, auto-coercing the latter via Tool._ensure_tool(). This respects any @tool decorator metadata (name, description, etc.) on the function, so the documented pattern works naturally:

@tool
def search(q: str, limit: int = 10) -> list[str]:
    """Search for items."""
    return [f"Result {i} for {q}" for i in range(limit)]

better_search = Tool.from_tool(
    search,
    name="find_items",
    transform_args={"q": ArgTransform(name="query")},
)

mcp = FastMCP("Server")
mcp.add_tool(better_search)

The coercion reuses FunctionTool.from_function(fn, metadata=meta) rather than expanding kwargs, keeping it in sync with the existing metadata path.

Closes #3232

@marvin-context-protocol marvin-context-protocol Bot added the bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. label Feb 19, 2026
@jlowin jlowin merged commit b894a0b into main Feb 19, 2026
9 checks passed
@jlowin jlowin deleted the fix/from-tool-accept-callables branch February 19, 2026 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ToolTransform AttributeError: 'function' object has no attribute 'parameters' when creating tool without registering it in v3.0

1 participant