@@ -22,13 +22,17 @@ function buildAllContentItemAttributes(content: unknown[]): Record<string, strin
22
22
} ;
23
23
24
24
for ( const [ i , item ] of content . entries ( ) ) {
25
- if ( typeof item !== 'object' || item === null ) continue ;
25
+ if ( typeof item !== 'object' || item === null ) {
26
+ continue ;
27
+ }
26
28
27
29
const contentItem = item as Record < string , unknown > ;
28
30
const prefix = content . length === 1 ? 'mcp.tool.result' : `mcp.tool.result.${ i } ` ;
29
31
30
32
const safeSet = ( key : string , value : unknown ) : void => {
31
- if ( typeof value === 'string' ) attributes [ `${ prefix } .${ key } ` ] = value ;
33
+ if ( typeof value === 'string' ) {
34
+ attributes [ `${ prefix } .${ key } ` ] = value ;
35
+ }
32
36
} ;
33
37
34
38
safeSet ( 'content_type' , contentItem . type ) ;
@@ -39,7 +43,11 @@ function buildAllContentItemAttributes(content: unknown[]): Record<string, strin
39
43
if ( typeof contentItem . text === 'string' ) {
40
44
const text = contentItem . text ;
41
45
const maxLength = 500 ;
42
- attributes [ `${ prefix } .content` ] = text . length > maxLength ? `${ text . slice ( 0 , maxLength - 3 ) } ...` : text ;
46
+ if ( text . length > maxLength ) {
47
+ attributes [ `${ prefix } .content` ] = `${ text . slice ( 0 , maxLength - 3 ) } ...` ;
48
+ } else {
49
+ attributes [ `${ prefix } .content` ] = text ;
50
+ }
43
51
}
44
52
45
53
if ( typeof contentItem . data === 'string' ) {
@@ -64,7 +72,9 @@ function buildAllContentItemAttributes(content: unknown[]): Record<string, strin
64
72
*/
65
73
export function extractToolResultAttributes ( result : unknown ) : Record < string , string | number | boolean > {
66
74
let attributes : Record < string , string | number | boolean > = { } ;
67
- if ( typeof result !== 'object' || result === null ) return attributes ;
75
+ if ( typeof result !== 'object' || result === null ) {
76
+ return attributes ;
77
+ }
68
78
69
79
const resultObj = result as Record < string , unknown > ;
70
80
if ( typeof resultObj . isError === 'boolean' ) {
@@ -83,19 +93,24 @@ export function extractToolResultAttributes(result: unknown): Record<string, str
83
93
*/
84
94
export function extractPromptResultAttributes ( result : unknown ) : Record < string , string | number | boolean > {
85
95
const attributes : Record < string , string | number | boolean > = { } ;
86
- if ( typeof result !== 'object' || result === null ) return attributes ;
96
+ if ( typeof result !== 'object' || result === null ) {
97
+ return attributes ;
98
+ }
87
99
88
100
const resultObj = result as Record < string , unknown > ;
89
101
90
- if ( typeof resultObj . description === 'string' )
102
+ if ( typeof resultObj . description === 'string' ) {
91
103
attributes [ MCP_PROMPT_RESULT_DESCRIPTION_ATTRIBUTE ] = resultObj . description ;
104
+ }
92
105
93
106
if ( Array . isArray ( resultObj . messages ) ) {
94
107
attributes [ MCP_PROMPT_RESULT_MESSAGE_COUNT_ATTRIBUTE ] = resultObj . messages . length ;
95
108
96
109
const messages = resultObj . messages ;
97
110
for ( const [ i , message ] of messages . entries ( ) ) {
98
- if ( typeof message !== 'object' || message === null ) continue ;
111
+ if ( typeof message !== 'object' || message === null ) {
112
+ continue ;
113
+ }
99
114
100
115
const messageObj = message as Record < string , unknown > ;
101
116
const prefix = messages . length === 1 ? 'mcp.prompt.result' : `mcp.prompt.result.${ i } ` ;
0 commit comments