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

Function defaultSendingMethodHandler

mcp/shared.go:94–119  ·  view source on GitHub ↗
(ctx context.Context, method string, req Request)

Source from the content-addressed store, hash-verified

92}
93
94func defaultSendingMethodHandler(ctx context.Context, method string, req Request) (Result, error) {
95 info, ok := req.GetSession().sendingMethodInfos()[method]
96 if !ok {
97 // This can be called from user code, with an arbitrary value for method.
98 return nil, jsonrpc2.ErrNotHandled
99 }
100 params := req.GetParams()
101 if initParams, ok := params.(*InitializeParams); ok {
102 // Fix the marshaling of initialize params, to work around #607.
103 //
104 // The initialize params we produce should never be nil, nor have nil
105 // capabilities, so any panic here is a bug.
106 params = initParams.toV2()
107 }
108 // Notifications don't have results.
109 if strings.HasPrefix(method, "notifications/") {
110 return nil, req.GetSession().getConn().Notify(ctx, method, params)
111 }
112 // Create the result to unmarshal into.
113 // The concrete type of the result is the return type of the receiving function.
114 res := info.newResult()
115 if err := call(ctx, req.GetSession().getConn(), method, params, res); err != nil {
116 return nil, err
117 }
118 return res, nil
119}
120
121// Helper method to avoid typed nil.
122func orZero[T any, P *U, U any](p P) T {

Callers

nothing calls this directly

Calls 7

callFunction · 0.85
NotifyMethod · 0.80
sendingMethodInfosMethod · 0.65
GetSessionMethod · 0.65
GetParamsMethod · 0.65
getConnMethod · 0.65
toV2Method · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…