@@ -84,52 +84,47 @@ def server_process() -> Generator[Optional[Process], None, None]:
8484 process .kill ()
8585
8686
87- def test_legacy_package_api (server_process ) -> None :
88- """Test legacy FastAPI package endpoints ."""
89- package_url = f"{ BASE_URL } /packages/python "
90- response = requests .get (package_url )
87+ def test_health_check (server_process ) -> None :
88+ """Test health check endpoint ."""
89+ health_url = f"{ BASE_URL } /health "
90+ response = requests .get (health_url )
9191
9292 # Check that the response is valid
93- assert response .status_code == 200 , f"Package endpoint failed: { response .text } "
93+ assert response .status_code == 200 , f"Health check endpoint failed: { response .text } "
9494 data = response .json ()
9595
96- # In test environments without Nix packages, we'll get an error response
97- # but it should still be properly formatted JSON
98- if "error" in data :
99- print (f"NOTE: Package test received error: { data ['error' ]} " )
100- print ("This is expected in environments without Nix packages" )
101- # The test passes if we at least got a valid error response
102- assert isinstance (data ["error" ], str ), "Error should be a string"
103- else :
104- # If we have package data, validate it
105- assert "name" in data , "Package data missing 'name' field"
106- assert "version" in data , "Package data missing 'version' field"
107- assert data ["name" ] == "python" , f"Expected python package, got { data ['name' ]} "
96+ # Validate health check data
97+ assert "status" in data , "Health check data missing 'status' field"
98+ assert data ["status" ] == "ok" , f"Expected status 'ok', got { data ['status' ]} "
99+ assert "timestamp" in data , "Health check data missing 'timestamp' field"
100+ assert "server" in data , "Health check data missing 'server' field"
101+ assert "version" in data , "Health check data missing 'version' field"
102+ assert data ["server" ] == "NixMCP" , f"Expected server 'NixMCP', got { data ['server' ]} "
108103
109104
110- def test_legacy_option_api (server_process ) -> None :
111- """Test legacy FastAPI option endpoints ."""
112- option_url = f"{ BASE_URL } /options/services.nginx "
113- response = requests .get (option_url )
105+ def test_server_status (server_process ) -> None :
106+ """Test server status endpoint ."""
107+ status_url = f"{ BASE_URL } /status "
108+ response = requests .get (status_url )
114109
115110 # Check that the response is valid
116- assert response .status_code == 200 , f"Option endpoint failed: { response .text } "
111+ assert response .status_code == 200 , f"Status endpoint failed: { response .text } "
117112 data = response .json ()
118113
119- # In test environments without Nix options, we'll get an error response
120- # but it should still be properly formatted JSON
121- if "error" in data :
122- print ( f"NOTE: Option test received error: { data [ 'error' ] } " )
123- print ( "This is expected in environments without nixos-option" )
124- # The test passes if we at least got a valid error response
125- assert isinstance ( data [ "error" ], str ) , "Error should be a string "
126- else :
127- # If we have option data, validate it
128- assert "name " in data , "Option data missing 'name' field"
129- assert "description" in data , "Option data missing 'description ' field"
130- assert (
131- data [ "name" ] == "services.nginx"
132- ), f"Expected services.nginx option, got { data [ 'name' ] } "
114+ # Validate status data
115+ assert "status" in data , "Status data missing 'status' field"
116+ assert data [ "status" ] == "ok" , f"Expected status 'ok', got { data [ 'status' ] } "
117+ assert "timestamp" in data , "Status data missing 'timestamp' field"
118+ assert "server" in data , "Status data missing 'server' field"
119+ assert "version" in data , "Status data missing 'version' field"
120+ assert "nix_installed" in data , "Status data missing 'nix_installed' field "
121+ assert "endpoints" in data , "Status data missing 'endpoints' field"
122+ assert (
123+ "mcp_resources " in data [ "endpoints" ]
124+ ) , "Endpoints missing 'mcp_resources ' field"
125+
126+
127+ # Legacy API endpoints removed - focusing on MCP standard only
133128
134129
135130def test_mcp_package_resource (server_process ) -> None :
@@ -241,6 +236,29 @@ def dry_run_test() -> None:
241236 print ("It's useful for checking if the test script itself works correctly." )
242237
243238 # Mock response data
239+ mock_health = {
240+ "status" : "ok" ,
241+ "timestamp" : time .time (),
242+ "server" : "NixMCP" ,
243+ "version" : "0.1.0" ,
244+ }
245+
246+ mock_status = {
247+ "status" : "ok" ,
248+ "timestamp" : time .time (),
249+ "server" : "NixMCP" ,
250+ "version" : "0.1.0" ,
251+ "nix_installed" : True ,
252+ "endpoints" : {
253+ "mcp_resources" : [
254+ "nixos://package/{package_name}" ,
255+ "nixos://package/{package_name}/{channel}" ,
256+ "nixos://option/{option_name}" ,
257+ "nixos://option/{option_name}/{channel}" ,
258+ ],
259+ },
260+ }
261+
244262 mock_package = {
245263 "name" : "python" ,
246264 "version" : "3.11.0" ,
@@ -256,6 +274,12 @@ def dry_run_test() -> None:
256274 "example" : {"enable" : True },
257275 }
258276
277+ print ("\n Mock health check response:" )
278+ print (json .dumps (mock_health , indent = 2 ))
279+
280+ print ("\n Mock status response:" )
281+ print (json .dumps (mock_status , indent = 2 ))
282+
259283 print ("\n Mock package response:" )
260284 print (json .dumps (mock_package , indent = 2 ))
261285
@@ -297,23 +321,49 @@ def dry_run_test() -> None:
297321 start_server ()
298322 print ("✓ Server started for debugging" )
299323
300- # Test the legacy API endpoints directly
301- print ("\n --- Testing /packages/python ---" )
324+ # Test the health check endpoint
325+ print ("\n --- Testing /health ---" )
302326 try :
303- response = requests .get (f"{ BASE_URL } /packages/python " )
327+ response = requests .get (f"{ BASE_URL } /health " )
304328 print (f"Status code: { response .status_code } " )
305329 print (f"Response data: { json .dumps (response .json (), indent = 2 )} " )
306330 except Exception as e :
307331 print (f"Error: { e } " )
308332
309- print ("\n --- Testing /options/services.nginx ---" )
333+ # Test the status endpoint
334+ print ("\n --- Testing /status ---" )
310335 try :
311- response = requests .get (f"{ BASE_URL } /options/services.nginx " )
336+ response = requests .get (f"{ BASE_URL } /status " )
312337 print (f"Status code: { response .status_code } " )
313338 print (f"Response data: { json .dumps (response .json (), indent = 2 )} " )
314339 except Exception as e :
315340 print (f"Error: { e } " )
316341
342+ # Test only MCP endpoints in debug mode
343+ print ("\n --- Testing MCP package endpoint ---" )
344+ try :
345+ response = requests .get (
346+ f"{ BASE_URL } /mcp/resource?uri=nixos://package/python"
347+ )
348+ print (f"Status code: { response .status_code } " )
349+ print (
350+ f"Response data: { json .dumps (response .json (), indent = 2 ) if response .status_code == 200 else response .text } "
351+ )
352+ except Exception as e :
353+ print (f"Error: { e } " )
354+
355+ print ("\n --- Testing MCP option endpoint ---" )
356+ try :
357+ response = requests .get (
358+ f"{ BASE_URL } /mcp/resource?uri=nixos://option/services.nginx"
359+ )
360+ print (f"Status code: { response .status_code } " )
361+ print (
362+ f"Response data: { json .dumps (response .json (), indent = 2 ) if response .status_code == 200 else response .text } "
363+ )
364+ except Exception as e :
365+ print (f"Error: { e } " )
366+
317367 print ("\n Debug complete - server is still running for manual testing" )
318368 exit (0 )
319369
@@ -388,8 +438,8 @@ def run_expected_fail_test(name, test_func):
388438 return True
389439
390440 # Run all tests
391- run_test ("Legacy package API " , test_legacy_package_api )
392- run_test ("Legacy option API " , test_legacy_option_api )
441+ run_test ("Health check " , test_health_check )
442+ run_test ("Server status " , test_server_status )
393443 run_expected_fail_test ("MCP package resource" , test_mcp_package_resource )
394444 run_expected_fail_test (
395445 "MCP package with channel" , test_mcp_package_with_channel
0 commit comments