Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions packages/backend/src/connectors/engines/engine-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* Type contracts for connector engines.
*
* `endpointMapping` is stored as a `Json` column in Prisma so the wire shape
* is `Record<string, unknown>` — 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<string, unknown>;
bodyMapping?: Record<string, unknown>;
bodyTemplate?: string;
bodyEncoding?: 'json' | 'form-urlencoded' | 'form-data' | string;
headers?: Record<string, string>;
}

export interface GraphqlEndpointMapping {
method: 'query' | 'mutation' | string;
path: string; // the GraphQL document
queryParams?: Record<string, unknown>;
bodyMapping?: Record<string, unknown>;
headers?: Record<string, string>;
}

export interface SoapEndpointMapping {
method: string; // SOAP operation name
path: string; // port name
queryParams?: Record<string, unknown>;
bodyMapping?: Record<string, unknown>;
paramOrder?: string[];
headers?: Record<string, string>;
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<string, unknown>;
headers?: Record<string, string>;
connectorId?: string;
specUrl?: string;
}
5 changes: 4 additions & 1 deletion packages/backend/src/mcp-server/dynamic-mcp-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading