Skip to content

kagent MCP server

Page as Markdown

Work with kagent from Claude Code, Codex, Cursor, or any other MCP client. The controller serves an MCP server that discovers and invokes agents, manages Sessions and checkpoints, and runs work in Sandboxes.

kagent MCP server

Work with kagent from Claude Code, Codex, Cursor, or any other MCP client. The controller serves an MCP server that discovers and invokes agents, manages Sessions and checkpoints, and runs work in Sandboxes.

Connect a client

Every kagent installation serves a Model Context Protocol (MCP) server. Point an MCP client at it, and the client can do from a chat what you otherwise do in the kagent UI or with the CLI: find your agents, talk to them, read back what they did, pin and fork their Sessions, and run code in a Sandbox in your cluster.

How it works

The MCP server runs on the controller’s HTTP port, so a default installation already serves it at /mcp on port 8083. The same port serves the gRPC API.

  • Transport: Clients connect over Streamable HTTP. Standalone Server-Sent Events (SSE) and stdio are unsupported.
  • State: The handler is stateless. Each request stands alone, and a client does not need to establish an MCP session first.
  • Extensions: The server advertises the io.modelcontextprotocol/tasks extension, so a client can invoke an agent without waiting for the reply. For more information, see Invoke without waiting.
  • Authentication: The server uses the controller’s authentication mode. When authentication is on, the client sends an Authorization: Bearer <token> header. For the available modes, see Controller authentication modes.

Warning

A default installation sets config.server.auth.mode to insecure. In this mode the endpoint accepts every request and reads the caller’s identity from an X-User-Id header that the caller sets itself, defaulting to admin@kagent.dev. The endpoint can invoke agents, create checkpoints, and create Sessions. Do not expose port 8083 outside the cluster. For the wider identity model, see Identity.

Connect a client

  1. Port-forward the controller’s API port in a separate terminal, and leave the command running.

    kubectl port-forward -n kagent svc/kagent-controller 8083:8083
  2. Prepare authentication for your client. If your installation requires authentication, get an access token for your user and export it in the shell where you run the client commands.

    export TOKEN="<access-token>"

    If your installation does not require authentication, leave TOKEN unset. For the available authentication modes, see Controller authentication modes.

  3. Add http://localhost:8083/mcp to your client.

    To limit the entry to the current project, add --scope project.

    claude mcp add --transport http kagent http://localhost:8083/mcp

    For an authenticated connection, add the token as a header.

    claude mcp add --transport http kagent http://localhost:8083/mcp \
      --header "Authorization: Bearer $TOKEN"
  4. Ask your client to list your agents, for example Which kagent agents can I use?. The client calls list_agents and shows the Agents that you can see.

What you can do

Agents and Sessions

Discover agents, hold conversations, read back what an agent did, and checkpoint and fork Sessions. An Agent is addressed by its namespace and name, and a Session by its own universally unique identifier (UUID). Every tool that returns a Session reports its agent as <namespace>/<name>.

ToolRequired argumentsWhat it does
list_agentsNoneLists the Agents that the caller can see. Takes namespace to filter, and page_size and page_token.
list_sessionsNoneLists the ready Sessions that the caller created. Takes agent to filter by Agent, all_states to include failed and suspended Sessions, and page_size and page_token.
create_sessionagentStarts a Session with the Agent. Takes message to send a first message, name for a display name, and request_id for idempotency. With message, the call returns once the agent accepts the turn. To read the reply, call get_session.
invoke_agentmessage, and exactly one of agent or session_idStarts a new Session with agent, or continues one with session_id, and returns the agent’s reply with the Session and task IDs. Takes message_id for idempotency.
get_sessionsession_idReturns the Session’s state, its failure if it has one, and its turns, oldest first. Each turn summarizes the user message, the reply, and the tool calls. Takes last_turns to return only the most recent turns, and max_bytes to cap the answer, which drops the oldest turns first. To poll a running turn, pass last_turns set to 1.
list_taskssession_idPages through the Session’s tasks, oldest first, each as the same summary that get_session returns. Takes page_token and max_bytes, and page_size, which accepts 1 to 100 and defaults to 50.
get_tasksession_id, task_idReturns one task’s A2A messages and artifacts in timeline order. Takes tool_call, an index or an ID, to return only the A2A parts of one tool call, from_item to continue a paged answer, and max_bytes.
rename_sessionsession_id, nameSets the Session’s display name. An empty name clears it.
delete_sessionsession_idDeletes the Session and its runtime state when no turn or other operation on the Session is in progress.
create_session_checkpointsession_id, expected_head_task_idPins the Session at a turn boundary. The call fails if the Session has advanced past that task. Takes request_id for idempotency.
list_session_checkpointssession_idLists that Session’s checkpoints. Takes page_size and page_token.
get_session_checkpointcheckpoint_idReturns one checkpoint’s state, and its failure if it has one.
delete_session_checkpointcheckpoint_idDeletes the checkpoint.
fork_sessioncheckpoint_idStarts a second Session from a checkpoint, replaying the Session’s transcript through the pinned turn. Takes request_id for idempotency.

Sandboxes

Create a Sandbox from a template, move files in and out, and run processes in it. The MCP tools move data through the model’s context, so their limits are tighter than the CLI’s and the gRPC API’s. For the limits, see Limits.

ToolRequired argumentsWhat it does
list_sandbox_templatesNoneLists the templates that the caller can create a Sandbox from. Takes namespace to filter.
create_sandboxnamespace, template, request_idCreates a Sandbox. Takes name and ttl_seconds. A retry with the same request_id and the same arguments returns the same Sandbox.
list_sandboxesNoneLists the Sandboxes that the caller owns. Takes page_size and page_token.
get_sandbox, suspend_sandbox, resume_sandbox, delete_sandboxsandbox_idReads, suspends, resumes, or deletes a Sandbox.
write_sandbox_filesandbox_id, path, data_base64Writes a file, replacing one that already exists. Takes mode as decimal Unix permission bits, such as 420 for 0644. Writes up to 1 MiB per call.
read_sandbox_filesandbox_id, pathReturns a file in a form that the model reads directly. Text returns as numbered lines, and a PNG, JPEG, or GIF image returns as an image.
start_sandbox_processsandbox_id, commandStarts a process from an argument list, such as ["python3", "main.py"]. Takes cwd and env. Returns a process_id without waiting.
get_sandbox_processsandbox_id, process_idReturns the process’s state, and its exit_code once the state is PROCESS_STATE_EXITED.
read_sandbox_outputssandbox_id, process_idReturns the output that is available now, in base64, up to 1 MiB, with the offsets to continue from. Takes stdout_offset and stderr_offset.
kill_sandbox_processsandbox_id, process_idSends SIGKILL to the process without waiting for it to exit.

Prompts

The server also gives the client instructions on how to use a Sandbox safely. A client that supports MCP prompts additionally lists two prompts that start a sandbox workflow. A prompt only returns instructions to the client. It does not call any tool by itself.

PromptArgumentsWhat it does
sandbox-tasktask, which is required, and namespace and template, which are optional. template requires namespace.Asks the model to complete the task in a temporary Sandbox. The model selects a template, stages the inputs, runs the work, checks the exit code and the result, retrieves the deliverables, and deletes the Sandbox.
sandbox-recoverysandbox_id, which is requiredAsks the model to inspect a Sandbox whose task was interrupted, and to decide how to continue without repeating work that already finished.

Guides