Skip to content

Commit eb07cd7

Browse files
committed
rename authCode to authInfo
1 parent bcae51e commit eb07cd7

22 files changed

+136
-136
lines changed

src/actor/server.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import express from 'express';
1212
import log from '@apify/log';
1313

1414
import { ActorsMcpServer } from '../mcp/server.js';
15-
import type { AuthToken } from '../types.js';
15+
import type { AuthInfo } from '../types.js';
1616
import { getHelpMessage, HEADER_READINESS_PROBE, Routes, TransportType } from './const.js';
1717
import { getActorRunData } from './utils.js';
1818

@@ -74,12 +74,12 @@ export function createExpressApp(
7474
const transport = new SSEServerTransport(Routes.MESSAGE, res);
7575

7676
// Load MCP server tools
77-
const authToken: AuthToken = {
77+
const authInfo: AuthInfo = {
7878
value: process.env.APIFY_TOKEN as string,
7979
type: 'apify',
8080
};
81-
log.debug('Loading tools from URL', { sessionId: transport.sessionId, tr: TransportType.SSE });
82-
await mcpServer.loadToolsFromUrl(req.url, authToken);
81+
log.debug('Loading tools from URL', { sessionId: transport.sessionId, tr: TransportType.HTTP });
82+
await mcpServer.loadToolsFromUrl(req.url, authInfo);
8383

8484
transportsSSE[transport.sessionId] = transport;
8585
mcpServers[transport.sessionId] = mcpServer;
@@ -159,12 +159,12 @@ export function createExpressApp(
159159
const mcpServer = new ActorsMcpServer(false);
160160

161161
// Load MCP server tools
162-
const authToken: AuthToken = {
162+
const authInfo: AuthInfo = {
163163
value: process.env.APIFY_TOKEN as string,
164164
type: 'apify',
165165
};
166166
log.debug('Loading tools from URL', { sessionId: transport.sessionId, tr: TransportType.HTTP });
167-
await mcpServer.loadToolsFromUrl(req.url, authToken);
167+
await mcpServer.loadToolsFromUrl(req.url, authInfo);
168168

169169
// Connect the transport to the MCP server BEFORE handling the request
170170
await mcpServer.connect(transport);

src/apify-client.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ApifyClient as _ApifyClient } from 'apify-client';
33
import type { AxiosRequestConfig } from 'axios';
44

55
import { USER_AGENT_ORIGIN } from './const.js';
6-
import type { AuthToken } from './types.js';
6+
import type { AuthInfo } from './types.js';
77

88
/**
99
* Adds a User-Agent header to the request config.
@@ -26,20 +26,20 @@ export function getApifyAPIBaseUrl(): string {
2626
/**
2727
* Adds Skyfire header to the request config if needed.
2828
* @param config
29-
* @param authToken
29+
* @param authInfo
3030
* @private
3131
*/
32-
function addSkyfireHeader(config: AxiosRequestConfig, authToken: AuthToken): AxiosRequestConfig {
32+
function addSkyfireHeader(config: AxiosRequestConfig, authInfo: AuthInfo): AxiosRequestConfig {
3333
const updatedConfig = { ...config };
3434
updatedConfig.headers = updatedConfig.headers ?? {};
35-
updatedConfig.headers['skyfire-pay-id'] = authToken.value;
35+
updatedConfig.headers['skyfire-pay-id'] = authInfo.value;
3636
return updatedConfig;
3737
}
3838

3939
export class ApifyClient extends _ApifyClient {
40-
constructor(options: ApifyClientOptions & { authToken?: AuthToken }) {
41-
// Destructure to separate authToken from other options
42-
const { authToken, ...clientOptions } = options;
40+
constructor(options: ApifyClientOptions & { authInfo?: AuthInfo }) {
41+
// Destructure to separate authInfo from other options
42+
const { authInfo, ...clientOptions } = options;
4343

4444
/**
4545
* In order to publish to DockerHub, we need to run their build task to validate our MCP server.
@@ -51,26 +51,26 @@ export class ApifyClient extends _ApifyClient {
5151
delete clientOptions.token;
5252
}
5353

54-
// Handle authToken if provided
55-
if (authToken) {
56-
if (authToken.type === 'skyfire') {
54+
// Handle authInfo if provided
55+
if (authInfo) {
56+
if (authInfo.type === 'skyfire') {
5757
// For Skyfire tokens: DO NOT set as bearer token
5858
// Only add the skyfire-pay-id header via request interceptor
5959
// Remove any existing token to ensure no bearer auth
6060
delete clientOptions.token;
6161
} else {
6262
// For Apify tokens: Use as regular bearer token (existing behavior)
63-
clientOptions.token = authToken.value;
63+
clientOptions.token = authInfo.value;
6464
}
6565
}
6666

6767
const requestInterceptors = [addUserAgent];
68-
if (authToken?.type === 'skyfire') {
69-
requestInterceptors.push((config) => addSkyfireHeader(config, authToken));
68+
if (authInfo?.type === 'skyfire') {
69+
requestInterceptors.push((config) => addSkyfireHeader(config, authInfo));
7070
}
7171

7272
super({
73-
...clientOptions, // safe to spread without authToken
73+
...clientOptions, // safe to spread without authInfo
7474
baseUrl: getApifyAPIBaseUrl(),
7575
requestInterceptors,
7676
});

src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import log from '@apify/log';
1111
import { createExpressApp } from './actor/server.js';
1212
import { processInput } from './input.js';
1313
import { callActorGetDataset } from './tools/index.js';
14-
import type { AuthToken, Input } from './types.js';
14+
import type { AuthInfo, Input } from './types.js';
1515

1616
const STANDBY_MODE = Actor.getEnv().metaOrigin === 'STANDBY';
1717

@@ -25,7 +25,7 @@ if (!process.env.APIFY_TOKEN) {
2525
process.exit(1);
2626
}
2727

28-
const authToken: AuthToken = {
28+
const authInfo: AuthInfo = {
2929
value: process.env.APIFY_TOKEN,
3030
type: 'apify',
3131
};
@@ -49,7 +49,7 @@ if (STANDBY_MODE) {
4949
await Actor.fail('If you need to debug a specific Actor, please provide the debugActor and debugActorInput fields in the input');
5050
}
5151
const options = { memory: input.maxActorMemoryBytes } as ActorCallOptions;
52-
const { items } = await callActorGetDataset(input.debugActor!, input.debugActorInput!, authToken, options);
52+
const { items } = await callActorGetDataset(input.debugActor!, input.debugActorInput!, authInfo, options);
5353

5454
await Actor.pushData(items);
5555
log.info('Pushed items to dataset', { itemCount: items.count });

src/mcp/server.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
import { prompts } from '../prompts/index.js';
3131
import { callActorGetDataset, defaultTools, getActorsAsTools, toolCategories } from '../tools/index.js';
3232
import { decodeDotPropertyNames } from '../tools/utils.js';
33-
import type { ActorMcpTool, ActorTool, AuthToken, HelperTool, ToolEntry } from '../types.js';
33+
import type { ActorMcpTool, ActorTool, AuthInfo, HelperTool, ToolEntry } from '../types.js';
3434
import { createProgressTracker } from '../utils/progress.js';
3535
import { getToolPublicFieldOnly } from '../utils/tools.js';
3636
import { connectMCPClient } from './client.js';
@@ -155,12 +155,12 @@ export class ActorsMcpServer {
155155
}
156156

157157
/**
158-
* Loads missing toolNames from a provided list of tool names.
159-
* Skips toolNames that are already loaded and loads only the missing ones.
160-
* @param toolNames - Array of tool names to ensure are loaded
161-
* @param authToken - Token for Apify service authentication
162-
*/
163-
public async loadToolsByName(toolNames: string[], authToken: AuthToken) {
158+
* Loads missing toolNames from a provided list of tool names.
159+
* Skips toolNames that are already loaded and loads only the missing ones.
160+
* @param toolNames - Array of tool names to ensure are loaded
161+
* @param authInfo - Info for Apify service authentication
162+
*/
163+
public async loadToolsByName(toolNames: string[], authInfo: AuthInfo) {
164164
const loadedTools = this.listAllToolNames();
165165
const actorsToLoad: string[] = [];
166166
const toolsToLoad: ToolEntry[] = [];
@@ -185,19 +185,19 @@ export class ActorsMcpServer {
185185
}
186186

187187
if (actorsToLoad.length > 0) {
188-
await this.loadActorsAsTools(actorsToLoad, authToken);
188+
await this.loadActorsAsTools(actorsToLoad, authInfo);
189189
}
190190
}
191191

192192
/**
193193
* Load actors as tools, upsert them to the server, and return the tool entries.
194194
* This is a public method that wraps getActorsAsTools and handles the upsert operation.
195195
* @param actorIdsOrNames - Array of actor IDs or names to load as tools
196-
* @param authToken - Token for Apify service authentication
196+
* @param authInfo - Info for Apify service authentication
197197
* @returns Promise<ToolEntry[]> - Array of loaded tool entries
198198
*/
199-
public async loadActorsAsTools(actorIdsOrNames: string[], authToken: AuthToken): Promise<ToolEntry[]> {
200-
const actorTools = await getActorsAsTools(actorIdsOrNames, authToken);
199+
public async loadActorsAsTools(actorIdsOrNames: string[], authInfo: AuthInfo): Promise<ToolEntry[]> {
200+
const actorTools = await getActorsAsTools(actorIdsOrNames, authInfo);
201201
if (actorTools.length > 0) {
202202
this.upsertTools(actorTools, true);
203203
}
@@ -211,8 +211,8 @@ export class ActorsMcpServer {
211211
*
212212
* Used primarily for SSE.
213213
*/
214-
public async loadToolsFromUrl(url: string, authToken: AuthToken) {
215-
const tools = await processParamsGetTools(url, authToken);
214+
public async loadToolsFromUrl(url: string, authInfo: AuthInfo) {
215+
const tools = await processParamsGetTools(url, authInfo);
216216
if (tools.length > 0) {
217217
log.debug('Loading tools from query parameters');
218218
this.upsertTools(tools, false);
@@ -381,27 +381,27 @@ export class ActorsMcpServer {
381381
// eslint-disable-next-line prefer-const
382382
let { name, arguments: args, _meta: meta } = request.params;
383383
const { progressToken } = meta || {};
384-
// Extract auth token with fallback to APIFY_TOKEN environment variable
385-
let authToken: AuthToken | undefined = request.params.authToken as AuthToken;
384+
// Extract auth info with fallback to APIFY_TOKEN environment variable
385+
let authInfo: AuthInfo | undefined = request.params.authInfo as AuthInfo;
386386

387387
// Fallback to APIFY_TOKEN environment variable for local development
388-
if (!authToken && process.env.APIFY_TOKEN) {
389-
authToken = {
388+
if (!authInfo && process.env.APIFY_TOKEN) {
389+
authInfo = {
390390
value: process.env.APIFY_TOKEN,
391391
type: 'apify', // Environment variable is always an Apify token
392392
};
393393
}
394394
const userRentedActorIds = request.params.userRentedActorIds as string[] | undefined;
395395

396-
// Remove authToken from request.params only if it was provided in params
397-
if (request.params.authToken) {
398-
delete request.params.authToken;
396+
// Remove authInfo from request.params only if it was provided in params
397+
if (request.params.authInfo) {
398+
delete request.params.authInfo;
399399
}
400400
// Remove other custom params passed from apify-mcp-server
401401
delete request.params.userRentedActorIds;
402402

403-
// Validate auth token
404-
if (!authToken || !authToken.value) {
403+
// Validate auth info
404+
if (!authInfo || !authInfo.value) {
405405
const msg = `Valid authentication token required. It must be provided either in the Bearer Authorization header, APIFY_TOKEN environment variable or skyfire-pay-id header as Skyfire payment token.`;
406406
log.error(msg);
407407
await this.server.sendLoggingMessage({ level: 'error', data: msg });
@@ -473,7 +473,7 @@ export class ActorsMcpServer {
473473
extra,
474474
apifyMcpServer: this,
475475
mcpServer: this.server,
476-
authToken,
476+
authInfo,
477477
userRentedActorIds,
478478
progressTracker,
479479
}) as object;
@@ -489,7 +489,7 @@ export class ActorsMcpServer {
489489
const serverTool = tool.tool as ActorMcpTool;
490490
let client: Client | undefined;
491491
try {
492-
client = await connectMCPClient(serverTool.serverUrl, authToken.value);
492+
client = await connectMCPClient(serverTool.serverUrl, authInfo.value);
493493

494494
// Only set up notification handlers if progressToken is provided by the client
495495
if (progressToken) {
@@ -538,7 +538,7 @@ export class ActorsMcpServer {
538538
const { runId, datasetId, items } = await callActorGetDataset(
539539
actorTool.actorFullName,
540540
args,
541-
authToken,
541+
authInfo,
542542
callOptions,
543543
progressTracker,
544544
);

src/mcp/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createHash } from 'node:crypto';
22
import { parse } from 'node:querystring';
33

44
import { processInput } from '../input.js';
5-
import type { AuthToken, Input } from '../types.js';
5+
import type { AuthInfo, Input } from '../types.js';
66
import { loadToolsFromInput } from '../utils/tools-loader.js';
77
import { MAX_TOOL_NAME_LENGTH, SERVER_ID_LENGTH } from './const.js';
88

@@ -37,11 +37,11 @@ export function getProxyMCPServerToolName(url: string, toolName: string): string
3737
* Process input parameters from URL and get tools
3838
* If URL contains query parameter `actors`, return tools from Actors otherwise return null.
3939
* @param url
40-
* @param authToken
40+
* @param authInfo
4141
*/
42-
export async function processParamsGetTools(url: string, authToken: AuthToken) {
42+
export async function processParamsGetTools(url: string, authInfo: AuthInfo) {
4343
const input = parseInputParamsFromUrl(url);
44-
return await loadToolsFromInput(input, authToken);
44+
return await loadToolsFromInput(input, authInfo);
4545
}
4646

4747
export function parseInputParamsFromUrl(url: string): Input {

src/stdio.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import log from '@apify/log';
2424

2525
import { processInput } from './input.js';
2626
import { ActorsMcpServer } from './mcp/server.js';
27-
import type { AuthToken, Input, ToolSelector } from './types.js';
27+
import type { AuthInfo, Input, ToolSelector } from './types.js';
2828
import { loadToolsFromInput } from './utils/tools-loader.js';
2929

3030
// Keeping this interface here and not types.ts since
@@ -122,11 +122,11 @@ async function main() {
122122
const normalized = processInput(input);
123123

124124
// Use the shared tools loading logic
125-
const authToken: AuthToken = {
125+
const authInfo: AuthInfo = {
126126
value: process.env.APIFY_TOKEN as string,
127127
type: 'apify',
128128
};
129-
const tools = await loadToolsFromInput(normalized, authToken);
129+
const tools = await loadToolsFromInput(normalized, authInfo);
130130

131131
mcpServer.upsertTools(tools);
132132

0 commit comments

Comments
 (0)