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.
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.
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.
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.
// 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.
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.