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

Method AddReceivingMiddleware

mcp/server.go:1352–1356  ·  view source on GitHub ↗

AddReceivingMiddleware wraps the current receiving method handler using the provided middleware. Middleware is applied from right to left, so that the first one is executed first. For example, AddReceivingMiddleware(m1, m2, m3) augments the method handler as m1(m2(m3(handler))). Receiving middlewa

(middleware ...Middleware)

Source from the content-addressed store, hash-verified

1350// Receiving middleware is called when a request is received. It is useful for tasks
1351// such as authentication, request logging and metrics.
1352func (s *Server) AddReceivingMiddleware(middleware ...Middleware) {
1353 s.mu.Lock()
1354 defer s.mu.Unlock()
1355 addMiddleware(&s.receivingMethodHandler_, middleware)
1356}
1357
1358// serverMethodInfos maps from the RPC method name to serverMethodInfos.
1359//

Callers 7

TestMiddlewareFunction · 0.95
TestToolErrorMiddlewareFunction · 0.95
runServerFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95

Calls 1

addMiddlewareFunction · 0.85

Tested by 3

TestMiddlewareFunction · 0.76
TestToolErrorMiddlewareFunction · 0.76