Skip to content

Commit c7cad8a

Browse files
xitzhangXiting Zhang
andauthored
Add MCP (Model Context Protocol) tool integration support (Azure#47276)
* Add MCP (Model Context Protocol) tool integration support * update date * update log --------- Co-authored-by: Xiting Zhang <[email protected]>
1 parent a43fab5 commit c7cad8a

33 files changed

+3349
-4
lines changed

sdk/ai/azure-ai-voicelive/CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,27 @@
44

55
### Features Added
66

7+
- Added Model Context Protocol (MCP) support for tool integration:
8+
- `MCPServer` class for defining MCP server configurations with server label, URL, authorization, headers, and tool restrictions
9+
- `MCPTool` class representing MCP tool definitions with name, description, input schema, and annotations
10+
- `ResponseMCPListToolItem` for listing available tools on an MCP server
11+
- `ResponseMCPCallItem` for MCP tool call responses with arguments, output, and error handling
12+
- `ResponseMCPApprovalRequestItem` and `ResponseMCPApprovalResponseItem` for tool call approval workflow
13+
- Server events: `ServerEventMcpListToolsInProgress`, `ServerEventMcpListToolsCompleted`, `ServerEventMcpListToolsFailed`
14+
- Server events: `ServerEventResponseMcpCallArgumentsDelta`, `ServerEventResponseMcpCallArgumentsDone`
15+
- New `ToolType.MCP` for MCP-based tool definitions
16+
- New `ServerEventType` constants for MCP-related events
17+
718
### Breaking Changes
819

920
### Bugs Fixed
1021

1122
### Other Changes
1223

24+
#### Dependency Updates
25+
26+
- Dependency versions remain unchanged from `1.0.0-beta.1`.
27+
1328
## 1.0.0-beta.1 (2025-11-10)
1429

1530
- Initial release of Azure VoiceLive client library for Java. This library enables real-time, bidirectional voice conversations with AI assistants using WebSocket-based streaming communication.

sdk/ai/azure-ai-voicelive/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Use the Azure VoiceLive client library for Java to:
2727
<dependency>
2828
<groupId>com.azure</groupId>
2929
<artifactId>azure-ai-voicelive</artifactId>
30-
<version>1.0.0-beta.1</version>
30+
<version>1.0.0-beta.2</version>
3131
</dependency>
3232
```
3333
[//]: # ({x-version-update-end})

sdk/ai/azure-ai-voicelive/src/main/java/com/azure/ai/voicelive/models/ClientEventType.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,10 @@ public static ClientEventType fromString(String name) {
138138
public static Collection<ClientEventType> values() {
139139
return values(ClientEventType.class);
140140
}
141+
142+
/**
143+
* Static value mcp_approval_response for ClientEventType.
144+
*/
145+
@Generated
146+
public static final ClientEventType MCP_APPROVAL_RESPONSE = fromString("mcp_approval_response");
141147
}

sdk/ai/azure-ai-voicelive/src/main/java/com/azure/ai/voicelive/models/ConversationRequestItem.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public static ConversationRequestItem fromJson(JsonReader jsonReader) throws IOE
112112
return FunctionCallItem.fromJson(readerToUse.reset());
113113
} else if ("function_call_output".equals(discriminatorValue)) {
114114
return FunctionCallOutputItem.fromJson(readerToUse.reset());
115+
} else if ("mcp_approval_response".equals(discriminatorValue)) {
116+
return MCPApprovalResponseRequestItem.fromJson(readerToUse.reset());
115117
} else {
116118
return fromJsonKnownDiscriminator(readerToUse.reset());
117119
}

sdk/ai/azure-ai-voicelive/src/main/java/com/azure/ai/voicelive/models/ItemType.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,28 @@ public static ItemType fromString(String name) {
6060
public static Collection<ItemType> values() {
6161
return values(ItemType.class);
6262
}
63+
64+
/**
65+
* Static value mcp_list_tools for ItemType.
66+
*/
67+
@Generated
68+
public static final ItemType MCP_LIST_TOOLS = fromString("mcp_list_tools");
69+
70+
/**
71+
* Static value mcp_call for ItemType.
72+
*/
73+
@Generated
74+
public static final ItemType MCP_CALL = fromString("mcp_call");
75+
76+
/**
77+
* Static value mcp_approval_request for ItemType.
78+
*/
79+
@Generated
80+
public static final ItemType MCP_APPROVAL_REQUEST = fromString("mcp_approval_request");
81+
82+
/**
83+
* Static value mcp_approval_response for ItemType.
84+
*/
85+
@Generated
86+
public static final ItemType MCP_APPROVAL_RESPONSE = fromString("mcp_approval_response");
6387
}
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
// Code generated by Microsoft (R) TypeSpec Code Generator.
4+
5+
package com.azure.ai.voicelive.models;
6+
7+
import com.azure.core.annotation.Fluent;
8+
import com.azure.core.annotation.Generated;
9+
import com.azure.json.JsonReader;
10+
import com.azure.json.JsonToken;
11+
import com.azure.json.JsonWriter;
12+
import java.io.IOException;
13+
14+
/**
15+
* A request item that represents a response to an MCP approval request.
16+
*/
17+
@Fluent
18+
public final class MCPApprovalResponseRequestItem extends ConversationRequestItem {
19+
/*
20+
* The type property.
21+
*/
22+
@Generated
23+
private ItemType type = ItemType.MCP_APPROVAL_RESPONSE;
24+
25+
/*
26+
* The ID of the approval request.
27+
*/
28+
@Generated
29+
private final String approvalRequestId;
30+
31+
/*
32+
* Whether the tool call was approved.
33+
*/
34+
@Generated
35+
private final boolean approve;
36+
37+
/**
38+
* Creates an instance of MCPApprovalResponseRequestItem class.
39+
*
40+
* @param approvalRequestId the approvalRequestId value to set.
41+
* @param approve the approve value to set.
42+
*/
43+
@Generated
44+
public MCPApprovalResponseRequestItem(String approvalRequestId, boolean approve) {
45+
this.approvalRequestId = approvalRequestId;
46+
this.approve = approve;
47+
}
48+
49+
/**
50+
* Get the type property: The type property.
51+
*
52+
* @return the type value.
53+
*/
54+
@Generated
55+
@Override
56+
public ItemType getType() {
57+
return this.type;
58+
}
59+
60+
/**
61+
* Get the approvalRequestId property: The ID of the approval request.
62+
*
63+
* @return the approvalRequestId value.
64+
*/
65+
@Generated
66+
public String getApprovalRequestId() {
67+
return this.approvalRequestId;
68+
}
69+
70+
/**
71+
* Get the approve property: Whether the tool call was approved.
72+
*
73+
* @return the approve value.
74+
*/
75+
@Generated
76+
public boolean isApprove() {
77+
return this.approve;
78+
}
79+
80+
/**
81+
* {@inheritDoc}
82+
*/
83+
@Generated
84+
@Override
85+
public MCPApprovalResponseRequestItem setId(String id) {
86+
super.setId(id);
87+
return this;
88+
}
89+
90+
/**
91+
* {@inheritDoc}
92+
*/
93+
@Generated
94+
@Override
95+
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
96+
jsonWriter.writeStartObject();
97+
jsonWriter.writeStringField("id", getId());
98+
jsonWriter.writeStringField("approval_request_id", this.approvalRequestId);
99+
jsonWriter.writeBooleanField("approve", this.approve);
100+
jsonWriter.writeStringField("type", this.type == null ? null : this.type.toString());
101+
return jsonWriter.writeEndObject();
102+
}
103+
104+
/**
105+
* Reads an instance of MCPApprovalResponseRequestItem from the JsonReader.
106+
*
107+
* @param jsonReader The JsonReader being read.
108+
* @return An instance of MCPApprovalResponseRequestItem if the JsonReader was pointing to an instance of it, or
109+
* null if it was pointing to JSON null.
110+
* @throws IllegalStateException If the deserialized JSON object was missing any required properties.
111+
* @throws IOException If an error occurs while reading the MCPApprovalResponseRequestItem.
112+
*/
113+
@Generated
114+
public static MCPApprovalResponseRequestItem fromJson(JsonReader jsonReader) throws IOException {
115+
return jsonReader.readObject(reader -> {
116+
String id = null;
117+
String approvalRequestId = null;
118+
boolean approve = false;
119+
ItemType type = ItemType.MCP_APPROVAL_RESPONSE;
120+
while (reader.nextToken() != JsonToken.END_OBJECT) {
121+
String fieldName = reader.getFieldName();
122+
reader.nextToken();
123+
124+
if ("id".equals(fieldName)) {
125+
id = reader.getString();
126+
} else if ("approval_request_id".equals(fieldName)) {
127+
approvalRequestId = reader.getString();
128+
} else if ("approve".equals(fieldName)) {
129+
approve = reader.getBoolean();
130+
} else if ("type".equals(fieldName)) {
131+
type = ItemType.fromString(reader.getString());
132+
} else {
133+
reader.skipChildren();
134+
}
135+
}
136+
MCPApprovalResponseRequestItem deserializedMCPApprovalResponseRequestItem
137+
= new MCPApprovalResponseRequestItem(approvalRequestId, approve);
138+
deserializedMCPApprovalResponseRequestItem.setId(id);
139+
deserializedMCPApprovalResponseRequestItem.type = type;
140+
141+
return deserializedMCPApprovalResponseRequestItem;
142+
});
143+
}
144+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
// Code generated by Microsoft (R) TypeSpec Code Generator.
4+
5+
package com.azure.ai.voicelive.models;
6+
7+
import com.azure.core.annotation.Generated;
8+
import com.azure.core.util.ExpandableStringEnum;
9+
import java.util.Collection;
10+
11+
/**
12+
* The available set of MCP approval types.
13+
*/
14+
public final class MCPApprovalType extends ExpandableStringEnum<MCPApprovalType> {
15+
/**
16+
* Approval is never required.
17+
*/
18+
@Generated
19+
public static final MCPApprovalType NEVER = fromString("never");
20+
21+
/**
22+
* Approval is always required.
23+
*/
24+
@Generated
25+
public static final MCPApprovalType ALWAYS = fromString("always");
26+
27+
/**
28+
* Creates a new instance of MCPApprovalType value.
29+
*
30+
* @deprecated Use the {@link #fromString(String)} factory method.
31+
*/
32+
@Generated
33+
@Deprecated
34+
public MCPApprovalType() {
35+
}
36+
37+
/**
38+
* Creates or finds a MCPApprovalType from its string representation.
39+
*
40+
* @param name a name to look for.
41+
* @return the corresponding MCPApprovalType.
42+
*/
43+
@Generated
44+
public static MCPApprovalType fromString(String name) {
45+
return fromString(name, MCPApprovalType.class);
46+
}
47+
48+
/**
49+
* Gets known MCPApprovalType values.
50+
*
51+
* @return known MCPApprovalType values.
52+
*/
53+
@Generated
54+
public static Collection<MCPApprovalType> values() {
55+
return values(MCPApprovalType.class);
56+
}
57+
}

0 commit comments

Comments
 (0)