@@ -3,6 +3,7 @@ import { UserError } from './errors';
33import {
44 MCPServerStdio as UnderlyingMCPServerStdio ,
55 MCPServerStreamableHttp as UnderlyingMCPServerStreamableHttp ,
6+ MCPServerSSE as UnderlyingMCPServerSSE ,
67} from '@openai/agents-core/_shims' ;
78import { getCurrentSpan , withMCPListToolsSpan } from './tracing' ;
89import { logger as globalLogger , getLogger , Logger } from './logger' ;
@@ -24,6 +25,9 @@ export const DEFAULT_STDIO_MCP_CLIENT_LOGGER_NAME =
2425export const DEFAULT_STREAMABLE_HTTP_MCP_CLIENT_LOGGER_NAME =
2526 'openai-agents:streamable-http-mcp-client' ;
2627
28+ export const DEFAULT_SSE_MCP_CLIENT_LOGGER_NAME =
29+ 'openai-agents:sse-mcp-client' ;
30+
2731/**
2832 * Interface for MCP server implementations.
2933 * Provides methods for connecting, listing tools, calling tools, and cleanup.
@@ -113,6 +117,41 @@ export abstract class BaseMCPServerStreamableHttp implements MCPServer {
113117 }
114118}
115119
120+ export abstract class BaseMCPServerSSE implements MCPServer {
121+ public cacheToolsList : boolean ;
122+ protected _cachedTools : any [ ] | undefined = undefined ;
123+ public toolFilter ?: MCPToolFilterCallable | MCPToolFilterStatic ;
124+
125+ protected logger : Logger ;
126+ constructor ( options : MCPServerSSEOptions ) {
127+ this . logger =
128+ options . logger ?? getLogger ( DEFAULT_SSE_MCP_CLIENT_LOGGER_NAME ) ;
129+ this . cacheToolsList = options . cacheToolsList ?? false ;
130+ this . toolFilter = options . toolFilter ;
131+ }
132+
133+ abstract get name ( ) : string ;
134+ abstract connect ( ) : Promise < void > ;
135+ abstract close ( ) : Promise < void > ;
136+ abstract listTools ( ) : Promise < any [ ] > ;
137+ abstract callTool (
138+ _toolName : string ,
139+ _args : Record < string , unknown > | null ,
140+ ) : Promise < CallToolResultContent > ;
141+ abstract invalidateToolsCache ( ) : Promise < void > ;
142+
143+ /**
144+ * Logs a debug message when debug logging is enabled.
145+ * @param buildMessage A function that returns the message to log.
146+ */
147+ protected debugLog ( buildMessage : ( ) => string ) : void {
148+ if ( debug . enabled ( this . logger . namespace ) ) {
149+ // only when this is true, the function to build the string is called
150+ this . logger . debug ( buildMessage ( ) ) ;
151+ }
152+ }
153+ }
154+
116155/**
117156 * Minimum MCP tool data definition.
118157 * This type definition does not intend to cover all possible properties.
@@ -206,6 +245,42 @@ export class MCPServerStreamableHttp extends BaseMCPServerStreamableHttp {
206245 }
207246}
208247
248+ export class MCPServerSSE extends BaseMCPServerSSE {
249+ private underlying : UnderlyingMCPServerSSE ;
250+ constructor ( options : MCPServerSSEOptions ) {
251+ super ( options ) ;
252+ this . underlying = new UnderlyingMCPServerSSE ( options ) ;
253+ }
254+ get name ( ) : string {
255+ return this . underlying . name ;
256+ }
257+ connect ( ) : Promise < void > {
258+ return this . underlying . connect ( ) ;
259+ }
260+ close ( ) : Promise < void > {
261+ return this . underlying . close ( ) ;
262+ }
263+ async listTools ( ) : Promise < MCPTool [ ] > {
264+ if ( this . cacheToolsList && this . _cachedTools ) {
265+ return this . _cachedTools ;
266+ }
267+ const tools = await this . underlying . listTools ( ) ;
268+ if ( this . cacheToolsList ) {
269+ this . _cachedTools = tools ;
270+ }
271+ return tools ;
272+ }
273+ callTool (
274+ toolName : string ,
275+ args : Record < string , unknown > | null ,
276+ ) : Promise < CallToolResultContent > {
277+ return this . underlying . callTool ( toolName , args ) ;
278+ }
279+ invalidateToolsCache ( ) : Promise < void > {
280+ return this . underlying . invalidateToolsCache ( ) ;
281+ }
282+ }
283+
209284/**
210285 * Fetches and flattens all tools from multiple MCP servers.
211286 * Logs and skips any servers that fail to respond.
@@ -467,6 +542,26 @@ export interface MCPServerStreamableHttpOptions {
467542 // ----------------------------------------------------
468543}
469544
545+ export interface MCPServerSSEOptions {
546+ url : string ;
547+ cacheToolsList ?: boolean ;
548+ clientSessionTimeoutSeconds ?: number ;
549+ name ?: string ;
550+ logger ?: Logger ;
551+ toolFilter ?: MCPToolFilterCallable | MCPToolFilterStatic ;
552+ timeout ?: number ;
553+
554+ // ----------------------------------------------------
555+ // OAuth
556+ // import { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js';
557+ authProvider ?: any ;
558+ // RequestInit
559+ requestInit ?: any ;
560+ // import { SSEReconnectionOptions } from '@modelcontextprotocol/sdk/client/sse.js';
561+ eventSourceInit ?: any ;
562+ // ----------------------------------------------------
563+ }
564+
470565/**
471566 * Represents a JSON-RPC request message.
472567 */
0 commit comments