Skip to content

Commit 297a332

Browse files
committed
feat(tui): group MCP integrations in connection dialog
1 parent 7f9e5e9 commit 297a332

7 files changed

Lines changed: 30 additions & 2 deletions

File tree

‎packages/client/src/promise/generated/types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,6 +2133,7 @@ export type SessionMessagesResponse = {
21332133
export type IntegrationInfo = {
21342134
id: string
21352135
name: string
2136+
metadata?: { [x: string]: any }
21362137
methods: Array<IntegrationMethod>
21372138
connections: Array<ConnectionInfo>
21382139
}

‎packages/core/src/integration.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ const layer = Layer.effect(
361361
Info.make({
362362
id: entry.ref.id,
363363
name: entry.ref.name,
364+
...(entry.ref.metadata === undefined ? {} : { metadata: entry.ref.metadata }),
364365
methods: entry.methods,
365366
connections,
366367
})

‎packages/core/src/mcp/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ export const layer = (options?: Options) =>
228228
.transform((draft) => {
229229
draft.update(integrationID, (ref) => {
230230
ref.name = name
231+
ref.metadata = { source: "mcp" }
231232
})
232233
draft.method.update({
233234
integrationID,

‎packages/core/test/integration.test.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,21 @@ describe("Integration", () => {
5252
const openai = Integration.ID.make("openai")
5353

5454
yield* integrations
55-
.transform((editor) => editor.update(openai, (integration) => (integration.name = "OpenAI")))
55+
.transform((editor) =>
56+
editor.update(openai, (integration) => {
57+
integration.name = "OpenAI"
58+
integration.metadata = { source: "plugin", featured: true }
59+
}),
60+
)
5661
.pipe(Scope.provide(scope))
5762
expect(yield* integrations.get(openai)).toEqual(
58-
Integration.Info.make({ id: openai, name: "OpenAI", methods: [], connections: [] }),
63+
Integration.Info.make({
64+
id: openai,
65+
name: "OpenAI",
66+
metadata: { source: "plugin", featured: true },
67+
methods: [],
68+
connections: [],
69+
}),
5970
)
6071

6172
yield* Scope.close(scope, Exit.void)

‎packages/schema/src/integration.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ export interface Ref extends Schema.Schema.Type<typeof Ref> {}
5959
export const Ref = Schema.Struct({
6060
id: ID,
6161
name: Schema.String,
62+
metadata: optional(Schema.Record(Schema.String, Schema.Any)),
6263
}).annotate({ identifier: "Integration.Ref" })
6364

6465
export const Info = Schema.Struct({
6566
id: ID,
6667
name: Schema.String,
68+
metadata: optional(Schema.Record(Schema.String, Schema.Any)),
6769
methods: Schema.Array(Method),
6870
connections: Schema.Array(Connection.Info),
6971
}).annotate({ identifier: "Integration.Info" })

‎packages/tui/src/component/dialog-integration.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const SUBMIT = Symbol("submit")
4545
export function integrationOptions(list: IntegrationInfo[]) {
4646
return list.toSorted(
4747
(a, b) =>
48+
Number(b.metadata?.source === "mcp") - Number(a.metadata?.source === "mcp") ||
4849
(INTEGRATION_PRIORITY[a.id] ?? 99) - (INTEGRATION_PRIORITY[b.id] ?? 99) ||
4950
a.name.localeCompare(b.name) ||
5051
a.id.localeCompare(b.id),
@@ -103,6 +104,7 @@ export function DialogIntegration(
103104
let category = "Services"
104105
if (integration.id in INTEGRATION_PRIORITY) category = "Popular"
105106
if (provider) category = "Web search"
107+
if (integration.metadata?.source === "mcp") category = "MCP"
106108
return {
107109
title: integration.name,
108110
value: integration.id,

‎packages/tui/test/cli/cmd/tui/integration-options.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ describe("integrationOptions", () => {
2424
]).map((item) => item.id),
2525
).toEqual(["openai", "anthropic", "mistral", "custom-z"])
2626
})
27+
28+
test("keeps MCP integrations above popular integrations without relying on their IDs", () => {
29+
expect(
30+
integrationOptions([
31+
integration({ id: "openai", name: "OpenAI" }),
32+
integration({ id: "linear", name: "Linear", metadata: { source: "mcp" } }),
33+
integration({ id: "github", name: "GitHub", metadata: { source: "mcp" } }),
34+
]).map((item) => item.id),
35+
).toEqual(["github", "linear", "openai"])
36+
})
2737
})
2838

2939
describe("connectMethods", () => {

0 commit comments

Comments
 (0)