Skip to content
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
5c11a41
feat: implement segment telemetry
MQ37 Nov 7, 2025
3e58be6
add reason input schema field for telemetry
MQ37 Nov 7, 2025
5eb7f70
fix: reorder telemetry section in the table of contents
MQ37 Nov 7, 2025
61480bc
fix: update default userId to an empty string in trackToolCall function
MQ37 Nov 7, 2025
1b1215d
fix typo
MQ37 Nov 7, 2025
6cd4af3
Merge remote-tracking branch 'origin/master' into segment-telemetry
MQ37 Nov 7, 2025
0f1fbda
Merge branch 'master' into segment-telemetry
jirispilka Nov 19, 2025
2f5a4a3
fix: add new variable telemetry-enabled instead of telemetry. Hide de…
jirispilka Nov 19, 2025
92e8024
fix: add constants instead of prod and dev
jirispilka Nov 19, 2025
4016352
fix: add capabilities to tracking
jirispilka Nov 19, 2025
82eefe5
fix: remove unused ENVIROMENT variable
jirispilka Nov 20, 2025
d779506
fix: add env variable to enable/disable telemetry
jirispilka Nov 20, 2025
0e6cdfd
fix: add env variable to enable/disable telemetry
jirispilka Nov 20, 2025
72b9ed6
fix: update unit-tests
jirispilka Nov 20, 2025
53bead4
fix: update telemetry properties
jirispilka Nov 20, 2025
f46bff9
fix: add status and exec time to telemetry
jirispilka Nov 20, 2025
f3fb01c
fix: add tool call number
jirispilka Nov 20, 2025
3f0d09d
fix: remove reason from telemetry
jirispilka Nov 20, 2025
a5fd735
fix: change tool status to match Actor run status
jirispilka Nov 20, 2025
a551686
fix: change event name
jirispilka Nov 20, 2025
0bf506b
fix: tests
jirispilka Nov 20, 2025
2004c6f
fix: remove TELEMETRY.md
jirispilka Nov 20, 2025
336b246
fix: add user-cache (TTL)
jirispilka Nov 20, 2025
92948ed
Apply suggestions from code review
jirispilka Nov 21, 2025
4c9592f
Apply suggestions from code review
jirispilka Nov 21, 2025
944875a
fix: remove map of clients (one client per deployment)
jirispilka Nov 21, 2025
3b14e56
fix: remove _initializeRequestData from loadToolsFromUrl
jirispilka Nov 21, 2025
4cc26d9
fix: in the ActorsMcpServer use nested telemetry object
jirispilka Nov 21, 2025
ab7f161
fix: in the ActorsMcpServer use nested telemetry object
jirispilka Nov 21, 2025
9da99b0
fix: log errors in telemetry
jirispilka Nov 21, 2025
d6e7c6d
fix: move ActorsMcpServerOptions and ToolCallCounterStore to types.ts
jirispilka Nov 21, 2025
da55972
fix: Improve getAndIncrementToolCallCounter and add test
jirispilka Nov 21, 2025
5ba5751
fix: Improve naming in setupTelemetry function
jirispilka Nov 21, 2025
a651486
fix: comment
jirispilka Nov 21, 2025
11e57f0
fix: refactor prepareTelemetryData
jirispilka Nov 21, 2025
571c087
fix: simplify userId cache
jirispilka Nov 21, 2025
421f1a3
fix: make telemetryEnv uppercase -> PROD, DEV
jirispilka Nov 21, 2025
8c8721f
fix: handle telemetry-enabled param in better way (also for null and …
jirispilka Nov 21, 2025
209e41f
fix: simplify - get package version
jirispilka Nov 24, 2025
a3c5ece
fix: rename app_name to app
jirispilka Nov 24, 2025
5165cc0
fix: save mcp_client_capabilities
jirispilka Nov 24, 2025
dd5291e
fix: set tool-status failed
jirispilka Nov 24, 2025
e3a4bc0
fix: Segment requires either userId OR anonymousId, but not both When…
jirispilka Nov 24, 2025
17c1860
Apply suggestions from code review
jirispilka Nov 25, 2025
8c05a44
fix: add units to analyticsClient creation. Replace `sessionToolCallC…
jirispilka Nov 25, 2025
7bfe235
fix: types, makes telemetry.enabled required
jirispilka Nov 25, 2025
0448298
fix: disable telemetry for tests
jirispilka Nov 25, 2025
f703e90
fix: remove tool_count_number, it is not required
jirispilka Nov 26, 2025
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
39 changes: 34 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The Apify Model Context Protocol (MCP) server at [**mcp.apify.com**](https://mcp
- [🤖 MCP clients and examples](#-mcp-clients-and-examples)
- [🪄 Try Apify MCP instantly](#-try-apify-mcp-instantly)
- [🛠️ Tools, resources, and prompts](#-tools-resources-and-prompts)
- [📊 Telemetry](#telemetry)
- [🐛 Troubleshooting (local MCP server)](#-troubleshooting-local-mcp-server)
- [⚙️ Development](#-development)
- [🤝 Contributing](#-contributing)
Expand Down Expand Up @@ -266,13 +267,32 @@ The server provides a set of predefined example prompts to help you get started

The server does not yet provide any resources.

### Debugging the NPM package
## 📡 Telemetry

To debug the server, use the [MCP Inspector](https://github.com/modelcontextprotocol/inspector) tool:
The Apify MCP Server collects telemetry data about tool calls to help Apify understand usage patterns and improve the service.
By default, telemetry is **enabled** for all tool calls.

```shell
export APIFY_TOKEN="your-apify-token"
npx @modelcontextprotocol/inspector npx -y @apify/actors-mcp-server
### Opting out of telemetry

You can opt out of telemetry by setting the `--telemetry-enabled` CLI flag to `false` or the `TELEMETRY_ENABLED` environment variable to `false`.
CLI flags take precedence over environment variables.

#### Examples

**For the remote server (mcp.apify.com)**:
```text
# Disable via URL parameter
https://mcp.apify.com?telemetry-enabled=false
```

**For the local stdio server**:
```bash
# Disable via CLI flag
npx @apify/actors-mcp-server --telemetry-enabled=false

# Or set environment variable
export TELEMETRY_ENABLED=false
npx @apify/actors-mcp-server
```

# ⚙️ Development
Expand Down Expand Up @@ -333,6 +353,15 @@ The Apify MCP Server is also available on [Docker Hub](https://hub.docker.com/mc
- Make sure the `APIFY_TOKEN` environment variable is set.
- Always use the latest version of the MCP server by using `@apify/actors-mcp-server@latest`.

### Debugging the NPM package

To debug the server, use the [MCP Inspector](https://github.com/modelcontextprotocol/inspector) tool:

```shell
export APIFY_TOKEN="your-apify-token"
npx @modelcontextprotocol/inspector npx -y @apify/actors-mcp-server
```

## 💡 Limitations

The Actor input schema is processed to be compatible with most MCP clients while adhering to [JSON Schema](https://json-schema.org/) standards. The processing includes:
Expand Down
127 changes: 123 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"files": [
"dist",
"LICENSE",
"package.json",
"server.json",
"manifest.json"
],
Expand All @@ -42,6 +43,7 @@
"@apify/datastructures": "^2.0.3",
"@apify/log": "^2.5.16",
"@modelcontextprotocol/sdk": "^1.18.1",
"@segment/analytics-node": "^2.3.0",
"@types/cheerio": "^0.22.35",
"@types/turndown": "^5.0.5",
"ajv": "^8.17.1",
Expand Down
33 changes: 30 additions & 3 deletions src/actor/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import express from 'express';
import log from '@apify/log';

import { ApifyClient } from '../apify-client.js';
import { type TelemetryEnv } from '../const.js';
import { ActorsMcpServer } from '../mcp/server.js';
import { getTelemetryEnv } from '../telemetry.js';
import { getHelpMessage, HEADER_READINESS_PROBE, Routes, TransportType } from './const.js';
import { getActorRunData } from './utils.js';

Expand Down Expand Up @@ -78,7 +80,19 @@ export function createExpressApp(
rt: Routes.SSE,
tr: TransportType.SSE,
});
const mcpServer = new ActorsMcpServer({ setupSigintHandler: false });
// Extract telemetry query parameters
const urlParams = new URL(req.url, `http://${req.headers.host}`).searchParams;
const telemetryEnabledParam = urlParams.get('telemetry-enabled');
const telemetryEnvParam = urlParams.get('telemetry-env');
const telemetryEnabled = telemetryEnabledParam !== 'false'; // Default to true
const telemetryEnv: TelemetryEnv = getTelemetryEnv(telemetryEnvParam);

const mcpServer = new ActorsMcpServer({
setupSigintHandler: false,
transportType: 'sse',
telemetryEnabled,
telemetryEnv,
});
const transport = new SSEServerTransport(Routes.MESSAGE, res);

// Load MCP server tools
Expand Down Expand Up @@ -157,12 +171,25 @@ export function createExpressApp(
// Reuse existing transport
transport = transports[sessionId];
} else if (!sessionId && isInitializeRequest(req.body)) {
// New initialization request - use JSON response mode
// New initialization request
transport = new StreamableHTTPServerTransport({
sessionIdGenerator: () => randomUUID(),
enableJsonResponse: false, // Use SSE response mode
});
const mcpServer = new ActorsMcpServer({ setupSigintHandler: false, initializeRequestData: req.body as InitializeRequest });
// Extract telemetry query parameters
const urlParams = new URL(req.url, `http://${req.headers.host}`).searchParams;
const telemetryEnabledParam = urlParams.get('telemetry-enabled');
const telemetryEnvParam = urlParams.get('telemetry-env');
const telemetryEnabled = telemetryEnabledParam !== 'false'; // Default to true
const telemetryEnv: TelemetryEnv = getTelemetryEnv(telemetryEnvParam);

const mcpServer = new ActorsMcpServer({
setupSigintHandler: false,
initializeRequestData: req.body as InitializeRequest,
transportType: 'http',
telemetryEnabled,
telemetryEnv,
});

// Load MCP server tools
const apifyToken = process.env.APIFY_TOKEN as string;
Expand Down
10 changes: 10 additions & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,13 @@ export const ALGOLIA = {
export const PROGRESS_NOTIFICATION_INTERVAL_MS = 5_000; // 5 seconds

export const APIFY_STORE_URL = 'https://apify.com';

// Telemetry
export type TelemetryEnv = 'dev' | 'prod';

export const TELEMETRY_ENV = {
DEV: 'dev',
PROD: 'prod',
} as const;

export const DEFAULT_TELEMETRY_ENV: TelemetryEnv = TELEMETRY_ENV.PROD;
Loading
Loading