Skip to content

Commit f1c0148

Browse files
committed
refactor: remove unused HelperTool type references from tools and server modules
1 parent 3dcff1e commit f1c0148

File tree

3 files changed

+22
-27
lines changed

3 files changed

+22
-27
lines changed

src/mcp/server.ts

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {
3737
import { prompts } from '../prompts/index.js';
3838
import { callActorGetDataset, defaultTools, getActorsAsTools, toolCategories } from '../tools/index.js';
3939
import { decodeDotPropertyNames } from '../tools/utils.js';
40-
import type { ActorMcpTool, ActorTool, HelperTool, ToolEntry } from '../types.js';
40+
import type { ToolEntry } from '../types.js';
4141
import { buildActorResponseContent } from '../utils/actor-response.js';
4242
import { buildMCPResponse } from '../utils/mcp.js';
4343
import { createProgressTracker } from '../utils/progress.js';
@@ -142,7 +142,7 @@ export class ActorsMcpServer {
142142
private listInternalToolNames(): string[] {
143143
return Array.from(this.tools.values())
144144
.filter((tool) => tool.type === 'internal')
145-
.map((tool) => (tool as HelperTool).name);
145+
.map((tool) => tool.name);
146146
}
147147

148148
/**
@@ -152,7 +152,7 @@ export class ActorsMcpServer {
152152
public listActorToolNames(): string[] {
153153
return Array.from(this.tools.values())
154154
.filter((tool) => tool.type === 'actor')
155-
.map((tool) => (tool as ActorTool).actorFullName);
155+
.map((tool) => tool.actorFullName);
156156
}
157157

158158
/**
@@ -162,7 +162,7 @@ export class ActorsMcpServer {
162162
private listActorMcpServerToolIds(): string[] {
163163
const ids = Array.from(this.tools.values())
164164
.filter((tool: ToolEntry) => tool.type === 'actor-mcp')
165-
.map((tool: ToolEntry) => (tool as ActorMcpTool).actorId);
165+
.map((tool) => tool.actorId);
166166
// Ensure uniqueness
167167
return Array.from(new Set(ids));
168168
}
@@ -504,7 +504,7 @@ export class ActorsMcpServer {
504504
// TODO - if connection is /mcp client will not receive notification on tool change
505505
// Find tool by name or actor full name
506506
const tool = Array.from(this.tools.values())
507-
.find((t) => t.name === name || (t.type === 'actor' && (t as ActorTool).actorFullName === name));
507+
.find((t) => t.name === name || (t.type === 'actor' && t.actorFullName === name));
508508
if (!tool) {
509509
const msg = `Tool ${name} not found. Available tools: ${this.listToolNames().join(', ')}`;
510510
log.error(msg);
@@ -540,15 +540,13 @@ export class ActorsMcpServer {
540540
try {
541541
// Handle internal tool
542542
if (tool.type === 'internal') {
543-
const internalTool = tool as HelperTool;
544-
545543
// Only create progress tracker for call-actor tool
546-
const progressTracker = internalTool.name === 'call-actor'
544+
const progressTracker = tool.name === 'call-actor'
547545
? createProgressTracker(progressToken, extra.sendNotification)
548546
: null;
549547

550-
log.info('Calling internal tool', { name: internalTool.name, input: args });
551-
const res = await internalTool.call({
548+
log.info('Calling internal tool', { name: tool.name, input: args });
549+
const res = await tool.call({
552550
args,
553551
extra,
554552
apifyMcpServer: this,
@@ -566,12 +564,11 @@ export class ActorsMcpServer {
566564
}
567565

568566
if (tool.type === 'actor-mcp') {
569-
const serverTool = tool as ActorMcpTool;
570567
let client: Client | null = null;
571568
try {
572-
client = await connectMCPClient(serverTool.serverUrl, apifyToken);
569+
client = await connectMCPClient(tool.serverUrl, apifyToken);
573570
if (!client) {
574-
const msg = `Failed to connect to MCP server ${serverTool.serverUrl}`;
571+
const msg = `Failed to connect to MCP server ${tool.serverUrl}`;
575572
log.error(msg);
576573
await this.server.sendLoggingMessage({ level: 'error', data: msg });
577574
return {
@@ -597,9 +594,9 @@ export class ActorsMcpServer {
597594
}
598595
}
599596

600-
log.info('Calling Actor-MCP', { actorId: serverTool.actorId, toolName: serverTool.originToolName, input: args });
597+
log.info('Calling Actor-MCP', { actorId: tool.actorId, toolName: tool.originToolName, input: args });
601598
const res = await client.callTool({
602-
name: serverTool.originToolName,
599+
name: tool.originToolName,
603600
arguments: args,
604601
_meta: {
605602
progressToken,
@@ -627,12 +624,10 @@ export class ActorsMcpServer {
627624
};
628625
}
629626

630-
const actorTool = tool as ActorTool;
631-
632627
// Create progress tracker if progressToken is available
633628
const progressTracker = createProgressTracker(progressToken, extra.sendNotification);
634629

635-
const callOptions: ActorCallOptions = { memory: actorTool.memoryMbytes };
630+
const callOptions: ActorCallOptions = { memory: tool.memoryMbytes };
636631

637632
/**
638633
* Create Apify token, for Skyfire mode use `skyfire-pay-id` and for normal mode use `apifyToken`.
@@ -643,9 +638,9 @@ export class ActorsMcpServer {
643638
: new ApifyClient({ token: apifyToken });
644639

645640
try {
646-
log.info('Calling Actor', { actorName: actorTool.actorFullName, input: actorArgs });
641+
log.info('Calling Actor', { actorName: tool.actorFullName, input: actorArgs });
647642
const callResult = await callActorGetDataset(
648-
actorTool.actorFullName,
643+
tool.actorFullName,
649644
actorArgs,
650645
apifyClient,
651646
callOptions,
@@ -659,7 +654,7 @@ export class ActorsMcpServer {
659654
return { };
660655
}
661656

662-
const content = buildActorResponseContent(actorTool.actorFullName, callResult);
657+
const content = buildActorResponseContent(tool.actorFullName, callResult);
663658
return { content };
664659
} finally {
665660
if (progressTracker) {

src/utils/tools-loader.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { callActor } from '../tools/actor.js';
1414
import { getActorOutput } from '../tools/get-actor-output.js';
1515
import { addTool } from '../tools/helpers.js';
1616
import { getActorsAsTools, toolCategories, toolCategoriesEnabledByDefault } from '../tools/index.js';
17-
import type { HelperTool, Input, InternalToolArgs, ToolCategory, ToolEntry } from '../types.js';
17+
import type { Input, InternalToolArgs, ToolCategory, ToolEntry } from '../types.js';
1818
import { getExpectedToolsByCategories } from './tools.js';
1919

2020
// Lazily-computed cache of internal tools by name to avoid circular init issues.
@@ -163,7 +163,7 @@ export async function loadToolsFromInput(
163163
const toolFunctions = new Map<string, { ajvValidate?: ValidateFunction<unknown>; call?:(args: InternalToolArgs) => Promise<object> }>();
164164
for (const entry of filtered) {
165165
if (entry.type === 'internal') {
166-
toolFunctions.set(entry.name, { ajvValidate: entry.ajvValidate, call: (entry as HelperTool).call });
166+
toolFunctions.set(entry.name, { ajvValidate: entry.ajvValidate, call: entry.call });
167167
} else {
168168
toolFunctions.set(entry.name, { ajvValidate: entry.ajvValidate });
169169
}
@@ -182,7 +182,7 @@ export async function loadToolsFromInput(
182182
entry.ajvValidate = funcs.ajvValidate;
183183
}
184184
if (entry.type === 'internal' && funcs.call) {
185-
(entry as HelperTool).call = funcs.call;
185+
entry.call = funcs.call;
186186
}
187187
}
188188
}

src/utils/tools.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { toolCategories } from '../tools/index.js';
2-
import type { HelperTool, ToolBase, ToolCategory, ToolEntry } from '../types.js';
2+
import type { ToolBase, ToolCategory, ToolEntry } from '../types.js';
33

44
/**
55
* Returns a public version of the tool containing only fields that should be exposed publicly.
@@ -35,7 +35,7 @@ export function getExpectedToolNamesByCategories(categories: ToolCategory[]): st
3535
export function cloneToolEntry(toolEntry: ToolEntry): ToolEntry {
3636
// Store the original functions
3737
const originalAjvValidate = toolEntry.ajvValidate;
38-
const originalCall = toolEntry.type === 'internal' ? (toolEntry as HelperTool).call : undefined;
38+
const originalCall = toolEntry.type === 'internal' ? toolEntry.call : undefined;
3939

4040
// Create a deep copy using JSON serialization (excluding functions)
4141
const cloned = JSON.parse(JSON.stringify(toolEntry, (key, value) => {
@@ -46,7 +46,7 @@ export function cloneToolEntry(toolEntry: ToolEntry): ToolEntry {
4646
// Restore the original functions
4747
cloned.ajvValidate = originalAjvValidate;
4848
if (toolEntry.type === 'internal' && originalCall) {
49-
(cloned as HelperTool).call = originalCall;
49+
cloned.call = originalCall;
5050
}
5151

5252
return cloned;

0 commit comments

Comments
 (0)