| @@ -63,9 +63,9 @@ | ||
| 63 | 63 | /** |
| 64 | 64 | * Handle incoming JSON-RPC request |
| 65 | 65 | * |
| 66 | 66 | * @param string $request_body Raw request body |
| 67 | - * @return array Response array | |
| 67 | + * @return array|null Response array, or null for a notification | |
| 68 | 68 | */ |
| 69 | 69 | public function handle_request($request_body) { |
| 70 | 70 | // Parse JSON |
| 71 | 71 | $request = json_decode($request_body, true); |
| @@ -88,8 +88,12 @@ | ||
| 88 | 88 | $id = isset($request['id']) ? $request['id'] : null; |
| 89 | 89 | |
| 90 | 90 | // Check if handler exists |
| 91 | 91 | if (!isset($this->handlers[$method])) { |
| 92 | + if (!array_key_exists('id', $request)) { | |
| 93 | + return null; | |
| 94 | + } | |
| 95 | + | |
| 92 | 96 | return $this->error_response($id, self::ERROR_METHOD_NOT_FOUND, "Method not found: {$method}"); |
| 93 | 97 | } |
| 94 | 98 | |
| 95 | 99 | try { |
| @@ -94,14 +98,26 @@ | ||
| 94 | 98 | |
| 95 | 99 | try { |
| 96 | 100 | // Call handler |
| 97 | 101 | $result = call_user_func($this->handlers[$method], $params); |
| 102 | + if (!array_key_exists('id', $request)) { | |
| 103 | + return null; | |
| 104 | + } | |
| 105 | + | |
| 98 | 106 | return $this->success_response($id, $result); |
| 99 | 107 | } catch (InvalidArgumentException $e) { |
| 108 | + if (!array_key_exists('id', $request)) { | |
| 109 | + return null; | |
| 110 | + } | |
| 111 | + | |
| 100 | 112 | return $this->error_response($id, self::ERROR_INVALID_PARAMS, $e->getMessage()); |
| 101 | 113 | } catch (Exception $e) { |
| 102 | 114 | // Log error |
| 103 | 115 | error_log('MCP JSON-RPC Error: ' . $e->getMessage()); |
| 116 | + if (!array_key_exists('id', $request)) { | |
| 117 | + return null; | |
| 118 | + } | |
| 119 | + | |
| 104 | 120 | return $this->error_response($id, self::ERROR_INTERNAL_ERROR, $e->getMessage()); |
| 105 | 121 | } |
| 106 | 122 | } |
| 107 | 123 | |