Download src/hooks/mutation/use-add-mcp-server.ts from SaylorTwift/openhands: direct link, hf CLI and curl.
- Browser
- Download file 1.32 kB
-
https://huggingface.co/SaylorTwift/openhands/resolve/main/src/hooks/mutation/use-add-mcp-server.ts
- Command line
-
hf download hf://SaylorTwift/openhands/src/hooks/mutation/use-add-mcp-server.ts
-
curl -L -o use-add-mcp-server.ts https://huggingface.co/SaylorTwift/openhands/resolve/main/src/hooks/mutation/use-add-mcp-server.ts
1.32 kB
| import { useMutation, useQueryClient } from "@tanstack/react-query"; | |
| import { useSettings } from "#/hooks/query/use-settings"; | |
| import SettingsService from "#/api/settings-service/settings-service.api"; | |
| import type { MCPServerConfig } from "#/types/mcp-server"; | |
| import { | |
| allocateMcpSettingsKey, | |
| parseMcpConfig, | |
| toCanonicalMcpServer, | |
| } from "#/utils/mcp-config"; | |
| import { SETTINGS_QUERY_KEYS } from "#/hooks/query/query-keys"; | |
| // @spec MCP-001 — Sparse mutations preserve sibling servers | |
| export function useAddMcpServer() { | |
| const queryClient = useQueryClient(); | |
| const { data: settings } = useSettings(); | |
| return useMutation({ | |
| mutationFn: async (server: MCPServerConfig): Promise<void> => { | |
| if (!settings) { | |
| throw new Error("MCP settings are still loading. Please try again."); | |
| } | |
| const currentConfig = | |
| settings.mcp_config ?? | |
| parseMcpConfig(settings.agent_settings?.mcp_config); | |
| const settingsKey = allocateMcpSettingsKey( | |
| currentConfig, | |
| server.name, | |
| server.type, | |
| ); | |
| await SettingsService.createMcpServer( | |
| settingsKey, | |
| toCanonicalMcpServer(server), | |
| ); | |
| }, | |
| onSuccess: () => { | |
| queryClient.invalidateQueries({ | |
| queryKey: SETTINGS_QUERY_KEYS.personal(), | |
| }); | |
| }, | |
| }); | |
| } | |