Skip to content

Commit f3d1ff8

Browse files
authored
Revert "feat(mcp): support structuredContent via useStructuredContent; return full CallToolResult" (#553)
1 parent 6b537b8 commit f3d1ff8

File tree

7 files changed

+41
-524
lines changed

7 files changed

+41
-524
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@openai/agents-core": patch
3+
---
4+
5+
Revert "feat(mcp): support structuredContent via useStructuredContent; return full CallToolResult"

packages/agents-core/src/mcp.ts

Lines changed: 9 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -35,35 +35,28 @@ export const DEFAULT_SSE_MCP_CLIENT_LOGGER_NAME =
3535
export interface MCPServer {
3636
cacheToolsList: boolean;
3737
toolFilter?: MCPToolFilterCallable | MCPToolFilterStatic;
38-
39-
/**
40-
* Whether to include structuredContent in tool outputs when available.
41-
*/
42-
useStructuredContent?: boolean;
4338
connect(): Promise<void>;
4439
readonly name: string;
4540
close(): Promise<void>;
4641
listTools(): Promise<MCPTool[]>;
4742
callTool(
4843
toolName: string,
4944
args: Record<string, unknown> | null,
50-
): Promise<CallToolResult>;
45+
): Promise<CallToolResultContent>;
5146
invalidateToolsCache(): Promise<void>;
5247
}
5348

5449
export abstract class BaseMCPServerStdio implements MCPServer {
5550
public cacheToolsList: boolean;
5651
protected _cachedTools: any[] | undefined = undefined;
5752
public toolFilter?: MCPToolFilterCallable | MCPToolFilterStatic;
58-
public useStructuredContent?: boolean;
5953

6054
protected logger: Logger;
6155
constructor(options: MCPServerStdioOptions) {
6256
this.logger =
6357
options.logger ?? getLogger(DEFAULT_STDIO_MCP_CLIENT_LOGGER_NAME);
6458
this.cacheToolsList = options.cacheToolsList ?? false;
6559
this.toolFilter = options.toolFilter;
66-
this.useStructuredContent = options.useStructuredContent ?? false;
6760
}
6861

6962
abstract get name(): string;
@@ -73,7 +66,7 @@ export abstract class BaseMCPServerStdio implements MCPServer {
7366
abstract callTool(
7467
_toolName: string,
7568
_args: Record<string, unknown> | null,
76-
): Promise<CallToolResult>;
69+
): Promise<CallToolResultContent>;
7770
abstract invalidateToolsCache(): Promise<void>;
7871

7972
/**
@@ -92,7 +85,6 @@ export abstract class BaseMCPServerStreamableHttp implements MCPServer {
9285
public cacheToolsList: boolean;
9386
protected _cachedTools: any[] | undefined = undefined;
9487
public toolFilter?: MCPToolFilterCallable | MCPToolFilterStatic;
95-
public useStructuredContent?: boolean;
9688

9789
protected logger: Logger;
9890
constructor(options: MCPServerStreamableHttpOptions) {
@@ -101,7 +93,6 @@ export abstract class BaseMCPServerStreamableHttp implements MCPServer {
10193
getLogger(DEFAULT_STREAMABLE_HTTP_MCP_CLIENT_LOGGER_NAME);
10294
this.cacheToolsList = options.cacheToolsList ?? false;
10395
this.toolFilter = options.toolFilter;
104-
this.useStructuredContent = options.useStructuredContent ?? false;
10596
}
10697

10798
abstract get name(): string;
@@ -111,7 +102,7 @@ export abstract class BaseMCPServerStreamableHttp implements MCPServer {
111102
abstract callTool(
112103
_toolName: string,
113104
_args: Record<string, unknown> | null,
114-
): Promise<CallToolResult>;
105+
): Promise<CallToolResultContent>;
115106
abstract invalidateToolsCache(): Promise<void>;
116107

117108
/**
@@ -130,15 +121,13 @@ export abstract class BaseMCPServerSSE implements MCPServer {
130121
public cacheToolsList: boolean;
131122
protected _cachedTools: any[] | undefined = undefined;
132123
public toolFilter?: MCPToolFilterCallable | MCPToolFilterStatic;
133-
public useStructuredContent?: boolean;
134124

135125
protected logger: Logger;
136126
constructor(options: MCPServerSSEOptions) {
137127
this.logger =
138128
options.logger ?? getLogger(DEFAULT_SSE_MCP_CLIENT_LOGGER_NAME);
139129
this.cacheToolsList = options.cacheToolsList ?? false;
140130
this.toolFilter = options.toolFilter;
141-
this.useStructuredContent = options.useStructuredContent ?? false;
142131
}
143132

144133
abstract get name(): string;
@@ -148,7 +137,7 @@ export abstract class BaseMCPServerSSE implements MCPServer {
148137
abstract callTool(
149138
_toolName: string,
150139
_args: Record<string, unknown> | null,
151-
): Promise<CallToolResult>;
140+
): Promise<CallToolResultContent>;
152141
abstract invalidateToolsCache(): Promise<void>;
153142

154143
/**
@@ -212,7 +201,7 @@ export class MCPServerStdio extends BaseMCPServerStdio {
212201
callTool(
213202
toolName: string,
214203
args: Record<string, unknown> | null,
215-
): Promise<CallToolResult> {
204+
): Promise<CallToolResultContent> {
216205
return this.underlying.callTool(toolName, args);
217206
}
218207
invalidateToolsCache(): Promise<void> {
@@ -248,7 +237,7 @@ export class MCPServerStreamableHttp extends BaseMCPServerStreamableHttp {
248237
callTool(
249238
toolName: string,
250239
args: Record<string, unknown> | null,
251-
): Promise<CallToolResult> {
240+
): Promise<CallToolResultContent> {
252241
return this.underlying.callTool(toolName, args);
253242
}
254243
invalidateToolsCache(): Promise<void> {
@@ -284,7 +273,7 @@ export class MCPServerSSE extends BaseMCPServerSSE {
284273
callTool(
285274
toolName: string,
286275
args: Record<string, unknown> | null,
287-
): Promise<CallToolResult> {
276+
): Promise<CallToolResultContent> {
288277
return this.underlying.callTool(toolName, args);
289278
}
290279
invalidateToolsCache(): Promise<void> {
@@ -457,7 +446,6 @@ export async function getAllMcpTools<TContext = UnknownContext>(
457446

458447
/**
459448
* Converts an MCP tool definition to a function tool for the Agents SDK.
460-
* When useStructuredContent is enabled, returns JSON strings for consistency with Python SDK.
461449
*/
462450
export function mcpToFunctionTool(
463451
mcpTool: MCPTool,
@@ -475,36 +463,8 @@ export function mcpToFunctionTool(
475463
if (currentSpan) {
476464
currentSpan.spanData['mcp_data'] = { server: server.name };
477465
}
478-
const result = await server.callTool(mcpTool.name, args);
479-
480-
if (result.content && result.content.length === 1) {
481-
if (
482-
server.useStructuredContent &&
483-
'structuredContent' in result &&
484-
result.structuredContent !== undefined
485-
) {
486-
return JSON.stringify([result.content[0], result.structuredContent]);
487-
}
488-
return result.content[0];
489-
} else if (result.content && result.content.length > 1) {
490-
if (
491-
server.useStructuredContent &&
492-
'structuredContent' in result &&
493-
result.structuredContent !== undefined
494-
) {
495-
const outputs = [...result.content, result.structuredContent];
496-
return JSON.stringify(outputs);
497-
}
498-
return result.content;
499-
} else if (
500-
server.useStructuredContent &&
501-
'structuredContent' in result &&
502-
result.structuredContent !== undefined
503-
) {
504-
return JSON.stringify(result.structuredContent);
505-
}
506-
// Preserve backward compatibility: return empty array when no content
507-
return result.content || [];
466+
const content = await server.callTool(mcpTool.name, args);
467+
return content.length === 1 ? content[0] : content;
508468
}
509469

510470
const schema: JsonObjectSchema<any> = {
@@ -573,11 +533,6 @@ export interface BaseMCPServerStdioOptions {
573533
encodingErrorHandler?: 'strict' | 'ignore' | 'replace';
574534
logger?: Logger;
575535
toolFilter?: MCPToolFilterCallable | MCPToolFilterStatic;
576-
577-
/**
578-
* Whether to include structuredContent in tool outputs when available.
579-
*/
580-
useStructuredContent?: boolean;
581536
timeout?: number;
582537
}
583538
export interface DefaultMCPServerStdioOptions
@@ -600,11 +555,6 @@ export interface MCPServerStreamableHttpOptions {
600555
name?: string;
601556
logger?: Logger;
602557
toolFilter?: MCPToolFilterCallable | MCPToolFilterStatic;
603-
604-
/**
605-
* Whether to include structuredContent in tool outputs when available.
606-
*/
607-
useStructuredContent?: boolean;
608558
timeout?: number;
609559

610560
// ----------------------------------------------------
@@ -629,11 +579,6 @@ export interface MCPServerSSEOptions {
629579
name?: string;
630580
logger?: Logger;
631581
toolFilter?: MCPToolFilterCallable | MCPToolFilterStatic;
632-
633-
/**
634-
* Whether to include structuredContent in tool outputs when available.
635-
*/
636-
useStructuredContent?: boolean;
637582
timeout?: number;
638583

639584
// ----------------------------------------------------
@@ -676,22 +621,9 @@ export interface JsonRpcResponse {
676621
error?: any;
677622
}
678623

679-
/**
680-
* Structured content that can be returned by MCP tools.
681-
* Supports various data types including objects, arrays, primitives, and null.
682-
*/
683-
export type StructuredContent =
684-
| Record<string, unknown>
685-
| unknown[]
686-
| string
687-
| number
688-
| boolean
689-
| null;
690-
691624
export interface CallToolResponse extends JsonRpcResponse {
692625
result: {
693626
content: { type: string; text: string }[];
694-
structuredContent?: StructuredContent;
695627
};
696628
}
697629
export type CallToolResult = CallToolResponse['result'];

packages/agents-core/src/shims/mcp-server/browser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
BaseMCPServerSSE,
33
BaseMCPServerStdio,
44
BaseMCPServerStreamableHttp,
5-
CallToolResult,
5+
CallToolResultContent,
66
MCPServerSSEOptions,
77
MCPServerStdioOptions,
88
MCPServerStreamableHttpOptions,
@@ -28,7 +28,7 @@ export class MCPServerStdio extends BaseMCPServerStdio {
2828
callTool(
2929
_toolName: string,
3030
_args: Record<string, unknown> | null,
31-
): Promise<CallToolResult> {
31+
): Promise<CallToolResultContent> {
3232
throw new Error('Method not implemented.');
3333
}
3434
invalidateToolsCache(): Promise<void> {
@@ -55,7 +55,7 @@ export class MCPServerStreamableHttp extends BaseMCPServerStreamableHttp {
5555
callTool(
5656
_toolName: string,
5757
_args: Record<string, unknown> | null,
58-
): Promise<CallToolResult> {
58+
): Promise<CallToolResultContent> {
5959
throw new Error('Method not implemented.');
6060
}
6161
invalidateToolsCache(): Promise<void> {
@@ -84,7 +84,7 @@ export class MCPServerSSE extends BaseMCPServerSSE {
8484
callTool(
8585
_toolName: string,
8686
_args: Record<string, unknown> | null,
87-
): Promise<CallToolResult> {
87+
): Promise<CallToolResultContent> {
8888
throw new Error('Method not implemented.');
8989
}
9090

packages/agents-core/src/shims/mcp-server/node.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
BaseMCPServerStdio,
66
BaseMCPServerStreamableHttp,
77
BaseMCPServerSSE,
8-
CallToolResult,
8+
CallToolResultContent,
99
DefaultMCPServerStdioOptions,
1010
InitializeResult,
1111
MCPServerStdioOptions,
@@ -124,7 +124,7 @@ export class NodeMCPServerStdio extends BaseMCPServerStdio {
124124
async callTool(
125125
toolName: string,
126126
args: Record<string, unknown> | null,
127-
): Promise<CallToolResult> {
127+
): Promise<CallToolResultContent> {
128128
const { CallToolResultSchema } = await import(
129129
'@modelcontextprotocol/sdk/types.js'
130130
).catch(failedToImport);
@@ -144,12 +144,12 @@ export class NodeMCPServerStdio extends BaseMCPServerStdio {
144144
},
145145
);
146146
const parsed = CallToolResultSchema.parse(response);
147-
const result = parsed;
147+
const result = parsed.content;
148148
this.debugLog(
149149
() =>
150-
`Called tool ${toolName} (args: ${JSON.stringify(args)}, result: ${JSON.stringify(result.content)})`,
150+
`Called tool ${toolName} (args: ${JSON.stringify(args)}, result: ${JSON.stringify(result)})`,
151151
);
152-
return result as CallToolResult;
152+
return result as CallToolResultContent;
153153
}
154154

155155
get name() {
@@ -245,7 +245,7 @@ export class NodeMCPServerSSE extends BaseMCPServerSSE {
245245
async callTool(
246246
toolName: string,
247247
args: Record<string, unknown> | null,
248-
): Promise<CallToolResult> {
248+
): Promise<CallToolResultContent> {
249249
const { CallToolResultSchema } = await import(
250250
'@modelcontextprotocol/sdk/types.js'
251251
).catch(failedToImport);
@@ -265,12 +265,12 @@ export class NodeMCPServerSSE extends BaseMCPServerSSE {
265265
},
266266
);
267267
const parsed = CallToolResultSchema.parse(response);
268-
const result = parsed;
268+
const result = parsed.content;
269269
this.debugLog(
270270
() =>
271-
`Called tool ${toolName} (args: ${JSON.stringify(args)}, result: ${JSON.stringify(result.content)})`,
271+
`Called tool ${toolName} (args: ${JSON.stringify(args)}, result: ${JSON.stringify(result)})`,
272272
);
273-
return result as CallToolResult;
273+
return result as CallToolResultContent;
274274
}
275275

276276
get name() {
@@ -371,7 +371,7 @@ export class NodeMCPServerStreamableHttp extends BaseMCPServerStreamableHttp {
371371
async callTool(
372372
toolName: string,
373373
args: Record<string, unknown> | null,
374-
): Promise<CallToolResult> {
374+
): Promise<CallToolResultContent> {
375375
const { CallToolResultSchema } = await import(
376376
'@modelcontextprotocol/sdk/types.js'
377377
).catch(failedToImport);
@@ -391,12 +391,12 @@ export class NodeMCPServerStreamableHttp extends BaseMCPServerStreamableHttp {
391391
},
392392
);
393393
const parsed = CallToolResultSchema.parse(response);
394-
const result = parsed;
394+
const result = parsed.content;
395395
this.debugLog(
396396
() =>
397-
`Called tool ${toolName} (args: ${JSON.stringify(args)}, result: ${JSON.stringify(result.content)})`,
397+
`Called tool ${toolName} (args: ${JSON.stringify(args)}, result: ${JSON.stringify(result)})`,
398398
);
399-
return result as CallToolResult;
399+
return result as CallToolResultContent;
400400
}
401401

402402
get name() {

packages/agents-core/test/mcpCache.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getAllMcpTools } from '../src/mcp';
33
import type { FunctionTool } from '../src/tool';
44
import { withTrace } from '../src/tracing';
55
import { NodeMCPServerStdio } from '../src/shims/mcp-server/node';
6-
import type { CallToolResult } from '../src/mcp';
6+
import type { CallToolResultContent } from '../src/mcp';
77
import { RunContext } from '../src/runContext';
88
import { Agent } from '../src/agent';
99

@@ -27,8 +27,8 @@ class StubServer extends NodeMCPServerStdio {
2727
async callTool(
2828
_toolName: string,
2929
_args: Record<string, unknown> | null,
30-
): Promise<CallToolResult> {
31-
return { content: [] };
30+
): Promise<CallToolResultContent> {
31+
return [];
3232
}
3333
}
3434

0 commit comments

Comments
 (0)