VVoyagent
Overview
AI agents7 min

Code Mode

Let AI agents orchestrate multi-step travel queries by writing sandboxed JavaScript instead of chaining tool calls.

What is Code Mode

Code Mode lets an AI agent orchestrate several travel queries by writing one short JavaScript snippet instead of calling tools one at a time. The snippet calls travel functions like rideclaw.flight.search() and can include conditions, loops and comparisons. The platform runs it securely and returns only the final result your agent needs — large intermediate data is handled for you and never has to flow back through the model.

Express multi-step logic as one snippet instead of many tool calls.
Use conditions, loops and comparisons directly in your query logic.
Only the final result is returned — intermediate data is handled for you.
A separate endpoint from standard MCP; same travel capabilities.

When to use Code Mode vs standard MCP

Code Mode is best for multi-step or conditional logic that would otherwise need several separate tool calls. For a single, unconditional query, standard MCP is the simpler and faster choice.

Use Code Mode: 'if no flight under ¥100 today, check tomorrow' (conditional).
Use Code Mode: 'compare lowest fares from 3 cities to Beijing' (loop + compare).
Use Code Mode: 'find the cheapest day in the next 7 days' (loop + aggregate).
Use standard MCP: 'search flights from Shenzhen to Beijing tomorrow' (single query).

What your code can do

Your snippet runs in a secure, sandboxed environment with no network or file access — it can only call the travel functions listed below. Call them with await; return values use the same field names as the regular API responses. Each request runs independently with sensible execution limits, so a runaway snippet can never affect other requests.

Runs securely — no network or file access, only travel functions.
rideclaw.flight.search / flight.airport_search / flight.pricing
rideclaw.hotel.search / hotel.detail
rideclaw.taxi.estimate
rideclaw.train.search / bus.search
console.log(...) for debugging output

Example: conditional fallback

This single snippet handles 'if there's no flight under ¥100 today, check tomorrow'. With standard MCP this would need several separate calls; with Code Mode you express it once and get back just the result.

Example
// the "code" argument you send to run_code
let r1 = await rideclaw.flight.search({
  trip_mode: "domestic", trip_type: "oneway",
  from_code: "SHA", to_code: "SZX",
  depart_date: "2026-06-05", sort_by: "price"
});
let cheap = (r1.flights || []).filter(f => f.price < 100);
if (cheap.length > 0) {
  return { date: "2026-06-05", flights: cheap };
}
let r2 = await rideclaw.flight.search({
  trip_mode: "domestic", trip_type: "oneway",
  from_code: "SHA", to_code: "SZX",
  depart_date: "2026-06-06", sort_by: "price"
});
return {
  date: "2026-06-06",
  flights: (r2.flights || []).slice(0, 5),
  note: "No sub-¥100 flight today; switched to tomorrow"
};

Calling the endpoint

Point your MCP client at the Code Mode endpoint and call the run_code tool, passing your snippet as the code argument. Listing tools on this endpoint returns only run_code. Authentication is the same as standard MCP — use your API key.

Example
POST https://open.longxiachuxing.com/api/open/v1/mcp/code
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "run_code",
    "arguments": { "code": "return await rideclaw.flight.search({...});" }
  }
}

Good to know

Writing a snippet takes the model slightly longer than emitting a single tool call, so for one-off lookups standard MCP feels snappier. Code Mode pays off when one snippet replaces several calls or works over a lot of data. In the Web Chat demo the snippet streams in as it is written, so you see progress right away.

Best when one snippet replaces several separate calls.
For single lookups, standard MCP is simpler and faster.
The Web Chat demo streams the snippet as it is written.
Return only what you need — keep results focused.