-
Notifications
You must be signed in to change notification settings - Fork 54
feat: enable MCP sampling support #380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ashu Bansal (im-ashu)
wants to merge
4
commits into
microsoft:main
Choose a base branch
from
im-ashu:feat/enable-mcp-sampling-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d6900f0
feat: enable MCP sampling support
im-ashu 37d5e9f
fix: implement real MCP sampling config and isolate sampling approval…
im-ashu 9616911
fix: address remaining review comments (annotation ordering comment, …
im-ashu e3b68ee
Merge remote-tracking branch 'upstream/main' into feat/enable-mcp-sam…
im-ashu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
...eclipse.core.test/src/com/microsoft/copilot/eclipse/core/chat/ChatEventsManagerTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| package com.microsoft.copilot.eclipse.core.chat; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import com.microsoft.copilot.eclipse.core.lsp.protocol.McpSamplingConfig; | ||
|
|
||
| class ChatEventsManagerTests { | ||
|
|
||
| private ChatEventsManager chatEventsManager; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| chatEventsManager = new ChatEventsManager(); | ||
| } | ||
|
|
||
| @Test | ||
| void getMcpSamplingConfig_returnsDefaultConfigWhenNoProviderRegistered() { | ||
| McpSamplingConfig config = chatEventsManager.getMcpSamplingConfig("test-server"); | ||
|
|
||
| assertFalse(config.alwaysAllow()); | ||
| assertFalse(config.alwaysDeny()); | ||
| assertEquals(List.of(), config.allowedModels()); | ||
| } | ||
|
|
||
| @Test | ||
| void getMcpSamplingConfig_delegatesToRegisteredProvider() { | ||
| McpSamplingConfigProvider provider = mock(McpSamplingConfigProvider.class); | ||
| McpSamplingConfig expected = new McpSamplingConfig(true, false, List.of()); | ||
| when(provider.getMcpSamplingConfig("test-server")).thenReturn(expected); | ||
|
|
||
| chatEventsManager.registerMcpSamplingConfigProvider(provider); | ||
|
|
||
| assertEquals(expected, chatEventsManager.getMcpSamplingConfig("test-server")); | ||
| } | ||
|
|
||
| @Test | ||
| void getMcpSamplingConfig_fallsBackToDefaultAfterUnregister() { | ||
| McpSamplingConfigProvider provider = mock(McpSamplingConfigProvider.class); | ||
| chatEventsManager.registerMcpSamplingConfigProvider(provider); | ||
| chatEventsManager.unregisterMcpSamplingConfigProvider(provider); | ||
|
|
||
| McpSamplingConfig config = chatEventsManager.getMcpSamplingConfig("test-server"); | ||
|
|
||
| assertFalse(config.alwaysAllow()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...t.eclipse.core/src/com/microsoft/copilot/eclipse/core/chat/McpSamplingConfigProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| package com.microsoft.copilot.eclipse.core.chat; | ||
|
|
||
| import com.microsoft.copilot.eclipse.core.lsp.protocol.McpSamplingConfig; | ||
|
|
||
| /** | ||
| * Provides the persisted MCP sampling (inference) approval preferences for a server, so that the | ||
| * {@code copilot/readMcpSamplingConfig} language server request reflects the user's actual | ||
| * previously-cached decisions instead of always requiring re-confirmation. | ||
| */ | ||
| public interface McpSamplingConfigProvider { | ||
|
|
||
| /** | ||
| * Reads the sampling preferences for the given MCP server. | ||
| * | ||
| * @param serverName the MCP server name, may be {@code null} | ||
| * @return the persisted sampling config for the server | ||
| */ | ||
| McpSamplingConfig getMcpSamplingConfig(String serverName); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...t.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/protocol/McpSamplingConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| package com.microsoft.copilot.eclipse.core.lsp.protocol; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * User preferences for MCP sampling requests from a server. | ||
| */ | ||
| public record McpSamplingConfig(boolean alwaysAllow, boolean alwaysDeny, List<String> allowedModels) { | ||
| } |
10 changes: 10 additions & 0 deletions
10
...core/src/com/microsoft/copilot/eclipse/core/lsp/protocol/ReadMcpSamplingConfigParams.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| package com.microsoft.copilot.eclipse.core.lsp.protocol; | ||
|
|
||
| /** | ||
| * Parameters for reading MCP sampling preferences. | ||
| */ | ||
| public record ReadMcpSamplingConfigParams(String serverName) { | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.