Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:8beeeaaat Touchdesigner mcp APIControllerOpenAPI

From Leeroopedia
Knowledge Sources
Domains HTTP_Controller, Request_Routing
Last Updated 2026-10-28 00:00 GMT

Overview

Concrete tool for handling TouchDesigner WebServer DAT HTTP requests, normalizing request shapes and dispatching them through an OpenAPI-schema-driven router to generated handlers.

Description

APIControllerOpenAPI is the Python-side HTTP controller that runs inside the TouchDesigner WebServer DAT. It implements the IController protocol's onHTTPRequest entry point: it normalizes the heterogeneous request dictionaries that different WebServer DAT versions produce (method, path, query, body spread across `uri`, `pars`, `data`, `body`), sets CORS headers, short-circuits OPTIONS preflight, then delegates to an OpenAPIRouter which matches the request to an OpenAPI `operationId` and invokes the registered generated handler. Responses are JSON-serialized via safe_serialize, and errors are categorized (NOT_FOUND, VALIDATION, INTERNAL) into status reasons.

Usage

Instantiate this controller inside the TouchDesigner WebServer DAT script to route incoming HTTP requests to the api_service. It is created once at module load as the singleton api_controller_openapi.

Code Reference

Source Location

Signature

class APIControllerOpenAPI(IController):
    def __init__(self, service: Optional[ApiServiceProtocol] = None):
        ...

    def onHTTPRequest(
        self, webServerDAT: Any, request: dict[str, Any], response: dict[str, Any]
    ) -> dict[str, Any]:
        ...

    def _normalize_request(
        self, request: dict[str, Any]
    ) -> tuple[str, str, dict[str, Any], str]:
        ...

    def register_handlers(self) -> None:
        ...

Import

from mcp.controllers.api_controller import api_controller_openapi

I/O Contract

Inputs

Name Type Required Description
webServerDAT Any Yes Reference to the WebServer DAT object
request dict Yes Request dict from WebServer DAT (method, uri, body, pars, query)
response dict Yes Response dict to populate (statusCode, data, headers)
service ApiServiceProtocol No Injected service (defaults to api_service singleton)

Outputs

Name Type Description
return dict Updated response dict with statusCode, statusReason, data (JSON string), headers

Usage Examples

Wiring inside the WebServer DAT script

from mcp.controllers.api_controller import api_controller_openapi

def onHTTPRequest(webServerDAT, request, response):
    # Delegate to the OpenAPI-driven controller singleton.
    return api_controller_openapi.onHTTPRequest(webServerDAT, request, response)

Injecting a mock service for testing

from mcp.controllers.api_controller import APIControllerOpenAPI

class FakeService:
    def get_td_info(self):
        return {"success": True, "data": {"mcpApiVersion": "2.0.0"}}

controller = APIControllerOpenAPI(service=FakeService())
response = {"headers": {}}
controller.onHTTPRequest(None, {"method": "GET", "uri": {"path": "/api/td/server/td"}}, response)
assert response["statusCode"] == 200

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment