diff --git a/packages/backend/src/connectors/engines/engine-types.ts b/packages/backend/src/connectors/engines/engine-types.ts new file mode 100644 index 00000000..37776232 --- /dev/null +++ b/packages/backend/src/connectors/engines/engine-types.ts @@ -0,0 +1,83 @@ +/** + * Type contracts for connector engines. + * + * `endpointMapping` is stored as a `Json` column in Prisma so the wire shape + * is `Record` — this file describes what each engine + * actually accepts, so the engines can drop their internal `as any` casts + * and the surrounding code is type-checked. + * + * Runtime behaviour is unchanged: the engine code already validates each + * field at use time. These types document the contract. + */ + +export interface RestEndpointMapping { + method: string; // GET / POST / PUT / PATCH / DELETE + path: string; + queryParams?: Record; + bodyMapping?: Record; + bodyTemplate?: string; + bodyEncoding?: 'json' | 'form-urlencoded' | 'form-data' | string; + headers?: Record; +} + +export interface GraphqlEndpointMapping { + method: 'query' | 'mutation' | string; + path: string; // the GraphQL document + queryParams?: Record; + bodyMapping?: Record; + headers?: Record; +} + +export interface SoapEndpointMapping { + method: string; // SOAP operation name + path: string; // port name + queryParams?: Record; + bodyMapping?: Record; + paramOrder?: string[]; + headers?: Record; + soapAction?: string; + endpoint?: string; + targetNamespace?: string; +} + +export interface DatabaseEndpointMapping { + method: + | 'query' + | 'static' + | 'mongo_schema' + | string; + path: string; + staticResponse?: string; +} + +export interface McpEndpointMapping { + method: string; // remote tool name + path: string; // remote MCP path (e.g. /mcp) +} + +export type AnyEndpointMapping = + | RestEndpointMapping + | GraphqlEndpointMapping + | SoapEndpointMapping + | DatabaseEndpointMapping + | McpEndpointMapping; + +/** + * Common metadata that may appear on responseMapping. We only use cacheTtl + * for the moment (used by dynamic-mcp-tools to short-circuit re-execution). + */ +export interface ResponseMapping { + cacheTtl?: number; + type?: string; + fields?: string[]; + [k: string]: unknown; +} + +export interface ConnectorEngineConfig { + baseUrl: string; + authType: string; + authConfig?: Record; + headers?: Record; + connectorId?: string; + specUrl?: string; +} diff --git a/packages/backend/src/mcp-server/dynamic-mcp-tools.ts b/packages/backend/src/mcp-server/dynamic-mcp-tools.ts index 23d6bc34..63c1c173 100644 --- a/packages/backend/src/mcp-server/dynamic-mcp-tools.ts +++ b/packages/backend/src/mcp-server/dynamic-mcp-tools.ts @@ -84,7 +84,10 @@ export class DynamicMcpTools { } // Check response cache - const cacheTtl = (tool.responseMapping as any)?.cacheTtl; + const responseMapping = tool.responseMapping as + | import('../connectors/engines/engine-types').ResponseMapping + | undefined; + const cacheTtl = responseMapping?.cacheTtl; if (cacheTtl && cacheTtl > 0) { const cacheKey = this.buildCacheKey(toolName, params); const cached = await this.redisService.get(cacheKey);