Skip to content

Commit c5ca000

Browse files
committed
Fix mcpgateway wrapper
Signed-off-by: Madhav Kandukuri <[email protected]>
1 parent d11fa1c commit c5ca000

File tree

7 files changed

+1343
-1250
lines changed

7 files changed

+1343
-1250
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ pkill mcpgateway
175175
export MCP_AUTH_TOKEN=${MCPGATEWAY_BEARER_TOKEN}
176176
export MCP_SERVER_CATALOG_URLS=http://localhost:4444/servers/1
177177
python3 -m mcpgateway.wrapper
178+
# Alternatively with uv
179+
uv run --directory . -m mcpgateway.wrapper
178180
```
179181

180182
See [.env.example](.env.example) for full list of ENV variables you can use to override the configuration.
@@ -241,6 +243,8 @@ export MCP_WRAPPER_LOG_LEVEL=DEBUG # or OFF to disable logging
241243

242244
# Run the wrapper from the installed module
243245
python3 -m mcpgateway.wrapper
246+
# Alternatively with uv
247+
uv run --directory . -m mcpgateway.wrapper
244248
```
245249

246250
**Or using the container image:**
@@ -268,6 +272,8 @@ npx -y supergateway --stdio "uvenv run mcp_server_time -- --local-timezone=Europ
268272
export MCP_AUTH_TOKEN=${MCPGATEWAY_BEARER_TOKEN}
269273
export MCP_SERVER_CATALOG_URLS=http://localhost:4444/servers/1
270274
python3 -m mcpgateway.wrapper
275+
# Alternatively with uv
276+
uv run --directory . -m mcpgateway.wrapper
271277
```
272278

273279
<details>
@@ -350,6 +356,8 @@ pipx install --include-deps mcp-contextforge-gateway
350356
MCP_AUTH_TOKEN=${MCPGATEWAY_BEARER_TOKEN} \
351357
MCP_SERVER_CATALOG_URLS=http://localhost:4444/servers/1 \
352358
python3 -m mcpgateway.wrapper
359+
# Alternatively with uv
360+
uv run --directory . -m mcpgateway.wrapper
353361
```
354362

355363
**Claude Desktop JSON** (uses the host Python that pipx injected):
@@ -400,11 +408,9 @@ uv pip install mcp-contextforge-gateway
400408
# Launch wrapper
401409
MCP_AUTH_TOKEN=${MCPGATEWAY_BEARER_TOKEN} \
402410
MCP_SERVER_CATALOG_URLS=http://localhost:4444/servers/1 \
403-
uv python -m mcpgateway.wrapper # Use this just for testing, as the Client will run the uv command
411+
uv run --directory . -m mcpgateway.wrapper # Use this just for testing, as the Client will run the uv command
404412
```
405413

406-
*(You can swap `uv python` for plain `python` if the venv is active.)*
407-
408414
#### Claude Desktop JSON (runs through **uvenv run**)
409415

410416
```json

docs/docs/using/clients/cline.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,31 @@ To integrate Cline with your MCP Gateway:
3434
1. **Configure MCP Server**:
3535
- Open the Cline settings in VS Code.
3636
- Navigate to the MCP Servers section.
37-
- Add a new MCP server with the following configuration:
37+
- Add a new MCP server with the following configuration under mcpServers as shown below:
3838

3939
```json
40-
{
41-
"name": "MCP Gateway",
42-
"url": "http://localhost:4444",
43-
"auth": {
44-
"type": "basic",
45-
"username": "admin",
46-
"password": "changeme"
47-
}
48-
}
40+
"mcpServers": {
41+
"mcpgateway-wrapper": {
42+
"disabled": true,
43+
"timeout": 60,
44+
"type": "stdio",
45+
"command": "uv",
46+
"args": [
47+
"run",
48+
"--directory",
49+
"REPLACE_WITH_PATH_TO_REPO",
50+
"-m",
51+
"mcpgateway.wrapper"
52+
],
53+
"env": {
54+
"MCP_SERVER_CATALOG_URLS": "http://localhost:4444",
55+
"MCP_AUTH_TOKEN": "REPLACE_WITH_MCPGATEWAY_BEARER_TOKEN",
56+
"MCP_WRAPPER_LOG_LEVEL": "OFF"
57+
}
58+
}
59+
}
4960
```
5061

51-
- Replace the URL, username, and password with your MCP Gateway's details.
52-
5362
2. **Enable the MCP Server**:
5463
- Ensure the newly added MCP server is enabled in the Cline settings.
5564

mcpgateway/main.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
ToolUpdate,
7979
)
8080
from mcpgateway.services.completion_service import CompletionService
81-
from mcpgateway.services.gateway_service import GatewayService
81+
from mcpgateway.services.gateway_service import GatewayService, GatewayConnectionError
8282
from mcpgateway.services.logging_service import LoggingService
8383
from mcpgateway.services.prompt_service import (
8484
PromptError,
@@ -1506,7 +1506,15 @@ async def register_gateway(
15061506
Created gateway.
15071507
"""
15081508
logger.debug(f"User '{user}' requested to register gateway: {gateway}")
1509-
return await gateway_service.register_gateway(db, gateway)
1509+
try:
1510+
return await gateway_service.register_gateway(db, gateway)
1511+
except Exception as ex:
1512+
if isinstance(ex, GatewayConnectionError):
1513+
return JSONResponse(
1514+
content={"message": "Unable to connect to gateway"},
1515+
status_code=502
1516+
)
1517+
15101518

15111519

15121520
@gateway_router.get("/{gateway_id}", response_model=GatewayRead)

mcpgateway/services/gateway_service.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,19 +232,16 @@ async def register_gateway(self, db: Session, gateway: GatewayCreate) -> Gateway
232232
await self._notify_gateway_added(db_gateway)
233233

234234
return GatewayRead.model_validate(gateway)
235+
except* GatewayConnectionError as ve:
236+
logger.error("GatewayConnectionError in group: %s", ve.exceptions)
237+
raise ve.exceptions[0]
235238
except* ValueError as ve:
236239
logger.error("ValueErrors in group: %s", ve.exceptions)
237240
except* RuntimeError as re:
238241
logger.error("RuntimeErrors in group: %s", re.exceptions)
239242
except* BaseException as other: # catches every other sub-exception
240243
logger.error("Other grouped errors: %s", other.exceptions)
241-
# except IntegrityError as ex:
242-
# logger.error(f"Error adding gateway: {ex}")
243-
# db.rollback()
244-
# raise GatewayError(f"Gateway already exists: {gateway.name}")
245-
# except Exception as e:
246-
# db.rollback()
247-
# raise GatewayError(f"Failed to register gateway: {str(e)}")
244+
raise Exception(other.exceptions)
248245

249246
async def list_gateways(self, db: Session, include_inactive: bool = False) -> List[GatewayRead]:
250247
"""List all registered gateways.

mcpgateway/wrapper.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ def _extract_base_url(url: str) -> str:
9292
parsed = urlparse(url)
9393
if not parsed.scheme or not parsed.netloc:
9494
raise ValueError(f"Invalid URL provided: {url}")
95-
return f"{parsed.scheme}://{parsed.netloc}"
95+
96+
before_servers = parsed.path.split('/servers')[0]
97+
return f"{parsed.scheme}://{parsed.netloc}{before_servers}"
9698

9799

98100
BASE_URL: str = _extract_base_url(SERVER_CATALOG_URLS[0]) if SERVER_CATALOG_URLS else ""

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ dev = [
142142

143143
# Convenience meta-extras
144144
all = [
145-
"mcpgateway[redis]",
145+
"mcp-contextforge-gateway[redis]",
146146
]
147147
dev-all = [
148-
"mcpgateway[redis,dev]",
148+
"mcp-contextforge-gateway[redis,dev]",
149149
]
150150

151151
# --------------------------------------------------------------------

0 commit comments

Comments
 (0)