MCP Tool Examples: Difference between revisions

From QPR ProcessAnalyzer Wiki
Jump to navigation Jump to search
 
Line 168: Line 168:


== Model filters ==
== Model filters ==
Returns all public [[Filtering_in_QPR_ProcessAnalyzer#Saving_filters|filters]] stored to a model. The case ID is provided as an MCP parameter, so the following '''Input''' configuration is needed:
Returns all public [[Filtering_in_QPR_ProcessAnalyzer#Saving_filters|filters]] stored to a model.
 
The modelId input parameter defines the model from where to get the filters:
<syntaxhighlight lang="json" line>
<syntaxhighlight lang="json" line>
{
{
Line 182: Line 184:
</syntaxhighlight>
</syntaxhighlight>


Optionally, output schema can be defined:
Output schema will be defined as follows:
<syntaxhighlight lang="json" line>
<syntaxhighlight lang="json" line>
{
{
   "type": "object",
   "type": "object",
Line 189: Line 192:
     "filters": {
     "filters": {
       "type": "array",
       "type": "array",
       "description": "Array of filters",
       "description": "List of defined filters in the given model (as parameter).",
       "items": {
       "items": {
         "type": "object",
         "type": "object",
Line 195: Line 198:
           "Filter name": {
           "Filter name": {
             "type": "string",
             "type": "string",
             "description": "Name of the filter"
             "description": "Human-readable name of the filter."
           },
           },
           "Filter ID": {
           "Filter ID": {
             "type": "integer",
             "type": "integer",
             "description": "Id of the filter"
             "description": "Unique identifier of the filter."
           },
           },
           "Privacy mode": {
           "Privacy mode": {
Line 207: Line 210:
               "Private"
               "Private"
             ],
             ],
             "description": "Privacy mode of the filter"
             "description": "Visibility and access level of the filter."
           },
           },
           "Filter description": {
           "Filter description": {
             "type": "string",
             "type": "string",
             "description": "Free text description of the filter"
             "description": "Optional free-text description explaining the purpose and intended use of the filter."
           },
           },
           "Filter rules": {
           "Filter rules": {
             "type": "string",
             "type": "string",
             "description": "Filter rules in json format. Rules describe the precise criateria what the filter is filtering."
             "description": "Filter definition expressed in JSON format. The rules specify the exact criteria used to include or exclude data."
           }
           }
         }
         }

Latest revision as of 13:27, 24 April 2026

This page contains example scripts intended for use as MCP tools. When developing MCP tool scripts, make sure they return a string value, as this is required for the MCP client's LLM to interpret the output correctly.

List of Models

Returns all models accessible for the user (in a CSV data) with following fields: Model name, Containing project name, Model ID, Case attributes, Event attributes, Case count, and Event count.

let result = Query(#{
	"Values": [
		#{
			"Name": "Model name",
			"Expression": "Name"
		},
		#{
			"Name": "Containing project name",
			"Expression": "Project.Name"
		},
		#{
			"Name": "Model ID",
			"Expression": "Id"
		},
		#{
			"Name": "Case attributes",
			"Expression": "ToJson(If(Status==\"Online\",OrderByValue(Flatten(EventLog.CaseAttributes.Name)), CasesDatatable?.ColumnNames ?? []))"
		},
		#{
			"Name": "Event attributes",
			"Expression": "ToJson(If(Status==\"Online\",OrderByValue(Flatten(EventLog.EventAttributes.Name)), EventsDatatable?.ColumnNames ?? []))"
		},
		#{
			"Name": "Case count",
			"Expression": "CasesDatatable?.NRows"
		},
		#{
			"Name": "Event count",
			"Expression": "EventsDatatable?.NRows"
		}
	],
	"Ordering": [
		#{
			"Name": "Containing project name",
			"Direction": "Ascending"
		},
		#{
			"Name": "Model name",
			"Direction": "Ascending"
		}
	],
	"Dimensions": null,
	"Root": "Models",
	"ContextType": "generic"
}).Collect();
return result.ToCsv();

Average case cost in specific model

Returns the average of the case Cost attribute value of all cases in the model with ID 1.

let result = Query(#{
	"Values": [
		#{
			"Name": "Average Cost",
			"Expression": "Column(\"Cost\")",
			"AggregationFunction": "average"
		}
	],
	"Dimensions": [],
	"Root": "Cases",
	"ModelId": 1,
	"ContextType": "model",
	"ProcessingMethod": "dataframe"
}).Collect();
return result.ToCsv();

Case details

Returns details of a specific case. The case ID is provided as an MCP parameter, so the following Input configuration is needed:

{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "CaseId": {
      "type": "string",
      "minLength": 1,
      "description": "Unique identifier of the case (i.e, Case ID). Cases may be orders, deliveries, invoices depending on the model name."
    }
  }
}

The above schema means that there is one input parameter named CaseId containing a textual value (which cannot be null or an empty string). In addition, no other parameters are accepted ("additionalProperties": false).

The tool script that returns details of a case ID including all case attribute values:

let modelId = 1;
let dataQuery = [
		#{
			"Name": "Start time",
			"Expression": "AggregateFrom(Events, \"Min\", TimeStamp, null)"
		},
		#{
			"Name": "End time",
			"Expression": "AggregateFrom(Events, \"Max\", TimeStamp, null)"
		},
		#{
			"Name": "Duration in hours",
			"Expression": "DurationBetweenDates(\"hour\", AggregateFrom(Events, \"Min\", TimeStamp, null), AggregateFrom(Events, \"Max\", TimeStamp, null), null)"
		},
		#{
			"Name": "Latest event",
			"Expression": "AggregateFrom(Events.WithRowNumberColumn(\"RowNumber\", [TimeStamp, EventType], [CaseId], [false, false]).Where(Column(\"RowNumber\") == 1), \"Any\", EventType, null)"
		},
		#{
			"Name": "Event count",
			"Expression": "Coalesce(AggregateFrom(Events, \"Count\", null, null), 0)"
		},
		#{
			"Name": "Event types count",
			"Expression": "Coalesce(AggregateFrom(Events, \"CountDistinct\", EventType, null), 0)"
		},
		#{
			"Name": "Repeating event types",
			"Expression": "Coalesce(AggregateFrom(Events, \"Count\", null, null), 0) - Coalesce(AggregateFrom(Events, \"CountDistinct\", EventType, null), 0)"
		},
		#{
			"Name": "Variation path",
			"Expression": "AggregateFrom(Events, #{\"Function\":\"Array\",\"Ordering\":[TimeStamp, EventType]}, EventType, null)"
		}
	];

let caseAttributes = ModelById(modelId).CasesDatatable.Columns.Name.{
	let caseAttributeName = _;
	dataQuery = Concat(dataQuery, #{
		"Name": caseAttributeName,
		"Expression": `Column(${ToJson(caseAttributeName)})`
	});
};

let result = Query(#{
	"Dimensions": null,
	"Values": dataQuery,
	"MaximumRowCount": 1,
	"Root": "Cases",
	"Filter": #{
		"Items": [
			#{
				"Type": "IncludeCases",
				"Items": [
					#{
						"Type": "CaseAttributeValue",
						"Attribute": "Case Name",
						"StringifiedValues": [
							"0" + orderID
						]
					}
				]
			}
		]
	},
	"ModelId": modelId,
	"ContextType": "model",
	"ProcessingMethod": "dataframe"
}).Collect();
return result.ToCsv();

Notes:

  • The script uses the CaseId variable containing the provided CaseId parameter value (which is generated by the calling agent).
  • The model ID is hardcoded, but the model ID can also be provided as an MCP parameter.

Model filters

Returns all public filters stored to a model.

The modelId input parameter defines the model from where to get the filters:

{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "modelId": {
      "type": "integer",
      "description": "Model ID (identifier)"
    }
  }
}

Output schema will be defined as follows:

{
  "type": "object",
  "properties": {
    "filters": {
      "type": "array",
      "description": "List of defined filters in the given model (as parameter).",
      "items": {
        "type": "object",
        "properties": {
          "Filter name": {
            "type": "string",
            "description": "Human-readable name of the filter."
          },
          "Filter ID": {
            "type": "integer",
            "description": "Unique identifier of the filter."
          },
          "Privacy mode": {
            "enum": [
              "Default Public",
              "Public",
              "Private"
            ],
            "description": "Visibility and access level of the filter."
          },
          "Filter description": {
            "type": "string",
            "description": "Optional free-text description explaining the purpose and intended use of the filter."
          },
          "Filter rules": {
            "type": "string",
            "description": "Filter definition expressed in JSON format. The rules specify the exact criteria used to include or exclude data."
          }
        }
      }
    }
  }
}

The MCP tool script that returns list of filters in the given model ID:

let result = Query(#{
	"Dimensions": null,
	"Values": [
		#{
			"Name": "Filter name",
			"Expression": "Name"
		},
		#{
			"Name": "Filter ID",
			"Expression": "Id"
		},
		#{
			"Name": "Privacy mode",
			"Expression": "switch (PublishMode) { case \"Public\": return \"Public\"; case \"Private\": return \"Private\"; case \"ModelDefault\": return \"Default Public\"; }"
		},
		#{
			"Name": "Filter description",
			"Expression": "Description"
		},
		#{
			"Name": "Filter rules",
			"Expression": "Rules == null ? null : ToJson(Rules)"
		}
	],
	"Ordering": [
		#{
			"Name": "Filter ID",
			"Direction": "Ascending"
		}
	],
	"Root": `ModelById(${modelId}).Filters`,
	"ContextType": "generic"
}).Collect();

return #{
  "filters": result.Rows.{
	let row = _;
	#{
	  "Filter name": row[0],
	  "Filter ID": row[1],
	  "Privacy mode": row[2],
	  "Filter description": row[3],
	  "Filter rules": row[4]
	}
  }
};