33 * Connect to the MCP server using SSE transport and call a tool.
44 * The Actors MCP Server will load default Actors.
55 *
6- * !!! NOT WORKING - This example needs to be fixed as it does not work !!!
76 */
87
98import path from 'path' ;
@@ -15,15 +14,17 @@ import { CallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';
1514import dotenv from 'dotenv' ;
1615import { EventSource } from 'eventsource' ;
1716
17+ const REQUEST_TIMEOUT = 120_000 ; // 2 minutes
1818// Resolve dirname equivalent in ES module
1919const filename = fileURLToPath ( import . meta. url ) ;
2020const dirname = path . dirname ( filename ) ;
2121
2222dotenv . config ( { path : path . resolve ( dirname , '../../.env' ) } ) ;
2323
24- const SERVER_URL = 'https://actors-mcp-server/sse' ;
24+ const SERVER_URL = 'https://actors-mcp-server.apify.actor /sse' ;
2525// We need to change forward slash / to underscore _ in the tool name as Anthropic does not allow forward slashes in the tool name
2626const SELECTED_TOOL = 'apify_rag-web-browser' ;
27+ const QUERY = 'web browser for Anthropic' ;
2728
2829if ( ! process . env . APIFY_TOKEN ) {
2930 console . error ( 'APIFY_TOKEN is required but not set in the environment variables.' ) ;
@@ -81,10 +82,11 @@ async function main(): Promise<void> {
8182 }
8283
8384 // Call a tool
84- console . log ( ' Calling actor ...' ) ;
85+ console . log ( ` Calling actor ... ${ SELECTED_TOOL } ` ) ;
8586 const result = await client . callTool (
86- { name : SELECTED_TOOL , arguments : { query : 'web browser for Anthropic' } } ,
87+ { name : SELECTED_TOOL , arguments : { query : QUERY } } ,
8788 CallToolResultSchema ,
89+ { timeout : REQUEST_TIMEOUT } ,
8890 ) ;
8991 console . log ( 'Tool result:' , JSON . stringify ( result , null , 2 ) ) ;
9092 } catch ( error : unknown ) {
0 commit comments