Implementation:8beeeaaat Touchdesigner mcp OpenAPIRouter
| Knowledge Sources | |
|---|---|
| Domains | Request_Routing, OpenAPI |
| Last Updated | 2026-10-28 00:00 GMT |
Overview
Concrete tool for matching incoming HTTP requests to OpenAPI operationIds and dispatching them to registered handler functions with path-parameter extraction.
Description
The OpenAPIRouter class extracts RouteDefinition objects from the bundled OpenAPI schema at initialization, then matches incoming (method, path) pairs via match_route. Matching is a two-pass algorithm: first an exact string match, then a parameterized pattern match that splits on `/` and captures `{param}` segments — including greedy last-segment capture so trailing path segments containing slashes (e.g. node paths) are preserved. The router then merges path params with query params, attaches the body for POST/PUT/PATCH, and invokes the handler registered for the matched operationId. Errors are categorized (NOT_FOUND for unmatched routes, VALIDATION for handler argument mismatches, and a general category for other exceptions).
Usage
Used by APIControllerOpenAPI to route each normalized HTTP request to the correct generated handler. Can also be instantiated standalone for testing.
Code Reference
Source Location
- Repository: 8beeeaaat_Touchdesigner-mcp
- File: td/modules/mcp/controllers/openapi_router.py
- Lines: 1-277
Signature
class OpenAPIRouter:
def __init__(self, load_schema: bool = True): ...
def register_handler(
self, operation_id: str, handler: RequestHandler
) -> None: ...
def route_request(
self, method: str, path: str,
query_params: dict[str, Any], body: Optional[str]
) -> Result: ...
def match_route(
method: str, path: str, routes: list[RouteDefinition]
) -> Optional[RouteMatch]: ...
def extract_routes(schema: dict[str, Any] = None) -> list[RouteDefinition]: ...
Import
from mcp.controllers.openapi_router import OpenAPIRouter
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| method | str | Yes | HTTP method (GET, POST, etc.) |
| path | str | Yes | URL path to match |
| query_params | dict | Yes | Query parameters |
| body | None | No | Request body string |
Outputs
| Name | Type | Description |
|---|---|---|
| return | Result | Handler return value, or error_result with errorCategory |
Usage Examples
Register and route a request
from mcp.controllers.openapi_router import OpenAPIRouter
router = OpenAPIRouter()
def get_td_info(**kwargs):
return {"success": True, "data": {"mcpApiVersion": "2.0.0"}}
router.register_handler("getTdInfo", get_td_info)
result = router.route_request("GET", "/api/td/server/td", {}, None)
assert result["success"]
Greedy path-parameter capture
# A route pattern like /api/nodes/{nodePath} with path /api/nodes/project1/geo1
# captures nodePath="project1/geo1" (last segment is greedy).