fix: add scheduled probe for mcp (#988)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Rajat Ahuja 2026-08-14 10:02:17 -04:00 committed by GitHub
parent e82d2ef497
commit c594469f05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 0 deletions

View File

@ -9,6 +9,7 @@ export interface HonchoConfig {
export interface Env {
HONCHO_API_URL?: string;
ALERT_WEBHOOK_URL?: string;
}
/**

View File

@ -20,6 +20,7 @@ const CORS_HEADERS = {
};
const PROTECTED_RESOURCE_PATH = "/.well-known/oauth-protected-resource";
const HEALTHCHECK_TIMEOUT_MS = 15_000;
function resourceUrl(request: Request): string {
return new URL(request.url).origin;
@ -30,6 +31,41 @@ function authorizationServer(env: Env): string {
}
export default {
// Probes the authorization server API to confirm it is reachable and healthy.
async scheduled(
_controller: ScheduledController,
env: Env,
_executionCtx: ExecutionContext,
): Promise<void> {
const upstream = `${authorizationServer(env)}/health`;
let failure: string | null = null;
try {
const response = await fetch(upstream, {
signal: AbortSignal.timeout(HEALTHCHECK_TIMEOUT_MS),
});
if (!response.ok) failure = `HTTP ${response.status}`;
} catch (e) {
failure = e instanceof Error ? e.message : String(e);
}
if (!failure) return;
console.error(`healthcheck failed: ${upstream} — ${failure}`);
if (!env.ALERT_WEBHOOK_URL) return;
const alertResponse = await fetch(env.ALERT_WEBHOOK_URL, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
content: `🚨 honcho-mcp cannot reach upstream API (${upstream}): ${failure}`,
}),
signal: AbortSignal.timeout(HEALTHCHECK_TIMEOUT_MS),
});
if (!alertResponse.ok) {
throw new Error(`alert webhook failed: HTTP ${alertResponse.status}`);
}
},
async fetch(
request: Request,
env: Env,

View File

@ -8,6 +8,10 @@ rules = [
{ type = "Text", globs = ["**/*.md"], fallthrough = true },
]
# Executes the scheduled() handler
[triggers]
crons = ["*/5 * * * *"]
[env.production]
name = "honcho-mcp"