-
Notifications
You must be signed in to change notification settings - Fork 4
XS✔ ◾ ✨ Custom prompts - Default built-in MCP servers to selected #770
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
efc8f5a
Initial plan
Copilot 4af4625
feat: auto-select built-in MCP servers for new custom prompts and loc…
Copilot 25b6ab0
make tools selected correctly
yaqi-lyu fc431f7
refactor to make it clean
yaqi-lyu 0a3caf7
perserve the selected mcp servers
yaqi-lyu 92f1b3a
decouple connecting with selected servers
yaqi-lyu 5f77b9b
Update src/ui/src/components/settings/custom-prompt/PromptForm.tsx
yaqi-lyu 43ce4c4
fix copilot feedback
yaqi-lyu 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import type { MCPServerConfig } from "../types/mcp"; | ||
| import { ensureBuiltinServerIds, getBuiltinServerIds, getConnectedOrBuiltinIds } from "./mcp-utils"; | ||
|
|
||
| describe("getBuiltinServerIds", () => { | ||
| it("returns only ids of built-in servers", () => { | ||
| const servers: MCPServerConfig[] = [ | ||
| { id: "builtin-1", name: "Built-in Server 1", transport: "inMemory", builtin: true }, | ||
| { | ||
| id: "external-1", | ||
| name: "External Server", | ||
| transport: "streamableHttp", | ||
| url: "http://example.com", | ||
| }, | ||
| { id: "builtin-2", name: "Built-in Server 2", transport: "inMemory", builtin: true }, | ||
| ]; | ||
|
|
||
| const result = getBuiltinServerIds(servers); | ||
|
|
||
| expect(result).toEqual(["builtin-1", "builtin-2"]); | ||
| }); | ||
|
|
||
| it("returns an empty array when there are no built-in servers", () => { | ||
| const servers: MCPServerConfig[] = [ | ||
| { | ||
| id: "external-1", | ||
| name: "External Server", | ||
| transport: "streamableHttp", | ||
| url: "http://example.com", | ||
| }, | ||
| ]; | ||
|
|
||
| const result = getBuiltinServerIds(servers); | ||
|
|
||
| expect(result).toEqual([]); | ||
| }); | ||
|
|
||
| it("returns an empty array when given an empty server list", () => { | ||
| const result = getBuiltinServerIds([]); | ||
|
|
||
| expect(result).toEqual([]); | ||
| }); | ||
|
|
||
| it("excludes servers with missing ids", () => { | ||
| const servers: MCPServerConfig[] = [ | ||
| { name: "No ID Server", transport: "inMemory", builtin: true } as unknown as MCPServerConfig, | ||
| { | ||
| id: "builtin-1", | ||
| name: "Built-in Server 1", | ||
| transport: "inMemory", | ||
| builtin: true, | ||
| } as MCPServerConfig, | ||
| ]; | ||
|
|
||
| const result = getBuiltinServerIds(servers); | ||
|
|
||
| expect(result).toEqual(["builtin-1"]); | ||
| }); | ||
| }); | ||
|
|
||
| describe("getConnectedOrBuiltinIds", () => { | ||
| it("includes built-in and connected servers", () => { | ||
| const servers: MCPServerConfig[] = [ | ||
| { id: "builtin-1", name: "Built-in", transport: "inMemory", builtin: true }, | ||
| { | ||
| id: "connected-1", | ||
| name: "Connected", | ||
| transport: "streamableHttp", | ||
| url: "http://example.com", | ||
| enabled: true, | ||
| }, | ||
| { | ||
| id: "disconnected-1", | ||
| name: "Disconnected", | ||
| transport: "streamableHttp", | ||
| url: "http://example.com", | ||
| enabled: false, | ||
| }, | ||
| ]; | ||
|
|
||
| const result = getConnectedOrBuiltinIds(servers); | ||
|
|
||
| expect(result).toEqual(new Set(["builtin-1", "connected-1"])); | ||
| }); | ||
|
|
||
| it("treats servers without explicit enabled flag as connected", () => { | ||
| const servers: MCPServerConfig[] = [ | ||
| { | ||
| id: "implicit-1", | ||
| name: "Implicit", | ||
| transport: "streamableHttp", | ||
| url: "http://example.com", | ||
| }, | ||
| ]; | ||
|
|
||
| const result = getConnectedOrBuiltinIds(servers); | ||
|
|
||
| expect(result).toEqual(new Set(["implicit-1"])); | ||
| }); | ||
|
|
||
| it("returns an empty set when given an empty list", () => { | ||
| expect(getConnectedOrBuiltinIds([])).toEqual(new Set()); | ||
| }); | ||
| }); | ||
|
|
||
| describe("ensureBuiltinServerIds", () => { | ||
| it("preserves selected disabled servers while adding missing built-ins", () => { | ||
| const servers: MCPServerConfig[] = [ | ||
| { id: "builtin-1", name: "Built-in", transport: "inMemory", builtin: true }, | ||
| { | ||
| id: "disabled-1", | ||
| name: "Disabled External", | ||
| transport: "streamableHttp", | ||
| url: "http://example.com", | ||
| enabled: false, | ||
| }, | ||
| { | ||
| id: "enabled-1", | ||
| name: "Enabled External", | ||
| transport: "streamableHttp", | ||
| url: "http://example.com", | ||
| enabled: true, | ||
| }, | ||
| ]; | ||
|
|
||
| expect(ensureBuiltinServerIds(["disabled-1"], servers)).toEqual(["disabled-1", "builtin-1"]); | ||
| }); | ||
|
|
||
| it("avoids duplicating built-in ids that are already selected", () => { | ||
| const servers: MCPServerConfig[] = [ | ||
| { id: "builtin-1", name: "Built-in", transport: "inMemory", builtin: true }, | ||
| ]; | ||
|
|
||
| expect(ensureBuiltinServerIds(["builtin-1"], servers)).toEqual(["builtin-1"]); | ||
| }); | ||
| }); |
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,37 @@ | ||
| import type { MCPServerConfig } from "../types/mcp"; | ||
|
|
||
| /** | ||
| * Returns the IDs of built-in MCP servers from the given list. | ||
| * Used to pre-select built-in servers when creating a new custom prompt. | ||
| * The id guard defends against deserialized storage objects with missing ids. | ||
| */ | ||
| export function getBuiltinServerIds(servers: readonly MCPServerConfig[]): string[] { | ||
| return servers | ||
| .filter((s) => s.builtin) | ||
| .map((s) => s.id) | ||
| .filter((id): id is string => !!id); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the IDs of servers that are either built-in or currently connected (enabled). | ||
| * Used to compute which servers are selectable in the prompt editor. | ||
| */ | ||
| export function getConnectedOrBuiltinIds(servers: readonly MCPServerConfig[]): Set<string> { | ||
| return new Set( | ||
| servers | ||
| .filter((s) => s.builtin || s.enabled !== false) | ||
| .map((s) => s.id) | ||
| .filter((id): id is string => !!id), | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Preserves the current prompt selection while ensuring built-in servers stay selected. | ||
| * This avoids dropping temporarily disabled external servers from saved prompt configs. | ||
| */ | ||
| export function ensureBuiltinServerIds( | ||
| selectedServerIds: readonly string[] | undefined, | ||
| servers: readonly MCPServerConfig[], | ||
| ): string[] { | ||
| return [...new Set([...(selectedServerIds ?? []), ...getBuiltinServerIds(servers)])]; | ||
| } |
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
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.