Skip to main content
Glama
andydukes
by andydukes

create_prediction

Send questions to Flowise chatflows or assistants to generate AI predictions and receive JSON responses.

Instructions

Create a prediction by sending a question to a specific chatflow or assistant.

Args:
    chatflow_id (str, optional): The ID of the chatflow to use. Defaults to FLOWISE_CHATFLOW_ID.
    question (str): The question or prompt to send to the chatflow.

Returns:
    str: The raw JSON response from Flowise API or an error message if something goes wrong.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chatflow_idNo
questionYes

Implementation Reference

  • Handler function for the 'create_prediction' tool, registered via @mcp.tool(). Handles input parameters, determines chatflow_id, calls flowise_predict, and returns the result or error.
    @mcp.tool()
    def create_prediction(*, chatflow_id: str = None, question: str) -> str:
        """
        Create a prediction by sending a question to a specific chatflow or assistant.
    
        Args:
            chatflow_id (str, optional): The ID of the chatflow to use. Defaults to FLOWISE_CHATFLOW_ID.
            question (str): The question or prompt to send to the chatflow.
    
        Returns:
            str: The raw JSON response from Flowise API or an error message if something goes wrong.
        """
        logger.debug(f"create_prediction called with chatflow_id={chatflow_id}, question={question}")
        chatflow_id = chatflow_id or FLOWISE_CHATFLOW_ID
    
        if not chatflow_id and not FLOWISE_ASSISTANT_ID:
            logger.error("No chatflow_id or assistant_id provided or pre-configured.")
            return json.dumps({"error": "chatflow_id or assistant_id is required"})
    
        try:
            # Determine which chatflow ID to use
            target_chatflow_id = chatflow_id or FLOWISE_ASSISTANT_ID
    
            # Call the prediction function and return the raw JSON result
            result = flowise_predict(target_chatflow_id, question)
            logger.debug(f"Prediction result: {result}")
            return result  # Returning raw JSON as a string
        except Exception as e:
            logger.error(f"Unhandled exception in create_prediction: {e}", exc_info=True)
            return json.dumps({"error": str(e)})
  • Supporting utility function that performs the actual HTTP POST request to Flowise API's /prediction endpoint to get the prediction result.
    def flowise_predict(chatflow_id: str, question: str) -> str:
        """
        Sends a question to a specific chatflow ID via the Flowise API and returns the response JSON text.
    
        Args:
            chatflow_id (str): The ID of the Flowise chatflow to be used.
            question (str): The question or prompt to send to the chatflow.
    
        Returns:
            str: The raw JSON response text from the Flowise API, or an error message if something goes wrong.
        """
        logger = logging.getLogger(__name__)
    
        # Construct the Flowise API URL for predictions
        url = f"{FLOWISE_API_ENDPOINT.rstrip('/')}/api/v1/prediction/{chatflow_id}"
        headers = {
            "Content-Type": "application/json",
        }
        if FLOWISE_API_KEY:
            headers["Authorization"] = f"Bearer {FLOWISE_API_KEY}"
    
        payload = {"question": question}
        logger.debug(f"Sending prediction request to {url} with payload: {payload}")
    
        try:
            # Send POST request to the Flowise API
            response = requests.post(url, json=payload, headers=headers, timeout=30)
            logger.debug(f"Prediction response code: HTTP {response.status_code}")
            # response.raise_for_status()
    
            # Log the raw response text for debugging
            logger.debug(f"Raw prediction response: {response.text}")
    
            # Return the raw JSON response text
            return response.text
    
        #except requests.exceptions.RequestException as e:
        except Exception as e:
            # Log and return an error message
            logger.error(f"Error during prediction: {e}")
            return json.dumps({"error": str(e)})
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It reveals this is a write operation ('Create a prediction') that makes an API call ('sending a question to a specific chatflow'), and mentions potential error responses. However, it lacks details about authentication requirements, rate limits, side effects, or what constitutes a successful prediction. The mention of 'raw JSON response' is helpful but vague.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately concise with three focused sentences. The first states the purpose, the second explains parameters, and the third describes returns. There's no wasted text, though the structure could be slightly improved by integrating the parameter explanations more naturally rather than using 'Args:' formatting.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a write operation with no annotations and no output schema, the description provides basic but incomplete context. It covers the core action and parameters adequately, but lacks information about authentication, error handling specifics, response format details beyond 'raw JSON,' and how this interacts with the sibling 'list_chatflows' tool. The absence of output schema increases the burden on the description.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description must compensate for the schema's lack of parameter documentation. It successfully explains both parameters: 'chatflow_id' as 'The ID of the chatflow to use' with its default, and 'question' as 'The question or prompt to send to the chatflow.' This adds meaningful context beyond the bare schema, though it doesn't elaborate on format constraints or examples.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Create a prediction by sending a question to a specific chatflow or assistant.' It specifies the verb ('create a prediction') and resource ('chatflow or assistant'), though it doesn't explicitly distinguish from the sibling tool 'list_chatflows' (which appears to be a read operation vs. this write operation).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It mentions 'specific chatflow or assistant' but doesn't explain how to choose between them or when to use this versus other prediction tools. There's no mention of prerequisites, constraints, or typical use cases.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/andydukes/mcp-flowise'

If you have feedback or need assistance with the MCP directory API, please join our Discord server