Skip to content

FastMCP Service Get Prompts Task¤

task api name: get_prompts

FastMCP service get_prompts task returns MCP prompts discovered from NorFab task metadata. A task can publish multiple prompts by defining a list under mcp["prompts"] in its Task decorator.

The detailed response includes the prompt name, title, description, arguments, and unrendered message templates. Use brief to return prompt names only.

Published prompts follow this naming convention:

service_<service_name>__task_<task_name>__prompt_<prompt_name>

Retrieving a prompt through MCP returns rendered messages. It does not execute the related NorFab task.

FastMCP Get Prompts Sample Usage¤

Example

List all prompts:

nf#show fastmcp prompts

The detailed output includes each prompt's messages list and its Jinja2 template text.

List prompt names for a specific service:

nf#show fastmcp prompts service nornir brief

Filter prompts by name using glob patterns:

nf#show fastmcp prompts name "*troubleshoot" brief
import pprint

from norfab.core.nfapi import NorFab

if __name__ == "__main__":
    nf = NorFab(inventory="inventory.yaml")
    nf.start()
    nfclient = nf.make_client()

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

    nf.destroy()

NORFAB FastMCP Get Prompts Command Shell Reference¤

NorFab shell supports these command options for FastMCP get_prompts task:

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

Python API Reference¤

Retrieve prompts published by NorFab services.

Source code in norfab\workers\fastmcp_worker\fastmcp_worker.py
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
@Task(
    input=GetPromptsInput,
    output=GetPromptsResult,
    fastapi={"methods": ["GET"]},
    mcp={
        "annotations": {
            "title": "Get MCP Prompts",
            "readOnlyHint": True,
            "destructiveHint": False,
            "idempotentHint": True,
            "openWorldHint": False,
        }
    },
)
def get_prompts(
    self, brief: bool = False, service: str = "all", name: str = "*"
) -> Result:
    """
    Retrieve prompts published by NorFab services.
    """
    ret = Result(result={} if not brief else [], task=f"{self.name}:get_prompts")
    for service_name, prompts in self.norfab_services_prompts.items():
        if service != "all" and service_name != service:
            continue
        for prompt_name, prompt_data in prompts.items():
            if not fnmatch(prompt_name, name):
                continue
            if brief:
                ret.result.append(prompt_name)
            else:
                prompt_definition = prompt_data["prompt"].model_dump()
                prompt_definition["messages"] = prompt_data["metadata"]["messages"]
                ret.result[prompt_name] = prompt_definition

    return ret