@@ -57,19 +57,13 @@ class InMemoryEventStore implements EventStore {
57
57
}
58
58
}
59
59
60
- // Global server instance to be used by tool callbacks
61
- Server ? globalServer;
62
-
63
60
// Create an MCP server with implementation details
64
61
McpServer getServer () {
65
62
// Create the McpServer with the implementation details and options
66
63
final server = McpServer (
67
64
Implementation (name: 'simple-streamable-http-server' , version: '1.0.0' ),
68
65
);
69
66
70
- // Save reference to underlying server for logging access
71
- globalServer = server.server;
72
-
73
67
// Register a simple tool that returns a greeting
74
68
server.tool (
75
69
'greet' ,
@@ -107,32 +101,29 @@ McpServer getServer() {
107
101
Future <void > sleep (int ms) => Future .delayed (Duration (milliseconds: ms));
108
102
109
103
// Send debug notification
110
- if (globalServer != null ) {
111
- await globalServer! .sendLoggingMessage (LoggingMessageNotificationParams (
112
- level: LoggingLevel .debug,
113
- data: 'Starting multi-greet for $name ' ,
114
- ));
115
- }
104
+ await extra? .sendNotification (JsonRpcLoggingMessageNotification (
105
+ logParams: LoggingMessageNotificationParams (
106
+ level: LoggingLevel .debug,
107
+ data: 'Starting multi-greet for $name ' ,
108
+ )));
116
109
117
110
await sleep (1000 ); // Wait 1 second before first greeting
118
111
119
112
// Send first info notification
120
- if (globalServer != null ) {
121
- await globalServer! .sendLoggingMessage (LoggingMessageNotificationParams (
122
- level: LoggingLevel .info,
123
- data: 'Sending first greeting to $name ' ,
124
- ));
125
- }
113
+ await extra? .sendNotification (JsonRpcLoggingMessageNotification (
114
+ logParams: LoggingMessageNotificationParams (
115
+ level: LoggingLevel .info,
116
+ data: 'Sending first greeting to $name ' ,
117
+ )));
126
118
127
119
await sleep (1000 ); // Wait another second before second greeting
128
120
129
121
// Send second info notification
130
- if (globalServer != null ) {
131
- await globalServer! .sendLoggingMessage (LoggingMessageNotificationParams (
132
- level: LoggingLevel .info,
133
- data: 'Sending second greeting to $name ' ,
134
- ));
135
- }
122
+ await extra? .sendNotification (JsonRpcLoggingMessageNotification (
123
+ logParams: LoggingMessageNotificationParams (
124
+ level: LoggingLevel .info,
125
+ data: 'Sending second greeting to $name ' ,
126
+ )));
136
127
137
128
return CallToolResult (
138
129
content: [
@@ -196,14 +187,12 @@ McpServer getServer() {
196
187
while (count == 0 || counter < count) {
197
188
counter++ ;
198
189
try {
199
- if (globalServer != null ) {
200
- await globalServer!
201
- .sendLoggingMessage (LoggingMessageNotificationParams (
202
- level: LoggingLevel .info,
203
- data:
204
- 'Periodic notification #$counter at ${DateTime .now ().toIso8601String ()}' ,
205
- ));
206
- }
190
+ await extra? .sendNotification (JsonRpcLoggingMessageNotification (
191
+ logParams: LoggingMessageNotificationParams (
192
+ level: LoggingLevel .info,
193
+ data:
194
+ 'Periodic notification #$counter at ${DateTime .now ().toIso8601String ()}' ,
195
+ )));
207
196
} catch (error) {
208
197
print ('Error sending notification: $error ' );
209
198
}
0 commit comments