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
This commit is contained in:
parent
5bd02a3c04
commit
4608401cc4
1 changed files with 7 additions and 10 deletions
|
|
@ -753,19 +753,16 @@ func (ss *ServerSession) initialize(ctx context.Context, params *InitializeParam
|
||||||
return nil, fmt.Errorf("%w: \"params\" must be be provided", jsonrpc2.ErrInvalidParams)
|
return nil, fmt.Errorf("%w: \"params\" must be be provided", jsonrpc2.ErrInvalidParams)
|
||||||
}
|
}
|
||||||
ss.mu.Lock()
|
ss.mu.Lock()
|
||||||
|
defer ss.mu.Unlock()
|
||||||
ss.initializeParams = params
|
ss.initializeParams = params
|
||||||
ss.mu.Unlock()
|
|
||||||
|
|
||||||
// Mark the connection as initialized when this method exits.
|
// Mark the connection as initialized when this method exits.
|
||||||
// TODO: Technically, the server should not be considered initialized until it has
|
// TODO(#26): Technically, the server should not be considered initialized
|
||||||
// *responded*, but we don't have adequate visibility into the jsonrpc2
|
// until it has *responded*, but since jsonrpc2 is currently serialized we
|
||||||
// connection to implement that easily. In any case, once we've initialized
|
// can mark the session as initialized here. If we ever implement a
|
||||||
// here, we can handle requests.
|
// concurrency model (#26), we need to guarantee that initialize is not
|
||||||
defer func() {
|
// handled concurrently to other requests.
|
||||||
ss.mu.Lock()
|
ss.initialized = true
|
||||||
ss.initialized = true
|
|
||||||
ss.mu.Unlock()
|
|
||||||
}()
|
|
||||||
|
|
||||||
// If we support the client's version, reply with it. Otherwise, reply with our
|
// If we support the client's version, reply with it. Otherwise, reply with our
|
||||||
// latest version.
|
// latest version.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue