File tree Expand file tree Collapse file tree 2 files changed +17
-38
lines changed Expand file tree Collapse file tree 2 files changed +17
-38
lines changed Original file line number Diff line number Diff line change @@ -875,24 +875,6 @@ describe('tool()', () => {
875
875
} )
876
876
) ;
877
877
878
- mcpServer . registerTool (
879
- 'test (new api)' ,
880
- {
881
- inputSchema : {
882
- name : z . string ( ) ,
883
- value : z . number ( )
884
- }
885
- } ,
886
- async ( { name, value } ) => ( {
887
- content : [
888
- {
889
- type : 'text' ,
890
- text : `${ name } : ${ value } `
891
- }
892
- ]
893
- } )
894
- ) ;
895
-
896
878
const [ clientTransport , serverTransport ] = InMemoryTransport . createLinkedPair ( ) ;
897
879
898
880
await Promise . all ( [ client . connect ( clientTransport ) , mcpServer . server . connect ( serverTransport ) ] ) ;
@@ -911,23 +893,15 @@ describe('tool()', () => {
911
893
} ,
912
894
CallToolResultSchema
913
895
)
914
- ) . rejects . toThrow ( / I n v a l i d a r g u m e n t s / ) ;
915
-
916
- await expect (
917
- client . request (
896
+ ) . resolves . toStrictEqual ( {
897
+ content : [
918
898
{
919
- method : 'tools/call' ,
920
- params : {
921
- name : 'test (new api)' ,
922
- arguments : {
923
- name : 'test' ,
924
- value : 'not a number'
925
- }
926
- }
927
- } ,
928
- CallToolResultSchema
929
- )
930
- ) . rejects . toThrow ( / I n v a l i d a r g u m e n t s / ) ;
899
+ type : 'text' ,
900
+ text : expect . stringMatching ( / I n v a l i d a r g u m e n t s f o r t o o l t e s t / )
901
+ }
902
+ ] ,
903
+ isError : true
904
+ } ) ;
931
905
} ) ;
932
906
933
907
/***
Original file line number Diff line number Diff line change @@ -137,10 +137,15 @@ export class McpServer {
137
137
if ( tool . inputSchema ) {
138
138
const parseResult = await tool . inputSchema . safeParseAsync ( request . params . arguments ) ;
139
139
if ( ! parseResult . success ) {
140
- throw new McpError (
141
- ErrorCode . InvalidParams ,
142
- `Invalid arguments for tool ${ request . params . name } : ${ parseResult . error . message } `
143
- ) ;
140
+ return {
141
+ content : [
142
+ {
143
+ type : 'text' ,
144
+ text : `Invalid arguments for tool ${ request . params . name } : ${ parseResult . error . message } `
145
+ }
146
+ ] ,
147
+ isError : true
148
+ } ;
144
149
}
145
150
146
151
const args = parseResult . data ;
You can’t perform that action at this time.
0 commit comments