diff --git a/src/react/types.ts b/src/react/types.ts index b80df54..88edd7c 100644 --- a/src/react/types.ts +++ b/src/react/types.ts @@ -1,4 +1,4 @@ -import { Tool, Resource, ResourceTemplate, Prompt } from '@modelcontextprotocol/sdk/types.js' +import { Tool, Resource, ResourceTemplate, Prompt, RequestOptions } from '@modelcontextprotocol/sdk/types.js' export type UseMcpOptions = { /** The /sse URL of your remote MCP server */ @@ -71,10 +71,11 @@ export type UseMcpResult = { * Function to call a tool on the MCP server. * @param name The name of the tool to call. * @param args Optional arguments for the tool. + * @param options Optional request options (e.g., timeout). * @returns A promise that resolves with the tool's result. * @throws If the client is not in the 'ready' state or the call fails. */ - callTool: (name: string, args?: Record) => Promise + callTool: (name: string, args?: Record, options?: RequestOptions) => Promise /** * Function to list resources from the MCP server. * @returns A promise that resolves when resources are refreshed. diff --git a/src/react/useMcp.ts b/src/react/useMcp.ts index 697f74a..d408958 100644 --- a/src/react/useMcp.ts +++ b/src/react/useMcp.ts @@ -22,6 +22,7 @@ import { sanitizeUrl } from 'strict-url-sanitise' import { BrowserOAuthClientProvider } from '../auth/browser-provider.js' // Adjust path import { assert } from '../utils/assert.js' // Adjust path import type { UseMcpOptions, UseMcpResult } from './types.js' // Adjust path +import type { RequestOptions } from '@modelcontextprotocol/sdk/types.js' import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js' // Added for type safety const DEFAULT_RECONNECT_DELAY = 3000 @@ -506,14 +507,14 @@ export function useMcp(options: UseMcpOptions): UseMcpResult { // callTool is stable (depends on stable addLog, failConnection, connect, and URL) const callTool = useCallback( - async (name: string, args?: Record) => { + async (name: string, args?: Record, options?: RequestOptions) => { // Use stateRef for check, state for throwing error message if (stateRef.current !== 'ready' || !clientRef.current) { throw new Error(`MCP client is not ready (current state: ${state}). Cannot call tool "${name}".`) } addLog('info', `Calling tool: ${name}`, args) try { - const result = await clientRef.current.request({ method: 'tools/call', params: { name, arguments: args } }, CallToolResultSchema) + const result = await clientRef.current.request({ method: 'tools/call', params: { name, arguments: args } }, CallToolResultSchema, options) addLog('info', `Tool "${name}" call successful:`, result) return result } catch (err) {