Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions src/mcp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ export class ActorsMcpServer {
*/
this.server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
// eslint-disable-next-line prefer-const
let { name, arguments: args } = request.params;
let { name, arguments: args, _meta: meta } = request.params;
const { progressToken } = meta || {};
const apifyToken = (request.params.apifyToken || process.env.APIFY_TOKEN) as string;
const userRentedActorIds = request.params.userRentedActorIds as string[] | undefined;

Expand Down Expand Up @@ -433,24 +434,28 @@ export class ActorsMcpServer {
try {
client = await connectMCPClient(serverTool.serverUrl, apifyToken);

// TODO: for some reason the client does not receive notifications
// we need to investigate this
// Set up notification handlers for the client
for (const schema of ServerNotificationSchema.options) {
const method = schema.shape.method.value;
// Forward notifications from the proxy client to the server
client.setNotificationHandler(schema, async (notification) => {
log.info('Sending MCP notification', {
method,
notification,
// Only set up notification handlers if progressToken is provided by the client
if (progressToken) {
// Set up notification handlers for the client
for (const schema of ServerNotificationSchema.options) {
const method = schema.shape.method.value;
// Forward notifications from the proxy client to the server
client.setNotificationHandler(schema, async (notification) => {
log.info('Sending MCP notification', {
method,
notification,
});
await extra.sendNotification(notification);
});
await extra.sendNotification(notification);
});
}
}

const res = await client.callTool({
name: serverTool.originToolName,
arguments: args,
_meta: {
progressToken,
},
}, CallToolResultSchema, {
timeout: EXTERNAL_TOOL_CALL_TIMEOUT_MSEC,
});
Expand Down