Skip to content

Commit bbd063b

Browse files
authored
feat: Refactor server to simplify it (#14)
* feat: Refactor and simplify mcp server
1 parent 0dc796c commit bbd063b

24 files changed

+2196
-1865
lines changed

.env.example

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
APIFY_API_TOKEN=
2-
ANTHROPIC_API_KEY=
1+
APIFY_TOKEN=

.eslintrc

-41
This file was deleted.
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const { execSync } = require('child_process');
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
const PKG_JSON_PATH = path.join(__dirname, '..', '..', 'package.json');
6+
7+
const pkgJson = require(PKG_JSON_PATH); // eslint-disable-line import/no-dynamic-require
8+
9+
const PACKAGE_NAME = pkgJson.name;
10+
const VERSION = pkgJson.version;
11+
12+
const nextVersion = getNextVersion(VERSION);
13+
console.log(`before-deploy: Setting version to ${nextVersion}`); // eslint-disable-line no-console
14+
pkgJson.version = nextVersion;
15+
16+
fs.writeFileSync(PKG_JSON_PATH, `${JSON.stringify(pkgJson, null, 2)}\n`);
17+
18+
function getNextVersion(version) {
19+
const versionString = execSync(`npm show ${PACKAGE_NAME} versions --json`, { encoding: 'utf8' });
20+
const versions = JSON.parse(versionString);
21+
22+
if (versions.some((v) => v === VERSION)) {
23+
console.error(`before-deploy: A release with version ${VERSION} already exists. Please increment version accordingly.`); // eslint-disable-line no-console
24+
process.exit(1);
25+
}
26+
27+
const prereleaseNumbers = versions
28+
.filter((v) => (v.startsWith(VERSION) && v.includes('-')))
29+
.map((v) => Number(v.match(/\.(\d+)$/)[1]));
30+
const lastPrereleaseNumber = Math.max(-1, ...prereleaseNumbers);
31+
return `${version}-beta.${lastPrereleaseNumber + 1}`;
32+
}

.github/workflows/check.yaml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This workflow runs for every pull request to lint and test the proposed changes.
2+
3+
name: Check
4+
5+
on:
6+
pull_request:
7+
8+
# Push to master will trigger code checks
9+
push:
10+
branches:
11+
- master
12+
tags-ignore:
13+
- "**" # Ignore all tags to prevent duplicate builds when tags are pushed.
14+
15+
jobs:
16+
lint_and_test:
17+
name: Lint
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Use Node.js 22
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: 22
26+
cache: 'npm'
27+
cache-dependency-path: 'package-lock.json'
28+
- name: Install Dependencies
29+
run: npm ci
30+
31+
- name: Lint
32+
run: npm run lint

.github/workflows/pre_release.yaml

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Create a pre-release
2+
3+
on:
4+
# Push to master will deploy a beta version
5+
push:
6+
branches:
7+
- master
8+
tags-ignore:
9+
- "**" # Ignore all tags to prevent duplicate builds when tags are pushed.
10+
11+
concurrency:
12+
group: release
13+
cancel-in-progress: false
14+
15+
jobs:
16+
release_metadata:
17+
if: "!startsWith(github.event.head_commit.message, 'docs') && !startsWith(github.event.head_commit.message, 'ci') && startsWith(github.repository, 'apify/')"
18+
name: Prepare release metadata
19+
runs-on: ubuntu-latest
20+
outputs:
21+
version_number: ${{ steps.release_metadata.outputs.version_number }}
22+
changelog: ${{ steps.release_metadata.outputs.changelog }}
23+
steps:
24+
- uses: apify/workflows/git-cliff-release@main
25+
name: Prepare release metadata
26+
id: release_metadata
27+
with:
28+
release_type: prerelease
29+
existing_changelog_path: CHANGELOG.md
30+
31+
wait_for_checks:
32+
name: Wait for code checks to pass
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: lewagon/[email protected]
36+
with:
37+
ref: ${{ github.ref }}
38+
repo-token: ${{ secrets.GITHUB_TOKEN }}
39+
check-regexp: (Build & Test .*|Lint|Docs build)
40+
wait-interval: 5
41+
42+
update_changelog:
43+
needs: [ release_metadata, wait_for_checks ]
44+
name: Update changelog
45+
runs-on: ubuntu-latest
46+
outputs:
47+
changelog_commitish: ${{ steps.commit.outputs.commit_long_sha || github.sha }}
48+
49+
steps:
50+
- name: Checkout repository
51+
uses: actions/checkout@v4
52+
with:
53+
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
54+
55+
- name: Use Node.js 22
56+
uses: actions/setup-node@v4
57+
with:
58+
node-version: 22
59+
60+
- name: Update package version in package.json
61+
run: npm version --no-git-tag-version --allow-same-version ${{ needs.release_metadata.outputs.version_number }}
62+
63+
- name: Update CHANGELOG.md
64+
uses: DamianReeves/write-file-action@master
65+
with:
66+
path: CHANGELOG.md
67+
write-mode: overwrite
68+
contents: ${{ needs.release_metadata.outputs.changelog }}
69+
70+
- name: Commit changes
71+
id: commit
72+
uses: EndBug/add-and-commit@v9
73+
with:
74+
author_name: Apify Release Bot
75+
author_email: [email protected]
76+
message: "chore(release): Update changelog and package version [skip ci]"
77+
78+
publish_to_npm:
79+
name: Publish to NPM
80+
needs: [ release_metadata, wait_for_checks ]
81+
runs-on: ubuntu-latest
82+
steps:
83+
- uses: actions/checkout@v4
84+
with:
85+
ref: ${{ needs.update_changelog.changelog_commitish }}
86+
- name: Use Node.js 22
87+
uses: actions/setup-node@v4
88+
with:
89+
node-version: 22
90+
cache: 'npm'
91+
cache-dependency-path: 'package-lock.json'
92+
- name: Install dependencies
93+
run: |
94+
echo "access=public" >> .npmrc
95+
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
96+
npm ci
97+
- # Check version consistency and increment pre-release version number for beta only.
98+
name: Bump pre-release version
99+
run: node ./.github/scripts/before-beta-release.cjs
100+
- name: Build module
101+
run: npm run build
102+
- name: Publish to NPM
103+
run: npm publish --tag beta
104+
105+
env:
106+
NODE_AUTH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }}
107+
NPM_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }}

.github/workflows/release.yaml

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
name: Create a release
2+
3+
on:
4+
# Trigger a stable version release via GitHub's UI, with the ability to specify the type of release.
5+
workflow_dispatch:
6+
inputs:
7+
release_type:
8+
description: Release type
9+
required: true
10+
type: choice
11+
default: auto
12+
options:
13+
- auto
14+
- custom
15+
- patch
16+
- minor
17+
- major
18+
custom_version:
19+
description: The custom version to bump to (only for "custom" type)
20+
required: false
21+
type: string
22+
default: ""
23+
24+
concurrency:
25+
group: release
26+
cancel-in-progress: false
27+
28+
jobs:
29+
release_metadata:
30+
name: Prepare release metadata
31+
runs-on: ubuntu-latest
32+
outputs:
33+
version_number: ${{ steps.release_metadata.outputs.version_number }}
34+
tag_name: ${{ steps.release_metadata.outputs.tag_name }}
35+
changelog: ${{ steps.release_metadata.outputs.changelog }}
36+
release_notes: ${{ steps.release_metadata.outputs.release_notes }}
37+
steps:
38+
- uses: apify/workflows/git-cliff-release@main
39+
name: Prepare release metadata
40+
id: release_metadata
41+
with:
42+
release_type: ${{ inputs.release_type }}
43+
custom_version: ${{ inputs.custom_version }}
44+
existing_changelog_path: CHANGELOG.md
45+
46+
update_changelog:
47+
needs: [ release_metadata ]
48+
name: Update changelog
49+
runs-on: ubuntu-latest
50+
outputs:
51+
changelog_commitish: ${{ steps.commit.outputs.commit_long_sha || github.sha }}
52+
53+
steps:
54+
- name: Checkout repository
55+
uses: actions/checkout@v4
56+
with:
57+
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
58+
59+
- name: Use Node.js 22
60+
uses: actions/setup-node@v4
61+
with:
62+
node-version: 22
63+
64+
- name: Update package version in package.json
65+
run: npm version --no-git-tag-version --allow-same-version ${{ needs.release_metadata.outputs.version_number }}
66+
67+
- name: Update CHANGELOG.md
68+
uses: DamianReeves/write-file-action@master
69+
with:
70+
path: CHANGELOG.md
71+
write-mode: overwrite
72+
contents: ${{ needs.release_metadata.outputs.changelog }}
73+
74+
- name: Commit changes
75+
id: commit
76+
uses: EndBug/add-and-commit@v9
77+
with:
78+
author_name: Apify Release Bot
79+
author_email: [email protected]
80+
message: "chore(release): Update changelog and package version [skip ci]"
81+
82+
create_github_release:
83+
name: Create github release
84+
needs: [release_metadata, update_changelog]
85+
runs-on: ubuntu-latest
86+
env:
87+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
steps:
89+
- name: Create release
90+
uses: softprops/action-gh-release@v2
91+
with:
92+
tag_name: ${{ needs.release_metadata.outputs.tag_name }}
93+
name: ${{ needs.release_metadata.outputs.version_number }}
94+
target_commitish: ${{ needs.update_changelog.outputs.changelog_commitish }}
95+
body: ${{ needs.release_metadata.outputs.release_notes }}
96+
97+
publish_to_npm:
98+
name: Publish to NPM
99+
needs: [ update_changelog ]
100+
runs-on: ubuntu-latest
101+
steps:
102+
- uses: actions/checkout@v4
103+
with:
104+
ref: ${{ needs.update_changelog.changelog_commitish }}
105+
- name: Use Node.js 22
106+
uses: actions/setup-node@v4
107+
with:
108+
node-version: 22
109+
cache: 'npm'
110+
cache-dependency-path: 'package-lock.json'
111+
- name: Install dependencies
112+
run: |
113+
echo "access=public" >> .npmrc
114+
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
115+
npm ci
116+
- name: Build module
117+
run: npm run build
118+
- name: Publish to NPM
119+
run: npm publish --tag latest
120+
121+
env:
122+
NODE_AUTH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }}
123+
NPM_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }}

.npmignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# .npmignore
2+
# Exclude everything by default
3+
*
4+
5+
# Include specific files and folders
6+
!dist/
7+
!README.md
8+
!LICENSE

.python-version

-1
This file was deleted.

CHANGELOG.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
## 0.1.1 (2025-03-14)
6+
7+
### 🐛 Bug Fixes
8+
9+
- Change env variable name from APIFY_API_TOKEN to APIFY_TOKEN
10+
- Add extra query parameters
11+
- Remove unnecessary example clients (SSE and chat client)
12+
- Create NPM package @apify/mcp-server-rag-web-browser
13+
- Update readme
14+
15+
## 0.1.0 (2025-01-17)
16+
17+
### 🚀 Features
18+
19+
- Initial release

0 commit comments

Comments
 (0)