MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / handleReceive

Function handleReceive

mcp/shared.go:157–176  ·  view source on GitHub ↗
(ctx context.Context, session S, jreq *jsonrpc.Request)

Source from the content-addressed store, hash-verified

155}
156
157func 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.

Callers 2

handleMethod · 0.85
handleMethod · 0.85

Calls 3

checkRequestFunction · 0.85
receivingMethodInfosMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…