Skip to content

Commit ced60e9

Browse files
Claudehotlong
andauthored
Fix metadata API to query MetadataService directly in server mode
**Problem**: In server mode (Vercel deployment), the metadata API endpoints were not returning runtime-registered types like 'agent' and 'tool'. **Root Cause**: The HTTP dispatcher's fallback chain tried: 1. Protocol service (only knows static types from packages) 2. Broker call (no metadata broker actions registered) 3. Hardcoded defaults ['object', 'app', 'plugin'] It never queried MetadataService directly, which holds runtime-registered metadata from AI Service Plugin and other sources. **Fix**: Modified HTTP dispatcher to query MetadataService directly: - `GET /api/v1/meta` now calls `metadataService.getRegisteredTypes()` - `GET /api/v1/meta/:type` now calls `metadataService.list(type)` Both are inserted into the fallback chain after protocol service but before broker calls, ensuring runtime metadata is available in server mode. **Affected Endpoints**: - GET /api/v1/meta → now includes 'agent' and 'tool' types - GET /api/v1/meta/agent → now returns registered agents - GET /api/v1/meta/tool → now returns registered tools 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 2dd6afd commit ced60e9

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

packages/runtime/src/http-dispatcher.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,17 @@ export class HttpDispatcher {
347347
const result = await protocol.getMetaTypes({});
348348
return { handled: true, response: this.success(result) };
349349
}
350+
// Try MetadataService directly (includes runtime-registered types like agents/tools)
351+
const metadataService = await this.getService(CoreServiceName.enum.metadata);
352+
if (metadataService && typeof (metadataService as any).getRegisteredTypes === 'function') {
353+
try {
354+
const types = await (metadataService as any).getRegisteredTypes();
355+
return { handled: true, response: this.success({ types }) };
356+
} catch (e: any) {
357+
// Log error but continue to fallbacks
358+
console.debug('[HttpDispatcher] MetadataService.getRegisteredTypes() failed:', e.message);
359+
}
360+
}
350361
// Fallback: ask broker for registered types
351362
if (broker) {
352363
try {
@@ -464,7 +475,7 @@ export class HttpDispatcher {
464475
const typeOrName = parts[0];
465476
// Extract optional package filter from query string
466477
const packageId = query?.package || undefined;
467-
478+
468479
// Try protocol service first for any type
469480
const protocol = await this.resolveService('protocol');
470481
if (protocol && typeof protocol.getMetaItems === 'function') {
@@ -479,6 +490,20 @@ export class HttpDispatcher {
479490
}
480491
}
481492

493+
// Try MetadataService directly for runtime-registered metadata (agents, tools, etc.)
494+
const metadataService = await this.getService(CoreServiceName.enum.metadata);
495+
if (metadataService && typeof (metadataService as any).list === 'function') {
496+
try {
497+
const items = await (metadataService as any).list(typeOrName);
498+
if (items && items.length > 0) {
499+
return { handled: true, response: this.success({ type: typeOrName, items }) };
500+
}
501+
} catch (e: any) {
502+
// MetadataService doesn't know this type or failed, continue to other fallbacks
503+
console.debug(`[HttpDispatcher] MetadataService.list('${typeOrName}') failed:`, e.message);
504+
}
505+
}
506+
482507
// Try broker for the type
483508
if (broker) {
484509
try {

0 commit comments

Comments
 (0)