Skip to content
LogoLogo

MCP run tool

picked_run is a tool of the MCP server. It runs JavaScript that you write against the Picked API. Each MCP tool is a function on the tools object. Only the value that your code returns goes back to your agent.

Use picked_run when a task needs many tool calls, for example to read each experience in a workspace. For one call, use the tool directly.

Arguments

NameTypeDefaultDescription
sourcestringNoneThe body of a JavaScript function. Use return to send back a result.
allow_writesbooleanfalseLets the code call the tools that change data. Without it, the code can only read.

Call a tool

Call a tool with await and one object of arguments. The arguments have the same names as the arguments of the MCP tool.

const { experiences } = await tools.list_experiences({ workspace_id: 'YOUR_WORKSPACE_ID' })
 
return experiences.map(({ id, name, status }) => ({ id, name, status }))

Many how-to guides end with an ## API and MCP section. Its Run column shows the call for each task, for example tools.update_step({ step_id, layout_content_entry_id }). Each name in the call is an argument. Give a value to each one.

Find a tool

  • picked_search_api finds the tools that match the words you give, for example content entry update.
  • picked_describe_api gives the arguments and the result of each tool that you name. With no names, it lists each tool on one line.

Do many calls

Use Promise.all to start many calls together. The run does a maximum of eight calls at the same time. Each other call waits until a call is complete.

const { experiences } = await tools.list_experiences({ workspace_id: 'YOUR_WORKSPACE_ID' })
const results = await Promise.all(
  experiences.map(({ id }) => tools.get_experience({ experience_id: id })),
)
 
return results.map(({ experience }) => ({
  name: experience.name,
  nodes: experience.flow_json.nodes.length,
}))

Get each page of a list

A list tool gives a maximum of 100 rows for each call. To get the next page, give the value of pageInfo.endCursor as after. Stop when pageInfo.hasNextPage is false.

const drafts = []
let after
 
do {
  const page = await tools.list_experiences({ workspace_id: 'YOUR_WORKSPACE_ID', after })
  for (const experience of page.experiences) {
    if (experience.status === 'draft') drafts.push(experience.name)
  }
  after = page.pageInfo.hasNextPage ? (page.pageInfo.endCursor ?? undefined) : undefined
} while (after)
 
return drafts

Errors

If a tool call fails, its promise rejects. error.message gives the reason, and error.code gives a code that does not change. Put try and catch around a call, and the run continues after an item that fails. If you do not have permission for a call, the run stops.

Result

The result of a run shows these items:

  • The value that the code returns.
  • The text that the code writes with console.log. This text is also there when the run fails.
  • Each tool that the code called, with the number of calls, the time that they took, and the calls that failed.

Return only the data that you need. A full tool result costs more than the same result from a direct call to the tool, because a direct call gives a short text.

Limits

  • A run stops after 20 seconds.
  • The code has no network access, no file system, and no eval.
  • The code can use JSON, Math, Date, Map, Set, Promise and RegExp.
  • The code cannot use fetch, crypto, Buffer, URL, Intl, structuredClone or setTimeout.
  • Each tool call uses your permissions. A tool that you cannot use from the MCP server is not available in a run.