with one click
build-mcp-use-client
// Use skill if you are building MCP client applications with the mcp-use TypeScript SDK — MCPClient, sessions, tools, resources, React hooks, code mode, and authentication.
// Use skill if you are building MCP client applications with the mcp-use TypeScript SDK — MCPClient, sessions, tools, resources, React hooks, code mode, and authentication.
[HINT] Download the complete skill directory including SKILL.md and all related files
| name | build-mcp-use-client |
| description | Use skill if you are writing TypeScript MCP client code with mcp-use — MCPClient, MCPSession, useMcp, McpClientProvider, mcp-use/browser, mcp-use/react, or npx mcp-use client. |
Build or audit deterministic TypeScript MCP client code using the mcp-use SDK: MCPClient, MCPSession, mcp-use/browser, mcp-use/react (useMcp, McpClientProvider, useMcpClient, useMcpServer), code mode, and the npx mcp-use client CLI.
The client is the half that connects to an MCP server, lists/calls tools, reads resources, manages sessions, and handles auth — without an LLM choosing what to call.
Use this skill when any of these are true:
"mcp-use", "mcp-use/browser", or "mcp-use/react"new MCPClient(...), calls createSession()/createAllSessions(), or uses client.close()/closeAllSessions()useMcp, McpClientProvider, useMcpClient, or useMcpServer (note: state not status; storageProvider not persistenceProvider)npx mcp-use client or has mcp.json, mcp.config.json, or .vscode/mcp.json config filesexecuteCode()/search_tools() from a clientDo NOT use this skill if:
MCPAgent — route to build-mcp-use-agent"mcp-use/server", defines server.tool/server.resource/server.prompt, or builds widgets/transports/server auth — route to build-mcp-use-server@modelcontextprotocol/sdk without the mcp-use wrapper — route to build-mcp-server-sdk-v1 or build-mcp-server-sdk-v2mcpc — route to test-by-mcpc-cliInspect the path the user named directly. Do not start with a repo-wide scan when a subdirectory is given.
These rules are load-bearing — violating them is the most common source of client bugs.
| # | Rule | Why |
|---|---|---|
| 1 | Import from mcp-use, mcp-use/browser, or mcp-use/react only | Hand-rolling raw @modelcontextprotocol/sdk calls inside a wrapper-library project re-implements features and breaks reconnection/auth integration |
| 2 | await createSession() / createAllSessions() before use | Sessions are async; using an unresolved promise yields runtime errors that look like config bugs |
| 3 | Always cleanup: closeAllSessions() for normal clients; client.close() for code mode | Code mode allocates external executors (VM/E2B) that leak without close() |
| 4 | Discover before hardcoding: list tools/resources/prompts before assuming names | Server schemas drift; hardcoded names break silently when the server adds optional args |
| 5 | Handle CallToolResult.isError, content, structuredContent, and _meta deliberately | The shape is union-like; assuming content[0].text exists masks real tool errors |
| 6 | Set timeout, maxTotalTimeout, and AbortSignal for long-running tools | Defaults will hang on slow tools; production work needs explicit cancellation |
| 7 | Tokens belong server-side or in OAuth flows; browser headers carry only public values | mcp-use/browser headers are visible to anyone who opens devtools |
| 8 | Use mcp.state (not status) and storageProvider (not persistenceProvider) | These names changed; older docs and AI-generated code still ship the old ones |
| 9 | Check optional capabilities (e.g. completion) before calling them | Servers advertise capabilities — calling unsupported ones throws confusing errors |
| 10 | Report what validation actually ran; do not imply runtime coverage from tsc alone | Type checks are necessary but not sufficient for client behavior verification |
Inspect the target path and look for client-side signals:
tree -L 3 2>/dev/null || find . -maxdepth 3 -type f | sort
Confirm:
package.json has "mcp-use" as a dependency"mcp-use", "mcp-use/browser", or "mcp-use/react"MCPClient, MCPSession, useMcp, McpClientProvider, useMcpClient, useMcpServernpx mcp-use client scripts, mcp.json, mcp.config.*, .vscode/mcp.json@modelcontextprotocol/sdk — these route to raw SDK skills, not here"mcp-use/server" — these route to build-mcp-use-serverMCPAgent usage — that routes to build-mcp-use-agentRun the version preflight when Node/npm are available:
bash skills/build-mcp-use-client/skills/build-mcp-use-client/scripts/check-mcp-use-version.sh <target-path>
Read scripts/check-mcp-use-version.sh.md before changing the script or interpreting non-obvious output.
Run the diagnostic script first:
bash skills/build-mcp-use-client/skills/build-mcp-use-client/scripts/diagnose-client.sh <target-path>
Read scripts/diagnose-client.sh.md for the diagnostic categories and exit-code contract.
Audit the implementation against the surface map below before editing. Apply focused fixes — do not rebuild a working client from scratch.
| Audit surface | Read | Check for |
|---|---|---|
| constructor, config files, sessions, imports | references/guides/client-configuration.md, references/guides/environments.md | correct entry point, current Node/package baseline, awaited session creation, cleanup |
| tools, resources, prompts, completion | references/guides/tools.md, references/guides/resources.md, references/guides/prompts.md, references/guides/completion.md | discovery before calls, isError handling, structuredContent, pagination, capability checks, timeouts/abort |
| callbacks, auth, notifications | references/guides/sampling.md, references/guides/elicitation.md, references/guides/authentication.md, references/guides/notifications-and-logging.md | callback names, browser secret boundary, token expiry/re-auth, list-changed handlers |
| React | references/guides/usemcp-and-react.md | state not status, one provider for multi-server apps, StrictMode-safe addServer, cleanup, all states handled |
| code mode | references/guides/code-mode.md | executor isolation, executeCode(), search_tools(), client.close() |
| production hardening | references/patterns/production-patterns.md, references/patterns/anti-patterns.md, references/troubleshooting/common-errors.md | reconnection, 404 recovery, idle proxy timeout, process shutdown, dropped connections |
If repo context already gives the environment, server target, and auth shape, skip the questionnaire and build directly.
Pick the server target before coding:
@modelcontextprotocol/server-everything for a smoke test.build-mcp-use-server first.If context is missing, ask only the questions you cannot answer:
npx mcp-use client.useMcp or provider-based multi-server app.npm view mcp-use metadata; do not keep old Node 18 guidance for current releases.mcp-use for Node, mcp-use/browser for browser, mcp-use/react for React.Route to the reference file matching the user's intent. Do not load files speculatively.
| Trigger | File | Why |
|---|---|---|
| install, first Node/browser/React/CLI client | references/guides/quick-start.md | minimal runnable paths and first calls |
| choose Node/browser/React/CLI entry point | references/guides/environments.md | environment matrix, imports, limits |
configure MCPClient, config files, sessions | references/guides/client-configuration.md | constructor shape, callbacks, 404 recovery |
| manage multiple servers dynamically | references/guides/server-manager.md | server manager and dynamic config patterns |
| list/call tools, set timeouts, abort | references/guides/tools.md | result handling, progress, cancellation |
| read resources, templates, subscriptions | references/guides/resources.md | pagination, content shapes, notifications |
| list/get prompts | references/guides/prompts.md | prompt arguments and prompt updates |
| implement argument/resource completion | references/guides/completion.md | capability checks and debounce guidance |
| handle sampling requests | references/guides/sampling.md | onSampling, model preferences, React callbacks |
| handle elicitation requests | references/guides/elicitation.md | onElicitation, helpers, form and URL modes |
| handle auth, re-auth, browser secrets | references/guides/authentication.md | OAuth, bearer tokens, headers, CLI auth, DCR/manual registration |
| receive list-changed events, roots, logs | references/guides/notifications-and-logging.md | notification listeners and logging callbacks |
| build React clients | references/guides/usemcp-and-react.md | hook/provider props, lifecycle, states, reconnection |
| use code mode | references/guides/code-mode.md | executors, imports, safety, browser/React limits |
use npx mcp-use client | references/guides/cli-reference.md | CLI commands, sessions, JSON scripting |
| copy complete examples | references/examples/client-recipes.md | Node, browser, React, code mode recipes |
| scaffold project layouts | references/examples/project-templates.md | package structures and starter files |
| harden production behavior | references/patterns/production-patterns.md | shutdown, retries, reconnect, observability |
| review mistakes before finalizing | references/patterns/anti-patterns.md | known bad patterns and fixes |
| diagnose specific errors | references/troubleshooting/common-errors.md | connection, auth, React, code mode, import failures |
| verify package baseline | scripts/check-mcp-use-version.sh | Node/package/npm drift diagnostics |
| diagnose a stuck client | scripts/diagnose-client.sh | config/import/auth/lifecycle scan |
npm view mcp-use version engines peerDependencies --json as the source of truth for current install guidance.scripts/check-mcp-use-version.sh before copying examples into a project.^1.21.0 style pins.McpClientProvider for multi-server apps.addServer() calls inside useEffect idempotent under StrictMode; clean up temporary servers with removeServer() when appropriate.discovering, authenticating, pending_auth, ready, failed.client.close() because code mode may allocate external resources.mcp-use does not target WebSocket transport.references/guides/tools.md and reconnection guidance in references/patterns/production-patterns.md.Use the smallest honest set:
npm run typecheck
npm run lint
npm test
npx tsx src/client.ts
npx mcp-use client connect --stdio "npx -y @modelcontextprotocol/server-everything" --name smoke
For React, exercise every rendered state: discovering, authenticating, pending_auth, ready, failed. For auth issues, test 401/403, expired refresh token, popup blocked, redirect callback failure, and pending_auth loops against references/guides/authentication.md plus references/troubleshooting/common-errors.md.
When finishing a client task, report:
MCPClient, MCPSession, useMcp, provider hooks, code mode, CLI.