Pywss logo

Pywss

Community
czasg

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

Publisherczasg
Repositorypywss
LanguagePython
Forks
22
Stars
99
Available tools
0
Transport typestdio
LicenseMIT
Links
  • Connect tools to AI workflows

    Pywss exposes MCP capabilities that can be used by compatible AI clients and agents.

  • 0 available tools

    Browse the callable actions below, including names and descriptions when provided by the server.

  • Ready-to-copy setup

    Use the installation snippets to configure this server in your preferred MCP client.

  • Open source signals

    99 stars and 22 forks from the linked repository.

pywss

Project status PyPI Codecov GitHub issues GitHub issues GitHub license

Pywss 简介

Pywss(发音 /piːwaɪz/,类似 p~whys)是一个轻量级的 Python Web 框架,它基于 Python3.6+ 特性构建。

与 Flask、Django 等主流框架不同的是,Pywss 的底层并没有实现 WSGI 接口协议。 其编程风格也更类似于 Gin、Iris 等框架,因此对于熟悉这些框架的开发者来说,Pywss 是一个非常值得探索的项目。

其关键特性有:

  • 简单:拒绝海量参数,减少心智负担。了解上下文 pywss.Context 即刻启程。
  • 快速:引入线程池机制,减少并发场景下线程创建/销毁开销。
  • 优雅:ctx.next 真的太优雅了。如果你也和我一样喜欢,那我觉得这件事情,泰裤辣!!
  • 标准化:集成了部分 OpenAPI(Swagger)能力,方便开发者快速生成 API 文档并进行调试。
  • 支持WebSocket:开箱即用的 WebSocket 能力。
  • 接口测试:开箱即用的 API 测试模块,不启动服务也能测试接口功能辣!
  • MCP PRO:一站式集成 SSE、StreamHTTP 和 MCPO 协议,助你轻松构建多 MCP 工具🔥

在线文档 https://czasg.github.io/pywss/

快速开始

1、安装 pywss

shell
pip3 install pywss

2、搭建 web 应用

首先创建 main.py 文件,并写入以下代码:

python
import time
import pywss

def log_handler(ctx: pywss.Context):
    start_time = time.time()
    ctx.next()
    print(
        f"Route: {ctx.route}, "
        f"Method: {ctx.method}, "
        f"Status: {ctx.response_status_code}, "
        f"Time: {time.time() - start_time:.3f}s"
    )

def handler(ctx: pywss.Context):
  ctx.write("hello~")

def main():
    app = pywss.App()
    app.get("/hello", handler)  # curl localhost:8080/hello
    app.any("*", log_handler, handler)  # curl -X POST localhost:8080/hello
    app.run()

if __name__ == '__main__':
    main()

接着启动服务:

shell
python3 main.py

至此,一个简单的 web 应用服务就完成了。

3、搭建 MCP 应用

要快速构建 MCP 服务,只需继承 pywss.mcp.MCPServer 并遵循以下规则:

核心约束:

  • 所有接口方法必须以 tool_ 开头(如 tool_query_user)
  • 必须使用 @pywss.openapi.docs 声明请求参数,且 request 必须从 pydantic.BaseModel 继承(自动生成 OpenAPI 文档)

请求处理:

  • 通过 ctx.data.req 直接获取结构化请求体
  • 使用 self.handle_success(ctx, data) 返回成功响应
  • 使用 self.handle_error(ctx, code, message) 返回标准错误
python
# coding: utf-8
import pywss
from pydantic import BaseModel
from pywss.mcp import MCPServer

class DomainReq(BaseModel):  # 定义 DomainReq 请求,必须从 pydantic.BaseModel 继承
    domain: str

class DomainMCPServer(MCPServer):  # 定义 DomainMCPServer 服务,必须从 pywss.mcp.MCPServer 继承
    @pywss.openapi.docs(description="获取单个域名服务", request=DomainReq)  # required,工具及其参数说明
    def tool_get_domain(self, ctx: pywss.Context):
        req: DomainReq = ctx.data.req  # 框架已经封装好了请求,可以从 ctx.data.req 直接获取使用,异常请求会被拦截
        self.handle_success(ctx, {  # handle_success 封装了 jsonrpc2.0 输出规范
            "domain": req.domain,
            "color": req.color
        })

class LogReq(BaseModel):
    traceId: str

class LogMCPServer(MCPServer):
    @pywss.openapi.docs(description="获取单个trace日志", request=LogReq)
    def tool_get_trace_log(self, ctx: pywss.Context):
        req: LogReq = ctx.data.req
        self.handle_success(ctx, {
            "traceId": req.traceId,
        })

domainMCPServer = DomainMCPServer()
logMCPServer = LogMCPServer()

app = pywss.App()
app.openapi()  # 开启 OpenAPI 文档
domainMCPServer.mount(app.group("/api/v1/domain"))  # 挂载 MCP 服务,同时指定路由
logMCPServer.mount(app.group("/api/v1/log"))  # 挂载 MCP 服务,同时指定路由
app.run()

接着启动服务:

shell
python3 main.py
协议类型服务类请求方法端点路径格式示例路径
SSEdomainMCPServerGET/api/v1/domain/sseGET /api/v1/domain/sse
logMCPServerGET/api/v1/log/sseGET /api/v1/log/sse
StreamHTTPdomainMCPServerPOST/api/v1/domain/mcpPOST /api/v1/domain/mcp
logMCPServerPOST/api/v1/log/mcpPOST /api/v1/log/mcp
MCPOdomainMCPServerPOST/api/v1/domain/tools/{tool_name}POST /api/v1/domain/tools/get_domain
logMCPServerPOST/api/v1/log/tools/{tool_name}POST /api/v1/log/tools/get_trace_log

更多功能见在线文档。

Activity

Alt

Use Pywss MCP with multiple AI models

TypingMind connects MCP tools at the workspace level, so once Pywss is connected, you can use it with different AI models in TypingMind instead of setting it up separately for each model. This MCP runs locally through the TypingMind MCP connector on your device.

Setup guide to use the local connector

Use this when the MCP server needs access to local files, apps, or private resources on your computer.

1

Open the MCP settings

In TypingMind, go to Settings, Advanced Settings, then Model Context Protocol and choose Setup Connector.

  1. Open TypingMind in your browser.
  2. Click the Settings icon.
  3. Go to Advanced Settings.
  4. Open the Model Context Protocol section.
  5. Click Setup Connector and choose This Device.
TypingMind MCP connector setup screen with This Device selected
2

Run the connector command

Choose This Device, copy the command from TypingMind, and run it in Terminal. Keep the process running while you use MCP.

  1. Copy the setup command shown by TypingMind.
  2. Open Terminal on macOS or Windows Terminal on Windows.
  3. Paste and run the command.
  4. Approve the package install if Terminal asks you to proceed.
  5. Keep the Terminal window running while using MCP tools.
3

Add Pywss as a server

When the connector status is Ready, click Edit Servers and paste the MCP server configuration.

  1. Wait until the connector status shows Ready.
  2. Click Edit Servers.
  3. Paste the Pywss MCP server configuration.
  4. Save the server list.
  5. Refresh if you want to confirm the connector is still ready.
TypingMind MCP settings showing active server and Edit Servers button
{
  "mcpServers": {
    "pywss": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

Use it across models

Save the server list, open Plugins, enable the Pywss MCP tools, then select any supported AI model in TypingMind and use the tools in chat or assign them to an AI agent.

  1. Open the Plugins page in TypingMind.
  2. Enable the Pywss MCP tools.
  3. Start a chat and choose the AI model you want to use.
  4. Use the MCP tools in chat or assign them to an AI agent.
  5. Switch to another AI model whenever needed without reconnecting MCP.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use Pywss to help me with this task?
Pywss
Sure. I read it.
Here is what I found using Pywss.

Frequently asked questions

What is the Pywss MCP server used for?

Pywss is an MCP server that lets compatible AI clients connect to external tools and context. In TypingMind, you can add this MCP server once and make its tools available in your AI workspace.

Can I use Pywss MCP with multiple AI models in TypingMind?

Yes. TypingMind connects MCP tools at the workspace level, so you can use Pywss with different AI models such as Claude, ChatGPT, Gemini, or other models you have configured in TypingMind without setting up the MCP server separately for each model.

Why use Pywss MCP with TypingMind?

TypingMind is one of the best frontends for LLM chat because it brings multiple AI models, prompts, plugins, AI agents, API keys, and MCP tools into one workspace. With Pywss connected, you can use its MCP tools across your preferred models while keeping your chat workflow organized in TypingMind.

How do I connect Pywss MCP to TypingMind?

Pywss runs through the TypingMind local MCP connector. This is best when the MCP server needs access to local files, desktop apps, command-line tools, or private resources on your computer.

What tools does Pywss MCP provide in TypingMind?

Pywss exposes MCP capabilities that can be enabled from the TypingMind Plugins page and used in chat or assigned to AI agents.

Do I need to share my API keys with TypingMind to use Pywss MCP?

No. TypingMind is local-first and lets you keep your model providers, API keys, prompts, and MCP configuration under your control. If Pywss requires authentication, add the required headers, OAuth settings, or local configuration for that MCP server when you create the connection.

Related MCP Servers

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇