From ab32e0bb6abc7b933e4f9eff6ddd8eb81abdf4f5 Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Sun, 8 Jun 2025 00:45:57 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - apps/gateway/.dev.vars.example | 5 +++++ apps/gateway/src/app.ts | 4 ++-- .../src/lib/create-request-for-openapi-operation.ts | 4 ++-- apps/gateway/src/lib/resolve-origin-request.ts | 8 ++++---- apps/gateway/src/lib/types.ts | 4 ++-- readme.md | 1 + 7 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 apps/gateway/.dev.vars.example diff --git a/.gitignore b/.gitignore index d0f5a58a..36566bcb 100644 --- a/.gitignore +++ b/.gitignore @@ -46,6 +46,5 @@ out/ apps/api/auth-db-temp.json .dev.vars -.dev.vars.* .wrangler \ No newline at end of file diff --git a/apps/gateway/.dev.vars.example b/apps/gateway/.dev.vars.example new file mode 100644 index 00000000..9990ae02 --- /dev/null +++ b/apps/gateway/.dev.vars.example @@ -0,0 +1,5 @@ +ENVIRONMENT= +SENTRY_DSN= + +AGENTIC_API_BASE_URL= +AGENTIC_API_KEY= diff --git a/apps/gateway/src/app.ts b/apps/gateway/src/app.ts index a39e1689..6264d3c1 100644 --- a/apps/gateway/src/app.ts +++ b/apps/gateway/src/app.ts @@ -78,7 +78,7 @@ app.all(async (ctx) => { case 'mcp': { assert( - resolvedOriginRequest.toolArgs, + resolvedOriginRequest.toolCallArgs, 500, 'Tool args are required for MCP origin requests' ) @@ -99,7 +99,7 @@ app.all(async (ctx) => { // TODO: add response caching for MCP tool calls const toolCallResponse = await client.callTool({ name: resolvedOriginRequest.tool.name, - arguments: resolvedOriginRequest.toolArgs + arguments: resolvedOriginRequest.toolCallArgs }) originResponse = await createHttpResponseFromMcpToolCallResponse(ctx, { diff --git a/apps/gateway/src/lib/create-request-for-openapi-operation.ts b/apps/gateway/src/lib/create-request-for-openapi-operation.ts index 864bd23a..ed087073 100644 --- a/apps/gateway/src/lib/create-request-for-openapi-operation.ts +++ b/apps/gateway/src/lib/create-request-for-openapi-operation.ts @@ -4,7 +4,7 @@ import type { } from '@agentic/platform-types' import { assert } from '@agentic/platform-core' -import type { GatewayHonoContext, ToolArgs } from './types' +import type { GatewayHonoContext, ToolCallArgs } from './types' export async function createRequestForOpenAPIOperation( ctx: GatewayHonoContext, @@ -13,7 +13,7 @@ export async function createRequestForOpenAPIOperation( operation, deployment }: { - toolArgs: ToolArgs + toolArgs: ToolCallArgs operation: OpenAPIToolOperation deployment: AdminDeployment } diff --git a/apps/gateway/src/lib/resolve-origin-request.ts b/apps/gateway/src/lib/resolve-origin-request.ts index feb42db8..169fd86d 100644 --- a/apps/gateway/src/lib/resolve-origin-request.ts +++ b/apps/gateway/src/lib/resolve-origin-request.ts @@ -6,7 +6,7 @@ import type { AdminConsumer, GatewayHonoContext, ResolvedOriginRequest, - ToolArgs + ToolCallArgs } from './types' import { createRequestForOpenAPIOperation } from './create-request-for-openapi-operation' import { enforceRateLimit } from './enforce-rate-limit' @@ -168,7 +168,7 @@ export async function resolveOriginRequest( if (rateLimit) { await enforceRateLimit(ctx, { id: consumer?.id ?? ip, - interval: rateLimit.interval * 1000, + interval: rateLimit.interval, maxPerInterval: rateLimit.maxPerInterval, method, pathname @@ -177,7 +177,7 @@ export async function resolveOriginRequest( const { originAdapter } = deployment let originRequest: Request | undefined - let toolArgs: ToolArgs | undefined + let toolArgs: ToolCallArgs | undefined if (originAdapter.type === 'raw') { const originRequestUrl = `${deployment.originUrl}/${toolName}${requestUrl.search}` @@ -207,7 +207,7 @@ export async function resolveOriginRequest( return { originRequest, - toolArgs, + toolCallArgs: toolArgs, deployment, consumer, tool, diff --git a/apps/gateway/src/lib/types.ts b/apps/gateway/src/lib/types.ts index 07461c40..da6fca47 100644 --- a/apps/gateway/src/lib/types.ts +++ b/apps/gateway/src/lib/types.ts @@ -42,7 +42,7 @@ export type GatewayHonoEnv = { export type GatewayHonoContext = Context // TODO: better type here -export type ToolArgs = Record +export type ToolCallArgs = Record export type ResolvedOriginRequest = { deployment: AdminDeployment @@ -55,5 +55,5 @@ export type ResolvedOriginRequest = { pricingPlanSlug?: string originRequest?: Request - toolArgs?: ToolArgs + toolCallArgs?: ToolCallArgs } diff --git a/readme.md b/readme.md index 0c57d52b..290d3aae 100644 --- a/readme.md +++ b/readme.md @@ -29,6 +29,7 @@ - auth - custom auth pages for `openauth` - API gateway + - enforce rate limits - how to handle binary bodies and responses? - add support for `immutable` in `toolConfigs` - **Public MCP server interface**