Skip to content

How to Pass API Token to @mcp.tool in langchain-mcp-adapters When Using LangGraph?Β #105

@wen020

Description

@wen020

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions