Skip to content

Commit 4608401

Browse files
committed
mcp: simplify ServerSession.initialize
Make the simplifications described in #222. I don't know why we originally had such fine granularity of locking: perhaps we were going to execute 'oninitialized' callbacks. Also update the TODO with a bit more information about jsonrpc2 behavior. Fixes #222
1 parent 5bd02a3 commit 4608401

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

mcp/server.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -753,19 +753,16 @@ func (ss *ServerSession) initialize(ctx context.Context, params *InitializeParam
753753
return nil, fmt.Errorf("%w: \"params\" must be be provided", jsonrpc2.ErrInvalidParams)
754754
}
755755
ss.mu.Lock()
756+
defer ss.mu.Unlock()
756757
ss.initializeParams = params
757-
ss.mu.Unlock()
758758

759759
// Mark the connection as initialized when this method exits.
760-
// TODO: Technically, the server should not be considered initialized until it has
761-
// *responded*, but we don't have adequate visibility into the jsonrpc2
762-
// connection to implement that easily. In any case, once we've initialized
763-
// here, we can handle requests.
764-
defer func() {
765-
ss.mu.Lock()
766-
ss.initialized = true
767-
ss.mu.Unlock()
768-
}()
760+
// TODO(#26): Technically, the server should not be considered initialized
761+
// until it has *responded*, but since jsonrpc2 is currently serialized we
762+
// can mark the session as initialized here. If we ever implement a
763+
// concurrency model (#26), we need to guarantee that initialize is not
764+
// handled concurrently to other requests.
765+
ss.initialized = true
769766

770767
// If we support the client's version, reply with it. Otherwise, reply with our
771768
// latest version.

0 commit comments

Comments
 (0)