Skip to main content

systemprompt_logging/trace/models/
tool.rs

1//! MCP tool execution DTOs and audit linkage rows.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use chrono::{DateTime, Utc};
7use serde::{Deserialize, Serialize};
8use serde_json::Value;
9use systemprompt_identifiers::{AiRequestId, ArtifactId, McpExecutionId, TaskId, TraceId};
10
11#[derive(Debug, Clone)]
12pub struct ToolExecutionFilter {
13    pub limit: i64,
14    pub since: Option<DateTime<Utc>>,
15    pub name: Option<String>,
16    pub server: Option<String>,
17    pub status: Option<String>,
18}
19
20impl ToolExecutionFilter {
21    pub const fn new(limit: i64) -> Self {
22        Self {
23            limit,
24            since: None,
25            name: None,
26            server: None,
27            status: None,
28        }
29    }
30
31    pub const fn with_since(mut self, since: DateTime<Utc>) -> Self {
32        self.since = Some(since);
33        self
34    }
35
36    systemprompt_models::builder_methods! {
37        with_name(name) -> String,
38        with_server(server) -> String,
39        with_status(status) -> String,
40    }
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct ToolExecutionItem {
45    pub timestamp: DateTime<Utc>,
46    pub trace_id: TraceId,
47    pub tool_name: String,
48    pub server_name: Option<String>,
49    pub status: String,
50    pub execution_time_ms: Option<i32>,
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
54pub struct AuditLookupResult {
55    pub id: AiRequestId,
56    /// `None` for a request rejected before routing resolved a provider.
57    pub provider: Option<String>,
58    /// `None` for a request rejected before a model was read.
59    pub model: Option<String>,
60    pub requested_model: Option<String>,
61    pub input_tokens: Option<i32>,
62    pub output_tokens: Option<i32>,
63    pub cost_microdollars: i64,
64    pub latency_ms: Option<i32>,
65    pub task_id: Option<TaskId>,
66    pub trace_id: Option<TraceId>,
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
70pub struct AuditToolCallRow {
71    pub tool_name: String,
72    pub tool_input: String,
73    pub sequence_number: i32,
74}
75
76#[derive(Debug, Clone, Serialize, Deserialize)]
77pub struct LinkedMcpCall {
78    pub tool_name: String,
79    pub server_name: String,
80    pub status: String,
81    pub execution_time_ms: Option<i32>,
82}
83
84#[derive(Debug, Clone, Serialize, Deserialize)]
85pub struct McpToolExecution {
86    pub mcp_execution_id: McpExecutionId,
87    pub tool_name: String,
88    pub server_name: String,
89    pub status: String,
90    pub execution_time_ms: Option<i32>,
91    pub error_message: Option<String>,
92    pub input: String,
93    pub output: Option<String>,
94}
95
96#[derive(Debug, Clone, Serialize, Deserialize)]
97pub struct ToolLogEntry {
98    pub timestamp: DateTime<Utc>,
99    pub level: String,
100    pub module: String,
101    pub message: String,
102}
103
104#[derive(Debug, Clone, Serialize, Deserialize)]
105pub struct TaskArtifact {
106    pub artifact_id: ArtifactId,
107    pub artifact_type: String,
108    pub name: Option<String>,
109    pub source: Option<String>,
110    pub tool_name: Option<String>,
111    pub part_kind: Option<String>,
112    pub text_content: Option<String>,
113    pub data_content: Option<Value>,
114}