Mastra Studio previews a server's tools with a hand-written 2025-03-26 handshake

Kind: idiosyncrasy · Status: current · Last verified: 2026-11-27 · Clients: mastra · Revisions: 2025-03-26, 2026-07-28

A search of the monorepo at bb984550 for the SDK import and for a hand-written initialize finds two MCP clients.

The first is MCPClient in packages/mcp, built on @modelcontextprotocol/client 2.4.0. Everything that runs tools goes through it: an application's Agent, Mastra Code (mastracode/sdk/src/mcp/manager.ts), the editor when it resolves a stored MCP client, @mastra/connect, and the mastra-mcp generate CLI. The registry entry describes this client.

The second is connectAndListTools in client-sdks/react/src/hooks/mcps/use-try-connect-mcp.ts, exported as the useTryConnectMcp hook. Studio's form for creating a stored MCP client calls it to show which tools a URL offers. It runs in the browser and uses fetch directly:

  1. POST initialize with protocolVersion: '2025-03-26', capabilities: {} and clientInfo: { name: 'mastra-playground', version: '1.0.0' }.
  2. POST notifications/initialized, carrying Mcp-Session-Id when the server returned one.
  3. POST tools/list with no params, and return result.tools.

Nothing picks between the two at run time. The form uses the hand-written client, and everything else uses MCPClient.

Where the preview and the runtime client differ

The preview offers 2025-03-26 and does not read the version in the server's answer. MCPClient probes server/discover at 2026-07-28 and falls back to initialize at 2025-11-25. A server that serves only 2026-07-28 is reachable by MCPClient and is sent an initialize it does not serve by the preview. What Studio shows in that case was not tested.

The preview sends no MCP-Protocol-Version header on the requests after initialize. It reads one page of tools/list and ignores nextCursor, where the SDK walks every page. It takes the first data: line of an SSE response as the answer. It does not close the session it opened.

It speaks Streamable HTTP only, so a stdio server has no preview.

Every request copies the headers configured on the Mastra API client (client.options.headers) and sets credentials: 'include'. Those headers go to whatever URL was typed into the form.

The editor's later tool resolution for the same stored client goes through MCPClient.listTools(), so the tool list the form previewed and the list an agent gets come from two different clients.

Sources