FastMCP Worker
FastMCPWorker(inventory: str, broker: str, worker_name: str, exit_event=None, init_done_event=None, log_level: str = None, log_queue: object = None)
¤
Bases: NFPWorker
Source code in norfab\workers\fastmcp_worker.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
get_diskcache() -> FanoutCache
¤
Initializes and returns a FanoutCache object.
The FanoutCache is configured with the following parameters:
- directory: The directory where the cache will be stored.
- shards: Number of shards to use for the cache.
- timeout: Timeout for cache operations in seconds.
- size_limit: Maximum size of the cache in bytes.
Returns:
| Name | Type | Description |
|---|---|---|
FanoutCache |
FanoutCache
|
An instance of FanoutCache configured with the specified parameters. |
Source code in norfab\workers\fastmcp_worker.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
get_version() -> Result
¤
Retrieves version information for key libraries and the current Python environment.
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
An object containing a dictionary with the version numbers of 'norfab', 'mcp', 'uvicorn', 'pydantic', the Python version, and the platform. If a package is not found, its version will be an empty string. |
Source code in norfab\workers\fastmcp_worker.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
get_inventory() -> Result
¤
Retrieves the current inventory from the FastMCP worker.
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
An object containing a copy of the worker's inventory and the task name. |
Source code in norfab\workers\fastmcp_worker.py
204 205 206 207 208 209 210 211 212 213 214 215 | |
get_tools(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.
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.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
discover(job, service: str = 'all', progress: bool = True) -> Result
¤
Discovers available services tasks and auto-generate tools for them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service
|
str
|
The name of the service to discover. Defaults to "all". |
'all'
|
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
An object containing the discovery results for the specified service. |
Source code in norfab\workers\fastmcp_worker.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
get_status() -> Result
¤
Retrieves the current status of the application, including its name, URL, and the count of available tools.
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
An object containing a dictionary with the application's name, URL, and the number of tools, as well as the task identifier. |
Source code in norfab\workers\fastmcp_worker.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
fastmcp_start()
¤
Starts the FastMCP server for the NorFab MCP application.
This method initializes a FastMCP application instance with
the specified host and port from self.fastmcp_inventory.
It registers two MCP server endpoints:
list_tools: Asynchronously returns a list of available tools by aggregating all tools fromself.norfab_services_tasks.call_tool: Asynchronously handles tool invocation requests by parsing the tool name, extracting the corresponding service and task, and running the job usingself.client.run_job.
The FastMCP server is started in a separate thread using the "streamable-http" transport.
Source code in norfab\workers\fastmcp_worker.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |
service_tasks_discovery(worker, cycles: int = 5, discover_service: str = 'all') -> None
¤
Discovers available tasks from NorFab services and registers them
as tools for the worker. This function periodically queries the
broker for available services and their tasks, and registers each
discovered task as a tool in the worker's norfab_services_tasks
dictionary. It continues this process for a specified number of
cycles or until the worker's exit event is set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
worker
|
The worker instance responsible for managing service tasks and tools. |
required | |
cycles
|
int
|
The number of discovery cycles to perform. |
5
|
discover_service
|
str
|
The name of a specific service to discover tasks from. If set to "all", tasks from all services are discovered. Defaults to "all". |
'all'
|
Source code in norfab\workers\fastmcp_worker.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |