mcp: reject notifications with unexpected ID field (#204)
Use the new 'isRequest' field on methodInfo to also reject notifications with an unexpected ID field. For #196
This commit is contained in:
parent
9f48a04971
commit
56734edf46
1 changed files with 14 additions and 1 deletions
|
|
@ -155,7 +155,10 @@ func checkRequest(req *jsonrpc.Request, infos map[string]methodInfo) (methodInfo
|
|||
return methodInfo{}, fmt.Errorf("%w: %q unsupported", jsonrpc2.ErrNotHandled, req.Method)
|
||||
}
|
||||
if info.isRequest && !req.ID.IsValid() {
|
||||
return methodInfo{}, fmt.Errorf("%w: %q missing ID", jsonrpc2.ErrInvalidRequest, req.Method)
|
||||
return methodInfo{}, fmt.Errorf("%w: missing ID, %q", jsonrpc2.ErrInvalidRequest, req.Method)
|
||||
}
|
||||
if !info.isRequest && req.ID.IsValid() {
|
||||
return methodInfo{}, fmt.Errorf("%w: unexpected id for %q", jsonrpc2.ErrInvalidRequest, req.Method)
|
||||
}
|
||||
return info, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue