@@ -11,15 +11,11 @@ type requestIDKey struct{}
1111// RequestSession represents an exchange with MCP client, and provides
1212// methods to interact with the client and query its capabilities.
1313type RequestSession struct {
14- mcpServer * MCPServer
15-
1614 progressToken * mcp.ProgressToken
1715}
1816
19- func NewRequestSession (mcpServer * MCPServer , requestParamMeta * mcp.Meta ) RequestSession {
20- requestSession := RequestSession {
21- mcpServer : mcpServer ,
22- }
17+ func NewRequestSession (requestParamMeta * mcp.Meta ) RequestSession {
18+ requestSession := RequestSession {}
2319
2420 // server should send progress notification if request metadata includes a progressToken
2521 if requestParamMeta != nil && requestParamMeta .ProgressToken != nil {
@@ -30,14 +26,15 @@ func NewRequestSession(mcpServer *MCPServer, requestParamMeta *mcp.Meta) Request
3026}
3127
3228// IsLoggingNotificationSupported returns true if server supports logging notification
33- func (exchange * RequestSession ) IsLoggingNotificationSupported () bool {
34- return exchange .mcpServer != nil && exchange .mcpServer .capabilities .logging != nil && * exchange .mcpServer .capabilities .logging
29+ func (exchange * RequestSession ) IsLoggingNotificationSupported (ctx context.Context ) bool {
30+ mcpServer := ServerFromContext (ctx )
31+ return mcpServer != nil && mcpServer .capabilities .logging != nil && * mcpServer .capabilities .logging
3532}
3633
3734// SendLoggingNotification send logging notification to client.
3835// If server does not support logging notification, this method will do nothing.
3936func (exchange * RequestSession ) SendLoggingNotification (ctx context.Context , level mcp.LoggingLevel , message map [string ]any ) error {
40- if ! exchange .IsLoggingNotificationSupported () {
37+ if ! exchange .IsLoggingNotificationSupported (ctx ) {
4138 return nil
4239 }
4340
@@ -58,7 +55,8 @@ func (exchange *RequestSession) SendLoggingNotification(ctx context.Context, lev
5855 params ["logger" ] = * ClientSessionFromContext (ctx ).GetLoggerName ()
5956 }
6057
61- return exchange .mcpServer .SendNotificationToClient (
58+ mcpServer := ServerFromContext (ctx )
59+ return mcpServer .SendNotificationToClient (
6260 ctx ,
6361 string (mcp .MethodNotificationMessage ),
6462 params ,
@@ -82,7 +80,8 @@ func (exchange *RequestSession) SendProgressNotification(ctx context.Context, pr
8280 params ["message" ] = * message
8381 }
8482
85- return exchange .mcpServer .SendNotificationToClient (
83+ mcpServer := ServerFromContext (ctx )
84+ return mcpServer .SendNotificationToClient (
8685 ctx ,
8786 string (mcp .MethodNotificationProgress ),
8887 params ,
@@ -108,7 +107,8 @@ func (exchange *RequestSession) SendCancellationNotification(ctx context.Context
108107 params ["reason" ] = reason
109108 }
110109
111- return exchange .mcpServer .SendNotificationToClient (
110+ mcpServer := ServerFromContext (ctx )
111+ return mcpServer .SendNotificationToClient (
112112 ctx ,
113113 string (mcp .MethodNotificationCancellation ),
114114 params ,
0 commit comments