-
Hey! I’m building an Agent that reviews Jira tickets and helps flesh out details. I’m passing in the ticket data programmatically as context for the chat session. Sometimes there’s a linked Confluence page, and I’d like the Agent to pull that in if it’s available. The issue is that the Agent is always trying to use the Confluence tool, even when no URL is present in the context. My question: how do I make the tool usage conditional—only if a Confluence URL is found? Should this logic be handled in the tool’s description, or is there a better way to indicate optional use? Example Tool Class: class GetConfluencePage extends Tool
{
public function __construct()
{
parent::__construct(
'get_confluence_document',
'If a Confluence wiki link is available retrieve a Confluence document by its ID',
);
$this->addProperty(
new ToolProperty(
name: 'document_id',
description: 'The ID of the Confluence document to retrieve',
type: 'string',
required: true,
)
)->setCallable(function(string $document_id): string {
Log::info("Retrieving Confluence document with ID: $document_id");
$doc = (new Confluence)->getPage($document_id);
$response = "### {$doc['title']} - {$doc['url']}\n\n{$doc['content']}";
return $response;
});
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
What AI provider are you using? |
Beta Was this translation helpful? Give feedback.
I could tell it was always calling because it get erroring out with the exception of a missing parameter (
document_id
). I actually did some additional reading on MCP servers and was reviewing how the descriptions were written. I have updated my descriptions so that they are more descriptive and that has seemed to fix the problem. Being more explicit with what the tool does and how it should be used does the trick.Example: