@@ -147,7 +147,7 @@ describe('MCP Server PII Filtering', () => {
147
147
148
148
mockTransport . send ?.( toolResponse ) ;
149
149
150
- // Tool result content should be filtered out
150
+ // Tool result content should be filtered out, but metadata should remain
151
151
const setAttributesCall = mockSpan . setAttributes . mock . calls [ 0 ] ?. [ 0 ] ;
152
152
expect ( setAttributesCall ) . toBeDefined ( ) ;
153
153
expect ( setAttributesCall ) . not . toHaveProperty ( 'mcp.tool.result.content' ) ;
@@ -163,8 +163,11 @@ describe('MCP Server PII Filtering', () => {
163
163
'client.port' : 54321 ,
164
164
'mcp.request.argument.location' : '"San Francisco"' ,
165
165
'mcp.tool.result.content' : 'Weather data: 18°C' ,
166
+ 'mcp.tool.result.content_count' : 1 ,
166
167
'mcp.prompt.result.description' : 'Code review prompt for sensitive analysis' ,
167
168
'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' ,
168
171
'mcp.logging.message' : 'User requested weather' ,
169
172
'mcp.resource.uri' : 'file:///private/docs/secret.txt' ,
170
173
'mcp.method.name' : 'tools/call' , // Non-PII should remain
@@ -182,8 +185,16 @@ describe('MCP Server PII Filtering', () => {
182
185
'mcp.request.argument.location' : '"San Francisco"' ,
183
186
'mcp.request.argument.units' : '"celsius"' ,
184
187
'mcp.tool.result.content' : 'Weather data: 18°C' ,
188
+ 'mcp.tool.result.content_count' : 1 ,
185
189
'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' ,
187
198
'mcp.logging.message' : 'User requested weather' ,
188
199
'mcp.resource.uri' : 'file:///private/docs/secret.txt' ,
189
200
'mcp.method.name' : 'tools/call' , // Non-PII should remain
@@ -192,16 +203,34 @@ describe('MCP Server PII Filtering', () => {
192
203
193
204
const result = filterMcpPiiFromSpanData ( spanData , false ) ;
194
205
206
+ // Client info should be filtered
195
207
expect ( result ) . not . toHaveProperty ( 'client.address' ) ;
196
208
expect ( result ) . not . toHaveProperty ( 'client.port' ) ;
209
+
210
+ // Request arguments should be filtered
197
211
expect ( result ) . not . toHaveProperty ( 'mcp.request.argument.location' ) ;
198
212
expect ( result ) . not . toHaveProperty ( 'mcp.request.argument.units' ) ;
213
+
214
+ // Specific PII content attributes should be filtered
199
215
expect ( result ) . not . toHaveProperty ( 'mcp.tool.result.content' ) ;
200
216
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
202
230
expect ( result ) . not . toHaveProperty ( 'mcp.logging.message' ) ;
203
231
expect ( result ) . not . toHaveProperty ( 'mcp.resource.uri' ) ;
204
232
233
+ // Non-PII attributes should remain
205
234
expect ( result ) . toHaveProperty ( 'mcp.method.name' , 'tools/call' ) ;
206
235
expect ( result ) . toHaveProperty ( 'mcp.session.id' , 'test-session-123' ) ;
207
236
} ) ;
0 commit comments