1- import { DynamicResourceAction , GenerateResponse , genkit , ModelReference , ToolAction } from 'genkit' ;
1+ import {
2+ Action ,
3+ DynamicResourceAction ,
4+ GenerateResponse ,
5+ genkit ,
6+ ModelReference ,
7+ ToolAction ,
8+ } from 'genkit' ;
29import { GenkitMcpHost , McpServerConfig , createMcpHost } from '@genkit-ai/mcp' ;
310import { GenkitPlugin , GenkitPluginV2 } from 'genkit/plugin' ;
411import { z } from 'zod' ;
@@ -11,6 +18,7 @@ import {
1118 LocalLlmGenerateTextResponse ,
1219 LocalLlmGenerateTextRequestOptions ,
1320 LocalLlmGenerateFilesRequestOptions ,
21+ McpServerDetails ,
1422} from '../llm-runner.js' ;
1523import { setTimeout } from 'node:timers/promises' ;
1624import { callWithTimeout } from '../../utils/timeout.js' ;
@@ -21,10 +29,18 @@ import {UserFacingError} from '../../utils/errors.js';
2129import { GenkitModelProvider , PromptDataForCounting } from './model-provider.js' ;
2230import { ToolLogEntry } from '../../shared-interfaces.js' ;
2331import { combineAbortSignals } from '../../utils/abort-signal.js' ;
32+ import { toToolDefinition } from 'genkit/tool' ;
2433
2534const globalLogger = new GenkitLogger ( ) ;
2635logger . init ( globalLogger ) ;
2736
37+ /**
38+ * Gets the name of a Genkit action.
39+ */
40+ function getActionName ( action : Action < any , any > ) : string {
41+ return toToolDefinition ( action ) . name ;
42+ }
43+
2844/** Runner that uses the Genkit API under the hood. */
2945export class GenkitRunner implements LlmRunner {
3046 readonly id = 'genkit' ;
@@ -199,7 +215,10 @@ export class GenkitRunner implements LlmRunner {
199215 }
200216 }
201217
202- startMcpServerHost ( hostName : string , servers : McpServerOptions [ ] ) : void {
218+ async startMcpServerHost (
219+ hostName : string ,
220+ servers : McpServerOptions [ ] ,
221+ ) : Promise < McpServerDetails > {
203222 if ( this . mcpHost !== null ) {
204223 throw new Error ( 'MCP host is already started' ) ;
205224 }
@@ -216,6 +235,12 @@ export class GenkitRunner implements LlmRunner {
216235
217236 globalLogger . startCapturingLogs ( ) ;
218237 this . mcpHost = createMcpHost ( { name : hostName , mcpServers} ) ;
238+ const tools = await this . mcpHost . getActiveTools ( this . genkitInstance ) ;
239+ const resources = await this . mcpHost . getActiveResources ( this . genkitInstance ) ;
240+ return {
241+ tools : tools . map ( getActionName ) ,
242+ resources : resources . map ( getActionName ) ,
243+ } ;
219244 }
220245
221246 flushMcpServerLogs ( ) : string [ ] {
0 commit comments