@@ -147,7 +147,7 @@ describe('MCP Server PII Filtering', () => {
147147
148148      mockTransport . send ?.( toolResponse ) ; 
149149
150-       // Tool result content should be filtered out 
150+       // Tool result content should be filtered out, but metadata should remain  
151151      const  setAttributesCall  =  mockSpan . setAttributes . mock . calls [ 0 ] ?. [ 0 ] ; 
152152      expect ( setAttributesCall ) . toBeDefined ( ) ; 
153153      expect ( setAttributesCall ) . not . toHaveProperty ( 'mcp.tool.result.content' ) ; 
@@ -163,8 +163,11 @@ describe('MCP Server PII Filtering', () => {
163163        'client.port' : 54321 , 
164164        'mcp.request.argument.location' : '"San Francisco"' , 
165165        'mcp.tool.result.content' : 'Weather data: 18°C' , 
166+         'mcp.tool.result.content_count' : 1 , 
166167        'mcp.prompt.result.description' : 'Code review prompt for sensitive analysis' , 
167168        'mcp.prompt.result.message_content' : 'Please review this confidential code.' , 
169+         'mcp.prompt.result.message_count' : 1 , 
170+         'mcp.resource.result.content' : 'Sensitive resource content' , 
168171        'mcp.logging.message' : 'User requested weather' , 
169172        'mcp.resource.uri' : 'file:///private/docs/secret.txt' , 
170173        'mcp.method.name' : 'tools/call' ,  // Non-PII should remain 
@@ -182,8 +185,16 @@ describe('MCP Server PII Filtering', () => {
182185        'mcp.request.argument.location' : '"San Francisco"' , 
183186        'mcp.request.argument.units' : '"celsius"' , 
184187        'mcp.tool.result.content' : 'Weather data: 18°C' , 
188+         'mcp.tool.result.content_count' : 1 , 
185189        'mcp.prompt.result.description' : 'Code review prompt for sensitive analysis' , 
186-         'mcp.prompt.result.message_content' : 'Please review this confidential code.' , 
190+         'mcp.prompt.result.message_count' : 2 , 
191+         'mcp.prompt.result.0.role' : 'user' , 
192+         'mcp.prompt.result.0.content' : 'Sensitive prompt content' , 
193+         'mcp.prompt.result.1.role' : 'assistant' , 
194+         'mcp.prompt.result.1.content' : 'Another sensitive response' , 
195+         'mcp.resource.result.content_count' : 1 , 
196+         'mcp.resource.result.uri' : 'file:///private/file.txt' , 
197+         'mcp.resource.result.content' : 'Sensitive resource content' , 
187198        'mcp.logging.message' : 'User requested weather' , 
188199        'mcp.resource.uri' : 'file:///private/docs/secret.txt' , 
189200        'mcp.method.name' : 'tools/call' ,  // Non-PII should remain 
@@ -192,16 +203,34 @@ describe('MCP Server PII Filtering', () => {
192203
193204      const  result  =  filterMcpPiiFromSpanData ( spanData ,  false ) ; 
194205
206+       // Client info should be filtered 
195207      expect ( result ) . not . toHaveProperty ( 'client.address' ) ; 
196208      expect ( result ) . not . toHaveProperty ( 'client.port' ) ; 
209+       
210+       // Request arguments should be filtered 
197211      expect ( result ) . not . toHaveProperty ( 'mcp.request.argument.location' ) ; 
198212      expect ( result ) . not . toHaveProperty ( 'mcp.request.argument.units' ) ; 
213+       
214+       // Specific PII content attributes should be filtered 
199215      expect ( result ) . not . toHaveProperty ( 'mcp.tool.result.content' ) ; 
200216      expect ( result ) . not . toHaveProperty ( 'mcp.prompt.result.description' ) ; 
201-       expect ( result ) . not . toHaveProperty ( 'mcp.prompt.result.message_content' ) ; 
217+       
218+       // Indexed/dynamic result attributes (not in PII_ATTRIBUTES) should remain 
219+       expect ( result ) . toHaveProperty ( 'mcp.tool.result.content_count' ,  1 ) ; 
220+       expect ( result ) . toHaveProperty ( 'mcp.prompt.result.message_count' ,  2 ) ; 
221+       expect ( result ) . toHaveProperty ( 'mcp.prompt.result.0.role' ,  'user' ) ; 
222+       expect ( result ) . toHaveProperty ( 'mcp.prompt.result.0.content' ,  'Sensitive prompt content' ) ; 
223+       expect ( result ) . toHaveProperty ( 'mcp.prompt.result.1.role' ,  'assistant' ) ; 
224+       expect ( result ) . toHaveProperty ( 'mcp.prompt.result.1.content' ,  'Another sensitive response' ) ; 
225+       expect ( result ) . toHaveProperty ( 'mcp.resource.result.content_count' ,  1 ) ; 
226+       expect ( result ) . toHaveProperty ( 'mcp.resource.result.uri' ,  'file:///private/file.txt' ) ; 
227+       expect ( result ) . toHaveProperty ( 'mcp.resource.result.content' ,  'Sensitive resource content' ) ; 
228+       
229+       // Other PII attributes should be filtered 
202230      expect ( result ) . not . toHaveProperty ( 'mcp.logging.message' ) ; 
203231      expect ( result ) . not . toHaveProperty ( 'mcp.resource.uri' ) ; 
204232
233+       // Non-PII attributes should remain 
205234      expect ( result ) . toHaveProperty ( 'mcp.method.name' ,  'tools/call' ) ; 
206235      expect ( result ) . toHaveProperty ( 'mcp.session.id' ,  'test-session-123' ) ; 
207236    } ) ; 
0 commit comments