llama-stack: Tool use with MCP is not identifying the tools accurately
System Info
GPU Type: NVIDIA A40 OS: Ubuntu 24.04 CUDA: 12.8 Llama Stack: 0.1.8 Model: Llama 3.2-3B Instruct
Information
- The official example scripts
- My own modified scripts
🐛 Describe the bug
I have been trying to integrate a custom MCP server with Llama Stack for Agent tool use. I have tried the example in the getting started guide with filesystem MCP server. This seems to be working but the tool identification is not accurate. When the prompt is about listing files, the model indicates list directory tool execution.
With the custom MCP servers, the tool identification is inaccurate. Here is what I tried.
- Build a custom MCP server using the steps:
uvx create-mcp-server
# Answer the prompts and name the server as demo-server
cd demo-server
uv sync --dev --all-extras
- Run the server using supergateway.
npx -y supergateway --port 8889 --stdio '/home/user/.local/bin/uv --directory /home/user/demo-server/ run demo-server'
- Run the following program: (make sure you update the HOST and SSE endpoint details)
from llama_stack_client.types.shared_params.url import URL
from llama_stack_client import LlamaStackClient
from llama_stack_client.lib.agents.agent import Agent
from llama_stack_client.lib.agents.event_logger import EventLogger
from llama_stack_client.lib.inference.event_logger import EventLogger as iel
from llama_stack_client.types.shared_params.agent_config import ToolConfig
from termcolor import cprint
import pprint
HOST='192.168.32.46'
PORT=8321
MODEL='meta-llama/Llama-3.2-3B-Instruct'
client = LlamaStackClient(
base_url=f"http://{HOST}:{PORT}",
)
client.toolgroups.register(
toolgroup_id="mcp::demo-server",
provider_id="model-context-protocol-4",
mcp_endpoint=URL(uri="http://192.168.32.46:8889/sse"),
)
agent = Agent(
client,
model=MODEL,
instructions="""
You are a helpful assistant with access to different tools.
You should use the tools from the list available to you
when the user prompt requires any tool usage.
""",
tools=["mcp::demo-server"],
tool_config=ToolConfig(
tool_choice="required"
),
)
pprint.pprint(client.tools.list())
user_prompts = [
"Hello",
"Create a note called demonote about demonstrating Llama Stack and MCP integration."
]
session_id = agent.create_session("demo-session")
for prompt in user_prompts:
cprint(f"User> {prompt}", "green")
response = agent.create_turn(
messages=[
{
"role": "user",
"content": prompt,
}
],
session_id=session_id,
)
for log in EventLogger().log(response):
log.print()
client.toolgroups.unregister(
toolgroup_id="mcp::demo-server"
)
You will see that the first user prompt (Hello) results in a add_note tool call for no reason. The tool call fails because the content field is required and is missing.
- Use the same MCP server with an Ollama local endpoint (with Llama 3.2:3B and mcp-cli) or Claude desktop (Sonnet 3X), it works flawlessly.
Error logs
Tool calling is not accurate.
Expected behavior
Tool calling has to be accurate.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 23 (12 by maintainers)
Commits related to this issue
- feat: update default tool use prompt (#1803) # What does this PR do? User reports in https://github.com/meta-llama/llama-stack/issues/1769#issuecomment-2755564632 that Agent uses tool even on a promp... — committed to meta-llama/llama-stack by ehhuang 2 years ago
- feat: update default tool use prompt (#1803) # What does this PR do? User reports in https://github.com/meta-llama/llama-stack/issues/1769#issuecomment-2755564632 that Agent uses tool even on a promp... — committed to MichaelClifford/llama-stack by ehhuang 2 years ago
As in agent.create_session
Put up https://github.com/meta-llama/llama-stack/pull/1803. Trying to see if I can repro the httpx timeout issue
@rchaganti
from llama_stack_client.types.shared_params.url import URLshould not work in 0.1.8, usefrom llama_stack_client.types.tool_group import McpEndpointinstead, as shown in this PR.