Skip to main content
A tools entry of type mcp names an MCP server. Moss connects to it, offers its tools to the model, and runs each call the model makes. Your code sends no results for these tools.

Add a server

A public server, such as https://mcp.deepwiki.com/mcp, needs no headers. OpenAI’s connectors (connector_id) and its authorization field are not supported, so send a token in headers. A response’s tools field leaves out MCP headers. One request can hold your own function tools and MCP servers together. When the model calls both in one round, only your function calls are returned, and the MCP calls are not run. A request with MCP servers can run for a few minutes.

Run a request with a server

These examples stream the answer and print each MCP call when it ends. Replace the URL with your server’s, and set CRM_TOKEN to its token.
Each call is an mcp_call item. It arrives in response.output_item.added when it starts and in response.output_item.done when it ends. The same items are in the response’s output.

Tool steps

Read steps on Responses

Each MCP call streams as these events, in order:
  1. response.output_item.added
  2. response.mcp_call.in_progress
  3. response.mcp_call_arguments.done
  4. response.mcp_call.completed, or response.mcp_call.failed
  5. response.output_item.done
The finished item holds the call and its result:
A failed call has status failed and output null. Its error is {"type": "mcp_tool_execution_error", "content": ...}.

Read steps on Chat Completions

A stream carries one extra chunk before each MCP call and one after it. Each has an empty delta and a moss_tool_step:
A call step comes before the tool runs and carries its arguments. A result step comes after, with is_error, duration_ms and output. Both have the same id, the server_label and the tool’s name. A reply without stream lists the steps in order in a top-level moss_tool_steps array. OpenAI clients ignore both fields. Chat Completions does not add MCP calls to the message history. Keep what you need from the steps in your own messages.

Send mcp_call items back

On Responses, put the mcp_call items back in input with the rest of output. The model sees their results and does not run the tools again. An mcp_call with neither output nor error never finished, and its tool may have run. Sending it back returns 400. Check whether the tool ran, and send the outcome as a message in its place.

Errors

A tool may already have changed data when a call fails after it, so Moss never retries that call:
  • Without stream, the reply is 424 with code failed_after_tool_call and the header x-should-retry: false. Its body holds the output items so far on Responses, or the moss_tool_steps that ran on Chat Completions.
  • On a Responses stream, response.failed has error.code failed_after_tool_call.
  • On a Chat Completions stream, an error frame follows the last step.
Never replay a request that failed with failed_after_tool_call. Read the items or steps that ran to see what the tool did. In the SDKs, every MCP failure is an InferenceError. It has status, type, code and retry_after in Python, and status, type, errorCode and retryAfter in JavaScript. Errors and limits lists every other error. Its Limits section covers the request limits.