Skip to main content
Blaxel supports “code mode” natively, enabling a more efficient way to execute tool calls over MCP. Essentially, code mode turns any OpenAPI specification into a two-tool MCP server: search lets an AI agent explore the API spec, and execute runs JavaScript code in a sandbox to call the actual API. This tutorial demonstrates by deploying an API as an MCP server on Blaxel and using an agent to work with it. It uses the Claude Agent SDK, but you could also use other frameworks like LangChain, Vercel AI SDK, Mastra, or your own custom code.
For more information on “code mode” or “code execution with MCP”, refer to blog posts by Cloudflare and Anthropic.

Prerequisites

1. Install required dependencies

In your project directory, install the Claude Agent SDK for the agent loop and the Blaxel TypeScript SDK / Python SDK for sandbox operations:
Export your API keys to the local environment:

2. Build and deploy an MCP server in code mode

This tutorial creates and deploys an MCP server for the example Petstore v2 API. In your project directory, create and run a file named setup.ts (TypeScript) or setup.py (Python) with the following code, or use the Blaxel CLI command shown, to deploy the API on Blaxel.
Check the deployment status:
Once the status shows DEPLOYED, any agent can use petstore-code-mode as a tool provider.

3. Build the agent

Obtain the MCP server URL with the following command:
In your project directory, create a file named index.ts (TypeScript) or main.py (Python) with the following code. Replace the placeholder with the MCP server URL from the previous command.

4. Test the agent

Send the agent a query:
You should see the agent using the two available tools, first searching for the correct API endpoint and then writing and executing code to query the API and respond to your prompt. In case of errors, you can view the logs of the deployed MCP server with the command below:
The following resources will help you go further:

Build and deploy an agent on Blaxel with Claude Agent SDK

Complete tutorial for building an agent with Claude Agent SDK and deploying it on Blaxel as a serverless auto-scalable API.

Give compute to your agent with the TypeScript SDK

Complete tutorial for using the TypeScript SDK to develop an agent using Blaxel services.

Give compute to your agent with the Python SDK

Complete tutorial for using the Python SDK to develop an agent using Blaxel services.

Deploy your agent code to Blaxel

Complete tutorial for deploying AI agents to Blaxel.
Last modified on May 18, 2026