Skip to content

Commit 8b5c296

Browse files
committed
feat: Add warning for non-primitive state values that may not serialize correctly into headers.
1 parent 8b1973f commit 8b5c296

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/google/adk/tools/mcp_tool/mcp_toolset.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ def provider(ctx: ReadonlyContext) -> Dict[str, str]:
103103
value = ctx.state.get(state_key, default_value)
104104
if value is None:
105105
return {}
106+
if not isinstance(value, (str, int, float, bool)):
107+
logger.warning(
108+
'Value for state key "%s" is of type %s, which may not serialize'
109+
' correctly into a header. Consider pre-serializing complex values or'
110+
' using a different header_format.',
111+
state_key,
112+
type(value).__name__,
113+
)
106114
formatted_value = header_format.format(value=value)
107115
return {header_name: formatted_value}
108116

@@ -297,6 +305,14 @@ def config_based_header_provider(
297305
for state_key, header_name in state_mapping.items():
298306
value = ctx.state.get(state_key)
299307
if value is not None:
308+
if not isinstance(value, (str, int, float, bool)):
309+
logger.warning(
310+
'Value for state key "%s" is of type %s, which may not'
311+
' serialize correctly into a header. Consider pre-serializing'
312+
' complex values or using a different header_format.',
313+
state_key,
314+
type(value).__name__,
315+
)
300316
# Apply formatting if specified for this header
301317
if header_name in state_format:
302318
formatted_value = state_format[header_name].format(value=value)

0 commit comments

Comments
 (0)