Manually triggers the authentication process. Useful if the initial attempt failed due to a blocked popup, allowing the user to initiate it via a button click.
A promise that resolves with the authorization URL opened (or intended to be opened), or undefined if auth cannot be started.
OptionalauthOAuth tokens if authentication was completed Available when state is 'ready' and OAuth was used
OAuth access token.
Optionalclient_id?: stringOAuth client id (from Dynamic Client Registration or a static client). Most token endpoints require it on refresh, so consumers can persist it for server-side proactive refresh.
Optionalclient_secret?: stringOAuth client secret, when the provider issued a confidential client.
Optionalexpires_at?: numberUnix timestamp in seconds when the access token expires.
Optionalrefresh_token?: stringOAuth refresh token, when issued.
Optionalresource?: stringCanonical protected-resource URL required by some token refresh flows.
Optionalscope?: stringSpace-delimited OAuth scopes granted to the token.
Optionaltoken_endpoint?: stringOAuth token endpoint resolved during discovery (when available). Lets consumers persist it so a backend can proactively refresh the token.
OAuth token type, commonly "Bearer".
OptionalauthIf authentication requires user interaction (e.g., popup was blocked), this URL can be presented to the user to complete authentication manually in a new tab.
Function to call a tool on the MCP server.
The name of the tool to call.
Optionalargs: Record<string, unknown>
Optional arguments for the tool.
Optionaloptions: {Optional request options including timeout configuration.
OptionalmaxTotalTimeout?: numberMaximum total timeout in milliseconds, even with progress resets
OptionalresetTimeoutOnProgress?: booleanReset the timeout when progress notifications are received (default: false)
Optionalsignal?: AbortSignalAbortSignal to cancel the request
Optionaltimeout?: numberTimeout in milliseconds for this tool call (default: 60000 / 60 seconds)
A promise that resolves with the tool's result.
// Simple tool call
const result = await mcp.callTool('my-tool', { arg: 'value' })
// Tool call with extended timeout (e.g., for tools that trigger sampling)
const result = await mcp.callTool('analyze-sentiment', { text: 'Hello' }, {
timeout: 300000, // 5 minutes
resetTimeoutOnProgress: true // Reset timeout when progress notifications are received
})
OptionalcapabilitiesServer capabilities normalized for the active connection.
Clears all stored authentication data (tokens, client info, etc.) for this server URL from localStorage.
The underlying runtime-neutral MCP client instance. Use this to create an MCPAgent for AI chat functionality.
import { MCPAgent } from "@mcp-use/agent"
import { ChatOpenAI } from '@langchain/openai'
const mcp = useMcp({ url: 'http://localhost:3000/mcp' })
const llm = new ChatOpenAI({ model: 'gpt-4' })
const agent = new MCPAgent({ llm, client: mcp.client })
await agent.initialize()
for await (const event of agent.streamEvents('Hello')) {
console.log(event)
}
Request completion suggestions for a prompt or resource template argument.
Completion request parameters specifying the ref and argument to complete.
A promise that resolves with completion suggestions from the server.
Disconnects the client from the MCP server.
Ensure the server icon is loaded and available in serverInfo Returns a promise that resolves when the icon is ready Use this before server creation to guarantee the icon is available
Promise that resolves with the base64 icon or null if not available
OptionalerrorIf the state is 'failed', this provides the error message
Protocol extension metadata normalized from the server capabilities.
Function to get a specific prompt from the MCP server.
The name of the prompt to get.
Optionalargs: Record<string, string>
Optional arguments for the prompt.
A promise that resolves with the prompt messages.
OptionalinstructionsOptional server instructions advertised for the active connection.
Function to list prompts from the MCP server.
A promise that resolves when prompts are refreshed.
Function to list resources from the MCP server.
A promise that resolves when resources are refreshed.
Array of internal log messages (useful for debugging)
Log severity.
Human-readable log message.
Unix timestamp in milliseconds when the entry was created.
Name advertised by the connected MCP server.
List of prompts available from the connected MCP server
OptionalprotocolNegotiated MCP protocol era for the active connection:
undefined until a connection has negotiated.OptionalprotocolNegotiated MCP protocol version string (e.g. '2025-06-18', '2026-07-28').
Function to read a resource from the MCP server.
The URI of the resource to read.
A promise that resolves with the resource contents.
Refresh all lists (tools, resources, resource templates, prompts) from the server. Useful after reconnection or for manual refresh.
Refresh the prompts list from the server. Called automatically when notifications/prompts/list_changed is received. Can also be called manually for explicit refresh.
Refresh the resources list from the server. Called automatically when notifications/resources/list_changed is received. Can also be called manually for explicit refresh.
Refresh the resource templates list from the server. Can be called manually for explicit refresh.
Refresh the tools list from the server. Called automatically when notifications/tools/list_changed is received. Can also be called manually for explicit refresh.
List of resources available from the connected MCP server
List of resource templates available from the connected MCP server
Manually attempts to reconnect if the state is 'failed'.
OptionalserverServer information normalized for the active connection.
Optionaldescription?: stringOptional human-readable server description.
Optionalicon?: stringBase64-encoded favicon auto-detected from server domain
Optionalicons?: { mimeType?: string; sizes?: string[]; src: string }[]Icons advertised by the server.
Stable server name.
Optionaltitle?: stringOptional human-readable server title.
Optionalversion?: stringServer version.
OptionalwebsiteUrl?: stringPublic website describing the server.
The current state of the MCP connection:
error property.List of tools available from the connected MCP server
Reactive state and operations returned by useMcp.