Token导航 LogoToken导航

Agent Skill · 研究检索

build-mcp-use-client(构建 MCP USE client)

build-mcp-use-client 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

build-mcp-use-client 是研究检索类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为接触敏感数据;许可证信息还不明确,第三方扫描有提醒项,按安装量在研究检索类的 73,675 个 Skill 里排第 59,000。

总安装 396周安装 17GitHub Stars 5下载 139核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:build-mcp-use-client(构建 MCP USE client)
来源仓库:https://github.com/yigitkonur/skills-by-yigitkonur
仓库路径:skills/build-mcp-use-client
安装命令:
npx skills add https://github.com/yigitkonur/skills-by-yigitkonur --skill build-mcp-use-client
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/yigitkonur/skills-by-yigitkonur --skill build-mcp-use-client

这个 Skill 是做什么的

研究检索类 Skill 主要解决「找资料、核对事实、把来源整理清楚」的问题,通常会让助手先检索再总结。

用于构建生产级 MCP 客户端应用,支持多服务器管理和协议操作。适合在 Codex、Claude、Cursor、Gemini CLI 中实现客户端连接、React 钩子集成或 CLI 工具开发。通过 npx skills add 命令从 GitHub 安装,需 Node 18+ 环境并确认项目依赖完整性。

注意权限范围和维护状态,避免触发不必要的联网、命令执行或文件写入操作。build-mcp-use-client 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

来源仓库内路径:skills/build-mcp-use-client

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/yigitkonur/skills-by-yigitkonur --skill build-…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要接触敏感数据,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

build-mcp-use-client 怎么安装?

在终端执行 npx skills add https://github.com/yigitkonur/skills-by-yigitkonur --skill build-mcp-use-cl…。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

build-mcp-use-client 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

build-mcp-use-client 需要什么权限?

权限级别是接触敏感数据。该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

build-mcp-use-client 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

build-mcp-use-client 用的人多吗?

公开数据是累计安装 396 次,近一周安装 17 次,下载 139 次,GitHub 5 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

build-mcp-use-client 安全吗?

第三方扫描有提醒项,说明存在需要人工确认的行为。安装前请打开源码看清它读了什么、联网到哪里。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。

先想清楚的地方

  • 需要接触敏感数据,装到常用环境前要先评估影响面。
  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方扫描存在提醒项或未通过项,需要人工逐条确认。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理研究检索类任务、又不想每次都手写提示词的人。

不太适合

  • 环境里有大量密钥、凭证,不方便给第三方 Skill 读取的人。
  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

研究检索类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
find-skills

寻找技能 · Codex、Claude

31,199,81316,486操作浏览器MIT有提醒
self-improving-agent

自我改进 Agent · OpenClaw

16,464,0023,396接触敏感数据MIT-0通过
soultrace

灵魂追踪 · Codex、Claude

7,588,94412需要联网未明确有提醒
self-improving

自我完善 · OpenClaw

6,829,2841,046需要联网MIT-0通过
microsoft-foundry

微软代工厂 · Codex、Claude

6,614,144764调用外部服务未明确有提醒
build-mcp-use-client

构建 MCP USE client · 本页

3965接触敏感数据未明确有提醒

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Build MCP Use Client

Build production-grade MCP client applications with the mcp-use TypeScript library (v1.21+, Node 18+ supported, Node 22 LTS recommended). The library provides MCPClient for multi-server management, MCPSession for per-server protocol operations, useMcp/McpClientProvider React hooks, CLI client, code mode, and environment-specific entry points (mcp-use, mcp-use/browser, mcp-use/react).

Building an MCP server? Use build-mcp-use-server. Building an AI agent? Use build-mcp-use-agent. Building widget-based MCP Apps? Use build-mcp-use-apps-widgets.

Behavioral flow — what to do when this skill is invoked

This is the decision procedure you MUST follow every time.

Step 1 — Detect what exists

Run tree -L 3 (or ls -R if tree is unavailable) at the actual project root you will edit. If the user named a package, fixture, or app subdirectory, scan that path instead of the repo root. Look for signs of an existing mcp-use client:

  • package.json with "mcp-use" as a dependency
  • Files importing from "mcp-use", "mcp-use/browser", or "mcp-use/react"
  • MCPClient constructor calls
  • useMcp / McpClientProvider usage
  • session.callTool(), session.readResource(), or similar session method calls

Step 2A — Existing mcp-use client found

When there IS an existing client implementation, launch four parallel subagents to explore the codebase and cross-reference with the reference files:

If the runtime cannot launch subagents, do the same audits sequentially yourself and keep the same four coverage areas. When you do use subagents, write each prompt as a bounded audit brief: why the audit matters, the desired end-state, hard constraints, and binary deliverables.

Subagent 1 — Client configuration audit Explore constructor options, server entries, transport types, loadConfigFile / MCPClient.fromConfigFile / MCPClient.fromDict usage, environment-specific imports. Cross-reference with references/guides/client-configuration.md and references/guides/environments.md. Surface: what is correctly configured, what violates best practices, what is missing.

Subagent 2 — Tool, resource, and prompt usage audit Explore how tools are listed/called, how resources are read, how prompts are retrieved, completion usage, timeout/abort config. Cross-reference with references/guides/tools.md, references/guides/resources.md, references/guides/prompts.md, and references/guides/completion.md. Surface: correct patterns, missing error handling, timeout gaps.

Subagent 3 — Callbacks and lifecycle audit Explore sampling callbacks, elicitation callbacks, notification handlers, logging setup, session cleanup, reconnection config. Cross-reference with references/guides/sampling.md, references/guides/elicitation.md, references/guides/notifications-and-logging.md, and references/guides/authentication.md. Surface: missing callbacks, wrong precedence, cleanup gaps.

Subagent 4 — React integration audit (only if React hooks are used) Explore useMcp options, McpClientProvider props, state handling, useMcpClient/useMcpServer usage, proxy config, persistence. Cross-reference with references/guides/usemcp-and-react.md. Surface: missing state guards, wrong prop names, reconnection gaps.

After all subagents report back:

  1. Synthesize findings into a prioritized improvement plan
  2. Apply improvements directly — fix anti-patterns, add missing callbacks, correct imports
  3. Review final result against references/patterns/anti-patterns.md
  4. Only ask the user if something is genuinely ambiguous (e.g., which LLM provider for sampling)

Step 2B — No existing mcp-use client found

Check context: is there an existing app that needs MCP client integration?

If context exists (e.g., a React app, a Node CLI, a backend service): infer what is needed and build the client integration directly using the reference files.

Pick the server target explicitly before coding:

  • If the repo already contains a real MCP server, connect to that server and discover its actual tool/resource names with listTools(), listResources(), and listPrompts().
  • If the task is only about client mechanics and no domain server exists yet, use @modelcontextprotocol/server-everything as a smoke-test server and discover the real tool names before calling them.
  • If the request depends on a domain-specific tool such as calculator, search-products, or repo-specific commands and no matching server exists, stop and add/build that server first instead of inventing tool names. Route to build-mcp-use-server when needed.

If no context exists: ask up to 10 questions, each with 5+ numbered options:

  1. What environment? (1) Node.js CLI, (2) Node.js backend service, (3) Browser app, (4) React app, (5) CLI scripting with npx mcp-use client
  2. How many MCP servers? (1) Single server, (2) Multiple servers
  3. Transport type? (1) STDIO for local servers, (2) HTTP for remote servers, (3) Both STDIO and HTTP
  4. Need authentication? (1) Bearer token, (2) OAuth 2.1, (3) Custom headers, (4) None
  5. Need React hooks? (1) useMcp for single server, (2) McpClientProvider for multi-server, (3) No React
  6. Need sampling/elicitation callbacks? (1) Sampling only, (2) Elicitation only, (3) Both, (4) Neither
  7. Need code mode? (1) VM executor (local), (2) E2B executor (cloud sandbox), (3) Custom executor, (4) No
  8. Session persistence needs? (1) In-memory only, (2) LocalStorage (React), (3) Custom StorageProvider, (4) None
  9. Need notifications/logging? (1) Tool/resource list changes, (2) Custom notifications, (3) Server log streaming, (4) None
  10. Production hardening? (1) Auto-reconnect + health checks, (2) Basic error handling only, (3) Full production setup

Then build the client using answers + reference files.


Reference routing — read these when you need depth

Each trigger below tells you exactly when and why to open a reference file. Read them with curiosity — they contain the full type signatures, edge cases, and validated patterns that this summary intentionally compresses.

Getting started and environment setup:

  • If you are starting from scratch and need the minimal happy-path to a working client — read references/guides/quick-start.md. It walks through install, first connection, first tool call, and first resource read.
  • If you are choosing between Node.js, Browser, React, or CLI and need to know what works where — read references/guides/environments.md. It has the full feature matrix (STDIO, HTTP, OAuth, code mode, persistence) and the correct import paths for each environment.

Client configuration and connections:

  • If you are connecting to servers, choosing between STDIO and HTTP, setting up multi-server configs, or wiring per-server callbacks — read references/guides/client-configuration.md. It has the full MCPClientConfigShape, discriminated union types for STDIO vs HTTP entries, loadConfigFile, MCPClient.fromConfigFile, MCPClient.fromDict, ClientInfo shape, and per-server callback overrides.
  • If you are managing multiple servers with lazy loading, composed capabilities, or disallowedTools filtering — read references/guides/server-manager.md. It covers useServerManager on MCPAgent, environment variable substitution in config JSON, and dynamic server addition.

Core protocol operations:

  • If you are listing or calling tools, setting timeouts, using AbortSignal, or handling CallToolResult — read references/guides/tools.md. It has CallToolOptions, maxTotalTimeout, resetTimeoutOnProgress, and the isError handling pattern.
  • If you are reading resources, working with resource templates, or handling binary vs text content — read references/guides/resources.md. It has listResources(), readResource(), ResourceContent[] shape, and MIME type handling.
  • If you are retrieving prompt templates with arguments or building multi-message prompt flows — read references/guides/prompts.md. It has listPrompts(), getPrompt(), PromptResult structure, and argument passing.
  • If you are implementing autocomplete for prompt arguments or resource template URIs — read references/guides/completion.md. It has session.complete(), CompleteRequestParams, debouncing strategy, and capability checking.

Callbacks and server interactions:

  • If a server uses ctx.sample() and you need to route LLM calls — read references/guides/sampling.md. It has CreateMessageRequestParams, CreateMessageResult, model preferences with hints/costPriority/speedPriority, per-server overrides, and the full callback precedence order.
  • If a server uses ctx.elicit() and you need to handle user input forms or URL-mode elicitation — read references/guides/elicitation.md. It has all eight helper utilities (accept, decline, cancel, reject, validate, acceptWithDefaults, getDefaults, applyDefaults), form vs URL mode discrimination, ElicitResult shape, and callback precedence.
  • If you need to listen for tool/resource/prompt list changes, send roots, handle custom notifications, or stream server logs — read references/guides/notifications-and-logging.md. It has session.on("notification"), setRoots(), getRoots(), loggingCallback, logging levels, and custom notification patterns.
  • If you need bearer tokens, OAuth 2.1 flows (popup vs redirect), BrowserOAuthClientProvider, or CLI --auth — read references/guides/authentication.md. It has headers config, authToken, callbackUrl, preventAutoAuth, useRedirectFlow, onMcpAuthorization(), and DCR.

React integration:

  • Building a React app with MCP? The useMcp hook has 20+ options and a full return type. Read references/guides/usemcp-and-react.md for connection states (discovering/authenticating/pending_auth/ready/failed), McpClientProvider props, useMcpClient/useMcpServer hooks, McpServerOptions table, proxy fallback, autoReconnect vs reconnectionOptions, LocalStorageProvider, and notification management.

Code mode:

  • If you need programmatic code execution across MCP tools — read references/guides/code-mode.md. It has VM executor options (timeoutMs, memoryLimitMb), E2B cloud sandbox setup, custom executor function/class patterns, executeCode(), searchTools() / search_tools(), BaseCodeExecutor, ExecutionResult, and PROMPTS.CODE_MODE.

CLI client:

  • If you are using the CLI for testing, scripting, or interactive sessions — read references/guides/cli-reference.md. It has connect, disconnect, sessions, tools call, resources read/subscribe, prompts get, interactive REPL, --json output, --auth, and session storage at ~/.mcp-use/cli-sessions.json.

Production hardening and patterns:

  • Before shipping to production, read references/patterns/production-patterns.md. It covers reconnection strategies, health checks, graceful shutdown, error handling, retry patterns, and cleanup.
  • Before finalizing any client, review against references/patterns/anti-patterns.md. It catalogs common client mistakes in configuration, callbacks, lifecycle management, and error handling.

Examples and templates:

  • Need a working example to copy from? Read references/examples/client-recipes.md for complete Node, Browser, React, and multi-server client recipes.
  • Starting a new project and want the right folder structure? Read references/examples/project-templates.md for starter projects for Node CLI, React app, and Browser extension.

Debugging:

  • Hit a specific error message? Read references/troubleshooting/common-errors.md for 404 auto-recovery, "Method not found", "Client not ready", timeout errors, and other known issues with cause and fix.

Quick start

Minimal MCP client in 15 lines:

import { MCPClient } from "mcp-use";  // mcp-use ^1.21.0

const client = new MCPClient({
  mcpServers: {
    myServer: {
      command: "npx",
      args: ["-y", "@modelcontextprotocol/server-everything"],
    },
  },
});
await client.createAllSessions();
const session = client.requireSession("myServer");

const tools = await session.listTools();
console.log("Tools:", tools.map((t) => t.name));

const result = await session.callTool("greet-user", { name: "Ada", formal: false });
console.log("Result:", result);

await client.closeAllSessions();

If the repo does not already have a TypeScript runner, add one first with npm install -D tsx typescript. Save this as src/client.ts or src/mcp-client.ts, keep the run command aligned with the filename you chose, then run npm pkg set scripts.start="tsx src/client.ts" and npm start, or npx tsx src/client.ts (substitute src/mcp-client.ts if that is the file you saved). Smoke test the same STDIO server from the CLI: npx mcp-use client connect --stdio "npx -y @modelcontextprotocol/server-everything" --name test

If the first connection prints an anonymized telemetry banner from mcp-use, treat it as informational unless the repo explicitly disables telemetry.


Core API summary

This section gives you the essential shapes. For full type definitions, options tables, and edge cases, follow the reference routing above.

MCPClient constructor

import { MCPClient, acceptWithDefaults, types } from "mcp-use";

const client = new MCPClient(
  {
    mcpServers: {
      // STDIO server (local):
      local: {
        command: "npx",
        args: ["-y", "@modelcontextprotocol/server-everything"],
        env: { NODE_ENV: "development" },
        clientInfo: { name: "my-app", version: "1.0.0" },
      },
      // HTTP server (remote):
      remote: {
        url: "https://api.example.com/mcp",
        headers: { Authorization: "Bearer ${AUTH_TOKEN}" },
        onSampling: async (params) => ({ /* ... */ }),
        onElicitation: async (params) => acceptWithDefaults(params),
        onNotification: (n) => console.log(n.method),
      },
    },
  },
  {
    onSampling: async (params) => ({ /* ... */ }),
    onElicitation: async (params) => acceptWithDefaults(params),
    onNotification: (n) => console.log(n.method),
    codeMode: true,
    loggingCallback: async (log: types.LoggingMessageNotificationParams) => {
      console.log(`[${log.level.toUpperCase()}]: ${log.message}`);
    },
  }
);

Other construction patterns:

// From JSON file (Node.js only):
import { MCPClient, loadConfigFile } from "mcp-use";
const config = loadConfigFile("path/to/config.json");
const client = new MCPClient(config);

// Convenience factory:
const fromFile = MCPClient.fromConfigFile("path/to/config.json");

// From in-memory object:
const client = MCPClient.fromDict({
  mcpServers: { "my-server": { url: "https://api.example.com/mcp", authToken: "sk-key" } },
});

Full config shape, ClientInfo interface, and per-server callback overrides are in references/guides/client-configuration.md.

Session management

await client.createAllSessions();              // connect to all configured servers
const session = await client.createSession("myServer"); // connect to one server
const session = client.getSession("myServer"); // get existing session or null
await client.closeAllSessions();               // disconnect all
await client.close();                          // alias — also cleans up E2B sandboxes

callTool

const result = await session.callTool("tool_name", { param: "value" });
// result.content — the result data
// result.isError — boolean indicating success/failure

// With timeout and abort:
const controller = new AbortController();
const result = await session.callTool("slow_tool", { data: "value" }, {
  timeout: 60000,
  maxTotalTimeout: 300000,
  resetTimeoutOnProgress: true,
  signal: controller.signal,
});

Full CallToolOptions, CallToolResult, and Tool types are in references/guides/tools.md.

listResources / listAllResources / readResource

const resources = await session.listResources();      // paginated
const allResources = await session.listAllResources(); // full catalog
const result = await session.readResource("file:///data/config.json");
for (const content of result.contents) {
  console.log(content.text ?? content.blob);
}

Full Resource, ResourceResult, and template patterns are in references/guides/resources.md.

getPrompt / complete

const prompts = await session.listPrompts();
const result = await session.getPrompt("plan_vacation", { destination: "Japan" });

const completions = await session.complete({
  ref: { type: "ref/prompt", name: "my-prompt" },
  argument: { name: "language", value: "py" },
});

Full types in references/guides/prompts.md and references/guides/completion.md.

Notifications and roots

session.on("notification", async (notification) => {
  if (notification.method === "notifications/tools/list_changed") {
    const tools = await session.listTools();
  }
});

await session.setRoots([
  { uri: "file:///home/user/project", name: "My Project" },
]);

Full notification types, custom events, and logging in references/guides/notifications-and-logging.md.

Sampling callback

import { MCPClient, type OnSamplingCallback } from "mcp-use";

const onSampling: OnSamplingCallback = async (params) => {
  const lastMsg = params.messages[params.messages.length - 1];
  const text = typeof lastMsg?.content === "object" && "text" in lastMsg.content
    ? lastMsg.content.text ?? "" : "";
  return {
    role: "assistant",
    content: { type: "text", text: await yourLLM.complete(text) },
    model: "your-model",
    stopReason: "endTurn",
  };
};

Callback precedence: per-server onSampling > global onSampling. Full CreateMessageRequestParams, CreateMessageResult, and model preferences in references/guides/sampling.md.

Elicitation callback

import { accept, decline, cancel, validate, acceptWithDefaults, MCPClient } from "mcp-use";
import type { OnElicitationCallback } from "mcp-use";

const onElicitation: OnElicitationCallback = async (params) => {
  if (params.mode === "url") {
    console.log(`Visit: ${params.url}`);
    return { action: "accept" };
  }
  return acceptWithDefaults(params);
};

Eight helper utilities (accept, decline, cancel, reject, validate, acceptWithDefaults, getDefaults, applyDefaults), form vs URL modes, and validation patterns are in references/guides/elicitation.md.

React hooks

// Single-server:
import { useMcp } from "mcp-use/react";
const mcp = useMcp({
  url: "http://localhost:3000/mcp",
  autoReconnect: true,
  callbackUrl: "http://localhost:3000/callback",
  onElicitation: async (params) => acceptWithDefaults(params),
});
// mcp.state: "discovering" | "authenticating" | "pending_auth" | "ready" | "failed"
// mcp.tools, mcp.resources, mcp.prompts
// mcp.callTool("name", args), mcp.readResource(uri), mcp.authenticate(), mcp.retry()

// Multi-server:
import { McpClientProvider, useMcpClient, useMcpServer } from "mcp-use/react";

<McpClientProvider storageProvider={new LocalStorageProvider("my-app")}>
  <App />
</McpClientProvider>

const { servers, addServer, removeServer } = useMcpClient();
const server = useMcpServer("linear");

Full useMcp options (20+), McpClientProvider props, McpServerOptions table, proxy fallback, autoReconnect vs reconnectionOptions, and notification management in references/guides/usemcp-and-react.md.

Code mode

const client = new MCPClient(config, { codeMode: true }); // VM executor (default)
const result = await client.executeCode(`
  const tools = await search_tools("github");
  return tools;
`);
// result.result, result.logs, result.error, result.execution_time
await client.close(); // required — cleans up E2B sandboxes if used

VM options, E2B setup, custom executors, BaseCodeExecutor, and PROMPTS.CODE_MODE in references/guides/code-mode.md.


Environment feature matrix

FeatureNode.jsBrowserReact (hook)CLI
STDIO connectionsYesNoNoYes
HTTP connectionsYesYesYesYes
File system accessYesNoNoYes
Code modeYesNoNoNo
OAuth flowYesYesYesYes
Automatic state managementNoNoYesNo
Session persistenceNoNoNoYes

Import paths:

EnvironmentImport
Node.jsimport {MCPClient, loadConfigFile} from "mcp-use"
Browserimport {MCPClient} from "mcp-use/browser"
Reactimport {useMcp} from "mcp-use/react"
Browser OAuthimport {BrowserOAuthClientProvider} from "mcp-use/browser"
OAuth callbackimport {onMcpAuthorization} from "mcp-use/auth"

Rules

  1. Always call client.closeAllSessions() or client.close() in cleanup — leaked sessions hold server processes open. Use client.close() when using E2B code mode.
  2. Check session.connector.serverCapabilities before calling complete() — not all servers support completions.
  3. Use acceptWithDefaults(params) as the default elicitation callback — never leave onElicitation undefined if the server uses elicitation.
  4. Import from the correct entry point: mcp-use (Node), mcp-use/browser (Browser), mcp-use/react (React) — wrong imports cause runtime errors.
  5. Set timeout and maxTotalTimeout on long-running tool calls — the default 60s timeout will abort slow operations.
  6. Handle isError: true in CallToolResult — tool errors are returned, not thrown.
  7. Use per-server callbacks when connecting to servers with different LLM providers.
  8. Debounce complete() calls in autocomplete UIs — servers may rate-limit completion requests.
  9. Listen for notifications/tools/list_changed and re-fetch tools — servers can add/remove tools dynamically.
  10. Use autoReconnect in production React apps — connections drop; the client handles re-initialization transparently.

Common pitfalls

MistakeFix
Not calling createAllSessions() before using sessionsCall await client.createAllSessions() after construction
Calling complete() without capability checkCheck session.connector.serverCapabilities?.completions first
Missing onElicitation when server uses ctx.elicit()Set onElicitation: (params) => acceptWithDefaults(params)
Missing onSampling when server uses ctx.sample()Provide onSampling callback routing to your LLM
Using mcp-use import in browserUse mcp-use/browser — main entry point requires Node APIs
Hardcoded secrets in client configUse environment variables: ` headers: {Authorization: Bearer ${process.env.TOKEN}} `
Not handling isError in tool resultsCheck result.isError before processing result.content
Forgetting cleanup on process exitRegister process.on("SIGINT", () => client.closeAllSessions())
Using legacy SSE for new HTTP connectionsPrefer streamable HTTP: use transport: "http" in client config or transportType: "http" in React
No reconnection config in ReactSet autoReconnect: true on useMcp or per-server options
Checking mcp.status instead of mcp.stateThe hook exposes state, not status
Assuming one listResources() call returns the full catalogUse session.listAllResources() for the full set, or follow nextCursor with listResources(cursor)
Treating readResource() as plain valueIt returns {contents: ResourceContent[]} — iterate result.contents
Using persistenceProvider on McpClientProviderCorrect prop is storageProvider
Confusing autoReconnect with reconnectionOptionsautoReconnect = app-level health checks; reconnectionOptions = SDK transport back-off
Not calling client.close() after E2B code modeE2B sandboxes stay alive until client.close() is called

Do this, not that

Do thisNot that
import {MCPClient} from "mcp-use"import {Client} from "@modelcontextprotocol/sdk/client"
session.callTool("name", args)Build JSON-RPC requests manually
acceptWithDefaults(params) for elicitationReturn {action: "accept"} without content
session.on("notification", handler)Poll session.listTools() on an interval
client.closeAllSessions() in cleanupLet sessions leak on process exit
loadConfigFile("config.json") then new MCPClient(config)Parse JSON and construct transports manually
useMcp({url, autoReconnect: true}) in ReactBuild custom WebSocket reconnection logic
validate(params, data) before accepting elicitationSkip validation and accept any input
Per-server onSampling for multi-LLM setupsOne global callback with server-name switch
session.listAllResources() for the full catalog, or session.listResources(cursor) for paginationAssume one listResources() page is exhaustive
mcp.state in Reactmcp.status (does not exist)
transport: "http" in client config or transportType: "http" in Reacttransport: "sse" or transportType: "sse" for new integrations
storageProvider={...} on McpClientProviderpersistenceProvider={...} (wrong prop name)
client.close() after E2B code modecloseAllSessions() alone (misses sandbox cleanup)

Guardrails

  • Never import from @modelcontextprotocol/sdk directly — use mcp-use, mcp-use/browser, or mcp-use/react.
  • Never call session.callTool() before createAllSessions() or session.initialize() completes.
  • Never leave onSampling undefined if a server uses ctx.sample() — the request fails silently.
  • Never leave onElicitation undefined if a server uses ctx.elicit() — use acceptWithDefaults(params) as minimum.
  • Never hardcode secrets in client config — use environment variables or OAuth providers.
  • Never skip client.closeAllSessions() on shutdown — leaked STDIO sessions leave orphan child processes.
  • Never use mcp-use (Node entry point) in a browser — it requires Node APIs; use mcp-use/browser.
  • Never assume all servers support completions — check serverCapabilities?.completions first.
  • Always handle isError: true in CallToolResult — tool errors are returned as results, not thrown.
  • Always set autoReconnect: true in production React apps.
  • Always debounce complete() calls in autocomplete UIs.
  • Always clean up sessions on process exit — register SIGINT/SIGTERM handlers.
  • Prefer streamable HTTP for new connections: use transport: "http" in server config, or transportType: "http" / "auto" in React.
  • Never treat readResource() return as a plain value — it returns {contents: ResourceContent[]}.
  • Do not await loadConfigFile() — it reads and parses JSON synchronously in Node. Use new MCPClient("config.json"), MCPClient.fromConfigFile("config.json"), or new MCPClient(loadConfigFile("config.json")).
  • Never use mcp.status in React — correct property is mcp.state.
  • Always check all connection states: "discovering", "authenticating", "pending_auth", "ready", "failed".
  • Never use persistenceProvider on McpClientProvider — correct prop is storageProvider.
  • Do not confuse autoReconnect (app-level health checks) with reconnectionOptions (SDK transport back-off).
  • Always call client.close() when using E2B code mode — sandboxes persist until explicitly closed.
  • Prefer onElicitation over the deprecated elicitationCallback alias.

平台分布

Claude

34.54%
按下载量换算48

Codex

33.48%
按下载量换算47

Cursor

17.95%
按下载量换算25

Gemini CLI

8.98%
按下载量换算12

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

可疑

权限和风险

接触敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在提醒或未通过项,安装前请自行复核。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills