(data)
| 123 | return _handle_mcp_request(await adapter.get_json()) |
| 124 | |
| 125 | def _handle_mcp_request(data) -> Any: |
| 126 | adapter = app.backend.request_adapter() |
| 127 | content_type = adapter.headers.get("Content-Type", "") |
| 128 | if "application/json" not in content_type: |
| 129 | return app.backend.make_response( |
| 130 | json.dumps({"error": "Content-Type must be application/json"}), |
| 131 | content_type="application/json", |
| 132 | status=415, |
| 133 | ) |
| 134 | |
| 135 | if data is None: |
| 136 | return app.backend.make_response( |
| 137 | json.dumps({"error": "Invalid JSON"}), |
| 138 | content_type="application/json", |
| 139 | status=400, |
| 140 | ) |
| 141 | |
| 142 | method = data.get("method", "") |
| 143 | |
| 144 | try: |
| 145 | is_stale_session = _check_session(method) |
| 146 | except ValueError as err: |
| 147 | return app.backend.make_response( |
| 148 | json.dumps({"error": str(err)}), |
| 149 | content_type="application/json", |
| 150 | status=400, |
| 151 | ) |
| 152 | |
| 153 | response_data = _process_mcp_message(data) |
| 154 | |
| 155 | if response_data is None: |
| 156 | return app.backend.make_response("", status=202) |
| 157 | |
| 158 | if is_stale_session: |
| 159 | return _json_response( |
| 160 | {"jsonrpc": "2.0", "method": "notifications/tools/list_changed"}, |
| 161 | { |
| 162 | "jsonrpc": "2.0", |
| 163 | "method": "notifications/resources/list_changed", |
| 164 | }, |
| 165 | response_data, |
| 166 | ) |
| 167 | |
| 168 | return _json_response(response_data) |
| 169 | |
| 170 | def _handle_get(): |
| 171 | """ |
no test coverage detected
searching dependent graphs…