nat.plugins.fastmcp.server.tool_converter#

Convert NeMo Agent Toolkit functions to FastMCP tools.

Attributes#

Functions#

_safe_json_schema(→ dict[str, Any])

Return a JSON schema for Pydantic models or dict-like schemas.

_get_field_default(→ Any)

Return field default or a sentinel to skip default.

_build_signature_from_schema(→ inspect.Signature)

Build a function signature from a Pydantic schema if possible.

_build_input_schema(→ Any)

Return an input schema for tool registration.

_build_annotations_from_schema(→ dict[str, Any])

Build function annotations from a Pydantic schema if possible.

_is_chat_request_schema(→ bool)

Return True when the schema represents a ChatRequest.

create_function_wrapper(function_name, ...)

Create a wrapper function for MCP that invokes the workflow via SessionManager.

get_function_description(→ str | None)

Retrieve a human-readable description for a NAT function or workflow.

register_function_with_mcp(→ None)

Register a NeMo Agent Toolkit function as a FastMCP tool.

format_schema_for_display(→ str)

Return a pretty JSON schema string for debug endpoints.

Module Contents#

logger#
_USE_PYDANTIC_DEFAULT#
_safe_json_schema(schema: Any) dict[str, Any]#

Return a JSON schema for Pydantic models or dict-like schemas.

_get_field_default(field_info: pydantic.fields.FieldInfo) Any#

Return field default or a sentinel to skip default.

_build_signature_from_schema(schema: Any) inspect.Signature#

Build a function signature from a Pydantic schema if possible.

_build_input_schema(schema: Any) Any#

Return an input schema for tool registration.

_build_annotations_from_schema(schema: Any) dict[str, Any]#

Build function annotations from a Pydantic schema if possible.

_is_chat_request_schema(schema: Any) bool#

Return True when the schema represents a ChatRequest.

create_function_wrapper(
function_name: str,
session_manager: nat.runtime.session.SessionManager,
input_schema: Any,
)#

Create a wrapper function for MCP that invokes the workflow via SessionManager.

Args:

function_name: The name of the function to register. session_manager: The session manager for the workflow. input_schema: Input schema for the workflow/function.

get_function_description(
function: nat.builder.function_base.FunctionBase | None,
) str | None#

Retrieve a human-readable description for a NAT function or workflow.

register_function_with_mcp(
mcp: fastmcp.FastMCP,
function_name: str,
session_manager: nat.runtime.session.SessionManager,
function: nat.builder.function_base.FunctionBase | None = None,
) None#

Register a NeMo Agent Toolkit function as a FastMCP tool.

Each function is wrapped in a SessionManager so that all calls go through the runner, which automatically handles observability.

Args:

mcp: The FastMCP instance. function_name: The name to register the function under. session_manager: SessionManager wrapping the function/workflow. function: Optional function metadata (for description/schema).

format_schema_for_display(schema: Any) str#

Return a pretty JSON schema string for debug endpoints.