method method

void method(
  1. String name,
  2. MethodHandler handler
)

Register a custom MCP method handler.

Custom handlers take priority over the built-in method routing in McpController, so you can override any standard method or add new ones.

mcp.method('notifications/initialized', (payload) async {
  return JSONRPCNotification(method: 'notifications/initialized');
});

Implementation

void method(String name, MethodHandler handler) {
  _methods[name] = handler;
}