Get the FREE Ultimate OpenClaw Setup Guide →

pywss

一个轻量级的 Python Web 框架,一站式集成 MCP SSE、StreamHTTP 和 MCPO 协议,助你轻松构建MCP Server🔥

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio czasg-pywss python main.py \
  --env PYWSS_LOG_LEVEL="INFO" \
  --env PYTHONUNBUFFERED="1"

How to use

pywss is a lightweight Python web framework with built-in support for MCP-style tooling. The MCP capabilities are exposed by creating MCP server classes that extend pywss.mcp.MCPServer and define methods that start with tool_. These methods are documented via OpenAPI decorators and receive structured input through pydantic models. The example in the README shows how to build and mount multiple MCP services (for example domain and log services) under grouped endpoints, exposing SSE, StreamHTTP, and MCPO endpoints. You can start an MCP service by running a Python script (for example python3 main.py) that creates a PyWSS app, mounts your MCP servers, and calls app.run(). Tools are invoked by making POST requests to endpoints like /api/v1/<service>/tools/{tool_name} with a properly shaped request body, and results are returned following the framework’s JSON-RPC 2.0–style success payloads. The OpenAPI integration also means you can browse and test the APIs via the generated docs.

In practice, you would define request models (subclassing pydantic.BaseModel), decorate tool methods with @pywss.openapi.docs to describe inputs, and then mount the service under an API group. The MCP protocol types supported include SSE, StreamHTTP, and MCPO, enabling you to build reactive streams, streaming HTTP endpoints, and multi-controller MCP tooling.

How to install

Prerequisites:

  • Python 3.6+ (as noted in the Pywss project)
  • pip or pip3

Install the PyWSS package (and any MCP-related dependencies):

pip3 install pywss

Create your MCP service in a Python script (for example main.py) following the README example:

# main.py
import pywss
from pywss.mcp import MCPServer

class MyMCPServer(MCPServer):
    # define tool_get_example and other tool methods with @pywss.openapi.docs
    pass

app = pywss.App()
# mount your MCP server(s) under a desired route group
# app.mount(...)
app.run()

Run the server:

python3 main.py

Access OpenAPI docs (if enabled in your script) at the provided docs endpoint and use the MCP endpoints as described in the README.

Additional notes

Tips and common notes:

  • The MCP pattern in pywss uses methods prefixed with tool_ to define tools, and each method should declare a request model via @pywss.openapi.docs with a request parameter inheriting from pydantic.BaseModel.
  • OpenAPI documentation can be enabled to auto-generate API docs for your MCP tools, which helps in testing and integration.
  • SSE and StreamHTTP endpoints provide streaming capabilities; MCPO endpoints enable multi-protocol MCP tooling. When testing locally, you can use curl or HTTPie to exercise the endpoints.
  • Environment variables like PYTHONUNBUFFERED can help with logging latency; consider configuring log levels via your app for production.
  • If you encounter import errors, ensure pywss is installed in the same Python environment that runs your script, and verify you are using Python 3.6+ as required by the project.
  • For deployment, packaging your script with a requirements.txt and pinned versions helps reproduce environments.

Related MCP Servers

Sponsor this space

Reach thousands of developers