Skip to content
Merged
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
16 changes: 10 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
tools reported no license. The MIT text is now in `LICENSE` and declared
in the package metadata; it covers all code published so far.

### Fixed
### Changed

- **A fresh install no longer breaks on MCP SDK 2.x.** The dependency
allowed any `mcp` from 1.0 on, so a clean install picked up 2.x, which
dropped the server API wbox is built on: `wbox-mcp` crashed at startup
with "'Server' object has no attribute 'list_tools'". It is now held
below 2.
- **Built on MCP Python SDK 2.x.** The dependency used to allow any `mcp`
from 1.0 on, so a clean install picked up 2.x, which dropped the server
API wbox was built on: `wbox-mcp` crashed at startup with "'Server'
object has no attribute 'list_tools'". wbox now runs on the 2.x API and
requires `mcp>=2.3,<3`. Nothing changes for MCP clients: tools, argument
checks and error results behave as before, and older clients still
connect. Re-run the installer to update.

### Fixed

- **`launch` fails when the compositor has no usable output.** A labwc or
cage that cannot allocate its output's buffers keeps running with the
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ requires-python = ">=3.10"
license = "MIT"
license-files = ["LICENSE"]
dependencies = [
"mcp>=1.0,<2",
"jsonschema>=4.20",
"mcp>=2.3,<3",
"pyyaml>=6.0",
]

Expand Down
45 changes: 39 additions & 6 deletions src/wbox/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@
from collections import deque
from pathlib import Path

from mcp.server import Server
import jsonschema
from mcp.server import Server, ServerRequestContext
from mcp.server.stdio import stdio_server
from mcp.types import (
CallToolRequestParams,
CallToolResult,
ImageContent,
ListToolsResult,
PaginatedRequestParams,
TextContent,
Tool,
)
Expand Down Expand Up @@ -455,13 +460,9 @@ def create_server(cfg: dict) -> tuple[Server, CompositorServer]:
wbox_logger.addHandler(file_handler)
wbox_logger.setLevel(getattr(logging, log_level, logging.INFO))

server_name = cfg.get("name", "wbox-mcp")
mcp = Server(server_name)

# Pre-launch hooks from config
pre_launch_scripts = cfg.get("app", {}).get("pre_launch", [])

@mcp.list_tools()
async def list_tools() -> list[Tool]:
tools = [
Tool(
Expand Down Expand Up @@ -879,7 +880,6 @@ async def list_tools() -> list[Tool]:

return tools

@mcp.call_tool()
async def call_tool(name: str, arguments: dict) -> list[TextContent | ImageContent]:
log.info("tool_call: %s %s", name, arguments or "")

Expand Down Expand Up @@ -1141,9 +1141,42 @@ def _tail():

return [TextContent(type="text", text=f"Unknown tool: {name}")]

async def on_list_tools(
ctx: ServerRequestContext, params: PaginatedRequestParams | None
) -> ListToolsResult:
return ListToolsResult(tools=await list_tools())

async def on_call_tool(
ctx: ServerRequestContext, params: CallToolRequestParams
) -> CallToolResult:
# The 1.x SDK decorator checked the arguments against the tool's
# schema and turned a raising tool into an error result; 2.x leaves
# both to the handler, so they are kept here.
name, arguments = params.name, params.arguments or {}
tool = next((t for t in await list_tools() if t.name == name), None)
if tool is not None:
try:
jsonschema.validate(instance=arguments, schema=tool.input_schema)
except jsonschema.ValidationError as e:
return _error_result(f"Input validation error: {e.message}")
try:
return CallToolResult(content=await call_tool(name, arguments))
except Exception as e:
log.exception("tool %s failed", name)
return _error_result(str(e))

mcp = Server(
cfg.get("name", "wbox-mcp"),
on_list_tools=on_list_tools,
on_call_tool=on_call_tool,
)
return mcp, compositor


def _error_result(text: str) -> CallToolResult:
return CallToolResult(content=[TextContent(type="text", text=text)], isError=True)


async def amain(config_path: str | None = None, overrides: list[str] | None = None):
cfg = load_config(config_path or "config.yaml")
if not cfg.get("_config_dir"):
Expand Down
20 changes: 15 additions & 5 deletions tests/mcp-dev/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@

from mcp.server import Server
from mcp.server.stdio import stdio_server
from mcp.types import ImageContent, TextContent, Tool
from mcp.types import CallToolResult, ImageContent, ListToolsResult, TextContent, Tool

TESTS_DIR = Path(__file__).resolve().parent.parent
CRASH_DUMMY_PY = TESTS_DIR / "crash-dummy" / "crash_dummy.py"

server = Server("mcp-dev")

# ── Shared state ──

_config = {
Expand Down Expand Up @@ -168,7 +166,6 @@ def _text(msg) -> list:

# ── MCP Tools ──

@server.list_tools()
async def list_tools():
return [
Tool(
Expand Down Expand Up @@ -255,7 +252,6 @@ async def list_tools():
]


@server.call_tool()
async def call_tool(name: str, arguments: dict):
global _worker, _config

Expand Down Expand Up @@ -361,6 +357,20 @@ async def call_tool(name: str, arguments: dict):
return _text(result)


async def on_list_tools(ctx, params) -> ListToolsResult:
return ListToolsResult(tools=await list_tools())


async def on_call_tool(ctx, params) -> CallToolResult:
try:
return CallToolResult(content=await call_tool(params.name, params.arguments or {}))
except Exception as e:
return CallToolResult(content=_text(f"Error: {e}"), isError=True)


server = Server("mcp-dev", on_list_tools=on_list_tools, on_call_tool=on_call_tool)


async def main():
async with stdio_server() as (read_stream, write_stream):
await server.run(
Expand Down
Loading
Loading