Skip to content

Commit 1d1c3a7

Browse files
authored
Merge pull request #79 from universal-tool-calling-protocol/dev
Fix some issues
2 parents a9df439 + 9f15e99 commit 1d1c3a7

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

core/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "utcp"
7-
version = "1.1.1"
7+
version = "1.1.2"
88
authors = [
99
{ name = "UTCP Contributors" },
1010
]

core/src/utcp/implementations/default_variable_substitutor.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ def substitute(self, obj: dict | list | str, config: UtcpClientConfig, variable_
100100
raise ValueError(f"Variable namespace '{variable_namespace}' contains invalid characters. Only alphanumeric characters and underscores are allowed.")
101101

102102
if isinstance(obj, str):
103-
# Skip substitution for JSON $ref strings
104-
if '$ref' in obj:
103+
# Skip substitution for JSON Schema $ref (but not variables like $refresh_token)
104+
if re.search(r'\$ref(?![a-zA-Z0-9_])', obj):
105105
return obj
106106

107107
# Use a regular expression to find all variables in the string, supporting ${VAR} and $VAR formats
@@ -168,9 +168,10 @@ def find_required_variables(self, obj: dict | list | str, variable_namespace: Op
168168
result.extend(vars)
169169
return result
170170
elif isinstance(obj, str):
171-
# Skip substitution for JSON $ref strings
172-
if '$ref' in obj:
171+
# Skip JSON Schema $ref (but not variables like $refresh_token)
172+
if re.search(r'\$ref(?![a-zA-Z0-9_])', obj):
173173
return []
174+
174175
# Find all variables in the string, supporting ${VAR} and $VAR formats
175176
variables = []
176177
pattern = r'\${([a-zA-Z0-9_]+)}|\$([a-zA-Z0-9_]+)'

plugins/communication_protocols/http/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "utcp-http"
7-
version = "1.1.0"
7+
version = "1.1.1"
88
authors = [
99
{ name = "UTCP Contributors" },
1010
]

plugins/communication_protocols/http/src/utcp_http/openapi_converter.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,12 @@ class OpenApiConverter:
8383
Attributes:
8484
spec: The parsed OpenAPI specification dictionary.
8585
spec_url: Optional URL where the specification was retrieved from.
86+
base_url: Optional base URL override for all API endpoints.
8687
placeholder_counter: Counter for generating unique placeholder variables.
8788
call_template_name: Normalized name for the call_template derived from the spec.
8889
"""
8990

90-
def __init__(self, openapi_spec: Dict[str, Any], spec_url: Optional[str] = None, call_template_name: Optional[str] = None, auth_tools: Optional[Auth] = None):
91+
def __init__(self, openapi_spec: Dict[str, Any], spec_url: Optional[str] = None, call_template_name: Optional[str] = None, auth_tools: Optional[Auth] = None, base_url: Optional[str] = None):
9192
"""Initializes the OpenAPI converter.
9293
9394
Args:
@@ -98,10 +99,13 @@ def __init__(self, openapi_spec: Dict[str, Any], spec_url: Optional[str] = None,
9899
the specification title is not provided.
99100
auth_tools: Optional auth configuration for generated tools.
100101
Applied only to endpoints that require authentication per OpenAPI spec.
102+
base_url: Optional base URL override for all API endpoints.
103+
When provided, this takes precedence over servers in the spec.
101104
"""
102105
self.spec = openapi_spec
103106
self.spec_url = spec_url
104107
self.auth_tools = auth_tools
108+
self._base_url_override = base_url
105109
# Single counter for all placeholder variables
106110
self.placeholder_counter = 0
107111
if call_template_name is None:
@@ -141,9 +145,12 @@ def convert(self) -> UtcpManual:
141145
"""
142146
self.placeholder_counter = 0
143147
tools = []
144-
servers = self.spec.get("servers")
145-
if servers:
146-
base_url = servers[0].get("url", "/")
148+
149+
# Determine base URL: override > servers > spec_url > fallback
150+
if self._base_url_override:
151+
base_url = self._base_url_override
152+
elif self.spec.get("servers"):
153+
base_url = self.spec["servers"][0].get("url", "/")
147154
elif self.spec_url:
148155
parsed_url = urlparse(self.spec_url)
149156
base_url = f"{parsed_url.scheme}://{parsed_url.netloc}"

0 commit comments

Comments
 (0)