# Server Actor Test (`apify/server-actor-test`) Actor

A simple Server Actor that adds two numbers through an HTTP API or a normal run. Includes endpoints for testing delays, status codes, response formats, sizes, and redirects. Built for fast, low-cost testing of the Apify MCP server.

- **URL**: https://apify.com/apify/server-actor-test.md
- **Developed by:** [Apify](https://apify.com/apify) (community)
- **Stats:** 2 total users, 0 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

### Apify MCP server test Server Actor

**Test Actor for the [Apify MCP server](https://mcp.apify.com/). Not for production use.**

It has both interfaces of a Server Actor: an HTTP API documented by an OpenAPI schema (`.actor/openapi.json`) and an input schema with the same fields as the `POST /add` body. It has no MCP endpoint. It adds two numbers, the same operation as the other fixtures in this repository: a normal run of `normal-actor` and the `add` MCP tool of `mcp-server-actor`.

### What it does

`src/main.ts` picks the entry path from the run's origin:

- **Standby run** (`metaOrigin === 'STANDBY'`): serves the HTTP API on `ACTOR_STANDBY_PORT` until the platform stops the run.
- **Any other run**: validates the input (`firstNumber`, `secondNumber`), pushes `{ firstNumber, secondNumber, sum }` to the default dataset as one item (the same item `POST /add` returns), and exits.

### Endpoints

| Method and path | Response |
|---|---|
| `GET /add?firstNumber=&secondNumber=`, `POST /add` | `200` JSON `{ firstNumber, secondNumber, sum }`. Numbers come from the query (GET) or the JSON body (POST). `asText=true` returns `2 + 3 = 5` as `text/plain`; `asText` accepts only `true` or `false`, so `1`/`0` return `400`. Other methods return `405`. |
| `GET /` | Readiness probe (`200 ok`) when the `x-apify-container-server-readiness-probe` header is set. Otherwise the echo below. |
| `GET /`, `POST /` | `200` JSON echo: `method`, `path`, `query`, `headers`, `body`. A JSON body is parsed; other bodies are returned as text. Other methods on `/` return `405`. |
| `GET /status/{code}` | That status (400–599) with a JSON `{ code, error }` body. |
| `GET /empty` | `204`, no body, no `Content-Type`. |
| `GET /text` | `200` `text/plain`. |
| `GET /binary` | `200` `application/octet-stream`, 256 bytes. |
| `GET /bytes?n=` | `200` `text/plain`, exactly `n` bytes (0 to 1,048,576) of `a`. |
| `GET /gzip?n=` | Same body as `/bytes`, with `Content-Encoding: gzip`. `n` counts decompressed bytes. |
| `GET /delay?ms=` | Waits `ms` milliseconds (0 to 150,000), then `200` JSON `{ delayedMs }`. |
| `GET /redirect` | `302` with `Location: /`. The target is fixed and never taken from the request. |

Unknown paths return `404` with a JSON `{ code, error }` body; invalid parameters return `400`.

#### What the Apify router changes

Checked on production against a single-tenant deployment:

- `Authorization` is removed before the request reaches the Actor, so the echo never contains the caller's token header. A `token` query parameter is consumed as authentication and removed too. A token sent in the `POST /` body or in another query parameter is echoed.
- `X-Apify-Request-Origin` is forwarded.
- Status codes, `Location`, `Content-Encoding: gzip` bodies and response sizes pass through unchanged. The router does not compress responses itself.
- `GET /delay?ms=125000` returns `200` after 125 s, so a 120 s client deadline expires first.
- A request without a token returns `401` from the router.

#### Example

```bash
curl -X POST https://example-server-actor.apify.actor/add \
  -H "Authorization: Bearer $APIFY_TOKEN" -H 'Content-Type: application/json' \
  -d '{"firstNumber": 2, "secondNumber": 3}'
## {"firstNumber":2,"secondNumber":3,"sum":5}
```

### Settings outside `actor.json`

Set these in Console on the Actor's **Settings** tab (Actor Standby) in each environment:

- Actor Standby enabled, single-tenant, build `latest`
- Idle timeout 120 s, memory 256 MB
- Max requests per run 40, desired requests per run 30

The request counts matter: under a burst the router starts extra runs in the caller's account instead of returning 429.

### Development

```bash
npm install
npm run lint
npm run format
npm run build
npm test
```

### Resources

- [Apify MCP server documentation](https://docs.apify.com/platform/integrations/mcp)
- [Actor Standby](https://docs.apify.com/platform/actors/running/standby)

# Actor input Schema

## `firstNumber` (type: `integer`):

First number to add.

## `secondNumber` (type: `integer`):

Second number to add.

## Actor input object example

```json
{
  "firstNumber": 1,
  "secondNumber": 2
}
```

# Actor output Schema

## `results` (type: `string`):

One dataset item containing firstNumber, secondNumber, and sum.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "firstNumber": 1,
    "secondNumber": 2
};

// Run the Actor and wait for it to finish
const run = await client.actor("apify/server-actor-test").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "firstNumber": 1,
    "secondNumber": 2,
}

# Run the Actor and wait for it to finish
run = client.actor("apify/server-actor-test").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "firstNumber": 1,
  "secondNumber": 2
}' |
apify call apify/server-actor-test --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,apify/server-actor-test"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/Bh5aUJoDlh7WOlG0O/builds/D5Jlc8FxuDePGBDtM/openapi.json
