61public class McpOptionsPanel extends JPanel {
63 static final String PREF_MCP_ENABLED =
"MCP_SERVER_ENABLED";
72 enabledCheckBox =
new JCheckBox(Bundle.McpOptionsPanel_enabledCheckBox_text());
79 setBorder(
new EmptyBorder(10, 10, 10, 10));
80 setLayout(
new GridBagLayout());
81 GridBagConstraints gbc =
new GridBagConstraints();
82 gbc.anchor = GridBagConstraints.NORTHWEST;
83 gbc.fill = GridBagConstraints.HORIZONTAL;
84 gbc.insets =
new Insets(4, 4, 4, 4);
91 add(
new JLabel(Bundle.McpOptionsPanel_descriptionLabel_text()), gbc);
99 add(
new JLabel(Bundle.McpOptionsPanel_windowsOnlyLabel_text()), gbc);
106 add(
new JLabel(Bundle.McpOptionsPanel_stdioLocationLabel_text()), gbc);
118 add(
new JLabel(Bundle.McpOptionsPanel_claudeConfigLabel_text()), gbc);
125 gbc.fill = GridBagConstraints.BOTH;
130 JButton copyButton =
new JButton(Bundle.McpOptionsPanel_copyButton_text());
131 copyButton.addActionListener(e -> {
133 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel, sel);
136 gbc.fill = GridBagConstraints.NONE;
137 gbc.anchor = GridBagConstraints.EAST;
139 add(copyButton, gbc);
145 static boolean isMcpEnabled() {
146 return NbPreferences.forModule(
McpOptionsPanel.class).getBoolean(PREF_MCP_ENABLED,
false);
153 enabledCheckBox.setSelected(isMcpEnabled());
154 String exePath = findStdioExePath();
155 stdioPathField.setText(exePath);
156 configSnippetArea.setText(buildConfigSnippet(exePath));
157 configSnippetArea.setCaretPosition(0);
165 boolean wasEnabled = isMcpEnabled();
166 boolean nowEnabled = enabledCheckBox.isSelected();
167 NbPreferences.forModule(McpOptionsPanel.class)
168 .putBoolean(PREF_MCP_ENABLED, nowEnabled);
169 if (wasEnabled != nowEnabled) {
170 AutopsyMcpModule mod = AutopsyMcpModule.getInstance();
175 }
catch (Exception ex) {
177 NbPreferences.forModule(McpOptionsPanel.class)
178 .putBoolean(PREF_MCP_ENABLED,
false);
179 enabledCheckBox.setSelected(
false);
180 JOptionPane.showMessageDialog(
182 Bundle.McpOptionsPanel_startErrorMessage_text(ex.getMessage()),
183 Bundle.McpOptionsPanel_startErrorTitle_text(),
184 JOptionPane.ERROR_MESSAGE);
199 ObjectMapper mapper =
new ObjectMapper();
200 ObjectNode autopsy = mapper.createObjectNode();
201 autopsy.put(
"command", exePath);
202 ObjectNode servers = mapper.createObjectNode();
203 servers.set(
"autopsy", autopsy);
204 ObjectNode root = mapper.createObjectNode();
205 root.set(
"mcpServers", servers);
206 return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root);
207 }
catch (Exception ex) {
217 + File.separator +
"bin"
218 + File.separator +
"autopsy-mcp-stdio.exe";
219 File exeFile =
new File(exePath);
220 return exeFile.exists() ? exeFile.getAbsolutePath()
221 : Bundle.McpOptionsPanel_stdioNotFoundLabel_text();