File tree Expand file tree Collapse file tree 2 files changed +63
-1
lines changed Expand file tree Collapse file tree 2 files changed +63
-1
lines changed Original file line number Diff line number Diff line change @@ -1212,6 +1212,68 @@ describe("tool()", () => {
12121212 } ) ,
12131213 ) . 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 / ) ;
12141214 } ) ;
1215+ /***
1216+ * Test: Tool with Output Schema Must Provide Structured Content
1217+ */
1218+ test ( "should skip outputSchema validation when isError is true" , async ( ) => {
1219+ const mcpServer = new McpServer ( {
1220+ name : "test server" ,
1221+ version : "1.0" ,
1222+ } ) ;
1223+
1224+ const client = new Client ( {
1225+ name : "test client" ,
1226+ version : "1.0" ,
1227+ } ) ;
1228+
1229+ mcpServer . registerTool (
1230+ "test" ,
1231+ {
1232+ description : "Test tool with output schema but missing structured content" ,
1233+ inputSchema : {
1234+ input : z . string ( ) ,
1235+ } ,
1236+ outputSchema : {
1237+ processedInput : z . string ( ) ,
1238+ resultType : z . string ( ) ,
1239+ } ,
1240+ } ,
1241+ async ( { input } ) => ( {
1242+ content : [
1243+ {
1244+ type : "text" ,
1245+ text : `Processed: ${ input } ` ,
1246+ } ,
1247+ ] ,
1248+ isError : true ,
1249+ } )
1250+ ) ;
1251+
1252+ const [ clientTransport , serverTransport ] =
1253+ InMemoryTransport . createLinkedPair ( ) ;
1254+
1255+ await Promise . all ( [
1256+ client . connect ( clientTransport ) ,
1257+ mcpServer . server . connect ( serverTransport ) ,
1258+ ] ) ;
1259+
1260+ await expect (
1261+ client . callTool ( {
1262+ name : "test" ,
1263+ arguments : {
1264+ input : "hello" ,
1265+ } ,
1266+ } ) ,
1267+ ) . resolves . toStrictEqual ( {
1268+ content : [
1269+ {
1270+ type : "text" ,
1271+ text : `Processed: hello` ,
1272+ } ,
1273+ ] ,
1274+ isError : true ,
1275+ } ) ;
1276+ } ) ;
12151277
12161278 /***
12171279 * Test: Schema Validation Failure for Invalid Structured Content
Original file line number Diff line number Diff line change @@ -200,7 +200,7 @@ export class McpServer {
200200 }
201201 }
202202
203- if ( tool . outputSchema ) {
203+ if ( tool . outputSchema && ! result . isError ) {
204204 if ( ! result . structuredContent ) {
205205 throw new McpError (
206206 ErrorCode . InvalidParams ,
You can’t perform that action at this time.
0 commit comments