Skip to content

feat: example clients #10

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

Merged
merged 9 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
APIFY_API_TOKEN=
APIFY_API_TOKEN=
ANTHROPIC_API_KEY=
104 changes: 89 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ The server does not provide any resources and prompts.

### Install

Follow the steps below to set up and run the server on your local machine:
First, clone the repository using the following command:

```bash
git clone [email protected]:apify/mcp-server-rag-web-browser.git
```

Navigate to the project directory and install the required dependencies:

```bash
cd mcp-server-rag-web-browser
npm install
```

Before running the server, you need to build the project:

```bash
npm run build
```

#### Claude Desktop

Configure Claude Desktop to recognize the MCP server.
Expand All @@ -59,7 +79,7 @@ Configure Claude Desktop to recognize the MCP server.
"mcp-server-rag-web-browser": {
"command": "npx",
"args": [
"/path/to/mcp-server-rag-web-browser/build/index.js",
"/path/to/mcp-server-rag-web-browser/build/index.js"
]
"env": {
"APIFY-API-TOKEN": "your-apify-api-token"
Expand All @@ -85,30 +105,84 @@ Configure Claude Desktop to recognize the MCP server.

## 👷🏼 Development

### Local Development
### Simple local client (stdio)

To test the server locally, you can use `example_client_stdio.ts`:

```bash
node build/example_client_stdio.js
```

The script will start the MCP server, fetch available tools, and then call the `search` tool with a query.

### Chat local client (stdio)

To run simple chat client, you can use `example_chat_stdio.ts`:

```bash
node build/example_chat_stdio.js
```
Here you can interact with the server using the chat interface.

### Test Server-Sent Events (SSE) Transport

The SSE transport enables **server-to-client streaming** while using **HTTP POST requests** for client-to-server communication.

#### Step 1: Start the Server

Start the server with the following command:

```bash
node build/sse.js
```

The server will start and listen on `http://localhost:3001`.

#### Step 2: Connect to the SSE Server (Client)

To connect to the SSE server, use the following command (acting as the client):

```bash
curl -X GET http://localhost:3001/sse
```

If you're working on an unpublished server, you can access the local server via the following command:
Upon connection, you will receive a message containing the `sessionId`, for example:

```text
"mcpServers": {
"mcp-server-rag-web-browser": {
"command": "/path/to/mcp-server-rag-web-browser/build/index.js",
}
"env": {
"APIFY-API-TOKEN": "your-apify-api-token"
}
}
event: endpoint
data: /message?sessionId=7bd075c8-bbd1-4854-884c-e6c837148b7b
```

### Local client
#### Step 3: Send a Message to the Server

To test the server locally, you can use `example_client`:
You can send a message to the server by making a POST request with the `sessionId` and your query:

```bash
node build/example_client.js
curl -X POST "http://localhost:3001/message?session_id=181c7a3d-01a9-498e-8e16-5d5878832cd7" -H "Content-Type: application/json" -d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"arguments": { "query": "recent news about LLMs" },
"name": "search"
}
}'
```

The script will start the MCP server, fetch available tools, and then call the `search` tool with a query.
#### Step 4: Receive the Response

For the POST request, the server will respond with:

```text
Accepted
```

The server will then invoke the `search` tool using the provided query and stream 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...\"}}
```

### Debugging

Expand Down
Loading
Loading