[Python] VSCode and Terminal result differently in identifying MCP Tools

Discussão em 'Python' iniciado por Stack, Junho 8, 2025.

  1. Stack

    Stack Membro Participativo

    I have this code

    import os
    import sys
    from dotenv import load_dotenv
    load_dotenv()
    from praisonaiagents import Agent, MCP

    agent = Agent(
    instructions="You are a Precise Assistant.",
    llm="ollama/llama3.2",
    tools=MCP("python server.py"),
    )
    agent.start("What is Apple’s stock price?")
    agent.start("What is Melbourne's Weather?")
    agent.start("What is the special of 3 and 4?")


    Where the server is

    from mcp.server.fastmcp import FastMCP
    import asyncio

    mcp = FastMCP("DemoServer")

    @mcp.tool()
    async def get_weather(city: str) -> str:
    """Get the current weather for a given city using wttr.in."""
    import httpx
    url = f"https://wttr.in/{city}?format=3"
    headers = {
    "User-Agent": (
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) "
    "AppleWebKit/537.36 (KHTML, like Gecko) "
    "Chrome/114.0.0.0 Safari/537.36"
    )
    }
    async with httpx.AsyncClient(headers=headers) as client:
    response = await client.get(url)
    return response.text.strip()

    @mcp.tool()
    async def get_stock_price(symbol: str) -> str:
    """Get the current stock price using yfinance."""
    import yfinance as yf
    stock = yf.Ticker(symbol)
    data = stock.info
    return f"{symbol.upper()} current price: ${data['regularMarketPrice']}"

    @mcp.tool()
    def get_special_number(a: int, b: int) -> int:
    """
    Provide a special number of the two numbers.

    Args:
    a (int): The first number
    b (int): The second number

    Returns:
    int: The secret number of the two numbers
    """
    return int(a) + int(b) + 1000


    if __name__ == "__main__":
    mcp.run(transport="stdio")


    When I run on terminal python environment, all good. It can detect the tools function

    ╭─ Agent Info ───────────────────────────────────────────────────────────────────────────────────────────────╮
    │ │
    │ Agent: Agent │
    │ Role: Assistant │
    │ Tools: get_weather, get_stock_price, get_special_number │
    │ │
    ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────╯


    However when I run it on VS Code environment, no tools are detected

    [11:52:51] WARNING [11:52:51] mcp.py:398 WARNING No MCP tools available to convert to OpenAI mcp.py:398
    format
    INFO [11:52:51] llm.py:296 INFO Getting response from ollama/llama3.2 llm.py:296
    ╭─ Agent Info ─────────────────────────────────────────────────────────────────────────────────────────╮
    │ │
    │ Agent: Agent │
    │ Role: Assistant │
    │ │
    ╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯


    I check the .env all works. The server.py is detected by both. What cause the different?

    Continue reading...

Compartilhe esta Página