websocket

command
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

README

Example: Exposing a WebSocket Service

This example demonstrates how to expose a WebSocket service as a tool through MCP Any.

Overview

This example consists of three main components:

  1. Upstream WebSocket Server: A simple Go-based WebSocket server (echo_server/) that echoes back any message it receives.
  2. MCP Any Configuration: A YAML file (config/mcp_any_config.yaml) that tells MCP Any how to connect to the WebSocket server.
  3. MCP Any Server: The MCP Any instance that acts as a proxy between the AI assistant and the WebSocket server.

Running the Example

1. Build the MCP Any Binary

Ensure the MCP Any binary is built. From the root of the repository, run:

make build
2. Run the Upstream WebSocket Server

In a separate terminal, start the upstream WebSocket server. From this directory (upstream_service/websocket), run:

go run ./echo_server/server/main.go

The server will start and listen on port 8082.

3. Run the MCP Any Server

In another terminal, start the MCP Any server using the provided script. Note that this example is configured to run the MCP Any server on port 8081 to avoid conflicts with other examples.

./start.sh

Interacting with the Tool

Once both servers are running, you can interact with the tool using the gemini CLI.

Using the gemini CLI

Now, you can call the echo tool by sending a tools/call request.

gemini --allowed-mcp-server-names mcpany-websocket -p "call the tool echo-service.echo with message 'Hello, WebSocket!'"

You should receive a JSON response echoing your message:

{
  "message": "Hello, WebSocket!"
}

Test Client

This example also includes a test client in client.go that demonstrates how to interact with the MCP Any server programmatically using the Go SDK. You can run it with go run ./client/main.go.

Documentation

Overview

Package main implements a demo WebSocket client.

Directories

Path Synopsis
Package main implements a demo WebSocket client.
Package main implements a demo WebSocket client.
echo_server
server command
Package main implements a simple WebSocket echo server for demonstration purposes.
Package main implements a simple WebSocket echo server for demonstration purposes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL