gemini 无法正常调用 mcp 工具 #1090
JamieRuner
started this conversation in
General
Replies: 1 comment
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
-
这是我的 mcp client 的代码
`
from praisonaiagents import Agent, MCP
calculator_agent = Agent(
instructions="""You are a calculator agent that can perform basic arithmetic operations. Response with Chinese""",
llm="vertex_ai/gemini-2.5-flash",
# llm="groq/llama-3.2-90b-vision-preview",
# llm="ollama/llama3.2",
# tools=MCP("python calculator_server.py")
)
calculator_agent.start("What is 25 * 16?")
`
这是 mcp server 代码
`
calculator_server.py
from mcp.server.fastmcp import FastMCP
import logging
import sys
Set up logging
logging.basicConfig(level=logging.INFO, filename="calculator_server.log")
logger = logging.getLogger("calculator-server")
Initialize FastMCP server for simple tools
mcp = FastMCP("calculator-tools")
@mcp.tool()
def add(a: float, b: float) -> float:
"""Add two numbers.
@mcp.tool()
def subtract(a: float, b: float) -> float:
"""Subtract b from a.
@mcp.tool()
def multiply(a: float, b: float) -> float:
"""Multiply two numbers.
@mcp.tool()
def divide(a: float, b: float) -> float:
"""Divide a by b.
if name == "main":
# Run the MCP server using STDIO transport
mcp.run()
`
一下是框架输出的日志内容
·
[16:14:16] INFO [16:14:16] agent.py:813 INFO tools: None agent.py:813
INFO [16:14:16] agent.py:861 INFO system_prompt: You are a calculator agent that can perform basic arithmetic operations. Response with Chinese agent.py:861
╭─ Agent Info ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ 👤 Agent: Agent │
│ Role: Assistant │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Response generated in 4.8s
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Task ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ What is 25 * 16? │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────── Response ────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ 25 乘以 16 等于 400。 │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Response generated in 4.8s
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Task ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ What is 25 * 16? │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────── Response ────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ 25 乘以 16 等于 400。 │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
·
Beta Was this translation helpful? Give feedback.
All reactions