{"id":101473,"plugin_id":"plugins_6af4333b6f008191806d76e5f43ec5f9","kind":"skill","collection_source":"plugin_package","comparison_source":null,"observed_at":"2026-11-17T12:11:35.665Z","digest":"dc53c9b298ae01c3128481efd4cb56f4bb769481c373083d3cbfe4638633e565","against":null,"payload":{"description":"Call tools on a remote MCP (Model Context Protocol) server over streamable HTTP. Use whenever a connector is an MCP server (e.g. the “MCP server” connector type), or the user asks to list or invoke an MCP server’s tools, prompts, or resources.","included_files":[],"name":"mcp-client","skill_md_contents":"---\nname: mcp-client\ndescription: Call tools on a remote MCP (Model Context Protocol) server over streamable HTTP. Use whenever a connector is an MCP server (e.g. the “MCP server” connector type), or the user asks to list or invoke an MCP server’s tools, prompts, or resources.\nlicense: Apache-2.0\ncompatibility: Tines 3B\n---\n\n# Using a remote MCP server\n\nAn MCP server is a JSON-RPC 2.0 API behind a single HTTP endpoint. Talk to it with plain `fetch` from `execute` or a step, with the MCP connector attached — the platform injects authentication on matching requests, so never set Authorization headers yourself, and never print or store tokens.\n\nRead the body of every error response, as the helper below does. A `403` with `\"error\": \"connector_not_connected\"` means the user hasn’t connected their own account to a visitor-mode connector: show them the body’s `message`, and its `connect_url` as a link if present, then retry once they’ve connected. A `403` whose body is a JSON-RPC error saying a tool “is not allowed by this connector” means the connector only allows the tools its message lists: don’t retry or reconnect, use an allowed tool or tell the user that a connector manager can allow this one. Any other 401 or 403 means the user needs to reconnect the connector; tell them so rather than attempting an auth flow yourself.\n\n## Request basics\n\nEvery request is a POST to the server URL with `Content-Type: application/json` and `Accept: application/json, text/event-stream`. The response is either plain JSON or an SSE stream; for SSE, parse each `data:` line as JSON and take the message whose `id` matches your request. This helper handles both:\n\n```ts\nlet sessionId: string | undefined;\n\nasync function mcp(\n  url: string,\n  method: string,\n  params?: Record<string, unknown>,\n  id?: number\n) {\n  const res = await fetch(url, {\n    method: \"POST\",\n    headers: {\n      \"Content-Type\": \"application/json\",\n      Accept: \"application/json, text/event-stream\",\n      ...(sessionId ? { \"Mcp-Session-Id\": sessionId } : {}),\n    },\n    body: JSON.stringify({\n      jsonrpc: \"2.0\",\n      method,\n      ...(params ? { params } : {}),\n      ...(id !== undefined ? { id } : {}),\n    }),\n  });\n  sessionId = res.headers.get(\"Mcp-Session-Id\") ?? sessionId;\n  const text = await res.text();\n  if (!res.ok)\n    throw new Error(`${method}: HTTP ${res.status}: ${text.slice(0, 500)}`);\n  if (id === undefined) return; // notification, no response expected\n  const messages = res.headers\n    .get(\"Content-Type\")\n    ?.includes(\"text/event-stream\")\n    ? text\n        .split(\"\\n\")\n        .filter((line) => line.startsWith(\"data:\"))\n        .map((line) => JSON.parse(line.slice(5)))\n    : [JSON.parse(text)];\n  const reply = messages.find((m) => m.id === id);\n  if (!reply) throw new Error(`${method}: no response with id ${id}`);\n  if (reply.error) throw new Error(`${method}: ${JSON.stringify(reply.error)}`);\n  return reply.result;\n}\n```\n\n## Session lifecycle\n\n1. Send `initialize` with `protocolVersion: \"2025-06-18\"`, `capabilities: {}`, and your `clientInfo`. If the server rejects the protocol version, retry with the version it offers in the error.\n2. If the response carries an `Mcp-Session-Id` header, echo it on every subsequent request (the helper above does this).\n3. Send a `notifications/initialized` notification (no `id`).\n4. When finished, send a DELETE to the endpoint with the session header if the server supports it; ignore a 405.\n\n```ts\nawait mcp(\n  SERVER_URL,\n  \"initialize\",\n  {\n    protocolVersion: \"2025-06-18\",\n    capabilities: {},\n    clientInfo: { name: \"3B\", version: \"1.0\" },\n  },\n  1\n);\nawait mcp(SERVER_URL, \"notifications/initialized\");\n```\n\n## Tools, prompts, and resources\n\n- `tools/list` returns tool names, descriptions, and JSON Schema inputs. Page with `cursor` if the result has `nextCursor`. Cache the list in a file instead of re-fetching every turn.\n- `tools/call` takes `{ name, arguments }`. The result has `content` blocks (usually `{ type: \"text\", text }`); check `isError` before trusting the output.\n- `prompts/list`, `prompts/get`, `resources/list`, and `resources/read` follow the same request shape.\n\n```ts\nconst { tools } = await mcp(SERVER_URL, \"tools/list\", {}, 2);\nconst result = await mcp(\n  SERVER_URL,\n  \"tools/call\",\n  {\n    name: \"some_tool\",\n    arguments: { query: \"example\" },\n  },\n  3\n);\nif (result.isError) throw new Error(result.content?.[0]?.text);\n```\n\nPrefer one short-lived session per task. If a long-running call streams progress notifications over SSE, ignore messages without your request `id` — only the matching response carries the result.\n"},"changes":[],"summary":"First saved snapshot. No earlier version is available for comparison.","summary_kind":"deterministic","summary_metadata":{}}