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. With brief=True, it 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
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
@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
                        ret.result[tool_name] = tool_definition

    return ret