( name: string, scope: ConfigScope, )
| 767 | * @throws Error if server not found in specified scope |
| 768 | */ |
| 769 | export async function removeMcpConfig( |
| 770 | name: string, |
| 771 | scope: ConfigScope, |
| 772 | ): Promise<void> { |
| 773 | switch (scope) { |
| 774 | case 'project': { |
| 775 | const { servers: existingServers } = getProjectMcpConfigsFromCwd() |
| 776 | |
| 777 | if (!existingServers[name]) { |
| 778 | throw new Error(`No MCP server found with name: ${name} in .mcp.json`) |
| 779 | } |
| 780 | |
| 781 | // Strip scope information when writing back to .mcp.json |
| 782 | const mcpServers: Record<string, McpServerConfig> = {} |
| 783 | for (const [serverName, serverConfig] of Object.entries( |
| 784 | existingServers, |
| 785 | )) { |
| 786 | if (serverName !== name) { |
| 787 | const { scope: _, ...configWithoutScope } = serverConfig |
| 788 | mcpServers[serverName] = configWithoutScope |
| 789 | } |
| 790 | } |
| 791 | const mcpConfig = { mcpServers } |
| 792 | try { |
| 793 | await writeMcpjsonFile(mcpConfig) |
| 794 | } catch (error) { |
| 795 | throw new Error(`Failed to remove from .mcp.json: ${error}`) |
| 796 | } |
| 797 | break |
| 798 | } |
| 799 | |
| 800 | case 'user': { |
| 801 | const config = getGlobalConfig() |
| 802 | if (!config.mcpServers?.[name]) { |
| 803 | throw new Error(`No user-scoped MCP server found with name: ${name}`) |
| 804 | } |
| 805 | saveGlobalConfig(current => { |
| 806 | const { [name]: _, ...restMcpServers } = current.mcpServers ?? {} |
| 807 | return { |
| 808 | ...current, |
| 809 | mcpServers: restMcpServers, |
| 810 | } |
| 811 | }) |
| 812 | break |
| 813 | } |
| 814 | |
| 815 | case 'local': { |
| 816 | // Check if server exists before updating |
| 817 | const config = getCurrentProjectConfig() |
| 818 | if (!config.mcpServers?.[name]) { |
| 819 | throw new Error(`No project-local MCP server found with name: ${name}`) |
| 820 | } |
| 821 | saveCurrentProjectConfig(current => { |
| 822 | const { [name]: _, ...restMcpServers } = current.mcpServers ?? {} |
| 823 | return { |
| 824 | ...current, |
| 825 | mcpServers: restMcpServers, |
| 826 | } |
no test coverage detected