Skip to content

feat: wrap FastMCP tools as AskUI Tool via Tool.from_mcp_tool#250

Open
mlikasam-askui wants to merge 2 commits intomainfrom
feat/tool-from-mcp-fastmcp
Open

feat: wrap FastMCP tools as AskUI Tool via Tool.from_mcp_tool#250
mlikasam-askui wants to merge 2 commits intomainfrom
feat/tool-from-mcp-fastmcp

Conversation

@mlikasam-askui
Copy link
Contributor

@mlikasam-askui mlikasam-askui commented Mar 24, 2026

Summary

Adds Tool.from_mcp_tool() so a FastMCP Tool can be used as an AskUI Tool in the same flows as hand-written tools (for example ToolCollection). Name, description, and JSON schema come from the FastMCP tool; execution delegates to its callable.

What changed

  • Tool.from_mcp_tool(mcp_tool, name_prefix=None) — factory that returns an adapter implementing AskUI’s Tool contract.
  • _McpToolAdapter — forwards __call__ to mcp_tool.fn, with optional name_prefix on the exposed tool name.
  • Result normalization_convert_from_mcp_tool_call_result maps return values to AskUI-friendly primitives:
    • str — unchanged
    • McpTextContent — text
    • McpImageContent — PIL image via base64_to_image
    • list / tuple of the above — same structure, items converted per element
  • McpToolAdapterException — raised when the wrapped tool returns an unsupported type or has no callable, with the tool name included for debugging.

Usage

from fastmcp.tools import Tool as FastMcpTool
from askui.models.shared.tools import Tool

mcp_tool = FastMcpTool.from_function(fn, name="my_tool", description="...")
askui_tool = Tool.from_mcp_tool(mcp_tool)

Notes

  • Complements existing Tool.to_mcp_tool() for the opposite direction (AskUI → FastMCP).

@mlikasam-askui mlikasam-askui changed the title feat: add Tool.from_mcp_tool to wrap FastMCP tools TO AskUI Tools feat: wrap FastMCP tools as AskUI Tool via Tool.from_mcp_tool Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant