Skip to content

Commit b438004

Browse files
committed
Add MCP tool
1 parent 936e698 commit b438004

File tree

59 files changed

+11794
-10099
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+11794
-10099
lines changed

.github/workflows/live-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
- name: Run live tests
3333
run: dotnet test ./tests/OpenAI.Tests.csproj
3434
--configuration Release
35-
--filter="TestCategory!=Smoke&TestCategory!=Assistants&TestCategory!=StoredChat&TestCategory!=Images&TestCategory!=Uploads&TestCategory!=Moderations&TestCategory!=FineTuning&TestCategory!=Conversation&TestCategory!=Manual"
35+
--filter="TestCategory!=Smoke&TestCategory!=Assistants&TestCategory!=StoredChat&TestCategory!=Images&TestCategory!=Uploads&TestCategory!=Moderations&TestCategory!=FineTuning&TestCategory!=Conversation&TestCategory!=MCP&TestCategory!=Manual"
3636
--logger "trx;LogFilePrefix=live"
3737
--results-directory ${{github.workspace}}/artifacts/test-results
3838
${{ env.version_suffix_args}}

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
- name: Run Live Tests
5656
run: dotnet test ./tests/OpenAI.Tests.csproj
5757
--configuration Release
58-
--filter="TestCategory!=Smoke&TestCategory!=Assistants&TestCategory!=StoredChat&TestCategory!=Images&TestCategory!=Uploads&TestCategory!=Moderations&TestCategory!=FineTuning&TestCategory!=Conversation&TestCategory!=Manual"
58+
--filter="TestCategory!=Smoke&TestCategory!=Assistants&TestCategory!=StoredChat&TestCategory!=Images&TestCategory!=Uploads&TestCategory!=Moderations&TestCategory!=FineTuning&TestCategory!=Conversation&TestCategory!=MCP&TestCategory!=Manual"
5959
--logger "trx;LogFilePrefix=live"
6060
--results-directory ${{ github.workspace }}/artifacts/test-results
6161
${{ env.version_suffix_args }}

api/OpenAI.net8.0.cs

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4716,6 +4716,15 @@ public class ComputerTool : ResponseTool, IJsonModel<ComputerTool>, IPersistable
47164716
public override readonly string ToString();
47174717
}
47184718
[Experimental("OPENAI001")]
4719+
public class CustomMCPToolCallApprovalPolicy : IJsonModel<CustomMCPToolCallApprovalPolicy>, IPersistableModel<CustomMCPToolCallApprovalPolicy> {
4720+
public MCPToolFilter ToolsAlwaysRequiringApproval { get; set; }
4721+
public MCPToolFilter ToolsNeverRequiringApproval { get; set; }
4722+
protected virtual CustomMCPToolCallApprovalPolicy JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
4723+
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
4724+
protected virtual CustomMCPToolCallApprovalPolicy PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
4725+
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
4726+
}
4727+
[Experimental("OPENAI001")]
47194728
public class FileCitationMessageAnnotation : ResponseMessageAnnotation, IJsonModel<FileCitationMessageAnnotation>, IPersistableModel<FileCitationMessageAnnotation> {
47204729
public FileCitationMessageAnnotation(string fileId, int index);
47214730
public string FileId { get; set; }
@@ -4851,6 +4860,112 @@ public class FunctionTool : ResponseTool, IJsonModel<FunctionTool>, IPersistable
48514860
protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
48524861
}
48534862
[Experimental("OPENAI001")]
4863+
public readonly partial struct GlobalMCPToolCallApprovalPolicy : IEquatable<GlobalMCPToolCallApprovalPolicy> {
4864+
public GlobalMCPToolCallApprovalPolicy(string value);
4865+
public static GlobalMCPToolCallApprovalPolicy AlwaysRequireApproval { get; }
4866+
public static GlobalMCPToolCallApprovalPolicy NeverRequireApproval { get; }
4867+
public readonly bool Equals(GlobalMCPToolCallApprovalPolicy other);
4868+
[EditorBrowsable(EditorBrowsableState.Never)]
4869+
public override readonly bool Equals(object obj);
4870+
[EditorBrowsable(EditorBrowsableState.Never)]
4871+
public override readonly int GetHashCode();
4872+
public static bool operator ==(GlobalMCPToolCallApprovalPolicy left, GlobalMCPToolCallApprovalPolicy right);
4873+
public static implicit operator GlobalMCPToolCallApprovalPolicy(string value);
4874+
public static implicit operator GlobalMCPToolCallApprovalPolicy?(string value);
4875+
public static bool operator !=(GlobalMCPToolCallApprovalPolicy left, GlobalMCPToolCallApprovalPolicy right);
4876+
public override readonly string ToString();
4877+
}
4878+
[Experimental("OPENAI001")]
4879+
public class MCPTool : ResponseTool, IJsonModel<MCPTool>, IPersistableModel<MCPTool> {
4880+
public MCPTool(string serverLabel, Uri serverUri);
4881+
public MCPToolFilter AllowedTools { get; set; }
4882+
public IDictionary<string, string> Headers { get; set; }
4883+
public string ServerLabel { get; set; }
4884+
public Uri ServerUri { get; set; }
4885+
public MCPToolCallApprovalPolicy ToolCallApprovalPolicy { get; set; }
4886+
protected override ResponseTool JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
4887+
protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
4888+
protected override ResponseTool PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
4889+
protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
4890+
}
4891+
[Experimental("OPENAI001")]
4892+
public class MCPToolCallApprovalPolicy : IJsonModel<MCPToolCallApprovalPolicy>, IPersistableModel<MCPToolCallApprovalPolicy> {
4893+
public MCPToolCallApprovalPolicy(CustomMCPToolCallApprovalPolicy customPolicy);
4894+
public MCPToolCallApprovalPolicy(GlobalMCPToolCallApprovalPolicy globalPolicy);
4895+
public CustomMCPToolCallApprovalPolicy CustomPolicy { get; }
4896+
public GlobalMCPToolCallApprovalPolicy? GlobalPolicy { get; }
4897+
protected virtual MCPToolCallApprovalPolicy JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
4898+
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
4899+
protected virtual MCPToolCallApprovalPolicy PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
4900+
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
4901+
}
4902+
[Experimental("OPENAI001")]
4903+
public class MCPToolCallApprovalRequestItem : ResponseItem, IJsonModel<MCPToolCallApprovalRequestItem>, IPersistableModel<MCPToolCallApprovalRequestItem> {
4904+
public MCPToolCallApprovalRequestItem(string serverLabel, string toolName, BinaryData toolArguments);
4905+
public string ServerLabel { get; set; }
4906+
public BinaryData ToolArguments { get; set; }
4907+
public string ToolName { get; set; }
4908+
protected override ResponseItem JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
4909+
protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
4910+
protected override ResponseItem PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
4911+
protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
4912+
}
4913+
[Experimental("OPENAI001")]
4914+
public class MCPToolCallApprovalResponseItem : ResponseItem, IJsonModel<MCPToolCallApprovalResponseItem>, IPersistableModel<MCPToolCallApprovalResponseItem> {
4915+
public MCPToolCallApprovalResponseItem(string approvalRequestId, bool approved);
4916+
public string ApprovalRequestId { get; set; }
4917+
public bool Approved { get; set; }
4918+
public string Reason { get; set; }
4919+
protected override ResponseItem JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
4920+
protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
4921+
protected override ResponseItem PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
4922+
protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
4923+
}
4924+
[Experimental("OPENAI001")]
4925+
public class MCPToolCallItem : ResponseItem, IJsonModel<MCPToolCallItem>, IPersistableModel<MCPToolCallItem> {
4926+
public MCPToolCallItem(string serverLabel, string toolName, BinaryData toolArguments);
4927+
public BinaryData Error { get; set; }
4928+
public string ServerLabel { get; set; }
4929+
public BinaryData ToolArguments { get; set; }
4930+
public string ToolName { get; set; }
4931+
public string ToolOutput { get; set; }
4932+
protected override ResponseItem JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
4933+
protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
4934+
protected override ResponseItem PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
4935+
protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
4936+
}
4937+
[Experimental("OPENAI001")]
4938+
public class MCPToolDefinition : IJsonModel<MCPToolDefinition>, IPersistableModel<MCPToolDefinition> {
4939+
public MCPToolDefinition(string name, BinaryData inputSchema);
4940+
public BinaryData Annotations { get; set; }
4941+
public string Description { get; set; }
4942+
public BinaryData InputSchema { get; set; }
4943+
public string Name { get; set; }
4944+
protected virtual MCPToolDefinition JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
4945+
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
4946+
protected virtual MCPToolDefinition PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
4947+
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
4948+
}
4949+
[Experimental("OPENAI001")]
4950+
public class MCPToolDefinitionListItem : ResponseItem, IJsonModel<MCPToolDefinitionListItem>, IPersistableModel<MCPToolDefinitionListItem> {
4951+
public MCPToolDefinitionListItem(string serverLabel, IEnumerable<MCPToolDefinition> toolDefinitions);
4952+
public BinaryData Error { get; set; }
4953+
public string ServerLabel { get; set; }
4954+
public IList<MCPToolDefinition> ToolDefinitions { get; }
4955+
protected override ResponseItem JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
4956+
protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
4957+
protected override ResponseItem PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
4958+
protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
4959+
}
4960+
[Experimental("OPENAI001")]
4961+
public class MCPToolFilter : IJsonModel<MCPToolFilter>, IPersistableModel<MCPToolFilter> {
4962+
public IList<string> ToolNames { get; }
4963+
protected virtual MCPToolFilter JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
4964+
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
4965+
protected virtual MCPToolFilter PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
4966+
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
4967+
}
4968+
[Experimental("OPENAI001")]
48544969
public class MessageResponseItem : ResponseItem, IJsonModel<MessageResponseItem>, IPersistableModel<MessageResponseItem> {
48554970
public IList<ResponseContentPart> Content { get; }
48564971
public MessageRole Role { get; }
@@ -5174,6 +5289,10 @@ public class ResponseItem : IJsonModel<ResponseItem>, IPersistableModel<Response
51745289
public static FileSearchCallResponseItem CreateFileSearchCallItem(IEnumerable<string> queries);
51755290
public static FunctionCallResponseItem CreateFunctionCallItem(string callId, string functionName, BinaryData functionArguments);
51765291
public static FunctionCallOutputResponseItem CreateFunctionCallOutputItem(string callId, string functionOutput);
5292+
public static MCPToolCallApprovalRequestItem CreateMCPApprovalRequestItem(string serverLabel, string name, BinaryData arguments);
5293+
public static MCPToolCallApprovalResponseItem CreateMCPApprovalResponseItem(string approvalRequestId, bool approved);
5294+
public static MCPToolCallItem CreateMCPToolCallItem(string serverLabel, string name, BinaryData arguments);
5295+
public static MCPToolDefinitionListItem CreateMCPToolDefinitionListItem(string serverLabel, IEnumerable<MCPToolDefinition> toolDefinitions);
51775296
public static ReasoningResponseItem CreateReasoningItem(IEnumerable<ReasoningSummaryPart> summaryParts);
51785297
public static ReasoningResponseItem CreateReasoningItem(string summaryText);
51795298
public static ReferenceResponseItem CreateReferenceItem(string id);
@@ -5351,6 +5470,7 @@ public class ResponseTool : IJsonModel<ResponseTool>, IPersistableModel<Response
53515470
public static ComputerTool CreateComputerTool(ComputerToolEnvironment environment, int displayWidth, int displayHeight);
53525471
public static FileSearchTool CreateFileSearchTool(IEnumerable<string> vectorStoreIds, int? maxResultCount = null, FileSearchToolRankingOptions rankingOptions = null, BinaryData filters = null);
53535472
public static FunctionTool CreateFunctionTool(string functionName, BinaryData functionParameters, bool? strictModeEnabled, string functionDescription = null);
5473+
public static MCPTool CreateMCPTool(string serverLabel, Uri serverUri, IDictionary<string, string> headers = null, MCPToolFilter allowedTools = null, MCPToolCallApprovalPolicy toolCallApprovalPolicy = null);
53545474
public static WebSearchTool CreateWebSearchTool(WebSearchToolLocation userLocation = null, WebSearchToolContextSize? searchContextSize = null);
53555475
protected virtual ResponseTool JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
53565476
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);

0 commit comments

Comments
 (0)