Skip to content

Commit ad31f34

Browse files
authored
feat: example clients (#10)
* Update server and packages * Add client over stdio with chat capability * Add stdio chat client * Update README.md * Update README.md to add information about SSE transport * Add SSE client * Refactor SSE client * Add SSE client * Fix Claude example in README.md
1 parent 5d26ece commit ad31f34

10 files changed

+659
-63
lines changed

.env.example

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

README.md

+89-15
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@ The server does not provide any resources and prompts.
4545

4646
### Install
4747

48+
Follow the steps below to set up and run the server on your local machine:
49+
First, clone the repository using the following command:
50+
51+
```bash
52+
git clone [email protected]:apify/mcp-server-rag-web-browser.git
53+
```
54+
55+
Navigate to the project directory and install the required dependencies:
56+
57+
```bash
58+
cd mcp-server-rag-web-browser
59+
npm install
60+
```
61+
62+
Before running the server, you need to build the project:
63+
64+
```bash
65+
npm run build
66+
```
67+
4868
#### Claude Desktop
4969

5070
Configure Claude Desktop to recognize the MCP server.
@@ -59,7 +79,7 @@ Configure Claude Desktop to recognize the MCP server.
5979
"mcp-server-rag-web-browser": {
6080
"command": "npx",
6181
"args": [
62-
"/path/to/mcp-server-rag-web-browser/build/index.js",
82+
"/path/to/mcp-server-rag-web-browser/build/index.js"
6383
]
6484
"env": {
6585
"APIFY-API-TOKEN": "your-apify-api-token"
@@ -85,30 +105,84 @@ Configure Claude Desktop to recognize the MCP server.
85105
86106
## 👷🏼 Development
87107
88-
### Local Development
108+
### Simple local client (stdio)
109+
110+
To test the server locally, you can use `example_client_stdio.ts`:
111+
112+
```bash
113+
node build/example_client_stdio.js
114+
```
115+
116+
The script will start the MCP server, fetch available tools, and then call the `search` tool with a query.
117+
118+
### Chat local client (stdio)
119+
120+
To run simple chat client, you can use `example_chat_stdio.ts`:
121+
122+
```bash
123+
node build/example_chat_stdio.js
124+
```
125+
Here you can interact with the server using the chat interface.
126+
127+
### Test Server-Sent Events (SSE) Transport
128+
129+
The SSE transport enables **server-to-client streaming** while using **HTTP POST requests** for client-to-server communication.
130+
131+
#### Step 1: Start the Server
132+
133+
Start the server with the following command:
134+
135+
```bash
136+
node build/sse.js
137+
```
138+
139+
The server will start and listen on `http://localhost:3001`.
140+
141+
#### Step 2: Connect to the SSE Server (Client)
142+
143+
To connect to the SSE server, use the following command (acting as the client):
144+
145+
```bash
146+
curl -X GET http://localhost:3001/sse
147+
```
89148

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

92151
```text
93-
"mcpServers": {
94-
"mcp-server-rag-web-browser": {
95-
"command": "/path/to/mcp-server-rag-web-browser/build/index.js",
96-
}
97-
"env": {
98-
"APIFY-API-TOKEN": "your-apify-api-token"
99-
}
100-
}
152+
event: endpoint
153+
data: /message?sessionId=7bd075c8-bbd1-4854-884c-e6c837148b7b
101154
```
102155

103-
### Local client
156+
#### Step 3: Send a Message to the Server
104157

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

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

111-
The script will start the MCP server, fetch available tools, and then call the `search` tool with a query.
172+
#### Step 4: Receive the Response
173+
174+
For the POST request, the server will respond with:
175+
176+
```text
177+
Accepted
178+
```
179+
180+
The server will then invoke the `search` tool using the provided query and stream the response back to the client via SSE:
181+
182+
```text
183+
event: message
184+
data: {"result":{"content":[{"type":"text","text":"[{\"searchResult\":{\"title\":\"Language models recent news\",\"description\":\"Amazon Launches New Generation of LLM Foundation Model...\"}}
185+
```
112186

113187
### Debugging
114188

0 commit comments

Comments
 (0)