1. Conduid
  2. Search
  3. Fastmcp Websockets Example
MCP server · Search

Fastmcp Websockets Example

Unclaimed last commit a year ago search
30Low

Scored 7 months ago · breakdown

About Fastmcp Websockets Example

Fastmcp Websockets Example is an MCP server published by thecodekitchen in the Search category.

The repository has 1 stars and 0 forks, with the last commit a year ago. Six months or more without a commit doesn't mean the server is broken, but check the open issues before depending on it in production.

Install

From source
git clone https://github.com/thecodekitchen/fastmcp_websockets_example

This server has no ConduID identity, so agent calls to it are not receipted. Pin the version you install and review the source before granting it credentials.

Ask AI

✦

Ask AI about Fastmcp Websockets Example

Powered by Claude · Grounded in docs

I know everything about Fastmcp Websockets Example. Ask me about installation, configuration, usage, or troubleshooting.

Security checks

  • ✓README presentThe repository ships documentation.

5 checks have not been run yet.

README

FastMCP WebSockets Example

This project demonstrates how to use the mcpsock package to create WebSocket-based communication between clients and FastMCP servers, enabling real-time communication between web clients and FastMCP services.

Overview

The FastMCP WebSockets Example showcases a complete implementation of the MCP (Model Context Protocol) over WebSockets using the mcpsock package. This implementation:

  1. Uses FastAPI to create a WebSocket server endpoint
  2. Implements a router-based FastMCP server with tools, resources, and prompts
  3. Demonstrates bidirectional communication between clients and the server
  4. Provides a clean, decorator-based API for defining MCP endpoints

Components

Server (server.py)

The server component:

  • Creates a FastAPI application with a WebSocket endpoint
  • Uses the WebSocketServer class from mcpsock to handle MCP protocol messages
  • Implements tools, resources, and prompts using decorators
  • Handles WebSocket connections and message routing
  • Processes client requests and sends responses

Client (client.py)

The client component:

  • Uses the WebSocketClient class from mcpsock to connect to the server
  • Demonstrates how to discover available capabilities (tools, resources, prompts)
  • Shows how to call tools, access resources, and use prompts
  • Handles responses from the server

How It Works

  1. The server creates a WebSocketServer instance and defines handlers using decorators:

    • @router.tool() for tool endpoints
    • @router.resource() for resource endpoints
    • @router.prompt() for prompt endpoints
    • @router.initialize() for connection initialization
    • @router.fallback() for handling unknown methods
  2. When a client connects via WebSocket:

    • The client initializes the connection with the server
    • The client can discover available capabilities
    • The client can call tools, access resources, and use prompts
    • The server processes requests and sends responses
  3. The mcpsock package handles all the protocol details, including:

    • Message serialization and deserialization
    • Request/response matching
    • Error handling
    • WebSocket connection management

Use Cases

This WebSocket implementation is useful for:

  • Web Applications: Integrate FastMCP capabilities into web frontends
  • Real-time Services: Enable real-time AI-powered features in applications
  • Distributed Systems: Connect remote clients to FastMCP servers across networks

Running the Example

  1. Start the server:

    pip install -r requirements.txt
    python server.py
    

    This will start the FastAPI server on port 8765.

  2. Run the client in a separate terminal:

    python client.py
    

    The client will connect to the server, discover available capabilities, and demonstrate various interactions.

Or with uv:

  1. Start the server:

    uv run server.py
    
  2. Run the client in a separate terminal:

    uv run client.py
    

Dependencies

This project uses the following dependencies:

  • mcpsock (>=0.1.0): The WebSocket implementation of the MCP protocol
  • FastAPI (>=0.110.0,<0.116.0): Web framework for building the WebSocket server
  • Uvicorn (>=0.27.0,<0.35.0): ASGI server for running the FastAPI application
  • FastMCP (>=2.2.0,<2.3.0): The FastMCP library for creating MCP servers and clients
  • Websockets (>=12.0,<16.0): WebSocket implementation for Python
  • Starlette (>=0.46.2): ASGI framework used by FastAPI

Installation

We strongly recommend using uv for package management, as it's significantly faster than pip and provides better dependency resolution. This is the same approach used by FastMCP.

This repository includes a uv.lock file to ensure consistent dependency resolution across different environments.

Installing uv

If you don't have uv installed:

  • macOS: brew install uv
  • Linux: curl -LsSf https://astral.sh/uv/install.sh | sh
  • Windows: powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

For more installation options, see the uv documentation.

Setting Up Project

  1. Clone the repository:

    git clone https://github.com/your-repo/fastmcp-websockets-example.git
    cd fastmcp-websockets-example
    
  2. Create a virtual environment:

    uv venv
    
  3. Install the package and dependencies:

    uv pip install -e .
    
  4. For development:

    uv pip install -e ".[dev]"
    

Alternative: Using pip

If you prefer using traditional pip:

  1. Create a virtual environment:

    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    
  2. Install the package and dependencies:

    pip install -e .
    
  3. For development:

    pip install -e ".[dev]"
    

About mcpsock

The mcpsock package is a standalone implementation of the MCP (Model Context Protocol) over WebSockets. It provides:

  1. A server-side implementation (WebSocketServer) for handling MCP requests
  2. A client-side implementation (WebSocketClient) for connecting to MCP servers
  3. A clean, decorator-based API for defining MCP endpoints
  4. Full support for the MCP protocol, including tools, resources, and prompts

The package is designed to be easy to use and integrate with existing FastAPI applications.

License

This example is provided under the same license as FastMCP (Apache-2.0).

README copy captured when this server was indexed; it may lag the repository. The original is authoritative.

Questions

About Fastmcp Websockets Example

How do I install Fastmcp Websockets Example?

No package has been published for this server, so install it from source: clone the repository and follow its README.

Is Fastmcp Websockets Example safe to use with an AI agent?

Its trust score is 30 out of 100 (low). It passes 1 of the 1 static security checks run so far. It has no ConduID identity yet, so agent calls to it are not receipted.

Is Fastmcp Websockets Example still maintained?

The last commit was a year ago. That's long enough that you should check whether the maintainer is responding to issues before depending on it.