Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

1.3 KB
Raw Blame
"""Loopback MCP test server: ``python mcp_echo_server.py [stdio|http PORT]``."""

import os
import sys
import time

from mcp.server.mcpserver import MCPServer

server = MCPServer("avibe-echo", description="Echo tools", version="0.1.0")


@server.tool(description="Echo text back, optionally repeated.")
def echo(text: str, repeat: int = 1) -> str:
    return text * repeat


@server.tool(description="Add two numbers.")
def add(a: float, b: float) -> dict:
    return {"sum": a + b}


@server.tool(description="Always fails.")
def fail(reason: str) -> str:
    raise ValueError(reason)


@server.tool(description="Reject with a JSON-RPC error.")
def reject() -> str:
    from mcp import MCPError

    raise MCPError(-32602, "rejected by server")


@server.tool(description="Return a tool error containing a session phrase.")
def session_text() -> str:
    from mcp import MCPError

    raise MCPError(-32602, "browser session not found")


@server.tool(description="Exit the server process mid-call.")
def crash() -> str:
    os._exit(1)


@server.tool(description="Sleep for some seconds.")
def nap(seconds: float) -> str:
    time.sleep(seconds)
    return "awake"


if __name__ == "__main__":
    if len(sys.argv) > 1 and sys.argv[1] == "http":
        server.run("streamable-http", host="127.0.0.1", port=int(sys.argv[2]))
    else:
        server.run("stdio")