nat.front_ends.mcp.tool_converter#
Attributes#
Functions#
|
Determine if a Pydantic field is optional and extract its default value for MCP signatures. |
|
Create a wrapper function that exposes the actual parameters of a NAT Function as an MCP tool. |
|
Retrieve a human-readable description for a NAT function or workflow. |
|
Register a NAT Function as an MCP tool. |
Module Contents#
- logger#
- _USE_PYDANTIC_DEFAULT#
- is_field_optional(
- field: pydantic.fields.FieldInfo,
Determine if a Pydantic field is optional and extract its default value for MCP signatures.
For MCP tool signatures, we need to distinguish: - Required fields: marked with Parameter.empty - Optional with concrete default: use that default - Optional with factory: use sentinel so Pydantic can apply the factory later
- Args:
field: The Pydantic FieldInfo to check
- Returns:
A tuple of (is_optional, default_value): - (False, Parameter.empty) for required fields - (True, actual_default) for optional fields with explicit defaults - (True, _USE_PYDANTIC_DEFAULT) for optional fields with default_factory
- create_function_wrapper(
- function_name: str,
- function: nat.builder.function_base.FunctionBase,
- schema: type[pydantic.BaseModel],
- is_workflow: bool = False,
- workflow: Workflow | None = None,
Create a wrapper function that exposes the actual parameters of a NAT Function as an MCP tool.
- Args:
function_name (str): The name of the function/tool function (FunctionBase): The NAT Function object schema (type[BaseModel]): The input schema of the function is_workflow (bool): Whether the function is a Workflow workflow (Workflow | None): The parent workflow for observability context
- Returns:
A wrapper function suitable for registration with MCP
- get_function_description(
- function: nat.builder.function_base.FunctionBase,
Retrieve a human-readable description for a NAT function or workflow.
- The description is determined using the following precedence:
If the function is a Workflow and has a ‘description’ attribute, use it.
If the Workflow’s config has a ‘description’, use it.
If the Workflow’s config has a ‘topic’, use it.
If the function is a regular Function, use its ‘description’ attribute.
- Args:
function: The NAT FunctionBase instance (Function or Workflow).
- Returns:
The best available description string for the function.
- register_function_with_mcp(
- mcp: mcp.server.fastmcp.FastMCP,
- function_name: str,
- function: nat.builder.function_base.FunctionBase,
- workflow: Workflow | None = None,
Register a NAT Function as an MCP tool.
- Args:
mcp: The FastMCP instance function_name: The name to register the function under function: The NAT Function to register workflow: The parent workflow for observability context (if available)