---
title: mcp
description: "The `mcp` Effects (ADR-0067, ADR-0079): `mcp.call(server, tool, { input })` calls a tool, `mcp.read(server, uri)` reads a resource, and `mcp.prompt(server, name, { input })` gets a prompt."
---

# `mcp`

Constant, in `@jr2/orchestrator/src/mcp-effect.ts`. It is an export of `@jr2/orchestrator`, in the [Effects](group-effects.md) group of the [Authoring surface](../authoring-surface.md) page.

```ts
const mcp: { readonly call: typeof call; readonly read: typeof read; readonly prompt: typeof prompt; }
```

The `mcp` Effects ([ADR-0067](../decisions/0067-an-effect-is-an-actor-slot-and-runs-at-most-once-unless-marked-idempotent.md), [ADR-0079](../decisions/0079-an-agent-holds-mcp-tools-a-machine-calls-them-as-an-effect-and-the-machine-is-the-approval.md)): `mcp.call(server, tool, { input })` calls a tool,
`mcp.read(server, uri)` reads a resource, and `mcp.prompt(server, name, { input })` gets a
prompt. Each one is an Effect that the Machine runs, with no model, in the Instance Effector.
Put it in `actors`, and invoke it by its key.

`server` is a name of the `mcp` block of `jr2.config.ts`: a remote server, whose url and secret
are the config's. The Instance Effector holds that secret as an Effect secret, and sends it as
`Authorization: Bearer <value>`. The Agent and the Orchestrator never read it. `jr2 up` refuses
a server that the `mcp` block does not declare, and a stdio server. `server`, and a call's
`tool`, can each be `open`: the composer binds them one time with `customize(machine, { effects:
{ <slot>: { server, tool } } })`.

Every outcome is output ([`McpCallOutput`](type-mcpcalloutput.md), [`McpReadOutput`](type-mcpreadoutput.md)): `returned`, `refused`,
`unreachable`, `input-required` or `unknown`. jr2 sends the request at most one time, unless you
mark it `idempotent`. jr2 does not read the tool's `idempotentHint`.

An Agent that holds a server's tools (its `mcp` list) calls them with no approval. When a call
needs an approval, the Machine makes it: the Agent picks, a Gate waits for a person, and the
Effect makes the call. The Effect's output is the pick's answer.

**Example**

```ts
import { assign } from "xstate";
import { z } from "zod";
import { agent, defineEvent, fail, gate, jr2Setup, mcp } from "@jr2/orchestrator";

const postMessage = defineEvent({
  name: "post_message",
  description: "Post one message to the team's channel. A person approves it first.",
  input: z.object({ text: z.string() }),
});
const approve = defineEvent({ name: "approve", input: z.object({ by: z.string() }) });
const reject = defineEvent({ name: "reject", input: z.object({ by: z.string() }) });

export const machine = jr2Setup({
  types: {} as { context: { text: string } },
  events: [postMessage, approve, reject],
  actors: {
    writer: agent({
      model: "anthropic/claude-haiku-5-5",
      instructions: "You write the release note for the team.",
      workspace: "none",
    }),
    // A person answers it, in the Console or with `jr2 answer`.
    approval: gate({ meta: z.object({ text: z.string() }), delivers: [approve, reject], look: "none" }),
    // "slack-acme" is a remote server of the mcp block of jr2.config.ts.
    post: mcp.call("slack-acme", "post_message", {
      input: z.object({ channel: z.string(), text: z.string() }),
    }),
    fail: fail(),
  },
}).createMachine({
  id: "release-note",
  context: { text: "" },
  on: { "agent.fault": ".failed" },
  initial: "writing",
  states: {
    writing: {
      invoke: { src: "writer", input: { prompt: "Write the release note, then post it." } },
      initial: "ready",
      states: {
        ready: {
          on: {
            post_message: { target: "approving", actions: assign({ text: ({ event }) => event.text }) },
          },
        },
        approving: {
          invoke: { src: "approval", input: ({ context }) => ({ meta: { text: context.text } }) },
          on: { approve: "posting", reject: "ready" },
        },
        posting: {
          invoke: {
            src: "post",
            input: ({ context }) => ({ channel: "#releases", text: context.text }),
            // On another outcome, the Agent reads the output as the answer to its pick.
            onDone: [
              { guard: ({ event }) => event.output.outcome === "returned" && !event.output.isError, target: "#posted" },
              { target: "ready" },
            ],
          },
        },
      },
    },
    posted: { id: "posted", type: "final" },
    failed: { invoke: { src: "fail", input: { reason: "the Agent's Turn could not go on" } } },
  },
});
```

**See also**

- [Effects](../../concepts/effects.md)
- [ADR-0079: An Agent holds MCP tools, a Machine calls them as an Effect, and the Machine is the approval](../decisions/0079-an-agent-holds-mcp-tools-a-machine-calls-them-as-an-effect-and-the-machine-is-the-approval.md)
