MCP Tool Examples: Difference between revisions
No edit summary |
No edit summary |
||
| Line 71: | Line 71: | ||
return result.ToCsv(); | return result.ToCsv(); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Case details == | |||
Returns the specified details of a specified case. The case ID is provided as parameter, so the following input configuration is needed: | |||
<syntaxhighlight lang="json" line> | |||
{ | |||
"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." | |||
} | |||
} | |||
} | |||
</syntaxhighlight> | |||
The tool script: | |||
<syntaxhighlight lang="typescript" line> | |||
let result = Query(#{ | |||
"Dimensions": null, | |||
"Values": [ | |||
#{ | |||
"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": "Customer Group", | |||
"Expression": "Column(\"Customer Group\")" | |||
}, | |||
#{ | |||
"Name": "Supplier", | |||
"Expression": "Column(\"Supplier\")" | |||
}, | |||
#{ | |||
"Name": "Product Group", | |||
"Expression": "Column(\"Product Group\")" | |||
}, | |||
#{ | |||
"Name": "Account Manager", | |||
"Expression": "Column(\"Account Manager\")" | |||
}, | |||
#{ | |||
"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)" | |||
} | |||
], | |||
"MaximumRowCount": 1, | |||
"Root": "Cases", | |||
"Filter": #{ | |||
"Items": [ | |||
#{ | |||
"Type": "IncludeCases", | |||
"Items": [ | |||
#{ | |||
"Type": "CaseAttributeValue", | |||
"Attribute": "Case Name", | |||
"StringifiedValues": [ | |||
"0" + CaseId | |||
] | |||
} | |||
] | |||
} | |||
] | |||
}, | |||
"ModelId": 1, | |||
"ContextType": "model", | |||
"ProcessingMethod": "dataframe" | |||
}).Collect(); | |||
return result.ToCsv(); | |||
</syntaxhighlight> | |||
Note that the script has the ''CaseId'' variable containing the provided CaseId parameter. | |||
The model ID is hardcoded in this example, but the model ID can also be provided as an MCP parameter. | |||
Revision as of 09:15, 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 the specified details of a specified case. The case ID is provided as 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 tool script:
let result = Query(#{
"Dimensions": null,
"Values": [
#{
"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": "Customer Group",
"Expression": "Column(\"Customer Group\")"
},
#{
"Name": "Supplier",
"Expression": "Column(\"Supplier\")"
},
#{
"Name": "Product Group",
"Expression": "Column(\"Product Group\")"
},
#{
"Name": "Account Manager",
"Expression": "Column(\"Account Manager\")"
},
#{
"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)"
}
],
"MaximumRowCount": 1,
"Root": "Cases",
"Filter": #{
"Items": [
#{
"Type": "IncludeCases",
"Items": [
#{
"Type": "CaseAttributeValue",
"Attribute": "Case Name",
"StringifiedValues": [
"0" + CaseId
]
}
]
}
]
},
"ModelId": 1,
"ContextType": "model",
"ProcessingMethod": "dataframe"
}).Collect();
return result.ToCsv();
Note that the script has the CaseId variable containing the provided CaseId parameter.
The model ID is hardcoded in this example, but the model ID can also be provided as an MCP parameter.