Skip to content

Commit

Permalink
Feat: add model context protocol (#40)
Browse files Browse the repository at this point in the history
* Refactor main.ts to move search request and normal mode into search.ts

* Add model context protocol server

* Use .actor/input_schema.json as input for MCP
  • Loading branch information
jirispilka authored Jan 6, 2025
1 parent 6fb7da4 commit 35b5a1c
Show file tree
Hide file tree
Showing 12 changed files with 1,126 additions and 224 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ node_modules

# data
data
src/storage
dist
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
This changelog summarizes all changes of the RAG Web Browser

### 2024-11-13
### 1.0.4 (2025-01-04)

🚀 Features
- Include Model Context Protocol in Standby Mode

### 1.0.3 (2024-11-13)

🚀 Features
- Improve README.md and simplify configuration
Expand All @@ -11,13 +16,13 @@ This changelog summarizes all changes of the RAG Web Browser
- Rename googleSearchResults to searchResults and searchProxyGroup to serpProxyGroup
- Implement input validation

### 2024-11-08
### 0.1.4 (2024-11-08)

🚀 Features
- Add functionality to extract content from a specific URL
- Update README.md to include new functionality and provide examples

### 2024-10-17
### 0.0.32 (2024-10-17)

🚀 Features
- Handle errors when request is added to Playwright queue.
Expand Down
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,45 @@ Learn more about [adding custom actions to your GPTs with Apify Actors](https://

The RAG Web Browser Actor can also be used as an [MCP server](https://github.com/modelcontextprotocol) and integrated with AI applications and agents, such as Claude Desktop.
For example, in Claude Desktop, you can configure the MCP server in its settings to perform web searches and extract content.

Alternatively, you can develop a custom MCP client to interact with the RAG Web Browser Actor.

In the Standby mode, the Actor runs an HTTP server that supports the MCP protocol via SSE (Server-Sent Events).

1. Initiate SSE connection:
```shell
curl https://rag-web-browser.apify.actor/sse?token=<APIFY_API_TOKEN>
```
On connection, you’ll receive a `sessionId`:
```text
event: endpoint
data: /message?sessionId=5b2
```

1. Send a message to the server by making a POST request with the `sessionId`, `APIFY-API-TOKEN` and your query:
```shell
curl -X POST "https://rag-web-browser.apify.actor/message?session_id=5b2&token=<APIFY-API-TOKEN>" -H "Content-Type: application/json" -d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"arguments": { "query": "recent news about LLMs", "maxResults": 1 },
"name": "rag-web-browser"
}
}'
```
For the POST request, the server will respond with:
```text
Accepted
```

1. Receive a response at the initiated SSE connection:
The server invoked `Actor` and its tool using the provided query and sent the response back to the client via SSE.

```text
event: message
data: {"result":{"content":[{"type":"text","text":"[{\"searchResult\":{\"title\":\"Language models recent news\",\"description\":\"Amazon Launches New Generation of LLM Foundation Model...\"}}
```
To learn more about MCP server integration, check out the [RAG Web Browser MCP server documentation](https://github.com/apify/mcp-server-rag-web-browser).
## ⏳ Performance optimization
Expand Down Expand Up @@ -277,3 +313,9 @@ And then you can run it locally using [Apify CLI](https://docs.apify.com/cli) as
```bash
APIFY_META_ORIGIN=STANDBY apify run -p
```
Server will start on `http://localhost:3000` and you can send requests to it, for example:
```bash
curl "http://localhost:3000/search?query=example.com"
```
Loading

0 comments on commit 35b5a1c

Please sign in to comment.