Back to blog

How to Interact with Any REST API Using YepCode Run and MCP Tools

LLMs are getting smarter every day — but how do we turn their potential into real, secure, and scalable workflows?

In this video, we show how to connect the dots using YepCode Run and MCP tools, automating interactions with Factorial’s REST API using nothing more than generated code and a bit of smart orchestration.

Whether you’re trying to pull data, trigger operations, or integrate with other systems like Supabase, the combination of LLMs + YepCode Run + MCP gives you the power and flexibility to do it all — with minimal human intervention.

From Prompt to Code Execution

We start by setting up an intelligent agent (in this case, using Claude Desktop) with a prompt that instructs it to solve tasks by generating and executing code through YepCode Run:

You are a helpful assistant responsible for solving tasks through code generation and execution using the YepCode Run Code MCP tool.

# Task

Generate and execute scripts using the YepCode Run Code MCP tool to perform operations as specified by the user. Outputs should be gathered and presented in a format that is clear and informative.

# Steps

1. **Review User Information**: Examine all provided user information, which may include API specifications, database environments or web references.
   
2. **Identify Operations**: Determine the necessary operations and workflows that need to be executed based on the user requirements.

3. **Environment Variables**: Identify the current run_code tool environment variables to authenticate or configure the required services effectively. If you need any credential that is not defined, ask the user to configure it on YepCode Dashboard.

4. **Script Writing**: Develop scripts to execute the identified operations using the YepCode platform. Ensure scripts are well-commented for clarity and understanding.

5. **Execution**: Execute the developed scripts with the YepCode run_code MCP tool. Collect and document the outputs or results obtained.

6. **Error Handling**: In case of execution errors, use the log and error information to refine and adapt the script to ensure successful execution.

# Output Format

- Provide any output or results from the script execution in a clear and logical format.

# Other tools

You can use available MCP tools to get information to be used during script creation:

* OpenAPI exploration tool: If you want to use one REST API, and you have the JSON or YAML specs URL, you may use this tool to find the available operations, and then get the full operation details to be more precise writting the code. If you are going to use one REST API, be sure to use this tool before, and if you don't know where the API Specs URL is, you may ask this to the user.

# Important Notes

- Use only the user-provided information and avoid assumptions.
- Maintain verbose logging within the scripts to facilitate debugging.
- Consider breaking down the task into multiple script executions if complex operations are involved.
- If script execution fails, try to rewrite it and go ahead on your own. Asking the user would be the last option.

After adding the initial guidelines, we can start to ask for tasks:

The agent is set up to solve tasks by generating and executing code with YepCode Run

Exploring APIs with OpenAPI Exploration Tool

To avoid flooding the agent with thousands of tokens from an OpenAPI spec, we’ve built a dedicated MCP tool: the OpenAPI Exploration Tool.

This tool allows the agent to progressively explore an API:

  • First retrieving available tags and their descriptions.
  • Then drilling down into specific operations.
  • Finally, fetching full operation payloads only when needed.
The OpenAPI Exploration Tool lets the agent explore Factorial’s API step-by-step.

Retrieve Employees information in Factorial

Using the exploration tool, the agent finds the right endpoint and writes code to count employees in Factorial. On its first attempt, the script fails — but the agent detects the issue, rewrites the code, and tries again.

The initial script fails, but the agent debugs and rewrites the code automatically.

After some iterations, the agent retrieves the requested information:

The agent retrieves and logs the number of employees

Creating Time-Off Requests Automatically

Next, we ask the agent to create a leave request for an employee named Elizabeth during the last week of June. The agent:

  • Looks up the relevant endpoints.
  • Retrieves the employee ID using her email.
  • Checks available leave types.
  • Submits the request.
The second prompt asks the agent to create a leave request for a specific employee.

This Isn’t Just Another REST API Wrapper

Although this flow might initially seem like just a smart wrapper over a REST API, it’s much more than that. What we’re building here is a flexible and extensible system where the agent isn’t limited to a predefined set of endpoints or rigid logic. Instead, it understands the context, explores APIs dynamically, and generates custom code to solve tasks — even combining multiple services or adapting to different environments as needed.

To take it a step further, we challenge the agent to store the employee data in Supabase. It attempts to create the table programmatically, fails, asks us for help — and after we manually create the table, it stores the data successfully.

The agent is prompted to store employee data in Supabase

A Glimpse into the Future of Workflow Automation

It might feel like using a sledgehammer to crack a nut — but with LLMs getting better and better at generating high-quality code, this approach makes a lot of sense. It’s not just about automating a simple task, but about building an environment where agents can adapt, iterate, and solve complex workflows autonomously. We’re laying the foundation for a new way of interacting with APIs and systems: smarter, more flexible, and with almost limitless potential.

Curious to try this for your own API or use case? Contact us — we’d love to hear what you’re building.

Last articles

See all articles