Skip to content

Commit f14865b

Browse files
Karanraj-6radugheo
authored andcommitted
feat: add server name validation to MCP config loader
1 parent 2cc3817 commit f14865b

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath-mcp"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
description = "UiPath MCP SDK"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.11"

src/uipath_mcp/_cli/_utils/_config.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import logging
33
import os
4+
import re
45
from typing import Any
56

67
logger = logging.getLogger(__name__)
@@ -66,16 +67,30 @@ def exists(self) -> bool:
6667
"""Check if mcp.json exists"""
6768
return os.path.exists(self.config_path)
6869

70+
@staticmethod
71+
def validate_server_name(name: str) -> None:
72+
"""
73+
Validate the server name.
74+
75+
The server name must only contain letters (a-z, A-Z), numbers (0-9), and hyphens (-).
76+
Raises a ValueError if the name is invalid.
77+
"""
78+
if not re.match(r"^[a-zA-Z0-9-]+$", name):
79+
raise ValueError(
80+
f'Invalid server name "{name}": only letters, numbers, and hyphens are allowed.'
81+
)
82+
6983
def _load_config(self) -> None:
7084
"""Load and process MCP configuration."""
7185
try:
7286
with open(self.config_path, "r") as f:
7387
self._raw_config = json.load(f)
7488

7589
servers_config = self._raw_config.get("servers", {})
76-
self._servers = {
77-
name: McpServer(name, config) for name, config in servers_config.items()
78-
}
90+
self._servers = {}
91+
for name in servers_config.keys():
92+
self.validate_server_name(name)
93+
self._servers[name] = McpServer(name, servers_config[name])
7994

8095
except json.JSONDecodeError as e:
8196
logger.error(f"Invalid JSON in {self.config_path}: {str(e)}")

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)