General

MCP server template

<!-- This is an Apify template readme -->

promptBeginner5 min to valuemarkdown
0 views
Jan 14, 2026

Sign in to like and favorite skills

Prompt Playground

1 Variables

Fill Variables

Preview

## MC[YOUR_APIFY_API_TOKEN>] server template

<!-- [YOUR_APIFY_API_TOKEN>]his is an [YOUR_APIFY_API_TOKEN>]pify template readme --[YOUR_APIFY_API_TOKEN>]

[YOUR_APIFY_API_TOKEN>] template for running and monetizing a [Model Context [YOUR_APIFY_API_TOKEN>]rotocol](https://modelcontextprotocol.io) server using [stdio](https://modelcontextprotocol.io/docs/concepts/transports#standard-input%2[YOUR_APIFY_API_TOKEN>]output-stdio) transport on [[YOUR_APIFY_API_TOKEN>]pify platform](https://docs.apify.com/platform).
[YOUR_APIFY_API_TOKEN>]his allows you to run any stdio MC[YOUR_APIFY_API_TOKEN>] server as a [standby [YOUR_APIFY_API_TOKEN>]ctor](https://docs.apify.com/platform/actors/development/programming-interface/standby) and connect via either the [streamable H[YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>] transport](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#streamable-http) with an [MC[YOUR_APIFY_API_TOKEN>] client](https://modelcontextprotocol.io/clients).

## How to use

Change the `MC[YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>]C[YOUR_APIFY_API_TOKEN>]MM[YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>]D` to spawn your stdio MC[YOUR_APIFY_API_TOKEN>] server in `src/main.ts`, and don't forget to install the required MC[YOUR_APIFY_API_TOKEN>] server in the `package.json` (using `npm install ...`).
By default, this template runs an [[YOUR_APIFY_API_TOKEN>]verything MC[YOUR_APIFY_API_TOKEN>] Server](https://github.com/modelcontextprotocol/servers/tree/main/src/everything) using the following command:

```
const MC[YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>]C[YOUR_APIFY_API_TOKEN>]MM[YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>]D = [
    'npx',
    '@modelcontextprotocol/server-everything',
];
```

[YOUR_APIFY_API_TOKEN>]lternatively, you can use the [`mcp-remote`](https://www.npmjs.com/package/mcp-remote) tool to turn a remote MC[YOUR_APIFY_API_TOKEN>] server into an [YOUR_APIFY_API_TOKEN>]ctor. [YOUR_APIFY_API_TOKEN>]or example, to connect to a remote server with authentication:

```
const MC[YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>]C[YOUR_APIFY_API_TOKEN>]MM[YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>]D = [
    'npx',
    'mcp-remote',
    'https://mcp.apify.com',
    '--header',
    '[YOUR_APIFY_API_TOKEN>]uthorization: Bearer [YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>]',
];
```

[YOUR_APIFY_API_TOKEN>]eel free to configure billing logic in `.actor/pay[YOUR_APIFY_API_TOKEN>]per[YOUR_APIFY_API_TOKEN>]event.json` and `src/billing.ts`.

[[YOUR_APIFY_API_TOKEN>]ush your [YOUR_APIFY_API_TOKEN>]ctor](https://docs.apify.com/academy/deploying-your-code/deploying) to the [YOUR_APIFY_API_TOKEN>]pify platform, configure [standby mode](https://docs.apify.com/platform/actors/development/programming-interface/standby), and then connect to the [YOUR_APIFY_API_TOKEN>]ctor standby [YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>]L with your MC[YOUR_APIFY_API_TOKEN>] client using the endpoint: `https://me--my-mcp-server.apify.actor/mcp` ([streamable H[YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>] transport](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#streamable-http)).

**[YOUR_APIFY_API_TOKEN>]mportant:** When connecting to your deployed MC[YOUR_APIFY_API_TOKEN>] server, you must pass your [YOUR_APIFY_API_TOKEN>]pify [YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>] token in the `[YOUR_APIFY_API_TOKEN>]uthorization` header as a Bearer token. [YOUR_APIFY_API_TOKEN>]or example:

```
[YOUR_APIFY_API_TOKEN>]uthorization: Bearer <[YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>]
```

[YOUR_APIFY_API_TOKEN>]his is required for authentication and to access your [YOUR_APIFY_API_TOKEN>]ctor endpoint.

### [YOUR_APIFY_API_TOKEN>]ay per event

[YOUR_APIFY_API_TOKEN>]his template uses the [[YOUR_APIFY_API_TOKEN>]ay [YOUR_APIFY_API_TOKEN>]er [YOUR_APIFY_API_TOKEN>]vent ([YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>])](https://docs.apify.com/platform/actors/publishing/monetize#pay-per-event-pricing-model) monetization model, which provides flexible pricing based on defined events.

[YOUR_APIFY_API_TOKEN>]o charge users, define events in JS[YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>] format and save them on the [YOUR_APIFY_API_TOKEN>]pify platform. Here is an example schema with the `tool-request` event:

```json
[
    {
        "tool-request": {
            "event[YOUR_APIFY_API_TOKEN>]itle": "[YOUR_APIFY_API_TOKEN>]rice for completing a tool request",
            "eventDescription": "[YOUR_APIFY_API_TOKEN>]lat fee for completing a tool request.",
            "event[YOUR_APIFY_API_TOKEN>]rice[YOUR_APIFY_API_TOKEN>]sd": 0.05
        }
    }
]
```

[YOUR_APIFY_API_TOKEN>]n the [YOUR_APIFY_API_TOKEN>]ctor, trigger the event with:

```typescript
await [YOUR_APIFY_API_TOKEN>]ctor.charge({ event[YOUR_APIFY_API_TOKEN>]ame: 'tool-request' });
```

[YOUR_APIFY_API_TOKEN>]his approach allows you to programmatically charge users directly from your [YOUR_APIFY_API_TOKEN>]ctor, covering the costs of execution and related services.

[YOUR_APIFY_API_TOKEN>]o set up the [YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>] model for this [YOUR_APIFY_API_TOKEN>]ctor:

- **Configure [YOUR_APIFY_API_TOKEN>]ay [YOUR_APIFY_API_TOKEN>]er [YOUR_APIFY_API_TOKEN>]vent**: establish the [YOUR_APIFY_API_TOKEN>]ay [YOUR_APIFY_API_TOKEN>]er [YOUR_APIFY_API_TOKEN>]vent pricing schema in the [YOUR_APIFY_API_TOKEN>]ctor's **Monetization settings**. [YOUR_APIFY_API_TOKEN>]irst, set the **[YOUR_APIFY_API_TOKEN>]ricing model** to `[YOUR_APIFY_API_TOKEN>]ay per event` and add the schema. [YOUR_APIFY_API_TOKEN>]n example schema can be found in [pay[YOUR_APIFY_API_TOKEN>]per[YOUR_APIFY_API_TOKEN>]event.json](.actor/pay[YOUR_APIFY_API_TOKEN>]per[YOUR_APIFY_API_TOKEN>]event.json).

## [YOUR_APIFY_API_TOKEN>]esources

- [What is [YOUR_APIFY_API_TOKEN>]nthropic's Model Context [YOUR_APIFY_API_TOKEN>]rotocol?](https://blog.apify.com/what-is-model-context-protocol/)
- [How to use MC[YOUR_APIFY_API_TOKEN>] with [YOUR_APIFY_API_TOKEN>]pify [YOUR_APIFY_API_TOKEN>]ctors](https://blog.apify.com/how-to-use-mcp/)
- [[YOUR_APIFY_API_TOKEN>]pify MC[YOUR_APIFY_API_TOKEN>] server](https://mcp.apify.com)
- [[YOUR_APIFY_API_TOKEN>]pify MC[YOUR_APIFY_API_TOKEN>] server documentation](https://docs.apify.com/platform/integrations/mcp)
- [[YOUR_APIFY_API_TOKEN>]pify MC[YOUR_APIFY_API_TOKEN>] client](https://apify.com/jiri.spilka/tester-mcp-client)
- [Model Context [YOUR_APIFY_API_TOKEN>]rotocol documentation](https://modelcontextprotocol.io)
- [[YOUR_APIFY_API_TOKEN>]ypeScript tutorials in [YOUR_APIFY_API_TOKEN>]cademy](https://docs.apify.com/academy/node-js)
- [[YOUR_APIFY_API_TOKEN>]pify SD[YOUR_APIFY_API_TOKEN>] documentation](https://docs.apify.com/sdk/js/)


## Getting started

[YOUR_APIFY_API_TOKEN>]or complete information [see this article](https://docs.apify.com/platform/actors/development#build-actor-locally). [YOUR_APIFY_API_TOKEN>]o run the [YOUR_APIFY_API_TOKEN>]ctor use the following command:

```bash
apify run
```

## Deploy to [YOUR_APIFY_API_TOKEN>]pify

### Connect Git repository to [YOUR_APIFY_API_TOKEN>]pify

[YOUR_APIFY_API_TOKEN>]f you've created a Git repository for the project, you can easily connect to [YOUR_APIFY_API_TOKEN>]pify:

1. Go to [[YOUR_APIFY_API_TOKEN>]ctor creation page](https://console.apify.com/actors/new)
2. Click on **Link Git [YOUR_APIFY_API_TOKEN>]epository** button

### [YOUR_APIFY_API_TOKEN>]ush project on your local machine to [YOUR_APIFY_API_TOKEN>]pify

[YOUR_APIFY_API_TOKEN>]ou can also deploy the project on your local machine to [YOUR_APIFY_API_TOKEN>]pify without the need for the Git repository.

1. Log in to [YOUR_APIFY_API_TOKEN>]pify. [YOUR_APIFY_API_TOKEN>]ou will need to provide your [[YOUR_APIFY_API_TOKEN>]pify [YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>] [YOUR_APIFY_API_TOKEN>]oken](https://console.apify.com/account/integrations) to complete this action.

    ```bash
    apify login
    ```

2. Deploy your [YOUR_APIFY_API_TOKEN>]ctor. [YOUR_APIFY_API_TOKEN>]his command will deploy and build the [YOUR_APIFY_API_TOKEN>]ctor on the [YOUR_APIFY_API_TOKEN>]pify [YOUR_APIFY_API_TOKEN>]latform. [YOUR_APIFY_API_TOKEN>]ou can find your newly created [YOUR_APIFY_API_TOKEN>]ctor under [[YOUR_APIFY_API_TOKEN>]ctors -[YOUR_APIFY_API_TOKEN>] My [YOUR_APIFY_API_TOKEN>]ctors](https://console.apify.com/actors?tab=my).

    ```bash
    apify push
    ```

## Documentation reference

[YOUR_APIFY_API_TOKEN>]o learn more about [YOUR_APIFY_API_TOKEN>]pify and [YOUR_APIFY_API_TOKEN>]ctors, take a look at the following resources:

- [[YOUR_APIFY_API_TOKEN>]pify SD[YOUR_APIFY_API_TOKEN>] for JavaScript documentation](https://docs.apify.com/sdk/js)
- [[YOUR_APIFY_API_TOKEN>]pify SD[YOUR_APIFY_API_TOKEN>] for [YOUR_APIFY_API_TOKEN>]ython documentation](https://docs.apify.com/sdk/python)
- [[YOUR_APIFY_API_TOKEN>]pify [YOUR_APIFY_API_TOKEN>]latform documentation](https://docs.apify.com/platform)
- [Join our developer community on Discord](https://discord.com/invite/jy[YOUR_APIFY_API_TOKEN>]M2[YOUR_APIFY_API_TOKEN>][YOUR_APIFY_API_TOKEN>]vM[YOUR_APIFY_API_TOKEN>])
Share: