Skip to content

Commit 18a17a7

Browse files
committed
feat: add support to define the port and the host to start the server
Signed-off-by: Rai Siqueira <rai93siqueira@gmail.com>
1 parent ef931bd commit 18a17a7

File tree

6 files changed

+61
-10
lines changed

6 files changed

+61
-10
lines changed

README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,18 @@ django-ai-boost
100100
# Or specify settings directly
101101
django-ai-boost --settings myproject.settings
102102

103-
# Run with SSE transport (default is stdio)
103+
# Run with SSE transport (default is stdio, which doesn't use network ports)
104104
django-ai-boost --settings myproject.settings --transport sse
105+
106+
# Run with SSE transport on a custom port (default port is 8000)
107+
django-ai-boost --settings myproject.settings --transport sse --port 3000
108+
109+
# Run with SSE transport on custom host and port
110+
django-ai-boost --settings myproject.settings --transport sse --host 0.0.0.0 --port 8080
105111
```
106112

113+
**Note:** The stdio transport (default) communicates via standard input/output and does not use network ports. The `--port` and `--host` options only apply when using `--transport sse`.
114+
107115
## AI Tools Setup
108116

109117
### Cursor
@@ -272,11 +280,17 @@ Add to your Zed MCP configuration (`~/.config/zed/mcp.json`):
272280
For any MCP-compatible client, you can run the server manually:
273281

274282
```bash
275-
# Standard I/O transport (default)
283+
# Standard I/O transport (default, no network port)
276284
django-ai-boost --settings myproject.settings
277285

278-
# Server-Sent Events transport
286+
# Server-Sent Events transport (default: 127.0.0.1:8000)
279287
django-ai-boost --settings myproject.settings --transport sse
288+
289+
# SSE transport with custom port
290+
django-ai-boost --settings myproject.settings --transport sse --port 3000
291+
292+
# SSE transport with custom host and port
293+
django-ai-boost --settings myproject.settings --transport sse --host 0.0.0.0 --port 8080
280294
```
281295

282296
## Available Tools and Prompts
@@ -465,6 +479,17 @@ Or in your MCP client configuration:
465479

466480
Ensure your Django database is properly configured and accessible. The MCP server needs the same database access as your Django application.
467481

482+
### Port Already in Use (SSE Transport)
483+
484+
If you see an error like "Address already in use" when using SSE transport, the default port 8000 is likely occupied by another service (such as your Django development server). Use a different port:
485+
486+
```bash
487+
# Use a different port for the MCP server
488+
django-ai-boost --settings myproject.settings --transport sse --port 8001
489+
```
490+
491+
**Note:** The stdio transport (default) does not use network ports and will not have this issue.
492+
468493
## Requirements
469494

470495
- Python 3.12+

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "django-ai-boost"
3-
version = "0.3.1"
3+
version = "0.4.0"
44
description = "A Model Context Protocol (MCP) server for Django applications, inspired by Laravel Boost"
55
readme = "README.md"
66
authors = [

server.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
"url": "https://github.com/vintasoftware/django-ai-boost",
77
"source": "github"
88
},
9-
"version": "0.3.1",
9+
"version": "0.4.0",
1010
"packages": [
1111
{
1212
"registryType": "pypi",
1313
"identifier": "django-ai-boost",
14-
"version": "0.3.1",
14+
"version": "0.4.0",
1515
"transport": {
1616
"type": "stdio"
1717
},

src/django_ai_boost/__init__.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,23 @@ def main() -> None:
1717
default="stdio",
1818
help="Transport type (default: stdio)",
1919
)
20+
parser.add_argument(
21+
"--host",
22+
default="127.0.0.1",
23+
help="Host to bind to for SSE transport (default: 127.0.0.1)",
24+
)
25+
parser.add_argument(
26+
"--port",
27+
type=int,
28+
default=8000,
29+
help="Port to bind to for SSE transport (default: 8000)",
30+
)
2031

2132
args = parser.parse_args()
2233

23-
run_server(settings_module=args.settings, transport=args.transport)
34+
run_server(
35+
settings_module=args.settings,
36+
transport=args.transport,
37+
host=args.host,
38+
port=args.port,
39+
)

src/django_ai_boost/server_fastmcp.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,19 +574,29 @@ async def search_django_docs(topic: str) -> str:
574574
return prompt
575575

576576

577-
def run_server(settings_module: str | None = None, transport: str = "stdio"):
577+
def run_server(
578+
settings_module: str | None = None,
579+
transport: str = "stdio",
580+
host: str = "127.0.0.1",
581+
port: int = 8000,
582+
):
578583
"""
579584
Run the Django MCP server.
580585
581586
Args:
582587
settings_module: Django settings module path
583588
transport: Transport type (stdio or sse)
589+
host: Host to bind to for SSE transport (default: 127.0.0.1)
590+
port: Port to bind to for SSE transport (default: 8000)
584591
"""
585592
# Initialize Django before starting the server
586593
initialize_django(settings_module)
587594

588595
# Run the FastMCP server
589-
mcp.run(transport=transport)
596+
if transport == "sse":
597+
mcp.run(transport=transport, host=host, port=port)
598+
else:
599+
mcp.run(transport=transport)
590600

591601

592602
if __name__ == "__main__":

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)