@@ -1203,72 +1203,68 @@ describe("tool()", () => {
1203
1203
} ) ,
1204
1204
) . rejects . toThrow ( / T o o l t e s t h a s a n o u t p u t s c h e m a b u t n o s t r u c t u r e d c o n t e n t w a s p r o v i d e d / ) ;
1205
1205
} ) ;
1206
-
1207
- /***
1206
+ /***
1208
1207
* Test: Tool with Output Schema Must Provide Structured Content
1209
1208
*/
1210
- test ( "should not throw error when tool with outputSchema returns no structuredContent and isError is true" , async ( ) => {
1211
- const mcpServer = new McpServer ( {
1212
- name : "test server" ,
1213
- version : "1.0" ,
1214
- } ) ;
1215
-
1216
- const client = new Client ( {
1217
- name : "test client" ,
1218
- version : "1.0" ,
1219
- } ) ;
1220
-
1221
- // Register a tool with outputSchema that returns only content without structuredContent
1222
- mcpServer . registerTool (
1223
- "test" ,
1224
- {
1225
- description : "Test tool with output schema but missing structured content" ,
1226
- inputSchema : {
1227
- input : z . string ( ) ,
1228
- } ,
1229
- outputSchema : {
1230
- processedInput : z . string ( ) ,
1231
- resultType : z . string ( ) ,
1232
- } ,
1209
+ test ( "should skip outputSchema validation when isError is true" , async ( ) => {
1210
+ const mcpServer = new McpServer ( {
1211
+ name : "test server" ,
1212
+ version : "1.0" ,
1213
+ } ) ;
1214
+
1215
+ const client = new Client ( {
1216
+ name : "test client" ,
1217
+ version : "1.0" ,
1218
+ } ) ;
1219
+
1220
+ mcpServer . registerTool (
1221
+ "test" ,
1222
+ {
1223
+ description : "Test tool with output schema but missing structured content" ,
1224
+ inputSchema : {
1225
+ input : z . string ( ) ,
1233
1226
} ,
1234
- async ( { input } ) => ( {
1235
- // Only return content without structuredContent
1236
- content : [
1237
- {
1238
- type : "text" ,
1239
- text : `Processed: ${ input } ` ,
1240
- } ,
1241
- ] ,
1242
- isError : true ,
1243
- } )
1244
- ) ;
1245
-
1246
- const [ clientTransport , serverTransport ] =
1247
- InMemoryTransport . createLinkedPair ( ) ;
1248
-
1249
- await Promise . all ( [
1250
- client . connect ( clientTransport ) ,
1251
- mcpServer . server . connect ( serverTransport ) ,
1252
- ] ) ;
1253
-
1254
- // Call the tool and expect it to not throw an error
1255
- await expect (
1256
- client . callTool ( {
1257
- name : "test" ,
1258
- arguments : {
1259
- input : "hello" ,
1260
- } ,
1261
- } ) ,
1262
- ) . resolves . toStrictEqual ( {
1227
+ outputSchema : {
1228
+ processedInput : z . string ( ) ,
1229
+ resultType : z . string ( ) ,
1230
+ } ,
1231
+ } ,
1232
+ async ( { input } ) => ( {
1263
1233
content : [
1264
1234
{
1265
1235
type : "text" ,
1266
- text : `Processed: hello ` ,
1236
+ text : `Processed: ${ input } ` ,
1267
1237
} ,
1268
1238
] ,
1269
1239
isError : true ,
1270
- } ) ;
1240
+ } )
1241
+ ) ;
1242
+
1243
+ const [ clientTransport , serverTransport ] =
1244
+ InMemoryTransport . createLinkedPair ( ) ;
1245
+
1246
+ await Promise . all ( [
1247
+ client . connect ( clientTransport ) ,
1248
+ mcpServer . server . connect ( serverTransport ) ,
1249
+ ] ) ;
1250
+
1251
+ await expect (
1252
+ client . callTool ( {
1253
+ name : "test" ,
1254
+ arguments : {
1255
+ input : "hello" ,
1256
+ } ,
1257
+ } ) ,
1258
+ ) . resolves . toStrictEqual ( {
1259
+ content : [
1260
+ {
1261
+ type : "text" ,
1262
+ text : `Processed: hello` ,
1263
+ } ,
1264
+ ] ,
1265
+ isError : true ,
1271
1266
} ) ;
1267
+ } ) ;
1272
1268
1273
1269
/***
1274
1270
* Test: Schema Validation Failure for Invalid Structured Content
0 commit comments