handleRequest method

Future<Map<String, dynamic>> handleRequest(
  1. Map<String, dynamic> request,
  2. McpEntrypointConfig config
)

Handle a single MCP JSON-RPC request and produce a response.

Implementation

Future<Map<String, dynamic>> handleRequest(
  Map<String, dynamic> request,
  McpEntrypointConfig config,
) async {
  final method = request['method'] as String?;
  final id = request['id'];
  final params = request['params'] as Map<String, dynamic>? ?? {};

  return switch (method) {
    'initialize' => _handleInitialize(id, params, config),
    'tools/list' => _handleToolsList(id, config),
    'tools/call' => await _handleToolsCall(id, params, config),
    'resources/list' => _handleResourcesList(id, config),
    'resources/read' => await _handleResourcesRead(id, params, config),
    'prompts/list' => _handlePromptsList(id, config),
    'prompts/get' => await _handlePromptsGet(id, params, config),
    'ping' => {'jsonrpc': '2.0', 'id': id, 'result': {}},
    _ => {
      'jsonrpc': '2.0',
      'id': id,
      'error': {'code': -32601, 'message': 'Method not found: $method'},
    },
  };
}