Skip to content

Add MCP Client + WebSockets transport support. #84

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.2.12](https://github.com/QuantGeekDev/mcp-framework/compare/mcp-framework-v0.2.11...mcp-framework-v0.2.12) (2025-04-08)

### Documentation

* Add detailed usage examples and explanation for `MCPClient`.
* Document WebSockets transport support and configuration.


## [0.2.11](https://github.com/QuantGeekDev/mcp-framework/compare/mcp-framework-v0.2.10...mcp-framework-v0.2.11) (2025-03-30)

Expand Down
83 changes: 83 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,42 @@ MCP-Framework gives you architecture out of the box, with automatic directory-ba
- Easy-to-use base classes for tools, prompts, and resources
- Out of the box authentication for SSE endpoints

### Purpose

- Facilitate communication with an MCP server from your application.
- Support multiple transports seamlessly.
- Simplify sending commands, receiving responses, and handling streaming data.

### Typical Usage

```typescript
import { MCPClient } from "mcp-framework";

const client = new MCPClient({
transport: {
type: "websocket",
options: {
url: "ws://localhost:8080/ws" // Your WebSocket endpoint
}
}
});

// Connect to the server
await client.connect();

// Send a request
const response = await client.send({
tool: "example_tool",
input: { message: "Hello MCP" }
});

console.log("Response:", response);

// Disconnect when done
await client.disconnect();
```

`MCPClient` can be configured to use other transports like SSE, HTTP, or stdio by changing the `transport` type and options.

# [Read the full docs here](https://mcp-framework.com)

Expand Down Expand Up @@ -257,6 +293,53 @@ const server = new MCPServer({
}
}
});
### WebSockets Transport
The WebSockets transport enables full-duplex, low-latency communication between `MCPClient` and the MCP server. It is ideal for interactive applications requiring real-time updates or bidirectional messaging.
#### Benefits
- Persistent connection with low overhead.
- Real-time, bidirectional communication.
- Efficient for streaming data and interactive workflows.
- Supports multiplexing multiple requests/responses over a single connection.
#### Integration with MCP Client
To use WebSockets, configure the `MCPClient` with the `websocket` transport type and specify the server URL:
```typescript
const client = new MCPClient({
transport: {
type: "websocket",
options: {
url: "ws://localhost:8080/ws"
}
}
});
await client.connect();
```
On the server side, enable the WebSockets transport:
```typescript
import { MCPServer } from "mcp-framework";
const server = new MCPServer({
transport: {
type: "websocket",
options: {
port: 8080,
path: "/ws" // default or custom WebSocket path
}
}
});
await server.start();
```
This setup allows the client and server to communicate efficiently over WebSockets.
```
### HTTP Stream Transport
Expand Down
14 changes: 14 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @type {import('jest').Config} */
export default {
preset: 'ts-jest/presets/default-esm',
testEnvironment: 'node',
testMatch: ['<rootDir>/src/**/*.test.ts'],
extensionsToTreatAsEsm: ['.ts'],
transform: {
'^.+\\.ts$': ['ts-jest', { useESM: true }],
},
transformIgnorePatterns: [
'/node_modules/(?!(\\@modelcontextprotocol/sdk)/)',
],
moduleFileExtensions: ['ts', 'js', 'json'],
};
Loading