> ## Documentation Index
> Fetch the complete documentation index at: https://docs.restate.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# MCP servers

> Load the tools of an MCP server in a handler, and pass them to an agent run.

Load an MCP server's tools with `mcpTools` from `@restatedev/harness/mcp` inside a handler, and pass them to the run:

```typescript {"CODE_LOAD::harness/src/tools.ts#mcp"}  theme={null}
export const docsGuide = restate.service({
  name: "DocsGuide",
  handlers: {
    *ask(question: string) {
      // The tool catalog is fetched once and journaled.
      const docs = yield* mcpTools({
        url: "https://docs.restate.dev/mcp",
        namespace: "docs",
        protocol: "stateless",
        allow: (name) => name !== "submit_feedback",
      });
      const result = yield* guide.run(question, {tools: docs.tools});
      return result.status === "completed" ? result.output : (result.output ?? result.reason);
    },
  },
});
```

## Options

| Option | Description |
| - | - |
| `namespace` | Prefix for the tool names: `docs` turns `search` into `docs_search`. 1 to 24 letters, digits, `_`, or `-`. |
| `protocol` | `stateless` for servers that support the MCP protocol revision `2026-07-28`. `stateful` for older servers, which use the `initialize` handshake and can open a session. Call `close()` when you're done with a stateful session. |
| `deferred` | Hide the tools until the model finds them with [tool search](https://docs.restate.dev/harness/code-mode.md#tool-search). Default: `true`. |
| `allow` | Filter the tools by their name on the server, before the namespace prefix. |
| `token` | A generator function that returns a bearer token. |
| `onAuthorizationRequired` | A generator function that refreshes the credentials when the server requires authorization. Without it, `mcpTools` or the tool call fails with a `TerminalError`. |
| `retry` | Retry policy for tool calls. Default: three attempts. A policy that you pass replaces the default, so set `maxAttempts` in it. Each call sends an `Idempotency-Key` header, but a server that ignores the header runs a retried call again. |
| `timeoutMs` | Timeout per request. Default: 60000. |

## Tool names and limits

Restate Harness renames a server tool whose prefixed name isn't a valid tool name, by replacing invalid characters, shortening it, and adding a hash.
It skips tools with a duplicate name, an input schema over 64000 characters, or an unsupported input schema, and lists them in the result's `warnings`.
`mcpTools` fails with a `TerminalError` if more than 128 of the server's tools pass `allow`. For a large server, use `allow` to select the tools that the agent needs.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.