Skip to content

FastMCP Service Get Tools Task¤

task api name: get_tools

FastMCP service get_tools task returns the list of MCP tools generated by FastMCP worker. Tools are created from NorFab service tasks and follow this naming convention:

service_<service_name>__task_<task_name>

Inputs¤

Parameter Required Description
brief No Return tool names only.
service No Filter tools by NorFab service name.
name No Filter tools by glob pattern.
workers No FastMCP workers to target. Defaults to any worker.

Output¤

The task returns MCP tool definitions. Detailed definitions include effective task call guardrails and task result_guardrails when configured. These are NorFab inspection fields and are not added to the MCP SDK Tool schema. With brief=True, the task returns tool names only.

Examples¤

Example

List all tools:

nf# show fastmcp tools

List tools for a specific service (names only):

nf# show fastmcp tools service nornir brief

Filter tools by name using glob patterns:

nf# show fastmcp tools name "*cli" brief

Context manager - list Nornir tool names:

import pprint

from norfab.core.nfapi import NorFab

with NorFab(inventory="inventory.yaml") as nf:
    client = nf.make_client()

    result = client.run_job(
        service="fastmcp",
        task="get_tools",
        kwargs={"brief": True, "service": "nornir"},
        workers="any",
    )
    pprint.pprint(result)

Direct lifecycle - filter tools by name:

import pprint

from norfab.core.nfapi import NorFab

nf = NorFab(inventory="inventory.yaml")
try:
    nf.start()
    client = nf.make_client()

    result = client.run_job(
        service="fastmcp",
        task="get_tools",
        kwargs={"brief": True, "name": "*cli"},
        workers="any",
    )
    pprint.pprint(result)
finally:
    nf.destroy()

NORFAB FastMCP Get Tools Command Shell Reference¤

NorFab shell supports these command options for FastMCP get_tools task:

nf# man tree show.fastmcp.tools
root
└── show:    NorFab show commands
    └── fastmcp:    Show FastMCP service
        └── tools:    show FastMCP server tools
            ├── brief:    show tools names only
            ├── service:    filter tools by service name
            ├── name:    filter tools by name using glob pattern
            ├── workers:    Filter worker to target, default 'any'
            └── timeout:    Job timeout
nf#

Python API Reference¤

Retrieve tools from the available norfab services, optionally filtered by service name and tool name pattern.

Parameters:

Name Type Description Default
brief bool

If True, returns a list of tool names. If False, returns a dictionary with tool details.

False
service str

The name of the service to filter tools by. Use "all" to include all services.

'all'
name str

A glob pattern to match tool names.

'*'

Returns:

Name Type Description
Result Result

An object containing the filtered tools. If brief is True, result is a list of tool names. Otherwise, result is a dictionary mapping tool names to their details.

Source code in norfab\workers\fastmcp_worker\fastmcp_worker.py
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
@Task(
    input=GetToolsInput,
    output=GetToolsResult,
    fastapi={"methods": ["GET"]},
    mcp={
        "annotations": {
            "title": "Get MCP Tools",
            "readOnlyHint": True,
            "destructiveHint": False,
            "idempotentHint": True,
            "openWorldHint": False,
        }
    },
)
def get_tools(
    self, brief: bool = False, service: str = "all", name: str = "*"
) -> Result:
    """
    Retrieve tools from the available norfab services, optionally filtered by service
    name and tool name pattern.

    Args:
        brief (bool, optional): If True, returns a list of tool names. If False,
            returns a dictionary with tool details.
        service (str, optional): The name of the service to filter tools by.
            Use "all" to include all services.
        name (str, optional): A glob pattern to match tool names.

    Returns:
        Result: An object containing the filtered tools. If brief is True, result
            is a list of tool names. Otherwise, result is a dictionary mapping tool
            names to their details.
    """
    ret = Result(
        result={},
        task=f"{self.name}:get_tools",
    )
    if brief:
        ret.result = []
        for service_name, tasks in self.norfab_services_tasks.items():
            if service == "all" or service_name == service:
                for tool_name, tool_data in tasks.items():
                    if fnmatch(tool_name, name):
                        ret.result.append(tool_name)
    else:
        for service_name, tasks in self.norfab_services_tasks.items():
            if service == "all" or service_name == service:
                for tool_name, tool_data in tasks.items():
                    if fnmatch(tool_name, name):
                        tool_definition = tool_data["tool"].model_dump()
                        guardrails = tool_data.get("guardrails")
                        if guardrails:
                            tool_definition["guardrails"] = guardrails
                        result_guardrails = tool_data.get("result_guardrails")
                        if result_guardrails:
                            tool_definition["result_guardrails"] = result_guardrails
                        ret.result[tool_name] = tool_definition

    return ret