Skip to content

Commit ebc48cb

Browse files
committed
fix(transport): support both stdio and sse modes via MCP_TRANSPORT env var
- Add MCP_TRANSPORT environment variable to switch between stdio (default) and sse modes - stdio mode: for Claude Desktop integration (default behavior) - sse mode: for Google Cloud Run and web deployments - Update deploy.sh to set MCP_TRANSPORT=sse for Cloud Run - Update README with transport modes documentation
1 parent 0366b8c commit ebc48cb

File tree

3 files changed

+32
-35
lines changed

3 files changed

+32
-35
lines changed

README.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,16 @@ uv run src/mcp_domain_availability/main.py
170170

171171
### Deploying with Docker to Google Cloud Run
172172

173-
You can deploy this service to Google Cloud Run using the provided Dockerfile and deployment script.
173+
The MCP server supports two transport modes:
174+
- **stdio** (default): For Claude Desktop integration via stdin/stdout
175+
- **sse**: For HTTP/web deployments like Google Cloud Run
176+
177+
When deploying to Cloud Run, the `MCP_TRANSPORT` environment variable must be set to `sse`.
174178

175179
**Prerequisites:**
176-
- [Google Cloud SDK](https://cloud.google.com/sdk/docs/install) installed and authenticated (`gcloud auth login`).
177-
- [Docker](https://docs.docker.com/get-docker/) installed and running.
178-
- A Google Cloud Project with the Cloud Run and Container Registry APIs enabled.
180+
- [Google Cloud SDK](https://cloud.google.com/sdk/docs/install) installed and authenticated (`gcloud auth login`)
181+
- [Docker](https://docs.docker.com/get-docker/) installed and running
182+
- A Google Cloud Project with the Cloud Run and Container Registry APIs enabled
179183

180184
#### Using the Deployment Script
181185

@@ -186,39 +190,41 @@ The easiest way to deploy is to use the `deploy.sh` script.
186190

187191
2. **Run the script:**
188192
Make the script executable and run it.
189-
```sh
193+
```sh
190194
chmod +x deploy.sh
191195
./deploy.sh
192-
```
193-
The script will build the Docker image, push it to Google Container Registry, and deploy it to Cloud Run.
196+
```
197+
The script will build the Docker image, push it to Google Container Registry, and deploy it to Cloud Run with `MCP_TRANSPORT=sse`.
194198

195199
#### Manual Deployment
196200

197201
Alternatively, you can run the commands manually.
198202

199203
1. **Set environment variables:**
200-
```sh
204+
```sh
201205
export PROJECT_ID="<YOUR_PROJECT_ID>"
202-
export REGION="<YOUR_REGION>" # e.g., us-central1
206+
export REGION="<YOUR_REGION>"
203207
export IMAGE="gcr.io/$PROJECT_ID/mcp-domain-availability:latest"
204-
```
208+
```
205209

206210
2. **Build and push the Docker image:**
207-
```sh
211+
```sh
208212
docker buildx build --platform linux/amd64 -t $IMAGE --push .
209-
```
213+
```
210214

211215
3. **Deploy to Google Cloud Run:**
212-
```sh
216+
```sh
213217
gcloud run deploy mcp-domain-availability \
214218
--image $IMAGE \
215219
--region $REGION \
216220
--platform managed \
217221
--allow-unauthenticated \
218222
--port 8080 \
223+
--set-env-vars MCP_TRANSPORT=sse \
219224
--project $PROJECT_ID
220-
```
225+
```
221226

227+
**Note:** For local Claude Desktop usage, no environment variables are needed. The server defaults to `stdio` transport mode.
222228

223229
### How It Works
224230

deploy.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ gcloud run deploy mcp-domain-availability \
1212
--platform managed \
1313
--allow-unauthenticated \
1414
--port 8080 \
15+
--set-env-vars MCP_TRANSPORT=sse \
1516
--project $PROJECT_ID

src/mcp_domain_availability/main.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@
1818

1919
from mcp.server.fastmcp import FastMCP
2020

21-
mcp = FastMCP("Domain Availability Checker", host="0.0.0.0", port=int(os.environ.get("PORT", 8080)))
21+
TRANSPORT_MODE = os.environ.get("MCP_TRANSPORT", "stdio")
22+
PORT = int(os.environ.get("PORT", 8080))
23+
24+
if TRANSPORT_MODE == "sse":
25+
mcp = FastMCP("Domain Availability Checker", host="0.0.0.0", port=PORT)
26+
else:
27+
mcp = FastMCP("Domain Availability Checker")
2228

2329
POPULAR_TLDS = [
2430
"com", "net", "org", "io", "ai", "app", "dev", "co", "xyz", "me", "info", "biz"
@@ -44,9 +50,7 @@
4450

4551
TLD_MIN_LENGTH = {
4652
"com": 2, "net": 2, "org": 2, "info": 2, "biz": 3,
47-
4853
"io": 2, "ai": 2, "co": 3, "me": 3,
49-
5054
"de": 2, "fr": 2, "it": 2, "es": 2, "nl": 3,
5155
"ch": 3, "at": 3, "be": 3, "dk": 3, "se": 3,
5256
"no": 3, "fi": 3, "pl": 3, "cz": 3, "pt": 3,
@@ -55,19 +59,16 @@
5559
"in": 3, "br": 3, "mx": 3, "ar": 3, "cl": 3,
5660
"pe": 3, "za": 3, "eg": 3, "ma": 3, "ng": 3,
5761
"ke": 3,
58-
5962
"app": 3, "dev": 3, "xyz": 3, "tech": 3,
6063
"online": 3, "site": 3, "website": 3, "store": 3,
6164
"shop": 3, "cloud": 3, "digital": 3, "blog": 3,
6265
"news": 3
6366
}
6467

6568
def get_min_length_for_tld(tld: str) -> int:
66-
"""Obtiene la longitud mínima requerida para un TLD"""
6769
return TLD_MIN_LENGTH.get(tld, 3)
6870

6971
def is_valid_domain_name(base_name: str, tld: str) -> bool:
70-
"""Valida si un nombre de dominio cumple con las reglas del TLD"""
7172
min_length = get_min_length_for_tld(tld)
7273
if len(base_name) < min_length:
7374
return False
@@ -295,20 +296,6 @@ async def run_domain_checks(domain_part: str) -> Dict:
295296

296297
@mcp.tool()
297298
async def check_domain(domain_query: str) -> Dict:
298-
"""
299-
Check domain availability.
300-
301-
Usage examples:
302-
- "mysite.com --domain" - checks exact domain
303-
- "mysite --domain" - checks mysite across all popular TLDs
304-
- "test.io --domain" - checks test.io exactly, plus test across all TLDs
305-
306-
Args:
307-
domain_query (str): Domain to check with --domain flag
308-
309-
Returns:
310-
Dict containing availability results for the domain and suggested alternatives
311-
"""
312299
if '--domain' not in domain_query:
313300
return {
314301
"error": "Please use --domain flag. Example: 'mysite.com --domain' or 'mysite --domain'"
@@ -336,4 +323,7 @@ async def check_domain(domain_query: str) -> Dict:
336323
}
337324

338325
if __name__ == "__main__":
339-
mcp.run(transport="sse")
326+
if TRANSPORT_MODE == "sse":
327+
mcp.run(transport="sse")
328+
else:
329+
mcp.run()

0 commit comments

Comments
 (0)