@burdenoff/microfe-botmanor 2026.813.1 → 2026.821.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/botlit/hooks/useMCPServers.js +60 -49
- package/dist/botlit/hooks/useMCPServers.js.map +1 -1
- package/dist/botlit/pages/DashboardPage.js +178 -254
- package/dist/botlit/pages/DashboardPage.js.map +1 -1
- package/dist/botlit/pages/MCPServerDetailPage.js +295 -238
- package/dist/botlit/pages/MCPServerDetailPage.js.map +1 -1
- package/dist/botlit/pages/SettingsPage.js +272 -603
- package/dist/botlit/pages/SettingsPage.js.map +1 -1
- package/dist/generated/wspace-operations.js +45 -29
- package/dist/generated/wspace-operations.js.map +1 -1
- package/dist/generated/wspace-types.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,134 +1,145 @@
|
|
|
1
1
|
import { buildMutationInput as e, fieldsOf as t } from "./internal/mutationInput.js";
|
|
2
|
-
import { CreateMcpConnectionDocument as n, DeleteMcpConnectionDocument as r, GetMcpConnectionDocument as i, ListMcpConnectionsDocument as a, ListMcpResourcesDocument as o, ListMcpToolsDocument as s, TestMcpConnectionDocument as c, UpdateMcpConnectionDocument as l } from "../../generated/wspace-operations.js";
|
|
3
|
-
import { useWorkspaceId as
|
|
4
|
-
import { useCallback as
|
|
2
|
+
import { CreateMcpConnectionDocument as n, DeleteMcpConnectionDocument as r, GetMcpConnectionDocument as i, ListMcpConnectionsDocument as a, ListMcpResourcesDocument as o, ListMcpToolsDocument as s, TestMcpConnectionDocument as c, UpdateMcpConnectionDocument as l, UpdateMcpToolDocument as u } from "../../generated/wspace-operations.js";
|
|
3
|
+
import { useWorkspaceId as d, useWorkspaceMutation as f, useWorkspaceQuery as p } from "./internal/workspaceGateway.js";
|
|
4
|
+
import { useCallback as m, useMemo as h } from "react";
|
|
5
5
|
//#region src/botlit/hooks/useMCPServers.ts
|
|
6
|
-
var
|
|
6
|
+
var g = 100, _ = t({
|
|
7
7
|
config: !0,
|
|
8
8
|
credentials: !0,
|
|
9
9
|
metadata: !0,
|
|
10
10
|
name: !0,
|
|
11
11
|
type: !0,
|
|
12
12
|
workspaceId: !0
|
|
13
|
-
}),
|
|
13
|
+
}), v = t({
|
|
14
14
|
config: !0,
|
|
15
15
|
credentials: !0,
|
|
16
16
|
metadata: !0,
|
|
17
17
|
name: !0
|
|
18
|
-
}),
|
|
19
|
-
function
|
|
18
|
+
}), y = [], b = [], x = [];
|
|
19
|
+
function S(e) {
|
|
20
20
|
return e === "CONNECTED";
|
|
21
21
|
}
|
|
22
|
-
function
|
|
22
|
+
function C(e) {
|
|
23
23
|
let t = e.config?.url;
|
|
24
24
|
return typeof t == "string" ? t : void 0;
|
|
25
25
|
}
|
|
26
|
-
function
|
|
26
|
+
function w(e) {
|
|
27
27
|
let t = e.config?.description;
|
|
28
28
|
return typeof t == "string" ? t : void 0;
|
|
29
29
|
}
|
|
30
|
-
function w(e) {
|
|
31
|
-
return e?.listMCPConnections ?? v;
|
|
32
|
-
}
|
|
33
30
|
function T(e) {
|
|
34
|
-
return e?.
|
|
31
|
+
return e?.listMCPConnections ?? y;
|
|
35
32
|
}
|
|
36
33
|
function E(e) {
|
|
37
|
-
return e?.
|
|
34
|
+
return e?.getMCPConnection ?? null;
|
|
38
35
|
}
|
|
39
36
|
function D(e) {
|
|
40
|
-
return e?.
|
|
37
|
+
return e?.listMCPTools ?? b;
|
|
41
38
|
}
|
|
42
39
|
function O(e) {
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
return e?.listMCPResources ?? x;
|
|
41
|
+
}
|
|
42
|
+
function k(e) {
|
|
43
|
+
let t = d(), n = e?.search?.trim().toLowerCase() ?? "";
|
|
44
|
+
return p({
|
|
45
45
|
document: a,
|
|
46
|
-
variables:
|
|
46
|
+
variables: h(() => ({
|
|
47
47
|
filters: { workspaceId: t },
|
|
48
48
|
pagination: {
|
|
49
|
-
limit:
|
|
49
|
+
limit: g,
|
|
50
50
|
offset: 0
|
|
51
51
|
}
|
|
52
52
|
}), [t]),
|
|
53
|
-
select:
|
|
54
|
-
let t =
|
|
53
|
+
select: m((e) => {
|
|
54
|
+
let t = T(e);
|
|
55
55
|
return n ? t.filter((e) => e.name.toLowerCase().includes(n)) : t;
|
|
56
56
|
}, [n]),
|
|
57
|
-
fallback:
|
|
57
|
+
fallback: y,
|
|
58
58
|
enabled: !!t,
|
|
59
59
|
errorMessage: "Failed to load MCP servers"
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
|
-
function
|
|
63
|
-
return
|
|
62
|
+
function A(e) {
|
|
63
|
+
return p({
|
|
64
64
|
document: i,
|
|
65
|
-
variables:
|
|
66
|
-
select:
|
|
65
|
+
variables: h(() => ({ id: e ?? "" }), [e]),
|
|
66
|
+
select: E,
|
|
67
67
|
fallback: null,
|
|
68
68
|
enabled: !!e,
|
|
69
69
|
errorMessage: "Failed to load MCP server"
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
|
-
function
|
|
73
|
-
return
|
|
72
|
+
function j(e) {
|
|
73
|
+
return p({
|
|
74
74
|
document: s,
|
|
75
|
-
variables:
|
|
76
|
-
select:
|
|
77
|
-
fallback:
|
|
75
|
+
variables: h(() => ({ connectionId: e ?? "" }), [e]),
|
|
76
|
+
select: D,
|
|
77
|
+
fallback: b,
|
|
78
78
|
enabled: !!e,
|
|
79
79
|
errorMessage: "Failed to load MCP tools"
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
|
-
function
|
|
83
|
-
return
|
|
82
|
+
function M(e) {
|
|
83
|
+
return p({
|
|
84
84
|
document: o,
|
|
85
|
-
variables:
|
|
86
|
-
select:
|
|
87
|
-
fallback:
|
|
85
|
+
variables: h(() => ({ connectionId: e ?? "" }), [e]),
|
|
86
|
+
select: O,
|
|
87
|
+
fallback: x,
|
|
88
88
|
enabled: !!e,
|
|
89
89
|
errorMessage: "Failed to load MCP resources"
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
|
-
function
|
|
93
|
-
let t =
|
|
94
|
-
return
|
|
92
|
+
function N() {
|
|
93
|
+
let t = d();
|
|
94
|
+
return f({
|
|
95
95
|
document: n,
|
|
96
|
-
variables:
|
|
96
|
+
variables: m((n) => ({ input: e({
|
|
97
97
|
...n,
|
|
98
98
|
workspaceId: t
|
|
99
|
-
},
|
|
99
|
+
}, _) }), [t]),
|
|
100
100
|
select: (e) => e?.createMCPConnection,
|
|
101
101
|
errorMessage: "Failed to connect MCP server"
|
|
102
102
|
});
|
|
103
103
|
}
|
|
104
|
-
function
|
|
105
|
-
return
|
|
104
|
+
function P() {
|
|
105
|
+
return f({
|
|
106
106
|
document: l,
|
|
107
107
|
variables: ({ serverId: t, input: n }) => ({
|
|
108
108
|
id: t,
|
|
109
|
-
input: e(n,
|
|
109
|
+
input: e(n, v)
|
|
110
110
|
}),
|
|
111
111
|
select: (e) => e?.updateMCPConnection,
|
|
112
112
|
errorMessage: "Failed to update MCP server"
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
|
-
function
|
|
116
|
-
return
|
|
115
|
+
function F() {
|
|
116
|
+
return f({
|
|
117
117
|
document: r,
|
|
118
118
|
variables: (e) => ({ id: e }),
|
|
119
119
|
select: (e) => e?.deleteMCPConnection,
|
|
120
120
|
errorMessage: "Failed to disconnect MCP server"
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
|
-
function
|
|
124
|
-
return
|
|
123
|
+
function I() {
|
|
124
|
+
return f({
|
|
125
125
|
document: c,
|
|
126
126
|
variables: (e) => ({ id: e }),
|
|
127
127
|
select: (e) => e?.testMCPConnection,
|
|
128
128
|
errorMessage: "Failed to test MCP connection"
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
|
+
function L() {
|
|
132
|
+
return f({
|
|
133
|
+
document: u,
|
|
134
|
+
variables: ({ toolId: e, input: t }) => ({
|
|
135
|
+
id: e,
|
|
136
|
+
input: t
|
|
137
|
+
}),
|
|
138
|
+
select: (e) => e?.updateMCPTool,
|
|
139
|
+
errorMessage: "Failed to update MCP tool risk level"
|
|
140
|
+
});
|
|
141
|
+
}
|
|
131
142
|
//#endregion
|
|
132
|
-
export {
|
|
143
|
+
export { S as isMCPServerHealthy, w as mcpServerDescription, C as mcpServerEndpoint, N as useCreateMCPServer, F as useDeleteMCPServer, M as useMCPResources, A as useMCPServer, k as useMCPServers, j as useMCPTools, I as useTestMCPConnection, P as useUpdateMCPServer, L as useUpdateMCPTool };
|
|
133
144
|
|
|
134
145
|
//# sourceMappingURL=useMCPServers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMCPServers.js","names":[],"sources":["../../../src/botlit/hooks/useMCPServers.ts"],"sourcesContent":["/**\n * MCP Servers Hooks\n * @module botlit/hooks\n *\n * Backed by the live `listMCPConnections` / `getMCPConnection` / `listMCPTools`\n * / `listMCPResources` operations and the create/update/delete/test mutations on\n * wspace-botlit-svc.\n *\n * The service models an MCP server as an `MCPConnection`: `type` is the\n * transport, `config` holds the endpoint, and `status` reports health.\n */\n\nimport { useCallback, useMemo } from 'react';\nimport {\n CreateMcpConnectionDocument,\n DeleteMcpConnectionDocument,\n GetMcpConnectionDocument,\n ListMcpConnectionsDocument,\n ListMcpResourcesDocument,\n ListMcpToolsDocument,\n TestMcpConnectionDocument,\n UpdateMcpConnectionDocument,\n type CreateMcpConnectionMutation,\n type DeleteMcpConnectionMutation,\n type GetMcpConnectionQuery,\n type ListMcpConnectionsQuery,\n type ListMcpResourcesQuery,\n type ListMcpToolsQuery,\n type TestMcpConnectionMutation,\n type UpdateMcpConnectionMutation,\n} from '../../generated/wspace-operations';\nimport type {\n CreateMcpConnectionInput,\n UpdateMcpConnectionInput,\n} from '../../generated/wspace-types';\nimport type { BaseFilter } from '../types';\nimport { buildMutationInput, fieldsOf, type GraphQLInput } from './internal/mutationInput';\nimport {\n useWorkspaceId,\n useWorkspaceMutation,\n useWorkspaceQuery,\n type QueryResult,\n} from './internal/workspaceGateway';\n\nconst LIST_LIMIT = 100;\n\nexport interface MCPServerRecord {\n id: string;\n name: string;\n /** Transport / server kind, e.g. `HTTP_JSON`. */\n type: string;\n status: string;\n config: Record<string, unknown>;\n credentialsHash?: string | null;\n errorMessage?: string | null;\n lastConnectedAt?: string | null;\n lastErrorAt?: string | null;\n deletedAt?: string | null;\n metadata?: Record<string, unknown> | null;\n createdAt: string;\n updatedAt: string;\n createdById: string;\n updatedById: string;\n workspaceId: string;\n}\n\nexport interface MCPToolRecord {\n name: string;\n description: string;\n inputSchema: Record<string, unknown>;\n}\n\nexport interface MCPResourceRecord {\n name: string;\n uri: string;\n description?: string | null;\n mimeType?: string | null;\n}\n\n/** `CreateMCPConnectionInput` minus the `workspaceId` the hook supplies. */\nexport type CreateMCPServerVariables = Omit<GraphQLInput<CreateMcpConnectionInput>, 'workspaceId'>;\n\nexport interface UpdateMCPServerVariables {\n serverId: string;\n input: GraphQLInput<UpdateMcpConnectionInput>;\n}\n\nconst CREATE_CONNECTION_FIELDS = fieldsOf<CreateMcpConnectionInput>({\n config: true,\n credentials: true,\n metadata: true,\n name: true,\n type: true,\n workspaceId: true,\n});\n\nconst UPDATE_CONNECTION_FIELDS = fieldsOf<UpdateMcpConnectionInput>({\n config: true,\n credentials: true,\n metadata: true,\n name: true,\n});\n\nconst NO_SERVERS: MCPServerRecord[] = [];\nconst NO_TOOLS: MCPToolRecord[] = [];\nconst NO_RESOURCES: MCPResourceRecord[] = [];\n\n/** `CONNECTED` is the only status that means the server is usable right now. */\nexport function isMCPServerHealthy(status: string | null | undefined): boolean {\n return status === 'CONNECTED';\n}\n\nexport function isMCPServerUnhealthy(status: string | null | undefined): boolean {\n return status === 'ERROR' || status === 'DISCONNECTED';\n}\n\n/** Endpoint the connection points at — the service stores it on the free-form config. */\nexport function mcpServerEndpoint(server: Pick<MCPServerRecord, 'config'>): string | undefined {\n const url = server.config?.url;\n return typeof url === 'string' ? url : undefined;\n}\n\n/** Optional human description the UI stores alongside the endpoint. */\nexport function mcpServerDescription(server: Pick<MCPServerRecord, 'config'>): string | undefined {\n const description = server.config?.description;\n return typeof description === 'string' ? description : undefined;\n}\n\nfunction selectServers(data: ListMcpConnectionsQuery | undefined): MCPServerRecord[] {\n return data?.listMCPConnections ?? NO_SERVERS;\n}\n\nfunction selectServer(data: GetMcpConnectionQuery | undefined): MCPServerRecord | null {\n return data?.getMCPConnection ?? null;\n}\n\nfunction selectTools(data: ListMcpToolsQuery | undefined): MCPToolRecord[] {\n return data?.listMCPTools ?? NO_TOOLS;\n}\n\nfunction selectResources(data: ListMcpResourcesQuery | undefined): MCPResourceRecord[] {\n return data?.listMCPResources ?? NO_RESOURCES;\n}\n\nexport const mcpServerKeys = {\n all: ['mcpServers'] as const,\n lists: () => [...mcpServerKeys.all, 'list'] as const,\n list: (filter?: BaseFilter) => [...mcpServerKeys.lists(), filter] as const,\n details: () => [...mcpServerKeys.all, 'detail'] as const,\n detail: (id: string) => [...mcpServerKeys.details(), id] as const,\n resources: (serverId?: string) => [...mcpServerKeys.all, 'resources', serverId] as const,\n tools: (serverId?: string) => [...mcpServerKeys.all, 'tools', serverId] as const,\n};\n\nexport function useMCPServers(filter?: BaseFilter): QueryResult<MCPServerRecord[]> {\n const workspaceId = useWorkspaceId();\n const search = filter?.search?.trim().toLowerCase() ?? '';\n\n const variables = useMemo(\n () => ({\n // MCPConnectionFilterInput has no free-text field — search is narrowed on the client.\n filters: { workspaceId },\n pagination: { limit: LIST_LIMIT, offset: 0 },\n }),\n [workspaceId]\n );\n\n const select = useCallback(\n (data: ListMcpConnectionsQuery | undefined): MCPServerRecord[] => {\n const rows = selectServers(data);\n if (!search) return rows;\n return rows.filter((row) => row.name.toLowerCase().includes(search));\n },\n [search]\n );\n\n return useWorkspaceQuery<ListMcpConnectionsQuery, MCPServerRecord[]>({\n document: ListMcpConnectionsDocument,\n variables,\n select,\n fallback: NO_SERVERS,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load MCP servers',\n });\n}\n\nexport function useMCPServer(serverId: string | undefined): QueryResult<MCPServerRecord | null> {\n const variables = useMemo(() => ({ id: serverId ?? '' }), [serverId]);\n\n return useWorkspaceQuery<GetMcpConnectionQuery, MCPServerRecord | null>({\n document: GetMcpConnectionDocument,\n variables,\n select: selectServer,\n fallback: null,\n enabled: Boolean(serverId),\n errorMessage: 'Failed to load MCP server',\n });\n}\n\nexport function useMCPTools(serverId: string | undefined): QueryResult<MCPToolRecord[]> {\n const variables = useMemo(() => ({ connectionId: serverId ?? '' }), [serverId]);\n\n return useWorkspaceQuery<ListMcpToolsQuery, MCPToolRecord[]>({\n document: ListMcpToolsDocument,\n variables,\n select: selectTools,\n fallback: NO_TOOLS,\n enabled: Boolean(serverId),\n errorMessage: 'Failed to load MCP tools',\n });\n}\n\nexport function useMCPResources(serverId: string | undefined): QueryResult<MCPResourceRecord[]> {\n const variables = useMemo(() => ({ connectionId: serverId ?? '' }), [serverId]);\n\n return useWorkspaceQuery<ListMcpResourcesQuery, MCPResourceRecord[]>({\n document: ListMcpResourcesDocument,\n variables,\n select: selectResources,\n fallback: NO_RESOURCES,\n enabled: Boolean(serverId),\n errorMessage: 'Failed to load MCP resources',\n });\n}\n\nexport function useCreateMCPServer() {\n const workspaceId = useWorkspaceId();\n\n const variables = useCallback(\n (input: CreateMCPServerVariables) => ({\n input: buildMutationInput({ ...input, workspaceId }, CREATE_CONNECTION_FIELDS),\n }),\n [workspaceId]\n );\n\n return useWorkspaceMutation<\n CreateMcpConnectionMutation,\n CreateMCPServerVariables,\n MCPServerRecord\n >({\n document: CreateMcpConnectionDocument,\n variables,\n select: (data) => data?.createMCPConnection,\n errorMessage: 'Failed to connect MCP server',\n });\n}\n\nexport function useUpdateMCPServer() {\n return useWorkspaceMutation<\n UpdateMcpConnectionMutation,\n UpdateMCPServerVariables,\n MCPServerRecord\n >({\n document: UpdateMcpConnectionDocument,\n variables: ({ serverId, input }) => ({\n id: serverId,\n input: buildMutationInput(input, UPDATE_CONNECTION_FIELDS),\n }),\n select: (data) => data?.updateMCPConnection,\n errorMessage: 'Failed to update MCP server',\n });\n}\n\nexport function useDeleteMCPServer() {\n return useWorkspaceMutation<DeleteMcpConnectionMutation, string, boolean>({\n document: DeleteMcpConnectionDocument,\n variables: (serverId) => ({ id: serverId }),\n select: (data) => data?.deleteMCPConnection,\n errorMessage: 'Failed to disconnect MCP server',\n });\n}\n\nexport function useTestMCPConnection() {\n return useWorkspaceMutation<TestMcpConnectionMutation, string, boolean>({\n document: TestMcpConnectionDocument,\n variables: (serverId) => ({ id: serverId }),\n select: (data) => data?.testMCPConnection,\n errorMessage: 'Failed to test MCP connection',\n });\n}\n"],"mappings":";;;;;AA4CA,IAAM,IAAa,KA2Cb,IAA2B,EAAmC;CAClE,QAAQ;CACR,aAAa;CACb,UAAU;CACV,MAAM;CACN,MAAM;CACN,aAAa;CACd,CAAC,EAEI,IAA2B,EAAmC;CAClE,QAAQ;CACR,aAAa;CACb,UAAU;CACV,MAAM;CACP,CAAC,EAEI,IAAgC,EAAE,EAClC,IAA4B,EAAE,EAC9B,IAAoC,EAAE;AAG5C,SAAgB,EAAmB,GAA4C;AAC7E,QAAO,MAAW;;AAQpB,SAAgB,EAAkB,GAA6D;CAC7F,IAAM,IAAM,EAAO,QAAQ;AAC3B,QAAO,OAAO,KAAQ,WAAW,IAAM,KAAA;;AAIzC,SAAgB,EAAqB,GAA6D;CAChG,IAAM,IAAc,EAAO,QAAQ;AACnC,QAAO,OAAO,KAAgB,WAAW,IAAc,KAAA;;AAGzD,SAAS,EAAc,GAA8D;AACnF,QAAO,GAAM,sBAAsB;;AAGrC,SAAS,EAAa,GAAiE;AACrF,QAAO,GAAM,oBAAoB;;AAGnC,SAAS,EAAY,GAAsD;AACzE,QAAO,GAAM,gBAAgB;;AAG/B,SAAS,EAAgB,GAA8D;AACrF,QAAO,GAAM,oBAAoB;;AAanC,SAAgB,EAAc,GAAqD;CACjF,IAAM,IAAc,GAAgB,EAC9B,IAAS,GAAQ,QAAQ,MAAM,CAAC,aAAa,IAAI;AAoBvD,QAAO,EAA8D;EACnE,UAAU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ACnC,IAAI;GACJ,OAAO,EAAmB,GAAO,EAAyB;GAC3D;EACD,SAAS,MAAS,GAAM;EACxB,cAAc;EACf,CAAC;;AAGJ,SAAgB,IAAqB;AACnC,QAAO,EAAmE;EACxE,UAAU;EACV,YAAY,OAAc,EAAE,IAAI,GAAU;EAC1C,SAAS,MAAS,GAAM;EACxB,cAAc;EACf,CAAC;;AAGJ,SAAgB,IAAuB;AACrC,QAAO,EAAiE;EACtE,UAAU;EACV,YAAY,OAAc,EAAE,IAAI,GAAU;EAC1C,SAAS,MAAS,GAAM;EACxB,cAAc;EACf,CAAC"}
|
|
1
|
+
{"version":3,"file":"useMCPServers.js","names":[],"sources":["../../../src/botlit/hooks/useMCPServers.ts"],"sourcesContent":["/**\n * MCP Servers Hooks\n * @module botlit/hooks\n *\n * Backed by the live `listMCPConnections` / `getMCPConnection` / `listMCPTools`\n * / `listMCPResources` operations and the create/update/delete/test mutations on\n * wspace-botlit-svc.\n *\n * The service models an MCP server as an `MCPConnection`: `type` is the\n * transport, `config` holds the endpoint, and `status` reports health.\n */\n\nimport { useCallback, useMemo } from 'react';\nimport {\n CreateMcpConnectionDocument,\n DeleteMcpConnectionDocument,\n GetMcpConnectionDocument,\n ListMcpConnectionsDocument,\n ListMcpResourcesDocument,\n ListMcpToolsDocument,\n TestMcpConnectionDocument,\n UpdateMcpConnectionDocument,\n UpdateMcpToolDocument,\n type CreateMcpConnectionMutation,\n type DeleteMcpConnectionMutation,\n type GetMcpConnectionQuery,\n type ListMcpConnectionsQuery,\n type ListMcpResourcesQuery,\n type ListMcpToolsQuery,\n type TestMcpConnectionMutation,\n type UpdateMcpConnectionMutation,\n type UpdateMcpToolMutation,\n} from '../../generated/wspace-operations';\nimport type {\n CreateMcpConnectionInput,\n McpToolRiskLevel,\n UpdateMcpConnectionInput,\n UpdateMcpToolInput,\n} from '../../generated/wspace-types';\nimport type { BaseFilter } from '../types';\nimport { buildMutationInput, fieldsOf, type GraphQLInput } from './internal/mutationInput';\nimport {\n useWorkspaceId,\n useWorkspaceMutation,\n useWorkspaceQuery,\n type QueryResult,\n} from './internal/workspaceGateway';\n\nconst LIST_LIMIT = 100;\n\nexport interface MCPServerRecord {\n id: string;\n name: string;\n /** Transport / server kind, e.g. `HTTP_JSON`. */\n type: string;\n status: string;\n config: Record<string, unknown>;\n credentialsHash?: string | null;\n errorMessage?: string | null;\n lastConnectedAt?: string | null;\n lastErrorAt?: string | null;\n deletedAt?: string | null;\n metadata?: Record<string, unknown> | null;\n createdAt: string;\n updatedAt: string;\n createdById: string;\n updatedById: string;\n workspaceId: string;\n}\n\nexport interface MCPToolRecord {\n id: string;\n name: string;\n description: string;\n inputSchema: Record<string, unknown>;\n riskLevel: McpToolRiskLevel;\n}\n\nexport interface MCPResourceRecord {\n name: string;\n uri: string;\n description?: string | null;\n mimeType?: string | null;\n}\n\n/** `CreateMCPConnectionInput` minus the `workspaceId` the hook supplies. */\nexport type CreateMCPServerVariables = Omit<GraphQLInput<CreateMcpConnectionInput>, 'workspaceId'>;\n\nexport interface UpdateMCPServerVariables {\n serverId: string;\n input: GraphQLInput<UpdateMcpConnectionInput>;\n}\n\nexport interface UpdateMCPToolVariables {\n toolId: string;\n input: GraphQLInput<UpdateMcpToolInput>;\n}\n\nconst CREATE_CONNECTION_FIELDS = fieldsOf<CreateMcpConnectionInput>({\n config: true,\n credentials: true,\n metadata: true,\n name: true,\n type: true,\n workspaceId: true,\n});\n\nconst UPDATE_CONNECTION_FIELDS = fieldsOf<UpdateMcpConnectionInput>({\n config: true,\n credentials: true,\n metadata: true,\n name: true,\n});\n\nconst NO_SERVERS: MCPServerRecord[] = [];\nconst NO_TOOLS: MCPToolRecord[] = [];\nconst NO_RESOURCES: MCPResourceRecord[] = [];\n\n/** `CONNECTED` is the only status that means the server is usable right now. */\nexport function isMCPServerHealthy(status: string | null | undefined): boolean {\n return status === 'CONNECTED';\n}\n\nexport function isMCPServerUnhealthy(status: string | null | undefined): boolean {\n return status === 'ERROR' || status === 'DISCONNECTED';\n}\n\n/** Endpoint the connection points at — the service stores it on the free-form config. */\nexport function mcpServerEndpoint(server: Pick<MCPServerRecord, 'config'>): string | undefined {\n const url = server.config?.url;\n return typeof url === 'string' ? url : undefined;\n}\n\n/** Optional human description the UI stores alongside the endpoint. */\nexport function mcpServerDescription(server: Pick<MCPServerRecord, 'config'>): string | undefined {\n const description = server.config?.description;\n return typeof description === 'string' ? description : undefined;\n}\n\nfunction selectServers(data: ListMcpConnectionsQuery | undefined): MCPServerRecord[] {\n return data?.listMCPConnections ?? NO_SERVERS;\n}\n\nfunction selectServer(data: GetMcpConnectionQuery | undefined): MCPServerRecord | null {\n return data?.getMCPConnection ?? null;\n}\n\nfunction selectTools(data: ListMcpToolsQuery | undefined): MCPToolRecord[] {\n return data?.listMCPTools ?? NO_TOOLS;\n}\n\nfunction selectResources(data: ListMcpResourcesQuery | undefined): MCPResourceRecord[] {\n return data?.listMCPResources ?? NO_RESOURCES;\n}\n\nexport const mcpServerKeys = {\n all: ['mcpServers'] as const,\n lists: () => [...mcpServerKeys.all, 'list'] as const,\n list: (filter?: BaseFilter) => [...mcpServerKeys.lists(), filter] as const,\n details: () => [...mcpServerKeys.all, 'detail'] as const,\n detail: (id: string) => [...mcpServerKeys.details(), id] as const,\n resources: (serverId?: string) => [...mcpServerKeys.all, 'resources', serverId] as const,\n tools: (serverId?: string) => [...mcpServerKeys.all, 'tools', serverId] as const,\n};\n\nexport function useMCPServers(filter?: BaseFilter): QueryResult<MCPServerRecord[]> {\n const workspaceId = useWorkspaceId();\n const search = filter?.search?.trim().toLowerCase() ?? '';\n\n const variables = useMemo(\n () => ({\n // MCPConnectionFilterInput has no free-text field — search is narrowed on the client.\n filters: { workspaceId },\n pagination: { limit: LIST_LIMIT, offset: 0 },\n }),\n [workspaceId]\n );\n\n const select = useCallback(\n (data: ListMcpConnectionsQuery | undefined): MCPServerRecord[] => {\n const rows = selectServers(data);\n if (!search) return rows;\n return rows.filter((row) => row.name.toLowerCase().includes(search));\n },\n [search]\n );\n\n return useWorkspaceQuery<ListMcpConnectionsQuery, MCPServerRecord[]>({\n document: ListMcpConnectionsDocument,\n variables,\n select,\n fallback: NO_SERVERS,\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load MCP servers',\n });\n}\n\nexport function useMCPServer(serverId: string | undefined): QueryResult<MCPServerRecord | null> {\n const variables = useMemo(() => ({ id: serverId ?? '' }), [serverId]);\n\n return useWorkspaceQuery<GetMcpConnectionQuery, MCPServerRecord | null>({\n document: GetMcpConnectionDocument,\n variables,\n select: selectServer,\n fallback: null,\n enabled: Boolean(serverId),\n errorMessage: 'Failed to load MCP server',\n });\n}\n\nexport function useMCPTools(serverId: string | undefined): QueryResult<MCPToolRecord[]> {\n const variables = useMemo(() => ({ connectionId: serverId ?? '' }), [serverId]);\n\n return useWorkspaceQuery<ListMcpToolsQuery, MCPToolRecord[]>({\n document: ListMcpToolsDocument,\n variables,\n select: selectTools,\n fallback: NO_TOOLS,\n enabled: Boolean(serverId),\n errorMessage: 'Failed to load MCP tools',\n });\n}\n\nexport function useMCPResources(serverId: string | undefined): QueryResult<MCPResourceRecord[]> {\n const variables = useMemo(() => ({ connectionId: serverId ?? '' }), [serverId]);\n\n return useWorkspaceQuery<ListMcpResourcesQuery, MCPResourceRecord[]>({\n document: ListMcpResourcesDocument,\n variables,\n select: selectResources,\n fallback: NO_RESOURCES,\n enabled: Boolean(serverId),\n errorMessage: 'Failed to load MCP resources',\n });\n}\n\nexport function useCreateMCPServer() {\n const workspaceId = useWorkspaceId();\n\n const variables = useCallback(\n (input: CreateMCPServerVariables) => ({\n input: buildMutationInput({ ...input, workspaceId }, CREATE_CONNECTION_FIELDS),\n }),\n [workspaceId]\n );\n\n return useWorkspaceMutation<\n CreateMcpConnectionMutation,\n CreateMCPServerVariables,\n MCPServerRecord\n >({\n document: CreateMcpConnectionDocument,\n variables,\n select: (data) => data?.createMCPConnection,\n errorMessage: 'Failed to connect MCP server',\n });\n}\n\nexport function useUpdateMCPServer() {\n return useWorkspaceMutation<\n UpdateMcpConnectionMutation,\n UpdateMCPServerVariables,\n MCPServerRecord\n >({\n document: UpdateMcpConnectionDocument,\n variables: ({ serverId, input }) => ({\n id: serverId,\n input: buildMutationInput(input, UPDATE_CONNECTION_FIELDS),\n }),\n select: (data) => data?.updateMCPConnection,\n errorMessage: 'Failed to update MCP server',\n });\n}\n\nexport function useDeleteMCPServer() {\n return useWorkspaceMutation<DeleteMcpConnectionMutation, string, boolean>({\n document: DeleteMcpConnectionDocument,\n variables: (serverId) => ({ id: serverId }),\n select: (data) => data?.deleteMCPConnection,\n errorMessage: 'Failed to disconnect MCP server',\n });\n}\n\nexport function useTestMCPConnection() {\n return useWorkspaceMutation<TestMcpConnectionMutation, string, boolean>({\n document: TestMcpConnectionDocument,\n variables: (serverId) => ({ id: serverId }),\n select: (data) => data?.testMCPConnection,\n errorMessage: 'Failed to test MCP connection',\n });\n}\n\nexport function useUpdateMCPTool() {\n return useWorkspaceMutation<UpdateMcpToolMutation, UpdateMCPToolVariables, MCPToolRecord>({\n document: UpdateMcpToolDocument,\n variables: ({ toolId, input }) => ({ id: toolId, input }),\n select: (data) => data?.updateMCPTool,\n errorMessage: 'Failed to update MCP tool risk level',\n });\n}\n"],"mappings":";;;;;AAgDA,IAAM,IAAa,KAkDb,IAA2B,EAAmC;CAClE,QAAQ;CACR,aAAa;CACb,UAAU;CACV,MAAM;CACN,MAAM;CACN,aAAa;CACd,CAAC,EAEI,IAA2B,EAAmC;CAClE,QAAQ;CACR,aAAa;CACb,UAAU;CACV,MAAM;CACP,CAAC,EAEI,IAAgC,EAAE,EAClC,IAA4B,EAAE,EAC9B,IAAoC,EAAE;AAG5C,SAAgB,EAAmB,GAA4C;AAC7E,QAAO,MAAW;;AAQpB,SAAgB,EAAkB,GAA6D;CAC7F,IAAM,IAAM,EAAO,QAAQ;AAC3B,QAAO,OAAO,KAAQ,WAAW,IAAM,KAAA;;AAIzC,SAAgB,EAAqB,GAA6D;CAChG,IAAM,I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