@@ -134,52 +134,126 @@ export type HostedMCPTool<Context = UnknownContext> = HostedTool & {
134134 */
135135export function hostedMcpTool < Context = UnknownContext > (
136136 options : {
137- serverLabel : string ;
138- serverUrl : string ;
139137 allowedTools ?: string [ ] | { toolNames ?: string [ ] } ;
140- headers ?: Record < string , string > ;
141- } & (
142- | { requireApproval ?: never }
143- | { requireApproval : 'never' }
144- | {
145- requireApproval :
146- | 'always'
147- | {
148- never ?: { toolNames : string [ ] } ;
149- always ?: { toolNames : string [ ] } ;
150- } ;
151- onApproval ?: HostedMCPApprovalFunction < Context > ;
152- }
153- ) ,
154- ) : HostedMCPTool < Context > {
155- const providerData : ProviderData . HostedMCPTool < Context > =
156- typeof options . requireApproval === 'undefined' ||
157- options . requireApproval === 'never'
158- ? {
159- type : 'mcp' ,
160- server_label : options . serverLabel ,
161- server_url : options . serverUrl ,
162- require_approval : 'never' ,
163- allowed_tools : toMcpAllowedToolsFilter ( options . allowedTools ) ,
164- headers : options . headers ,
138+ } &
139+ // MCP server
140+ ( | {
141+ serverLabel : string ;
142+ serverUrl ?: string ;
143+ authorization ?: string ;
144+ headers ?: Record < string , string > ;
165145 }
166- : {
167- type : 'mcp' ,
168- server_label : options . serverLabel ,
169- server_url : options . serverUrl ,
170- allowed_tools : toMcpAllowedToolsFilter ( options . allowedTools ) ,
171- headers : options . headers ,
172- require_approval :
173- typeof options . requireApproval === 'string'
174- ? 'always'
175- : buildRequireApproval ( options . requireApproval ) ,
176- on_approval : options . onApproval ,
177- } ;
178- return {
179- type : 'hosted_tool' ,
180- name : 'hosted_mcp' ,
181- providerData,
182- } ;
146+ // OpenAI Connector
147+ | {
148+ serverLabel : string ;
149+ connectorId : string ;
150+ authorization ?: string ;
151+ headers ?: Record < string , string > ;
152+ }
153+ ) &
154+ (
155+ | { requireApproval ?: never }
156+ | { requireApproval : 'never' }
157+ | {
158+ requireApproval :
159+ | 'always'
160+ | {
161+ never ?: { toolNames : string [ ] } ;
162+ always ?: { toolNames : string [ ] } ;
163+ } ;
164+ onApproval ?: HostedMCPApprovalFunction < Context > ;
165+ }
166+ ) ,
167+ ) : HostedMCPTool < Context > {
168+ if ( 'serverUrl' in options ) {
169+ // the MCP servers comaptible with the specification
170+ const providerData : ProviderData . HostedMCPTool < Context > =
171+ typeof options . requireApproval === 'undefined' ||
172+ options . requireApproval === 'never'
173+ ? {
174+ type : 'mcp' ,
175+ server_label : options . serverLabel ,
176+ server_url : options . serverUrl ,
177+ require_approval : 'never' ,
178+ allowed_tools : toMcpAllowedToolsFilter ( options . allowedTools ) ,
179+ headers : options . headers ,
180+ }
181+ : {
182+ type : 'mcp' ,
183+ server_label : options . serverLabel ,
184+ server_url : options . serverUrl ,
185+ allowed_tools : toMcpAllowedToolsFilter ( options . allowedTools ) ,
186+ headers : options . headers ,
187+ require_approval :
188+ typeof options . requireApproval === 'string'
189+ ? 'always'
190+ : buildRequireApproval ( options . requireApproval ) ,
191+ on_approval : options . onApproval ,
192+ } ;
193+ return {
194+ type : 'hosted_tool' ,
195+ name : 'hosted_mcp' ,
196+ providerData,
197+ } ;
198+ } else if ( 'connectorId' in options ) {
199+ // OpenAI's connectors
200+ const providerData : ProviderData . HostedMCPTool < Context > =
201+ typeof options . requireApproval === 'undefined' ||
202+ options . requireApproval === 'never'
203+ ? {
204+ type : 'mcp' ,
205+ server_label : options . serverLabel ,
206+ connector_id : options . connectorId ,
207+ authorization : options . authorization ,
208+ require_approval : 'never' ,
209+ allowed_tools : toMcpAllowedToolsFilter ( options . allowedTools ) ,
210+ headers : options . headers ,
211+ }
212+ : {
213+ type : 'mcp' ,
214+ server_label : options . serverLabel ,
215+ connector_id : options . connectorId ,
216+ authorization : options . authorization ,
217+ allowed_tools : toMcpAllowedToolsFilter ( options . allowedTools ) ,
218+ headers : options . headers ,
219+ require_approval :
220+ typeof options . requireApproval === 'string'
221+ ? 'always'
222+ : buildRequireApproval ( options . requireApproval ) ,
223+ on_approval : options . onApproval ,
224+ } ;
225+ return {
226+ type : 'hosted_tool' ,
227+ name : 'hosted_mcp' ,
228+ providerData,
229+ } ;
230+ } else {
231+ // the MCP servers comaptible with the specification
232+ const providerData : ProviderData . HostedMCPTool < Context > =
233+ typeof options . requireApproval === 'undefined' ||
234+ options . requireApproval === 'never'
235+ ? {
236+ type : 'mcp' ,
237+ server_label : options . serverLabel ,
238+ require_approval : 'never' ,
239+ allowed_tools : toMcpAllowedToolsFilter ( options . allowedTools ) ,
240+ }
241+ : {
242+ type : 'mcp' ,
243+ server_label : options . serverLabel ,
244+ allowed_tools : toMcpAllowedToolsFilter ( options . allowedTools ) ,
245+ require_approval :
246+ typeof options . requireApproval === 'string'
247+ ? 'always'
248+ : buildRequireApproval ( options . requireApproval ) ,
249+ on_approval : options . onApproval ,
250+ } ;
251+ return {
252+ type : 'hosted_tool' ,
253+ name : 'hosted_mcp' ,
254+ providerData,
255+ } ;
256+ }
183257}
184258
185259/**
0 commit comments