Skip to content

Commit 46db6f5

Browse files
author
Lasim
committed
docs: Update event system and tool discovery documentation to reflect changes in event types and metadata collection
1 parent c83d3c9 commit 46db6f5

3 files changed

Lines changed: 80 additions & 9 deletions

File tree

development/satellite/architecture.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ The satellite service has completed **Phase 1: MCP Transport Implementation** an
450450
- **Command Processing**: HTTP MCP server management (spawn/kill/restart/health_check)
451451
- **Heartbeat Service**: Process status reporting and system metrics
452452
- **Configuration Sync**: Real-time MCP server configuration updates
453-
- **Event System**: Real-time event emission with automatic batching (10 event types)
453+
- **Event System**: Real-time event emission with automatic batching (13 event types including tool metadata)
454454

455455
**Foundation Infrastructure:**
456456
- **HTTP Server**: Fastify with Swagger documentation

development/satellite/event-system.mdx

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Satellite Components EventBus Backend
6565
**Naming Convention**: All event data fields use **snake_case** (e.g., `server_id`, `team_id`, `spawn_duration_ms`) to match the backend API convention.
6666
</Note>
6767

68-
The satellite emits 12 event types across 4 categories:
68+
The satellite emits 13 event types across 4 categories:
6969

7070
### MCP Server Lifecycle
7171

@@ -226,21 +226,40 @@ Emitted when SSE connection closes (client disconnect, timeout, or error).
226226
### Tool Discovery
227227

228228
#### `mcp.tools.discovered`
229-
Emitted after successful tool discovery from HTTP or stdio MCP server.
229+
Emitted after successful tool discovery from HTTP or stdio MCP server with complete tool metadata and token consumption.
230230

231231
**Data Structure:**
232232
```typescript
233233
{
234-
server_id: string;
235-
server_slug: string;
234+
installation_id: string;
235+
installation_name: string;
236236
team_id: string;
237-
tool_count: number;
238-
tool_names: string[];
239-
discovery_duration_ms: number;
240-
previous_tool_count: number;
237+
server_slug: string;
238+
tool_count: number; // Total tools discovered
239+
total_tokens: number; // Sum of all tool token counts
240+
tools: Array<{
241+
tool_name: string;
242+
description: string;
243+
input_schema: Record<string, unknown>;
244+
token_count: number; // Tokens for this specific tool
245+
}>;
246+
discovered_at: string; // ISO 8601 timestamp
241247
}
242248
```
243249

250+
**Purpose:**
251+
- Store tool metadata in backend database (`mcpToolMetadata` table)
252+
- Calculate hierarchical router token savings (traditional vs 2-meta-tool approach)
253+
- Enable frontend tool catalog display with token consumption metrics
254+
- Provide analytics on MCP server complexity and context window usage
255+
256+
**Emission Timing:**
257+
- stdio servers: After handshake completion and tool caching
258+
- HTTP/SSE servers: After startup tool discovery and caching
259+
260+
**Token Calculation:**
261+
Uses `token-counter.ts` utility to estimate tokens for each tool based on name, description, and input schema JSON.
262+
244263
#### `mcp.tools.updated`
245264
Emitted when tool list changes during configuration refresh.
246265

development/satellite/tool-discovery.mdx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,58 @@ stdio tools persist in cache for optimal performance:
231231
**Idle Process Management**: stdio processes that remain inactive for the configured idle timeout (default: 3 minutes) are automatically terminated to save memory. However, **tools remain cached** so when a client requests them, the process respawns instantly without needing to rediscover tools. This reduces respawn time from 1-3 seconds to 1-2 seconds. See [Idle Process Management](/development/satellite/idle-process-management) for details.
232232
</Info>
233233

234+
## Tool Metadata Collection
235+
236+
After tool discovery completes, the satellite emits tool metadata to the backend for storage and analysis.
237+
238+
### Event Emission (Post-Discovery)
239+
240+
Following successful tool discovery (both HTTP/SSE and stdio), the satellite:
241+
242+
1. **Calculates token consumption** using the `token-counter.ts` utility
243+
2. **Builds event payload** with tool metadata including per-tool token counts
244+
3. **Emits `mcp.tools.discovered` event** to backend via EventBus
245+
4. **Backend stores metadata** in `mcpToolMetadata` table for team visibility
246+
247+
**Event Payload Structure:**
248+
```typescript
249+
{
250+
installation_id: string;
251+
installation_name: string;
252+
team_id: string;
253+
server_slug: string;
254+
tool_count: number; // Total tools discovered
255+
total_tokens: number; // Sum of all tool token counts
256+
tools: Array<{
257+
tool_name: string;
258+
description: string;
259+
input_schema: Record<string, unknown>;
260+
token_count: number; // Tokens for this specific tool
261+
}>;
262+
discovered_at: string; // ISO 8601 timestamp
263+
}
264+
```
265+
266+
**Integration Points:**
267+
- `StdioToolDiscoveryManager`: Emits after stdio tool discovery completes
268+
- `RemoteToolDiscoveryManager`: Emits after HTTP/SSE tool discovery completes
269+
- `EventBus`: Batches events every 3 seconds for efficient transmission
270+
- Backend handler: Stores tools with delete-then-insert strategy
271+
272+
**Token Calculation:**
273+
The satellite uses `estimateMcpServerTokens()` from `token-counter.ts` to calculate:
274+
- Per-tool tokens: `name` + `description` + `JSON.stringify(inputSchema)`
275+
- Total server tokens: Sum of all tool tokens
276+
- Uses `gpt-tokenizer` library (provider-agnostic)
277+
278+
**Purpose:**
279+
- Store tool metadata in backend database for team visibility
280+
- Calculate hierarchical router token savings (traditional vs 2-meta-tool approach)
281+
- Enable frontend tool catalog display with token consumption metrics
282+
- Provide analytics on MCP server complexity and context window usage
283+
284+
See [Event System](/development/satellite/event-system) for event batching and delivery details.
285+
234286
## Development Considerations
235287

236288
### Debugging Support

0 commit comments

Comments
 (0)