- The agent receives a user prompt (e.g. “List all pets”)
- It calls
searchto discover relevant endpoints in the OpenAPI spec - It calls
executewith afetch()script targeting the right endpoint - Blaxel spins up a sandbox, injects credentials, and runs the code
- The result flows back to the agent
- The agent typically does a search first to find the right endpoint, then executes a
fetchcall. - When an agent calls
search, code mode evaluates a JavaScript function against the in-memory OpenAPI specification. All$refpointers are auto-resolved so the agent sees the complete schema. - When an agent calls
execute, the code runs inside an auto-scaling sandbox with a 10-minute idle TTL.
Deployment
Use the following code or Blaxel CLI command to deploy an MCP server in code mode. Replace theOPENAPI_REFERENCE variable with the URL to the API specification you want to expose.
DEPLOYED, any agent can use the MCP server as a tool provider.
Authentication
Code mode MCP servers auto-detects security schemes defined in the OpenAPI spec and maps them to environment variables namedAUTH_<SCHEME_NAME>. For example, if the spec defines a scheme called ApiKeyAuth, define an environment variable in your deployment schema called AUTH_APIKEYAUTH with the corresponding secret:
Supported auth types
| OpenAPI scheme type | Env var usage |
|---|---|
http / bearer | Authorization: Bearer <token> |
http / basic | Authorization: Basic <base64> |
apiKey (header) | Custom header with the key value |
apiKey (query) | Appended as query parameter |
oauth2 / openIdConnect | Authorization: Bearer <token> |
Use Claude Agent SDK with MCP code mode on Blaxel
Build an agent that connects to a Blaxel MCP server running in code mode using Claude Agent SDK.
