DEV Community

Cover image for Two Buttons Share One SVG Icon. Which Command Reaches the MCP Server?
Axialis Software
Axialis Software

Posted on Edited on

Two Buttons Share One SVG Icon. Which Command Reaches the MCP Server?

Click the eye on Preview desktop and the browser can report <use> as the event target. Focus the same button and press Enter, and it reports <button>. In both cases, the server should receive preview-desktop.

That was the test. We built a small MCP App with two native buttons, one SVG symbol and one server tool. The tool records the command ID it receives and echoes it back to the app. That gives us an end-to-end check we can compare with the browser event.

Two preview buttons in a local MCP Apps host. The event log shows four activations, their DOM targets, and matching command IDs sent by the app and received by the server.

Give the artwork and the command their own IDs

#preview-eye identifies the drawing. Both buttons reference it, while their data-command values identify the two actions.

<button type="button" data-command="preview-desktop">
  <svg aria-hidden="true"><use href="#preview-eye"></use></svg>
  Preview desktop
</button>

<button type="button" data-command="preview-mobile">
  <svg aria-hidden="true"><use href="#preview-eye"></use></svg>
  Preview mobile
</button>
Enter fullscreen mode Exit fullscreen mode

This is where IconVectors 2.30 fits. Keep the eye as a symbol in an SVG sprite and edit its artwork in IconVectors. For this test, we bundled the symbol into the app's HTML as an inline sprite. As long as its ID stays the same, both buttons can pick up an artwork update through the same reference. The command IDs live on the HTML buttons.

Read the command from the button before calling the tool

The app loads in an iframe inside a local MCP Apps test host. After the app connects to the host, a click handler attached directly to each button reads its command ID from event.currentTarget. We also record event.target for the event log.

async function sendPreview(event) {
  const target = event.target.localName;
  const commandId = event.currentTarget.dataset.command;

  const result = await app.callServerTool({
    name: "run_preview",
    arguments: { commandId },
  });

  if (result.isError || result.structuredContent?.commandId !== commandId) {
    throw new Error("The server did not acknowledge the expected command");
  }

  return { target, sent: commandId, received: result.structuredContent.commandId };
}
Enter fullscreen mode Exit fullscreen mode

A native button turns keyboard activation into a click, so both inputs go through the same handler. The app sends only commandId to the tool. The host forwards the call to the MCP server, where run_preview validates the ID against an enum, records it and returns it in structuredContent.

Check the server log

We opened the app in a local test host built with the MCP Apps SDK and ran the four activations below in Chromium. For the mouse runs, we clicked on the painted stroke of each eye. For the keyboard runs, we moved focus between the buttons and used Enter and Space.

Activation Browser target Command recorded by the MCP server
Click the desktop eye stroke <use> preview-desktop
Click the mobile eye stroke <use> preview-mobile
Activate Preview desktop with Enter <button> preview-desktop
Activate Preview mobile with Space <button> preview-mobile

The server recorded exactly four calls, and all four returned the command ID the app had sent. It also wrote each ID to its own log, independently of what the iframe displayed. The tool in this test only acknowledges preview commands.

When you test an icon button in an MCP App, check the tool argument at the server. Mouse and keyboard can produce different DOM targets. The command ID should follow the button you activated.

Top comments (0)