(ctx context.Context, session S, jreq *jsonrpc.Request)
| 155 | } |
| 156 | |
| 157 | func handleReceive[S Session](ctx context.Context, session S, jreq *jsonrpc.Request) (Result, error) { |
| 158 | info, err := checkRequest(jreq, session.receivingMethodInfos()) |
| 159 | if err != nil { |
| 160 | return nil, err |
| 161 | } |
| 162 | params, err := info.unmarshalParams(jreq.Params) |
| 163 | if err != nil { |
| 164 | return nil, fmt.Errorf("handling '%s': %w", jreq.Method, err) |
| 165 | } |
| 166 | |
| 167 | mh := session.receivingMethodHandler() |
| 168 | re, _ := jreq.Extra.(*RequestExtra) |
| 169 | req := info.newRequest(session, params, re) |
| 170 | // mh might be user code, so ensure that it returns the right values for the jsonrpc2 protocol. |
| 171 | res, err := mh(ctx, jreq.Method, req) |
| 172 | if err != nil { |
| 173 | return nil, err |
| 174 | } |
| 175 | return res, nil |
| 176 | } |
| 177 | |
| 178 | // checkRequest checks the given request against the provided method info, to |
| 179 | // ensure it is a valid MCP request. |
no test coverage detected
searching dependent graphs…