Body:
Hi,
I'm using LangGraph to call langchain-mcp-adapters and set up an MCP server. I have a question about securely passing authentication tokens (such as an API key) into an MCP tool function.
For example, given this MCP tool:
@mcp.tool()
async def get_weather(location: str) -> str:
"""Get weather for location."""
return "It's always sunny in New York"
How can I pass an API token (used to call an external weather API) into this function? What's the recommended way to make sure the token is accessible inside get_weather? Should I use function parameters, environment variables, context, or something else?
If possible, could you provide a concrete code example of how to do this with langchain-mcp-adapters and LangGraph?
Thank you!
Body:
Hi,
I'm using LangGraph to call langchain-mcp-adapters and set up an MCP server. I have a question about securely passing authentication tokens (such as an API key) into an MCP tool function.
For example, given this MCP tool:
How can I pass an API token (used to call an external weather API) into this function? What's the recommended way to make sure the token is accessible inside
get_weather? Should I use function parameters, environment variables, context, or something else?If possible, could you provide a concrete code example of how to do this with langchain-mcp-adapters and LangGraph?
Thank you!