Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: MCP server implementation #1

Merged
merged 54 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
959e421
first version
jirispilka Jan 3, 2025
9b06472
Change logger, simplify fetching of Actor input
jirispilka Jan 3, 2025
672d79e
Change env variable APIFY_API_TOKEN to APIFY_TOKEN
jirispilka Jan 3, 2025
1d27199
Push data into Apify dataset
jirispilka Jan 3, 2025
cbc172a
Fix standby mode
jirispilka Jan 3, 2025
7dd8fb2
Improve log messages
jirispilka Jan 3, 2025
b4d3bd9
- rename `actorNames` to `actors`
jirispilka Jan 3, 2025
e1984a0
Update README.md
jirispilka Jan 3, 2025
0c792d5
Ability to initiate SSE with a selected actors
jirispilka Jan 6, 2025
65f6e41
Update README.md, remove defaults.
jirispilka Jan 7, 2025
552cedd
Remove query parameters from SSE
jirispilka Jan 7, 2025
5cf7c00
Update README.md
jirispilka Jan 7, 2025
ff4ec05
Add eventsource
jirispilka Jan 8, 2025
f516fe2
Add example clients
jirispilka Jan 8, 2025
76bf0fb
Load 5 default Actors as a tool, to simplify onboarding
jirispilka Jan 8, 2025
1655d70
Update README.md
jirispilka Jan 8, 2025
259e1c4
Add chat stdio
jirispilka Jan 8, 2025
8a9cad3
Improve error handling
jirispilka Jan 9, 2025
405f70c
Update clientStdioChat.ts
jirispilka Jan 9, 2025
af4d696
Update README.md
jirispilka Jan 9, 2025
1c92990
Change env variable
jirispilka Jan 10, 2025
19bb130
Clean up ts-config
jirispilka Jan 10, 2025
22ac5ed
Update package.json and add github workflow from apify-eslint-config
jirispilka Jan 10, 2025
147f7a8
Fix lint issues in before-beta-release.js
jirispilka Jan 10, 2025
7e975e5
Remove dead code
jirispilka Jan 10, 2025
d2bc65a
docs: Update documentation (#2)
jirispilka Jan 10, 2025
c6128c3
Update section title
jirispilka Jan 10, 2025
c676bc2
Update docs
jirispilka Jan 10, 2025
7ced4a4
Update docs
jirispilka Jan 10, 2025
5cbf12c
Update docs
jirispilka Jan 10, 2025
8355f3a
fix return value
jirispilka Jan 12, 2025
1f5c841
Update README.md
jirispilka Jan 13, 2025
a857a74
Update README.md
jirispilka Jan 13, 2025
472be0c
Update README.md
jirispilka Jan 13, 2025
036c6b3
Update README.md
jirispilka Jan 13, 2025
e1a0c6a
Apply suggestions from code review
jirispilka Jan 13, 2025
34ecf25
Update README.md
jirispilka Jan 13, 2025
50e3d85
Replace APIFY-API-TOKEN by APIFY_API_TOKEN
jirispilka Jan 13, 2025
364f49d
Update package-lock.json
jirispilka Jan 13, 2025
1e7d6f8
Fix clientStdio.ts for win
jirispilka Jan 15, 2025
5233088
Fix clientStdio.ts for win
jirispilka Jan 15, 2025
5c9d89d
Update mcp typescript sdk to the newest version.
jirispilka Jan 15, 2025
57af156
Fix clientStdio.ts
jirispilka Jan 15, 2025
0aae5c6
Add roadmap to README.md
jirispilka Jan 15, 2025
c8b2da4
Start Standby server with Actors provided at input
jirispilka Jan 15, 2025
e12cf8e
Truncate tool output and limit tool response.
jirispilka Jan 15, 2025
2d474ce
Limit number of default Actors
jirispilka Jan 15, 2025
ca69a88
Rename APIFY_API_TOKEN to APIFY_TOKEN (env variable at Apify platform…
jirispilka Jan 15, 2025
b84651e
Minor changes, add clientSse.ts
jirispilka Jan 15, 2025
479e9be
Update README.md with task changes.
jirispilka Jan 15, 2025
f39dfc5
Add explanation to Actor definition
jirispilka Jan 15, 2025
d6e03fc
Fix lint issues
jirispilka Jan 15, 2025
3a5be34
Update .actor/input_schema.json
jirispilka Jan 16, 2025
fc40b59
Add log message to explain users how to add Actors. Simplify handling…
jirispilka Jan 16, 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
57 changes: 57 additions & 0 deletions .actor/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Specify the base Docker image. You can read more about
# the available images at https://docs.apify.com/sdk/js/docs/guides/docker-images
# You can also use any other image from Docker Hub.
FROM apify/actor-node:20 AS builder

# Check preinstalled packages
RUN npm ls crawlee apify puppeteer playwright

# Copy just package.json and package-lock.json
# to speed up the build using Docker layer cache.
COPY package*.json ./

# Install all dependencies. Don't audit to speed up the installation.
RUN npm install --include=dev --audit=false

# Next, copy the source files using the user set
# in the base image.
COPY . ./

# Install all dependencies and build the project.
# Don't audit to speed up the installation.
RUN npm run build

# Create final image
FROM apify/actor-node:20

# Check preinstalled packages
RUN npm ls crawlee apify puppeteer playwright

# Copy just package.json and package-lock.json
# to speed up the build using Docker layer cache.
COPY package*.json ./

# Install NPM packages, skip optional and development dependencies to
# keep the image small. Avoid logging too much and print the dependency
# tree for debugging
RUN npm --quiet set progress=false \
&& npm install --omit=dev --omit=optional \
&& echo "Installed NPM packages:" \
&& (npm list --omit=dev --all || true) \
&& echo "Node.js version:" \
&& node --version \
&& echo "NPM version:" \
&& npm --version \
&& rm -r ~/.npm

# Copy built JS files from builder image
COPY --from=builder /usr/src/app/dist ./dist

# Next, copy the remaining files and directories with the source code.
# Since we do this after NPM install, quick build will be really fast
# for most source file changes.
COPY . ./


# Run the image.
CMD npm run start:prod --silent
9 changes: 9 additions & 0 deletions .actor/actor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"actorSpecification": 1,
"name": "apify-mcp-server",
"title": "Model Context Protocol Server for Apify Actors",
"description": "Implementation of a Model Context Protocol (MCP) Server for Apify Actors that enables AI applications (and AI agents) to interact with Apify Actors",
"version": "0.0",
"input": "./input_schema.json",
"dockerfile": "./Dockerfile"
}
35 changes: 35 additions & 0 deletions .actor/input_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"title": "Apify MCP Server",
"type": "object",
"schemaVersion": 1,
"properties": {
"actors": {
"title": "Actors names to be exposed for an AI application (AI agent)",
jirispilka marked this conversation as resolved.
Show resolved Hide resolved
"type": "array",
"description": "List the names of Actors to be exposed to an AI application (AI agent) for communication via the MCP protocol. \n\n Ensure the Actor definitions fit within the LLM context by limiting the number of used Actors.",
"editor": "stringList",
"prefill": [
"apify/instagram-scraper",
"apify/rag-web-browser",
"lukaskrivka/google-maps-with-contact-details"
]
},
"debugActor": {
"title": "Debug actor",
"type": "string",
"description": "Specify the name of the actor that will be used for debugging in normal mode",
"editor": "textfield",
"prefill": "apify/rag-web-browser",
"sectionCaption": "Debugging settings (normal mode)"
},
"debugActorInput": {
"title": "Debug actor input",
"type": "object",
"description": "Specify the input for the actor that will be used for debugging in normal mode",
"editor": "json",
"prefill": {
"query": "hello world"
}
}
}
}
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ node_modules
data
src/storage
dist
.env
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
APIFY_TOKEN=
# ANTHROPIC_API_KEY is only required when you want to run examples/clientStdioChat.js
ANTHROPIC_API_KEY=
32 changes: 32 additions & 0 deletions .github/scripts/before-beta-release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');

const PKG_JSON_PATH = path.join(__dirname, '..', '..', 'package.json');

const pkgJson = require(PKG_JSON_PATH); // eslint-disable-line import/no-dynamic-require

const PACKAGE_NAME = pkgJson.name;
const VERSION = pkgJson.version;

const nextVersion = getNextVersion(VERSION);
console.log(`before-deploy: Setting version to ${nextVersion}`); // eslint-disable-line no-console
pkgJson.version = nextVersion;

fs.writeFileSync(PKG_JSON_PATH, `${JSON.stringify(pkgJson, null, 2)}\n`);

function getNextVersion(version) {
const versionString = execSync(`npm show ${PACKAGE_NAME} versions --json`, { encoding: 'utf8' });
const versions = JSON.parse(versionString);

if (versions.some((v) => v === VERSION)) {
console.error(`before-deploy: A release with version ${VERSION} already exists. Please increment version accordingly.`); // eslint-disable-line no-console
process.exit(1);
}

const prereleaseNumbers = versions
.filter((v) => (v.startsWith(VERSION) && v.includes('-')))
.map((v) => Number(v.match(/\.(\d+)$/)[1]));
const lastPrereleaseNumber = Math.max(-1, ...prereleaseNumbers);
return `${version}-beta.${lastPrereleaseNumber + 1}`;
}
30 changes: 30 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This workflow runs for every pull request to lint and test the proposed changes.

name: Check

on:
pull_request:

# Push to master will trigger code checks
push:
branches:
- master
tags-ignore:
- "**" # Ignore all tags to prevent duplicate builds when tags are pushed.

jobs:
lint:
name: Lint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Use Node.js 22
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'npm'
cache-dependency-path: 'package-lock.json'
- name: Install Dependencies
run: npm ci
- run: npm run lint
103 changes: 103 additions & 0 deletions .github/workflows/pre_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Create a pre-release

on:
# Push to master will deploy a beta version
push:
branches:
- master
tags-ignore:
- "**" # Ignore all tags to prevent duplicate builds when tags are pushed.

concurrency:
group: release
cancel-in-progress: false

jobs:
release_metadata:
if: "!startsWith(github.event.head_commit.message, 'docs') && !startsWith(github.event.head_commit.message, 'ci') && startsWith(github.repository, 'apify/')"
name: Prepare release metadata
runs-on: ubuntu-latest
outputs:
version_number: ${{ steps.release_metadata.outputs.version_number }}
changelog: ${{ steps.release_metadata.outputs.changelog }}
steps:
- uses: apify/workflows/git-cliff-release@main
name: Prepare release metadata
id: release_metadata
with:
release_type: prerelease
existing_changelog_path: CHANGELOG.md

wait_for_checks:
name: Wait for code checks to pass
runs-on: ubuntu-latest
steps:
- uses: lewagon/[email protected]
with:
ref: ${{ github.ref }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
check-name: 'Lint'
wait-interval: 5

update_changelog:
needs: [ release_metadata ]
name: Update changelog
runs-on: ubuntu-latest
outputs:
changelog_commitish: ${{ steps.commit.outputs.commit_long_sha || github.sha }}

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}

- name: Use Node.js 22
uses: actions/setup-node@v4
with:
node-version: 22

- name: Update package version in package.json
run: npm version --no-git-tag-version --allow-same-version ${{ needs.release_metadata.outputs.version_number }}

- name: Update CHANGELOG.md
uses: DamianReeves/write-file-action@master
with:
path: CHANGELOG.md
write-mode: overwrite
contents: ${{ needs.release_metadata.outputs.changelog }}

- name: Commit changes
id: commit
uses: EndBug/add-and-commit@v9
with:
author_name: Apify Release Bot
author_email: [email protected]
message: "chore(release): Update changelog and package version [skip ci]"

publish_to_npm:
name: Publish to NPM
needs: [ release_metadata ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.update_changelog.changelog_commitish }}
- name: Use Node.js 22
uses: actions/setup-node@v4
with:
node-version: 22
- name: Install dependencies
run: |
echo "access=public" >> .npmrc
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
npm install
- # Check version consistency and increment pre-release version number for beta only.
name: Bump pre-release version
run: node ./.github/scripts/before-beta-release.js
- name: Publish to NPM
run: npm publish --tag beta

env:
NODE_AUTH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }}
Loading
Loading