adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

ADK giving error with MCP tools || parsing start time: syntax error: unexpected $end

Open amansingh207 opened this issue 1 year ago • 2 comments

I have deployed mcp-grafana on kubernetes and connected my grafana instance. I have created an agent using google-adk which can use the mcp-grafana tools in the sse mode.

I ask questions on google-adk UI. It works fine in most of the cases. I can search for dashboards, get the panel queries, ask about alert rules and things are working fine.

The issue: Whenever I ask for the exact values inside the dsahboard or something that needs to query prometheus, it does not work and gives me error like this:

[Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: Error in event_generator: parsing start time: syntax error: unexpected $end, expecting tNOW or tDIGIT at character 2 starting with "" [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: Traceback (most recent call last): [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: File "/usr/local/lib/python3.12/site-packages/google/adk/cli/fast_api.py", line 916, in event_generator [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: async for event in runner.run_async( [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: File "/usr/local/lib/python3.12/site-packages/google/adk/runners.py", line 233, in run_async [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: async for event in self._exec_with_plugin( [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: File "/usr/local/lib/python3.12/site-packages/google/adk/runners.py", line 273, in _exec_with_plugin [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: async for event in execute_fn(invocation_context): [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: File "/usr/local/lib/python3.12/site-packages/google/adk/runners.py", line 230, in execute [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: async for event in ctx.agent.run_async(ctx): [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: File "/usr/local/lib/python3.12/site-packages/google/adk/agents/base_agent.py", line 209, in run_async [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: async for event in self._run_async_impl(ctx): [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: File "/usr/local/lib/python3.12/site-packages/google/adk/agents/llm_agent.py", line 283, in _run_async_impl [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: async for event in self._llm_flow.run_async(ctx): [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: File "/usr/local/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 290, in run_async [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: async for event in self._run_one_step_async(invocation_context): [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: File "/usr/local/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 322, in _run_one_step_async [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: async for event in self._postprocess_async( [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: File "/usr/local/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 407, in _postprocess_async [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: async for event in self._postprocess_handle_function_calls_async( [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: File "/usr/local/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 482, in _postprocess_handle_function_calls_async [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: if function_response_event := await functions.handle_function_calls_async( [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: File "/usr/local/lib/python3.12/site-packages/google/adk/flows/llm_flows/functions.py", line 179, in handle_function_calls_async [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: function_response = await __call_tool_async( [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: ^^^^^^^^^^^^^^^^^^^^^^^^ [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: File "/usr/local/lib/python3.12/site-packages/google/adk/flows/llm_flows/functions.py", line 474, in __call_tool_async [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: return await tool.run_async(args=args, tool_context=tool_context) [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: File "/usr/local/lib/python3.12/site-packages/google/adk/tools/base_authenticated_tool.py", line 93, in run_async [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: return await self._run_async_impl( [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: ^^^^^^^^^^^^^^^^^^^^^^^^^^^ [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: File "/usr/local/lib/python3.12/site-packages/google/adk/tools/mcp_tool/mcp_session_manager.py", line 128, in wrapper [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: return await func(self, *args, **kwargs) [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: File "/usr/local/lib/python3.12/site-packages/google/adk/tools/mcp_tool/mcp_tool.py", line 133, in _run_async_impl [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: response = await session.call_tool(self.name, arguments=args) [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: File "/usr/local/lib/python3.12/site-packages/mcp/client/session.py", line 293, in call_tool [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: result = await self.send_request( [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: ^^^^^^^^^^^^^^^^^^^^^^^^ [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: File "/usr/local/lib/python3.12/site-packages/mcp/shared/session.py", line 286, in send_request [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: raise McpError(response_or_error.error) [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: mcp.shared.exceptions.McpError: parsing start time: syntax error: unexpected $end, expecting tNOW or tDIGIT at character 2 starting with "" [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: Failed to detach context [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: Traceback (most recent call last): [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: File "/usr/local/lib/python3.12/site-packages/opentelemetry/trace/init.py", line 589, in use_span [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: yield span [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: File "/usr/local/lib/python3.12/site-packages/opentelemetry/sdk/trace/init.py", line 1105, in start_as_current_span [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: yield span [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: File "/usr/local/lib/python3.12/site-packages/opentelemetry/trace/init.py", line 454, in start_as_current_span [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: yield span [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: File "/usr/local/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 573, in _call_llm_async [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: yield llm_response [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: GeneratorExit [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: During handling of the above exception, another exception occurred: [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: Traceback (most recent call last): [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: File "/usr/local/lib/python3.12/site-packages/opentelemetry/context/init.py", line 155, in detach [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: _RUNTIME_CONTEXT.detach(token) [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: File "/usr/local/lib/python3.12/site-packages/opentelemetry/context/contextvars_context.py", line 53, in detach [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: self._current_context.reset(token) [Aug 18 2025 13:48:33 GMT+0530] adk-agent-6895b79487-59mlh: ValueError: <Token var=<ContextVar name='current_context' default={} at 0x7a28f0c622f0> at 0x7a28dee9fa80> was created in a different Context

I am not sure what am I doing wrong here. Apart from these all other queries are working fine. I used other MCPs as well and they also seem to work fine.

SS:

Image

LLM model used: gpt-4.1-mini behind self hosted lite-llm.

To Reproduce Steps to reproduce the behavior:

  1. Deploy mcp-grafana in sse mode from this github repo: https://github.com/grafana/mcp-grafana
  2. Create a root agent with tool list including the above mcp server
  3. In the adk ui ask questions about your grafana instance.
  4. you will see all the questions answered correctly apart from the ones which require querying to prometheus.

Expected behavior It should run the prom query and give the correct result.

Additional context This open source mcp is being used: https://github.com/grafana/mcp-grafana the mcp expects the time to be in RFC3339 format this is the code for mcp: https://github.com/grafana/mcp-grafana/blob/main/tools/prometheus.go This MCP is working fine with cursor, n8n and some other tools that i have used.

Please let me know if anything else is required.

amansingh207 avatar Aug 21 '25 12:08 amansingh207

can you attach the agent.py file you used? I think it's likely a problem with the LLM outputting the wrong time format. To fix, you can try improving the agent's prompt and tool definition to specify the time format it should use, i.e. "Use RFC3339 format (e.g., YYYY-MM-DDTHH:MM:SSZ)"

wukath avatar Nov 06 '25 01:11 wukath

Closing as it's likely a model issue.

hangfei avatar Nov 11 '25 04:11 hangfei