Skip to content

Commit 6bd3197

Browse files
authored
feat: include tools and resources in MCP server info
1 parent 260cda1 commit 6bd3197

File tree

6 files changed

+78
-15
lines changed

6 files changed

+78
-15
lines changed

report-app/src/app/pages/report-viewer/report-viewer.html

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ <h4>Servers</h4>
218218
<ul>
219219
@for (server of details.mcp.servers; track server) {
220220
<li>
221-
<span>
221+
<div>
222222
<strong>{{ server.name }}</strong
223223
>:
224224
<code
@@ -227,7 +227,27 @@ <h4>Servers</h4>
227227
{{ arg }}
228228
}
229229
</code>
230-
</span>
230+
</div>
231+
@if (server.tools && server.tools.length > 0) {
232+
<div>
233+
Tools
234+
<ul>
235+
@for (tool of server.tools; track tool) {
236+
<li>{{ tool }}</li>
237+
}
238+
</ul>
239+
</div>
240+
}
241+
@if (server.resources && server.resources.length > 0) {
242+
<div>
243+
Resources
244+
<ul>
245+
@for (tool of server.resources; track tool) {
246+
<li>{{ tool }}</li>
247+
}
248+
</ul>
249+
</div>
250+
}
231251
</li>
232252
}
233253
</ul>

runner/codegen/genkit/genkit-runner.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
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';
29
import {GenkitMcpHost, McpServerConfig, createMcpHost} from '@genkit-ai/mcp';
310
import {GenkitPlugin, GenkitPluginV2} from 'genkit/plugin';
411
import {z} from 'zod';
@@ -11,6 +18,7 @@ import {
1118
LocalLlmGenerateTextResponse,
1219
LocalLlmGenerateTextRequestOptions,
1320
LocalLlmGenerateFilesRequestOptions,
21+
McpServerDetails,
1422
} from '../llm-runner.js';
1523
import {setTimeout} from 'node:timers/promises';
1624
import {callWithTimeout} from '../../utils/timeout.js';
@@ -21,10 +29,18 @@ import {UserFacingError} from '../../utils/errors.js';
2129
import {GenkitModelProvider, PromptDataForCounting} from './model-provider.js';
2230
import {ToolLogEntry} from '../../shared-interfaces.js';
2331
import {combineAbortSignals} from '../../utils/abort-signal.js';
32+
import {toToolDefinition} from 'genkit/tool';
2433

2534
const globalLogger = new GenkitLogger();
2635
logger.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. */
2945
export 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[] {

runner/codegen/llm-runner.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ export interface LlmRunner {
5858
* Optional since not all runners may support MCP.
5959
* @param hostName Name for the MCP host.
6060
* @param servers Configured servers that should be started.
61+
* @returns Details about the created server.
6162
*/
62-
startMcpServerHost?(hostName: string, servers: McpServerOptions[]): void;
63+
startMcpServerHost?(hostName: string, servers: McpServerOptions[]): Promise<McpServerDetails>;
6364

6465
/** Stops tracking MCP server logs and returns the current ones. */
6566
flushMcpServerLogs?(): string[];
@@ -171,6 +172,12 @@ export const mcpServerOptionsSchema = z.object({
171172
/** Options used to start an MCP server. */
172173
export type McpServerOptions = z.infer<typeof mcpServerOptionsSchema>;
173174

175+
/** Details about an MCP server. */
176+
export interface McpServerDetails {
177+
tools: string[];
178+
resources: string[];
179+
}
180+
174181
/**
175182
* Type for a prompt message may be passed to LLM runner in the eval tool.
176183
*

runner/orchestration/executors/local-executor.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {ChildProcess, fork} from 'node:child_process';
22
import path, {join} from 'node:path';
33
import PQueue from 'p-queue';
4-
import {LlmRunner} from '../../codegen/llm-runner.js';
4+
import {LlmRunner, McpServerDetails} from '../../codegen/llm-runner.js';
55
import {getRunnerByName, RunnerName} from '../../codegen/runner-creation.js';
66
import {ProgressLogger} from '../../progress/progress-logger.js';
77
import {
@@ -225,16 +225,16 @@ export class LocalExecutor implements Executor {
225225
};
226226
}
227227

228-
async startMcpServerHost(hostName: string) {
228+
async startMcpServerHost(hostName: string): Promise<McpServerDetails | undefined> {
229229
const llm = await this.llm;
230230
if (llm.startMcpServerHost === undefined) {
231-
return;
231+
return undefined;
232232
}
233233

234-
llm.startMcpServerHost(hostName, this.config.mcpServers ?? []);
234+
return llm.startMcpServerHost(hostName, this.config.mcpServers ?? []);
235235
}
236236

237-
async collectMcpServerLogs() {
237+
async collectMcpServerLogs(mcpServerDetails: McpServerDetails | undefined) {
238238
const llm = await this.llm;
239239
if (llm.flushMcpServerLogs === undefined) {
240240
return;
@@ -245,6 +245,8 @@ export class LocalExecutor implements Executor {
245245
name: m.name,
246246
command: m.command,
247247
args: m.args,
248+
tools: mcpServerDetails?.tools ?? [],
249+
resources: mcpServerDetails?.resources ?? [],
248250
})),
249251
logs: llm.flushMcpServerLogs().join('\n'),
250252
};

runner/orchestration/generate.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ export async function generateCodeAndAssess(options: AssessmentConfig): Promise<
8585
// We need Chrome to collect runtime information.
8686
await installChrome();
8787

88-
if (options.startMcp && env.executor instanceof LocalExecutor) {
89-
env.executor.startMcpServerHost(`mcp-${env.clientSideFramework.id}`);
90-
}
88+
const mcpServerDetails =
89+
env.executor instanceof LocalExecutor && options.startMcp && env.executor.startMcpServerHost
90+
? await env.executor.startMcpServerHost(`mcp-${env.clientSideFramework.id}`)
91+
: undefined;
9192

9293
progress.initialize(promptsToProcess.length);
9394

@@ -163,7 +164,7 @@ export async function generateCodeAndAssess(options: AssessmentConfig): Promise<
163164

164165
const mcp =
165166
env.executor instanceof LocalExecutor && options.startMcp
166-
? await env.executor.collectMcpServerLogs()
167+
? await env.executor.collectMcpServerLogs(mcpServerDetails)
167168
: undefined;
168169

169170
const timestamp = new Date();

runner/shared-interfaces.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,15 @@ export interface RunDetails {
437437
/** Information about configured MCP servers, if any. */
438438
mcp?: {
439439
/** MCP servers that were configured. */
440-
servers: {name: string; command: string; args: string[]}[];
440+
servers: {
441+
name: string;
442+
command: string;
443+
args: string[];
444+
/** Tools reported for this server. */
445+
tools?: string[];
446+
/** Resources reported for this server. */
447+
resources?: string[];
448+
}[];
441449

442450
/** Logs produced by all of the servers. */
443451
logs: string;

0 commit comments

Comments
 (0)