How to Pass MCP Tool Output to CodeInterpreterTool in CrewAI

Hi team,

Goal

Answer user questions by dynamically writing and executing Python code on data returned from APIs.


Current Setup

  • I have built an MCP server with one or more tools.

  • Each MCP tool:

    • Calls a specific API endpoint

    • Returns data (often large datasets, e.g., 800–1000 rows as a list of dictionaries)

  • I have created a CrewAI agent with the following tools:

    • CodeInterpreterTool

    • MCP tools


Intended Flow

Input

  • User asks a question

  • Example: “What is the highest material value?”

Data Fetching

  • An MCP tool is called

  • The tool returns the required dataset

Data Manipulation (Core Requirement)

  • The agent should dynamically write Python code

  • That Python code should:

    • Receive the MCP tool output as input

    • Manipulate/analyze the data

    • Produce the final answer

Example:

  • The agent writes Python code to compute the maximum value from the dataset.

Problem / Blocker

I am able to receive the data from the MCP server, but I am stuck at the next step.


Questions

  1. How can I pass the output of an MCP tool into the CodeInterpreterTool for data manipulation?

  2. Is it possible for the CodeInterpreterTool to directly call an MCP tool?

  3. any ideas to solve above blocker