Description
** Please make sure you read the contribution guide and file the issues in the rigth place. **
Contribution guide.
Describe the bug
I am using adk web from a shell. I have a mcp tool "print_env_var" which can print the environment variable.
The environment variables of the shell are not accessible to the mcp server.
To Reproduce
Steps to reproduce the behavior:
@mcp.tool()
def print_env_variables(env_var_name: str):
"""Prints the value of the specified environment variable.
Args:
env_var_name (str): The name of the environment variable to print.
Returns:
str: The value of the environment variable.
"""
env_var_value = os.getenv(env_var_name)
if env_var_value is not None:
return f"{env_var_name}: {env_var_value}"
else:
return f"Environment variable '{env_var_name}' not found."
This is in /path/to/mcp_script.py
and I am using python /path/to/mcp_script.py
for mcp stdio connection.
async def get_tools_async():
"""Gets tools from the File System MCP Server."""
print("Attempting to connect to MCP Filesystem server...")
tools, exit_stack = await MCPToolset.from_server(
# Use StdioServerParameters for local process communication
connection_params=StdioServerParameters(
command="python", # Command to run the server
args=[
f"/path/to/mcp_server.py",
],
)
)
print("MCP Toolset created successfully.")
return tools, exit_stack
I am adding this function to the agent.
tools, exit_stack = await get_tools_async()
root_agent = Agent(
model=llm,
name="root_agent",
description="""An agent that can check env variable.""",
instruction="""You are an agent whose job is to print environment variables through print_env_variables.
""",
tools=tools,
)
Then I run adk web, select the agent and ask question on a specific env variable (say PATH)
The agent says - I don't have access to env var.
Expected behavior
The mcp function should be running on the base shell the adk web
is created.
It seems like the adk/mcp is created on a completely new virtual shell without access to the existing environment variables.
This is really an IMPORTANT factor.
Screenshots
Desktop (please complete the following information):
- OS: [e.g. iOS] - Linux, "SUSE Linux Enterprise Server 15 SP4"
- Python version(python -V): Python 3.11.1
- ADK version(pip show google-adk): google-adk==0.5.0
Additional context
Add any other context about the problem here.