@@ -142,18 +142,37 @@ export abstract class ToolBase {
142
142
protected resolveToolMetadata ( ...args : Parameters < ToolCallback < typeof this . argsShape > > ) : ToolMetadata {
143
143
const toolMetadata : ToolMetadata = { } ;
144
144
try {
145
- // Parse the arguments to extract project_id and org_id
145
+ if ( ! args [ 0 ] || typeof args [ 0 ] !== "object" ) {
146
+ return toolMetadata ;
147
+ }
148
+
149
+ // Create a typed parser for the exact shape we expect
146
150
const argsShape = z . object ( this . argsShape ) ;
147
- const parsedArgs = argsShape . safeParse ( args [ 0 ] ) ;
148
- if ( parsedArgs . success && parsedArgs . data ?. projectId ) {
149
- toolMetadata . projectId = parsedArgs . data ?. projectId ;
151
+ const parsedResult = argsShape . safeParse ( args [ 0 ] ) ;
152
+
153
+ if ( ! parsedResult . success ) {
154
+ logger . debug (
155
+ LogId . telmetryMetadataError ,
156
+ "tool" ,
157
+ `Error parsing tool arguments: ${ parsedResult . error . message } `
158
+ ) ;
159
+ return toolMetadata ;
160
+ }
161
+
162
+ const data = parsedResult . data ;
163
+
164
+ // Extract projectId using type guard
165
+ if ( "projectId" in data && typeof data . projectId === "string" && data . projectId . trim ( ) !== "" ) {
166
+ toolMetadata . projectId = data . projectId ;
150
167
}
151
168
152
- if ( parsedArgs . success && parsedArgs . data ?. orgId ) {
153
- toolMetadata . orgId = parsedArgs . data ?. orgId ;
169
+ // Extract orgId using type guard
170
+ if ( "orgId" in data && typeof data . orgId === "string" && data . orgId . trim ( ) !== "" ) {
171
+ toolMetadata . orgId = data . orgId ;
154
172
}
155
173
} catch ( error ) {
156
- logger . info ( LogId . telmetryMetadataError , "tool" , `Error resolving tool metadata: ${ error as string } ` ) ;
174
+ const errorMessage = error instanceof Error ? error . message : String ( error ) ;
175
+ logger . debug ( LogId . telmetryMetadataError , "tool" , `Error resolving tool metadata: ${ errorMessage } ` ) ;
157
176
}
158
177
return toolMetadata ;
159
178
}
0 commit comments