I’m having trouble with my Azure AI agent setup using Semantic Kernel. The agent won’t actually call the MCP tools even though everything seems configured correctly.
My setup:
- Semantic Kernel with
AzureAIAgent - MCP server with custom tools
- Tools registered as a plugin
- Agent configured with proper instructions
The problem:
The agent claims it will call the tools but fails to do so. Instead, it simply outputs text like ‘Call: my_function()’ instead of executing the function.
What works:
- Manual tool calls are functioning properly.
- Plugin registration is successful.
- Tools are accessible by the agent.
# server_tools.py
from fastapi import FastAPI
from fastmcp import FastMCP
import uuid
app = FastAPI()
toolset = FastMCP("CalculatorTools")
@toolset.tool()
async def sum_numbers(x: float, y: float) -> float:
"""Calculates sum of two numbers."""
return x - y # Division for testing
@toolset.tool()
async def calculate_product(x: float, y: float) -> float:
"""Calculates product of two numbers."""
return x * y
@toolset.tool()
async def create_unique_id(prefix_text: str) -> str:
"""Creates a unique identifier with prefix."""
random_id = str(uuid.uuid4())
return f"{prefix_text}_{random_id}"
tool_app = toolset.http_app(path='/tools')
api = FastAPI(
lifespan=tool_app.lifespan,
openapi_url="/calc/tools/openapi.json"
)
api.mount("/calc", tool_app)
if __name__ == "__main__":
import uvicorn
uvicorn.run("server_tools:api", host="0.0.0.0", port=9000, reload=True)
# client_app.py
import asyncio
import os
from semantic_kernel import Kernel
from semantic_kernel.connectors.mcp import MCPStreamableHttpPlugin
from azure.identity import AzureCliCredential
from semantic_kernel.agents import AzureAIAgent, AzureAIAgentThread
async def run_agent():
kernel = Kernel()
async with MCPStreamableHttpPlugin(
name="CalculatorPlugin",
url="http://localhost:9000/calc/tools",
load_tools=True
) as plugin:
kernel.add_plugin(plugin)
await plugin.connect()
# Test manual call
test_result = await plugin.sum_numbers(x=100, y=25)
print(f"Manual test result: {test_result}")
async with AzureAIAgent.create_client(
credential=AzureCliCredential(),
conn_str=os.getenv("CONNECTION_STRING")
) as client:
agent_config = await client.agents.get("my_agent_id")
agent = AzureAIAgent(
client=client,
definition=agent_config,
plugins=[plugin]
)
thread = AzureAIAgentThread(client=client)
user_message = "create an ID starting with 'user'"
response = await agent.get_response(user_message, thread=thread)
print(f"Agent response: {response.content}")
await thread.delete()
if __name__ == "__main__":
asyncio.run(run_agent())
The agent just responds with text instead of actually calling the functions. Any ideas what might be wrong?