Skip to content

Python: [Bug]: as_agent tools typing rejects MCPStdioTool #3936

@moonbox3

Description

@moonbox3

When I pass MCPStdioTool in client.as_agent(..., tools=[...]), static type checking fails with reportArgumentType.

What happened:

  1. Create a file with the code sample below.
  2. Run uv run pyright <file>.py.
  3. Pyright reports MCPStdioTool is not assignable to as_agent(..., tools=...).

What I expected:

  • MCPStdioTool should be accepted by type checking for as_agent(..., tools=...), or docs should explicitly say MCP tools must only be passed at run time.

Code Sample

# Copyright (c) Microsoft. All rights reserved.

import asyncio
import os
from random import randint
from typing import Annotated

from agent_framework import MCPStdioTool, tool
from agent_framework.azure import AzureOpenAIResponsesClient
from azure.identity import AzureCliCredential
from pydantic import Field


@tool(approval_mode="never_require")
def get_weather(
    location: Annotated[str, Field(description="The location to get the weather for.")],
) -> str:
    conditions = ["sunny", "cloudy", "rainy", "stormy"]
    return f"The weather in {location} is {conditions[randint(0, 3)]} with a high of {randint(10, 30)}°C."


async def main() -> None:
    credential = AzureCliCredential()
    client = AzureOpenAIResponsesClient(
        project_endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"],
        deployment_name=os.environ["AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME"],
        credential=credential,
    )

    agent = client.as_agent(
        name="WeatherAgent",
        instructions="You are a helpful weather agent. Use the get_weather tool to answer questions.",
        tools=[
            get_weather,
            MCPStdioTool(
                name="MCP",
                description="A tool for interacting with the MCP system.",
                command="docker",
                args=["run", "--rm", "-i", "microsoft/ai-mcp:latest"],
            ),
        ],
    )

    result = await agent.run("What's the weather like in Seattle?")
    print(f"Agent: {result}")


if __name__ == "__main__":
    asyncio.run(main())

Error Messages / Stack Traces

error: Argument of type "list[FunctionTool[Any] | MCPStdioTool]" cannot be assigned to parameter "tools" of type
"FunctionTool[BaseModel] | ((...) -> Any) | MutableMapping[str, Any] |
 Sequence[FunctionTool[BaseModel] | ((...) -> Any) | MutableMapping[str, Any]] | None"
in function "as_agent" (reportArgumentType)

Package Versions

agent-framework-core: 1.0.0b260212, agent-framework-azure-ai: 1.0.0b260212, agent-framework-anthropic: 1.0.0b260212

Python Version

Python 3.13.5

Additional Context

pyright 1.1.408
Repo commit: 9a0e5a160

Metadata

Metadata

Labels

bugSomething isn't workingpythonv1.0Features being tracked for the version 1.0 GA

Type

No type
No fields configured for issues without a type.

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions