Skip to content

Commit 9bdb198

Browse files
authored
feat: apify docs tools (#162)
* Add apify docs serach and fetch tool. Write integration tests for docs. Update readme. * lint * cache apify docs results * address review comments
1 parent 6a89eb8 commit 9bdb198

File tree

12 files changed

+591
-6
lines changed

12 files changed

+591
-6
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,8 @@ You can refer to the specific Actor's documentation for a list of available argu
9292
### Helper tools
9393
One of the powerful features of MCP with Apify is dynamic actor tooling – the ability for an AI agent to find new tools (Actors) as needed and incorporate them. Here are some special MCP operations and how Apify MCP Server supports them:
9494

95-
- Actor discovery and management: Search for Actors (`search-actors`), view details (`get-actor-details`), and dynamically add or remove tools (`add-actor`, `remove-actor`).
96-
- Actor execution and monitoring: Start Actor runs, fetch run results (`get-actor-run`), logs (`get-actor-log`), and abort runs (`abort-actor-run`).
97-
- Dataset access: List datasets, retrieve dataset info and items (`get-dataset`, `get-dataset-list`, `get-dataset-items`).
98-
- Key-value store access: List key-value stores, view keys, and retrieve records (`get-key-value-store-list`, `get-key-value-store`, `get-key-value-store-keys`, `get-key-value-store-record`).
95+
- Actor discovery and management: Search for Actors (`search-actors`), view details (`get-actor-details`), and dynamically add them (`add-actor`).
96+
- Apify documentation: Search Apify documentation (`search-apify-docs`) and fetch specific documents (`fetch-apify-docs`).
9997
- Built-in help tool: A static helper (`apify-actor-help-tool`) that returns usage info for the Apify MCP Server.
10098

10199
## Prompt & Resources

package-lock.json

Lines changed: 228 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@
3333
"@apify/datastructures": "^2.0.3",
3434
"@apify/log": "^2.5.16",
3535
"@modelcontextprotocol/sdk": "^1.13.2",
36+
"@types/turndown": "^5.0.5",
3637
"ajv": "^8.17.1",
38+
"algoliasearch": "^5.31.0",
3739
"apify": "^3.4.2",
3840
"apify-client": "^2.12.6",
3941
"express": "^4.21.2",
42+
"turndown": "^7.2.0",
4043
"yargs": "^17.7.2",
4144
"zod": "^3.24.1",
4245
"zod-to-json-schema": "^3.24.1"

src/const.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export enum HelperTools {
3434
KEY_VALUE_STORE_RECORD_GET = 'get-key-value-store-record',
3535
APIFY_MCP_HELP_TOOL = 'apify-actor-help-tool',
3636
STORE_SEARCH = 'search-actors',
37+
DOCS_SEARCH = 'search-apify-docs',
38+
DOCS_FETCH = 'fetch-apify-docs',
3739
}
3840

3941
export const defaults = {
@@ -49,8 +51,11 @@ export const ACTOR_OUTPUT_TRUNCATED_MESSAGE = `Output was truncated because it w
4951

5052
export const ACTOR_ADDITIONAL_INSTRUCTIONS = 'Never call/execute tool/Actor unless confirmed by the user.';
5153

54+
// Cache
5255
export const ACTOR_CACHE_MAX_SIZE = 500;
5356
export const ACTOR_CACHE_TTL_SECS = 30 * 60; // 30 minutes
57+
export const APIFY_DOCS_CACHE_MAX_SIZE = 500;
58+
export const APIFY_DOCS_CACHE_TTL_SECS = 60 * 60; // 1 hour
5459

5560
export const ACTOR_PRICING_MODEL = {
5661
/** Rental actors */
@@ -69,3 +74,9 @@ export const ACTOR_PRICING_MODEL = {
6974
export const ACTOR_SEARCH_ABOVE_LIMIT = 50;
7075

7176
export const MCP_STREAMABLE_ENDPOINT = '/mcp';
77+
78+
export const ALGOLIA = {
79+
appId: 'N8EOCSBQGH',
80+
apiKey: 'e97714a64e2b4b8b8fe0b01cd8592870', // search only (public) API key
81+
indexName: 'test_test_apify_sdk',
82+
};

src/state.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import { ACTOR_CACHE_MAX_SIZE, ACTOR_CACHE_TTL_SECS } from './const.js';
2-
import type { ActorDefinitionPruned } from './types.js';
1+
import { ACTOR_CACHE_MAX_SIZE, ACTOR_CACHE_TTL_SECS, APIFY_DOCS_CACHE_MAX_SIZE, APIFY_DOCS_CACHE_TTL_SECS } from './const.js';
2+
import type { ActorDefinitionPruned, ApifyDocsSearchResult } from './types.js';
33
import { TTLLRUCache } from './utils/ttl-lru.js';
44

55
export const actorDefinitionPrunedCache = new TTLLRUCache<ActorDefinitionPruned>(ACTOR_CACHE_MAX_SIZE, ACTOR_CACHE_TTL_SECS);
6+
export const searchApifyDocsCache = new TTLLRUCache<ApifyDocsSearchResult[]>(APIFY_DOCS_CACHE_MAX_SIZE, APIFY_DOCS_CACHE_TTL_SECS);
7+
/** Stores processed Markdown content */
8+
export const fetchApifyDocsCache = new TTLLRUCache<string>(APIFY_DOCS_CACHE_MAX_SIZE, APIFY_DOCS_CACHE_TTL_SECS);

0 commit comments

Comments
 (0)