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 cache_read_tokens: Option<i32>,
64    pub cache_creation_tokens: Option<i32>,
65    pub cost_microdollars: i64,
66    pub latency_ms: Option<i32>,
67    pub status: String,
68    pub error_message: Option<String>,
69    pub task_id: Option<TaskId>,
70    pub trace_id: Option<TraceId>,
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize)]
74pub struct AuditToolCallRow {
75    pub tool_name: String,
76    pub tool_input: String,
77    pub sequence_number: i32,
78}
79
80#[derive(Debug, Clone, Serialize, Deserialize)]
81pub struct LinkedMcpCall {
82    pub tool_name: String,
83    pub server_name: String,
84    pub status: String,
85    pub execution_time_ms: Option<i32>,
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize)]
89pub struct McpToolExecution {
90    pub mcp_execution_id: McpExecutionId,
91    pub tool_name: String,
92    pub server_name: String,
93    pub status: String,
94    pub execution_time_ms: Option<i32>,
95    pub error_message: Option<String>,
96    pub input: String,
97    pub output: Option<String>,
98}
99
100#[derive(Debug, Clone, Serialize, Deserialize)]
101pub struct ToolLogEntry {
102    pub timestamp: DateTime<Utc>,
103    pub level: String,
104    pub module: String,
105    pub message: String,
106}
107
108#[derive(Debug, Clone, Serialize, Deserialize)]
109pub struct TaskArtifact {
110    pub artifact_id: ArtifactId,
111    pub artifact_type: String,
112    pub name: Option<String>,
113    pub source: Option<String>,
114    pub tool_name: Option<String>,
115    pub part_kind: Option<String>,
116    pub text_content: Option<String>,
117    pub data_content: Option<Value>,
118}