feat(exa): add MCP-compatible proxy endpoint for Kilo-authenticated clients#2855
Open
kilo-code-bot[bot] wants to merge 3 commits intomainfrom
Open
feat(exa): add MCP-compatible proxy endpoint for Kilo-authenticated clients#2855kilo-code-bot[bot] wants to merge 3 commits intomainfrom
kilo-code-bot[bot] wants to merge 3 commits intomainfrom
Conversation
…lients Adds POST /api/exa/mcp that speaks JSON-RPC 2.0 over SSE (matching mcp.exa.ai/mcp) but authenticates via Kilo auth and bills to the user's Kilo Exa allowance/balance. Translates web_search_exa and get_code_context_exa tool calls into the underlying Exa /search REST API, reusing the existing allowance/balance/usage-recording plumbing.
|
|
||
| let rpcRequest: JsonRpcRequest; | ||
| try { | ||
| rpcRequest = (await request.json()) as JsonRpcRequest; |
Contributor
Author
There was a problem hiding this comment.
WARNING: JSON null requests can crash the handler
request.json() successfully parses a body of null, but the cast does not validate the shape. The later destructuring of rpcRequest will throw a TypeError and return a 500 instead of an invalid-request response. Please guard that the parsed value is a non-null object before reading id, method, and params.
Contributor
Author
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (1 files)
Reviewed by gpt-5.5-2026-04-23 · 436,324 tokens |
request.json() accepts null, primitives, and arrays; destructuring those was throwing a TypeError and returning 500 instead of a clean 400. Guard with a typeof/Array.isArray check before reading id/method/params. Caught by kilo-code-bot review.
…e out of console CodeQL flagged the upstream-error console.error as log injection because toolName is derived from the request body. Keep the console line to numeric status only; report tool/userId through Sentry tags instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
POST /api/exa/mcp, an MCP (JSON-RPC 2.0 over SSE) endpoint that mirrors the interface ofmcp.exa.ai/mcpbut authenticates via Kilo'sAuthorization: Bearer <token>+X-KiloCode-OrganizationIdauth, so the Kilo CLI can route Exa web/code search traffic throughapi.kilo.aiand get free Exa credits billed to the user's Kilo account.web_search_exa(withquery,type,numResults,livecrawl,contextMaxCharacters) andget_code_context_exa(withquery,tokensNum). Both translate into the same Exa REST/searchcall that the existing/api/exa/[...path]proxy already uses.getExaMonthlyUsage,getExaFreeAllowanceMicrodollars,recordExaUsage, balance check againstgetBalanceAndOrgSettings) so this traffic counts toward the same monthly allowance / org balance as the REST proxy. Also implements the standard MCP bootstrap (initialize,tools/list,notifications/*) so MCP clients can handshake normally.Once this merges, the CLI-side change in
mcp-exa.tsis just swapping the URL constant frommcp.exa.ai/mcptoapi.kilo.ai/api/exa/mcpwhen Kilo auth is present — no protocol translation on the client.Verification
tools/call web_search_exabody against the Exa REST mapping — matches what/api/exa/[...path]already sends for/search.initialize/tools/list/ notification handling, unknown method, argument translation for both tools (includingtokensNum * 4and default-when-omitted forcontextMaxCharacters/numResults/type/livecrawl), missingquery, unknown tool, request signal forwarding, free-tier allowance vs balance check, org id propagation, cost recording withchargedToBalanceflag, upstream-error wrapping, no cost recording on errors / missingcostDollars, SSEcontent-type/content-encodingheaders, 400 for invalid JSON.Visual Changes
N/A (backend-only).
Reviewer Notes
event: message\ndata: <json>\n\nand returns200withcontent-type: text/event-stream,content-encoding: identity. Notifications (no/nullid) get202with no body per the MCP streamable-HTTP spec.200SSE response (MCP convention) rather than returning upstream HTTP status codes, since the MCP client only parsesresult/errorfrom the RPC payload. The existing REST proxy keeps passing through upstream HTTP status codes — that behavior is unchanged.recordExaUsagewithpath: '/search', so MCP traffic shows up inexa_usage_log/exa_monthly_usagealongside REST traffic under the same path. If you'd rather distinguish them (e.g.path: '/mcp/search'), easy to change.