Skip to content

[FEATURE] Lazy connecting to MCP Server when creating a strands agent #868

@rliuamzn

Description

@rliuamzn

Problem Statement

Existing code of creating creating a strands agent with mcp client

We can see connecting to MCP Server to list tools is in the critical path of creating a strands agent to server a user prompt.

# existing code 

    http_mcp_client = MCPClient(
        lambda: streamablehttp_client(
            url="my-remote-mcp.com/mcp",
            auth=...,
            headers={},
        )
    )

    with http_mcp_client:
        # fetch latest tool list, contributing high latency !!!
        mcp_tools = http_mcp_client.list_tools_sync()

        agent = Agent(model=model, tools=filtered_tools)

        #  agent.stream_async(payload.user_prompt) ...

What we want:

Initialize Strands agents with tool spec list and mcp client. Connecting to MCP Server is not in critical path of creating strands agent. Only when a tool use is required, MCP client will be used to connect to the MCP Server.

# desired
    http_mcp_client = MCPClient(
        lambda: streamablehttp_client(
            url="my-remote-mcp.com/mcp",
            auth=...,
            headers={},
        )
    )

    with http_mcp_client:
        # hardcode a list of tool specs, so we can skip connecting to MCP server when constructing a strands agent
        # mcp client is used for calling mcp tool only when needed
        mcp_tools: list[Union[str, dict[str, str] = [
             # hardcoded tool specs + http_mcp_client
        ]

        agent = Agent(model=model, tools=mcp_tools)

        #  agent.stream_async(payload.user_prompt) ...
        # only when payload mentions tool call us needed, mcp client will be used to connect to the mcp tool

Proposed Solution

No response

Use Case

This feature request can help us build low latency agent with AgentCore. Currently connecting to mcp server to list tools is in the critical path:

app = BedrockAgentCoreApp()

@app.entrypoint
async def strands_agent_bedrock_streaming(payload):
    user_input = payload.get("prompt")
    with http_mcp_client:
        all_mcp_tools = http_mcp_client.list_tools_sync()
        agent = Agent(model=model, tools=all_mcp_tools)
        ....

Alternatives Solutions

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions