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

# MCP v2 and Tasks

> Use the split MCP client SDK with explicit protocol negotiation, credential audience, and task ownership.

`MCPV2ToolProvider` uses `@modelcontextprotocol/client@^2.3.0`. It defaults to protocol `2026-07-28` without silent fallback. Choose `versionNegotiation: { mode: "auto" }` explicitly for SDK legacy negotiation.

Supported transports are `http`, `stdio`, and a host-supplied `custom` transport. Legacy SSE stays on `MCPToolProvider` with `@modelcontextprotocol/sdk@^1.27.1`.

## Select tools from a server

```typescript theme={null}
import { Agent, MCPV2ToolProvider, openai } from "@agentium/core";

const token = process.env.MCP_ACCESS_TOKEN;
if (!token) throw new Error("Set MCP_ACCESS_TOKEN");
const mcp = new MCPV2ToolProvider({
  name: "reports",
  transport: "http",
  url: "https://mcp.example.com/mcp",
  audience: "https://mcp.example.com/mcp",
  headers: { Authorization: `Bearer ${token}` },
});
try {
  const tools = await mcp.getTools({ include: ["find_reports"] });
  const agent = new Agent({ name: "reports", model: openai(process.env.OPENAI_MODEL ?? "gpt-6.1-sol"), tools });
  try {
    console.log(await agent.run("Find the latest shipping report."));
  } finally {
    await agent.close();
  }
} finally {
  await mcp.close();
}
```

Replace the example endpoint with your server and pre-obtain its token. A provider instance is scoped to one authenticated principal; changing Agent run identity does not change its credentials. Credentialed HTTP requires an exact audience URL and rejects redirects/cross-origin forwarding. A host-reviewed custom transport is needed for multi-origin OAuth flows.

## Preserve tool results

Both adapters preserve MCP content/metadata as an `mcp-result` artifact. Read `ToolResult.content` rather than assuming every result is a string. Tool-level errors throw `MCPToolError` with the mapped result.

Tool discovery changes affect future `getTools()` calls. An Agent's bound tool array is a snapshot; rebuild selection deliberately. Requests propagate the run's cancellation signal. Closing the provider invalidates pending initialization and closes late transports.

## Optional Tasks extension

Enable Tasks explicitly. Handles are opaque and owned by run, session, user, and tenant. The adapter bounds retained handles and TTL; cross-owner lookup sends no remote request. Completed, failed, and cancelled states are terminal locally.

Handles are connection-local. `close()` drops local state and disconnects; it does not cancel remote tasks or recover them after restart. Use a host task store and the [durable MCP bridge](/durable/protocols) for an explicitly designed cross-process lifecycle.


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