Skip to content

Commit 38e2dfa

Browse files
committed
feat: Fix flake.nix to not break build process (and maybe fix some other things too)
🔥💩😒 ass, you've be... Fix flake.nix to avoid breaking build process, and maybe fix some other things too. Don't make us do it again, developers.
1 parent 8c49516 commit 38e2dfa

File tree

8 files changed

+89
-20
lines changed

8 files changed

+89
-20
lines changed

.cursorrules

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ When updating rules:
1515

1616
### Using Nix Develop (Recommended)
1717
- Development environment: `nix develop`
18-
- Run server: `run`
18+
- Run server: `run [--port=PORT]`
19+
- Run with hot reloading for development: `run-dev [--port=PORT]`
1920
- Run tests (automatically manages server): `run-tests`
2021
- Run tests with existing server: `run-tests-with-server`
2122
- Run test mocks (no server needed): `run-tests-dry`

.goosehints

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ When updating rules:
1515

1616
### Using Nix Develop (Recommended)
1717
- Development environment: `nix develop`
18-
- Run server: `run`
18+
- Run server: `run [--port=PORT]`
19+
- Run with hot reloading for development: `run-dev [--port=PORT]`
1920
- Run tests (automatically manages server): `run-tests`
2021
- Run tests with existing server: `run-tests-with-server`
2122
- Run test mocks (no server needed): `run-tests-dry`

.windsurfrules

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ When updating rules:
1515

1616
### Using Nix Develop (Recommended)
1717
- Development environment: `nix develop`
18-
- Run server: `run`
18+
- Run server: `run [--port=PORT]`
19+
- Run with hot reloading for development: `run-dev [--port=PORT]`
1920
- Run tests (automatically manages server): `run-tests`
2021
- Run tests with existing server: `run-tests-with-server`
2122
- Run test mocks (no server needed): `run-tests-dry`

CLAUDE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ When updating rules:
1515

1616
### Using Nix Develop (Recommended)
1717
- Development environment: `nix develop`
18-
- Run server: `run`
18+
- Run server: `run [--port=PORT]`
19+
- Run with hot reloading for development: `run-dev [--port=PORT]`
1920
- Run tests (automatically manages server): `run-tests`
2021
- Run tests with existing server: `run-tests-with-server`
2122
- Run test mocks (no server needed): `run-tests-dry`

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,15 @@ nix develop
2727
# List all available commands
2828
menu
2929

30-
# Run the server
30+
# Run the server (default port is 9421)
3131
run
3232

33+
# Run the server with hot reloading for development
34+
run-dev
35+
36+
# Run on specific port with hot reloading
37+
run-dev --port=8080
38+
3339
# Run tests (automatically handles server startup/shutdown)
3440
run-tests
3541

@@ -113,10 +119,10 @@ The project includes comprehensive test coverage that can be run in several ways
113119
4. **Manual Testing with curl:**
114120
```bash
115121
# Test MCP package resource
116-
curl -X GET "http://localhost:8000/mcp/resource?uri=nixos://package/python"
122+
curl -X GET "http://localhost:9421/mcp/resource?uri=nixos://package/python"
117123

118124
# Test MCP option resource
119-
curl -X GET "http://localhost:8000/mcp/resource?uri=nixos://option/services.nginx"
125+
curl -X GET "http://localhost:9421/mcp/resource?uri=nixos://option/services.nginx"
120126
```
121127

122128
5. **Debug Testing:**
@@ -130,7 +136,7 @@ The project includes comprehensive test coverage that can be run in several ways
130136
This runs tests in debug mode with detailed output for troubleshooting.
131137

132138
6. **Exploring with the MCP UI:**
133-
- Open your browser to: http://localhost:8000/mcp
139+
- Open your browser to: http://localhost:9421/mcp
134140
- This provides a UI to explore MCP resources and tools
135141

136142
### Available Resources

flake.nix

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
echo ""
4747
echo "MCP SDK is installed in .venv/"
4848
echo "Run the server with: python server.py"
49-
echo "Access the MCP Inspector at: http://localhost:8000/docs"
49+
echo "Access the MCP Inspector at: http://localhost:9421/docs"
5050
'';
5151

5252
in {
@@ -114,7 +114,51 @@
114114
command = ''
115115
echo "Starting NixMCP server..."
116116
source .venv/bin/activate
117-
python server.py
117+
118+
# Default port
119+
PORT=9421
120+
121+
# Parse arguments to extract port if specified
122+
for arg in "$@"; do
123+
case $arg in
124+
--port=*)
125+
PORT=''${arg#*=}
126+
shift
127+
;;
128+
*)
129+
# Unknown option
130+
;;
131+
esac
132+
done
133+
134+
python server.py --port $PORT
135+
'';
136+
}
137+
{
138+
name = "run-dev";
139+
category = "server";
140+
help = "Run the NixMCP server with hot reloading for development";
141+
command = ''
142+
echo "Starting NixMCP development server with hot reloading..."
143+
source .venv/bin/activate
144+
145+
# Default port
146+
PORT=9421
147+
148+
# Parse arguments to extract port if specified
149+
for arg in "$@"; do
150+
case $arg in
151+
--port=*)
152+
PORT=''${arg#*=}
153+
shift
154+
;;
155+
*)
156+
# Unknown option
157+
;;
158+
esac
159+
done
160+
161+
python server.py --reload --port $PORT
118162
'';
119163
}
120164
{
@@ -182,7 +226,7 @@
182226
fi
183227
184228
# Check if server is running
185-
if ! curl -s http://localhost:8000/docs -o /dev/null; then
229+
if ! curl -s http://localhost:9421/docs -o /dev/null; then
186230
echo -e "\n❌ ERROR: Server is not running!"
187231
echo "Please start the server with 'run' command first"
188232
exit 1
@@ -265,6 +309,7 @@
265309
echo "└─────────────────────────────────────────────────┘"
266310
echo ""
267311
echo " ⚡ run - Start the NixMCP server"
312+
echo " ⚡ run-dev - Start the NixMCP server with hot reloading"
268313
echo " 🧪 run-tests - Run all tests (auto-manages server)"
269314
echo " 🧪 run-tests-dry - Run test mocks (no server needed)"
270315
echo " 🧪 run-tests-debug - Run tests in debug mode"

server.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,15 @@ async def get_option_resource_with_channel(option_name: str, channel: str):
289289
if __name__ == "__main__":
290290
import uvicorn
291291
import logging
292+
import argparse
292293
from fastapi.middleware.cors import CORSMiddleware
293294

295+
# Parse command-line arguments
296+
parser = argparse.ArgumentParser(description="NixMCP Server")
297+
parser.add_argument("--reload", action="store_true", help="Enable hot reloading for development")
298+
parser.add_argument("--port", type=int, default=9421, help="Port to run the server on (default: 9421)")
299+
args = parser.parse_args()
300+
294301
# Enable debug logging
295302
logging.basicConfig(level=logging.DEBUG)
296303

@@ -324,12 +331,19 @@ def debug_mcp_registered():
324331
print(f"Error accessing resources: {e}")
325332
print(f"MCP object dir: {dir(mcp)}")
326333

334+
port = args.port
327335
print("\nDebug access URLs:")
328-
print(" - Test URL: http://localhost:8000/mcp/resource?uri=nixos://package/python")
329-
print(" - Direct FastAPI: http://localhost:8000/packages/python")
330-
331-
print("\nStarting NixMCP server on port 8000...")
332-
print("Access FastAPI docs at http://localhost:8000/docs")
333-
print("Access MCP endpoints at http://localhost:8000/mcp")
334-
335-
uvicorn.run("server:app", host="0.0.0.0", port=8000, log_level="debug")
336+
print(f" - Test URL: http://localhost:{port}/mcp/resource?uri=nixos://package/python")
337+
print(f" - Direct FastAPI: http://localhost:{port}/packages/python")
338+
339+
print(f"\nStarting NixMCP server on port {port}...")
340+
print(f"Access FastAPI docs at http://localhost:{port}/docs")
341+
print(f"Access MCP endpoints at http://localhost:{port}/mcp")
342+
343+
uvicorn.run(
344+
"server:app",
345+
host="0.0.0.0",
346+
port=port,
347+
log_level="debug",
348+
reload=args.reload
349+
)

test_mcp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
# Server configuration
2323
SERVER_HOST = "localhost"
24-
SERVER_PORT = 8000
24+
SERVER_PORT = 9421
2525
BASE_URL = f"http://{SERVER_HOST}:{SERVER_PORT}"
2626
SERVER_STARTUP_TIMEOUT = 5 # seconds
2727

0 commit comments

Comments
 (0)