Implement notetaking app, ST7796 display with touch support, audio beep navigation, and video streaming
This commit is contained in:
@@ -146,6 +146,76 @@ class MainHandler(tornado.web.RequestHandler):
|
||||
# Serve the index.html from the same directory
|
||||
self.render("index.html")
|
||||
|
||||
class APIHandler(tornado.web.RequestHandler):
|
||||
def set_default_headers(self):
|
||||
self.set_header("Access-Control-Allow-Origin", "*")
|
||||
self.set_header("Access-Control-Allow-Headers", "x-requested-with, content-type")
|
||||
self.set_header("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
|
||||
|
||||
def options(self):
|
||||
self.set_status(204)
|
||||
self.finish()
|
||||
|
||||
async def post(self):
|
||||
try:
|
||||
req = json.loads(self.request.body.decode('utf-8'))
|
||||
method = req.get("method")
|
||||
rpc_id = req.get("id")
|
||||
|
||||
if method == "tools/call":
|
||||
params = req.get("params", {})
|
||||
tool_name = params.get("name")
|
||||
arguments = params.get("arguments", {})
|
||||
|
||||
result = await execute_mcp_tool(tool_name, arguments)
|
||||
if isinstance(result, list):
|
||||
content = result
|
||||
else:
|
||||
content = [{"type": "text", "text": str(result)}]
|
||||
|
||||
resp = {
|
||||
"jsonrpc": "2.0",
|
||||
"id": rpc_id,
|
||||
"result": {
|
||||
"content": content
|
||||
}
|
||||
}
|
||||
elif method == "initialize":
|
||||
resp = {
|
||||
"jsonrpc": "2.0",
|
||||
"id": rpc_id,
|
||||
"result": {
|
||||
"protocolVersion": "2024-11-05",
|
||||
"capabilities": {
|
||||
"tools": {}
|
||||
},
|
||||
"serverInfo": {
|
||||
"name": "virtual-screen-mcp",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
else:
|
||||
resp = {
|
||||
"jsonrpc": "2.0",
|
||||
"id": rpc_id,
|
||||
"error": {
|
||||
"code": -32601,
|
||||
"message": f"Method {method} not found"
|
||||
}
|
||||
}
|
||||
self.write(json.dumps(resp))
|
||||
except Exception as e:
|
||||
resp = {
|
||||
"jsonrpc": "2.0",
|
||||
"id": None,
|
||||
"error": {
|
||||
"code": -32000,
|
||||
"message": str(e)
|
||||
}
|
||||
}
|
||||
self.write(json.dumps(resp))
|
||||
|
||||
class ClientWebSocketHandler(tornado.websocket.WebSocketHandler):
|
||||
clients = set()
|
||||
|
||||
@@ -633,6 +703,7 @@ background_tasks = set()
|
||||
async def main_async(port):
|
||||
app = tornado.web.Application([
|
||||
(r"/", MainHandler),
|
||||
(r"/api/mcp", APIHandler),
|
||||
(r"/ws", ClientWebSocketHandler),
|
||||
], template_path=os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user