@@ -79,6 +79,99 @@ describe("McpServer", () => {
79
79
}
80
80
] )
81
81
} ) ;
82
+
83
+ /***
84
+ * Test: Progress Notification with Message Field
85
+ */
86
+ test ( "should send progress notifications with message field" , async ( ) => {
87
+ const mcpServer = new McpServer (
88
+ {
89
+ name : "test server" ,
90
+ version : "1.0" ,
91
+ }
92
+ ) ;
93
+
94
+ // Create a tool that sends progress updates
95
+ mcpServer . tool (
96
+ "long-operation" ,
97
+ "A long running operation with progress updates" ,
98
+ {
99
+ steps : z . number ( ) . min ( 1 ) . describe ( "Number of steps to perform" ) ,
100
+ } ,
101
+ async ( { steps } , { sendNotification, _meta } ) => {
102
+ const progressToken = _meta ?. progressToken ;
103
+
104
+ if ( progressToken ) {
105
+ // Send progress notification for each step
106
+ for ( let i = 1 ; i <= steps ; i ++ ) {
107
+ await sendNotification ( {
108
+ method : "notifications/progress" ,
109
+ params : {
110
+ progressToken,
111
+ progress : i ,
112
+ total : steps ,
113
+ message : `Completed step ${ i } of ${ steps } ` ,
114
+ } ,
115
+ } ) ;
116
+ }
117
+ }
118
+
119
+ return { content : [ { type : "text" as const , text : `Operation completed with ${ steps } steps` } ] } ;
120
+ }
121
+ ) ;
122
+
123
+ const progressUpdates : Array < { progress : number , total ?: number , message ?: string } > = [ ] ;
124
+
125
+ const client = new Client ( {
126
+ name : "test client" ,
127
+ version : "1.0" ,
128
+ } ) ;
129
+
130
+ const [ clientTransport , serverTransport ] = InMemoryTransport . createLinkedPair ( ) ;
131
+
132
+ await Promise . all ( [
133
+ client . connect ( clientTransport ) ,
134
+ mcpServer . server . connect ( serverTransport ) ,
135
+ ] ) ;
136
+
137
+ // Call the tool with progress tracking
138
+ await client . request (
139
+ {
140
+ method : "tools/call" ,
141
+ params : {
142
+ name : "long-operation" ,
143
+ arguments : { steps : 3 } ,
144
+ _meta : {
145
+ progressToken : "progress-test-1"
146
+ }
147
+ }
148
+ } ,
149
+ CallToolResultSchema ,
150
+ {
151
+ onprogress : ( progress ) => {
152
+ progressUpdates . push ( progress ) ;
153
+ }
154
+ }
155
+ ) ;
156
+
157
+ // Verify progress notifications were received with message field
158
+ expect ( progressUpdates ) . toHaveLength ( 3 ) ;
159
+ expect ( progressUpdates [ 0 ] ) . toMatchObject ( {
160
+ progress : 1 ,
161
+ total : 3 ,
162
+ message : "Completed step 1 of 3" ,
163
+ } ) ;
164
+ expect ( progressUpdates [ 1 ] ) . toMatchObject ( {
165
+ progress : 2 ,
166
+ total : 3 ,
167
+ message : "Completed step 2 of 3" ,
168
+ } ) ;
169
+ expect ( progressUpdates [ 2 ] ) . toMatchObject ( {
170
+ progress : 3 ,
171
+ total : 3 ,
172
+ message : "Completed step 3 of 3" ,
173
+ } ) ;
174
+ } ) ;
82
175
} ) ;
83
176
84
177
describe ( "ResourceTemplate" , ( ) => {
0 commit comments