File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -254,6 +254,8 @@ export async function createMcpServer(
254254 } finally {
255255 void clearcutLogger ?. logToolInvocation ( {
256256 toolName : tool . name ,
257+ params,
258+ schema,
257259 success,
258260 latencyMs : bucketizeLatency ( Date . now ( ) - startTime ) ,
259261 } ) ;
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import {
1717 type FlagUsage ,
1818 WatchdogMessageType ,
1919 OsType ,
20+ type ToolInvocation ,
2021} from './types.js' ;
2122import { WatchdogClient } from './WatchdogClient.js' ;
2223
@@ -207,18 +208,27 @@ export class ClearcutLogger {
207208
208209 async logToolInvocation ( args : {
209210 toolName : string ;
211+ params : ShapeOutput < zod . ZodRawShape > ;
212+ schema : zod . ZodRawShape ;
210213 success : boolean ;
211214 latencyMs : number ;
212215 } ) : Promise < void > {
216+ const tool_invocation : ToolInvocation = {
217+ tool_name : args . toolName ,
218+ success : args . success ,
219+ latency_ms : args . latencyMs ,
220+ } ;
221+ if ( Object . keys ( args . params ) . length > 0 ) {
222+ tool_invocation . tool_params = {
223+ [ `${ args . toolName } _params` ] : sanitizeParams ( args . params , args . schema ) ,
224+ } ;
225+ }
226+
213227 this . #watchdog. send ( {
214228 type : WatchdogMessageType . LOG_EVENT ,
215229 payload : {
216230 mcp_client : this . #mcpClient,
217- tool_invocation : {
218- tool_name : args . toolName ,
219- success : args . success ,
220- latency_ms : args . latencyMs ,
221- } ,
231+ tool_invocation : tool_invocation ,
222232 } ,
223233 } ) ;
224234 }
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ export interface ToolInvocation {
2222 tool_name : string ;
2323 success : boolean ;
2424 latency_ms : number ;
25+ tool_params ?: object ;
2526}
2627
2728export interface ServerStart {
Original file line number Diff line number Diff line change @@ -46,6 +46,8 @@ describe('ClearcutLogger', () => {
4646 } ) ;
4747 await logger . logToolInvocation ( {
4848 toolName : 'test_tool' ,
49+ params : { } ,
50+ schema : { } ,
4951 success : true ,
5052 latencyMs : 123 ,
5153 } ) ;
@@ -57,6 +59,40 @@ describe('ClearcutLogger', () => {
5759 assert . strictEqual ( msg . payload . tool_invocation ?. success , true ) ;
5860 assert . strictEqual ( msg . payload . tool_invocation ?. latency_ms , 123 ) ;
5961 } ) ;
62+ it ( 'sends sanitized params' , async ( ) => {
63+ const logger = new ClearcutLogger ( {
64+ persistence : mockPersistence ,
65+ appVersion : '1.0.0' ,
66+ watchdogClient : mockWatchdogClient ,
67+ } ) ;
68+
69+ const schema = {
70+ uid : zod . string ( ) ,
71+ myString : zod . string ( ) ,
72+ } ;
73+
74+ const params = {
75+ uid : 'sensitive' ,
76+ myString : 'hello' ,
77+ } ;
78+
79+ await logger . logToolInvocation ( {
80+ toolName : 'test_tool' ,
81+ params,
82+ schema,
83+ success : true ,
84+ latencyMs : 123 ,
85+ } ) ;
86+
87+ assert ( mockWatchdogClient . send . calledOnce ) ;
88+ const msg = mockWatchdogClient . send . firstCall . args [ 0 ] ;
89+ assert . strictEqual ( msg . type , WatchdogMessageType . LOG_EVENT ) ;
90+ assert . deepStrictEqual ( msg . payload . tool_invocation ?. tool_params , {
91+ test_tool_params : {
92+ my_string_length : 5 ,
93+ } ,
94+ } ) ;
95+ } ) ;
6096 } ) ;
6197
6298 describe ( 'setClientName' , ( ) => {
You can’t perform that action at this time.
0 commit comments