Building MagicSword MCP: From API Routes to AI Tools
MagicSword MCP connects your AI assistant directly to endpoint data, policies, and alerts, no copy-paste required. Here's how it's built.

“Can I just ask my assistant what happened on my endpoints?”
That is a reasonable question. We already have the endpoint data, policies, alerts, and API routes. The next step is giving an assistant a way to use them.
We built MagicSword MCP to do that. It lets a supported assistant investigate endpoints, search events, work with policies, and manage intelligence through named tools backed by our customer API.
If you have been seeing MCP everywhere and wondering what you would actually build, follow one request through ours. The pieces get a lot easier to understand when you can see where the tool ends and the API begins.
What an MCP server actually does
MCP stands for Model Context Protocol. It gives AI applications a common way to discover and use external capabilities. An MCP server publishes what it offers, the inputs each operation accepts, and the results it returns.
For a tool, that means a name, a description, and a schema. The schema defines the arguments: perhaps a platform, an endpoint ID, or a time range. The assistant can use that information to choose a tool and construct a request. The host application controls whether that request runs.
MCP also supports resources, which expose context or data, and prompts, which provide reusable message templates. MagicSword’s local server focuses on tools. You can build a useful server without implementing every feature in the protocol.
Three terms help keep the architecture straight:
| Component | Its job | In our example |
|---|---|---|
| Host | Runs the assistant experience and controls tool use | Claude Desktop, Cursor, or a supported coding assistant |
| MCP client | Handles the MCP connection inside the host | The component that discovers and calls MagicSword tools |
| MCP server | Publishes tools and executes their handlers | The MagicSword MCP process |
The model helps decide what to call. Ordinary application code handles the request. Our local MCP process does not need to run its own language model.
Follow the request to the API
Say I ask:
Show me active Windows endpoints whose names start with prod.
The assistant can select list_endpoints and supply platform=windows, status=active, and hostname_pattern=prod-*.
The MCP handler validates those arguments and passes them to the API client. That client makes an authenticated request to MagicSword:
GET /api/public/v1/endpoints?platform=windows&status=active&hostname_pattern=prod-*
Authorization: Bearer <API key held by the MCP process>The API returns endpoint data. The handler packages it as an MCP result, and the assistant can explain it in the conversation. The key is attached by the API client; it does not need to appear in the user’s message.

So yes, an MCP server can act as a gateway to API routes. That describes much of ours. MCP also works with local files, databases, calculations, and other systems. An HTTP API is one possible backend.
The useful design question is how much of that backend to expose.
I would start with a concrete task such as “list endpoints” or “preview this policy assignment.” Give the assistant a clear operation with bounded inputs. A generic tool that accepts any URL and any request body leaves far more of the integration’s behavior to the caller.
The tool name and the API route have different jobs
A tool describes an operation in terms the assistant can discover. A route identifies the backend request that performs some part of it.
Sometimes the mapping is straightforward. Sometimes one tool coordinates several routes.
Here are examples from our API client. Every path below is relative to /api/public/v1.
| MCP tool | API request | Purpose |
|---|---|---|
| whoami | GET /me | Identify the organization, key ID, and scopes |
| list_endpoints | GET /endpoints | Find devices with filters and pagination |
| list_events | GET /events | Search investigation events |
| find_alerts | GET /alerts | Find alerts for review |
| create_policy | POST /policies | Create an empty audit policy |
| clone_policy | POST /policies | Create an independent audit copy |
| manage_policy_rules | GET /policies/{id}/rules, POST /policies/{id}/rules, or POST /policies/rules | List or add rules, depending on the supplied action and policy selector |
| apply_policy_to_endpoints | POST /policies/{id}/assignment-preview, then POST /policies/{id}/assign | Preview concrete targets, then commit the approved assignment |
| flip_to_enforcing | POST /policies/{id}/enforce-preview, then POST /policies/{id}/enforce | Review readiness before changing enforcement |
| download_policy | GET /policies/{id}/download?format=wdac or format=applocker | Export a Windows policy artifact |
The handler provides the glue: input validation, workflow checks, error handling, and a result the assistant can use. The API remains responsible for backend authorization and policy behavior.

The protocol underneath the conversation
The user sees a conversation. Underneath it, MCP carries JSON-RPC messages: structured requests with method names, arguments, and IDs used to match replies.
Two methods are especially useful to recognize: tools/list discovers the available tool definitions, and tools/call invokes one with arguments. The server returns content or an error. Those are protocol operations; list_endpoints is the product-specific tool named inside the call.
In a simplified view, the interesting part of a call looks like this:
{
"method": "tools/call",
"params": {
"name": "list_endpoints",
"arguments": {
"platform": "windows",
"status": "active",
"hostname_pattern": "prod-*",
"limit": 100
}
}
}This shows the method and arguments, rather than a complete wire message. An SDK supplies the JSON-RPC envelope and applicable protocol metadata.
Protocol versions matter. Older MCP revisions establish compatibility through an initialize handshake. The July 2026 revision carries version and capability metadata on individual requests. Use an SDK compatible with your target clients and let it handle those mechanics. The official versioning guidance and tool specification explain the details.
Transport is a separate choice. stdio carries messages over the standard input and output of a local process. Streamable HTTP carries them over HTTP to a reachable MCP service. The transport specification describes both.
Our npm package runs locally over stdio and makes HTTPS requests to MagicSword. It still needs network access to the portal. The repository also documents a separate hosted OAuth connector for Microsoft Copilot Studio, where administrators have enabled it. Installing the local package does not make it reachable by a browser-only assistant.
What we built for MagicSword
The current local tool registry registers 26 tools. They cover the work I want to do when investigating a fleet and turning that investigation into a policy change.
| Work | Tools and behavior |
|---|---|
| Understand the fleet | Identify the connected organization; list endpoints and groups; inspect device details, agent versions, and policy state |
| Investigate activity | Search events, find alerts, and retrieve alert evidence; acknowledging or dismissing an alert requires write access |
| Build policies | Create an empty audit policy, clone an existing policy into an audit copy, inspect policies, and add explicit or event-derived rules |
| Work with intelligence | Discover sources, manage private feeds and indicators, and attach sources to policies |
| Roll out changes | Preview policy assignments, review enforcement readiness, queue upgrades, and request endpoint check-ins |
| Enroll and export | Mint enrollment tokens, return installation instructions, and download supported Windows policy artifacts |
A workflow might start with events showing software running in audit mode. The assistant can retrieve those events, explain the file and publisher context, help select the relevant records, and propose rules for a policy.
For Windows WDAC, the tool guidance steers callers toward event-derived rules or appropriate intelligence feeds rather than explicit flat file-hash rules. Platform semantics still matter when a conversation starts the request.
There are useful boundaries around individual operations, too. Creating or cloning a policy starts it in audit mode with no devices assigned. Downloading a Windows policy produces files for review and deployment; it does not install them. A saved endpoint assignment remains pending agent check-in.
Those distinctions help the assistant describe what actually happened.
Build the first tool around one useful question
If I were building another MCP server, I would start with a small read operation. Pick a question you can answer through a backend you already understand. “Which endpoints match these filters?” is a good first target.
Our implementation separates the work into three places:
- The tool definition gives the operation a name, description, schema, and handler.
- The API client handles authentication, URLs, timeouts, and HTTP responses.
- The server entry point registers the tools and starts the MCP transport.
That structure makes it easier to review a tool without reading every HTTP detail, and to update HTTP behavior without rewriting every tool.
Our server entry point uses the TypeScript MCP SDK and Zod schemas. This shortened registration example shows the same pattern:
import { McpServer } from '@modelcontextprotocol/server';
import { serveStdio } from '@modelcontextprotocol/server/stdio';
import { z } from 'zod';
// client is the configured MagicSwordClient.
const server = new McpServer({
name: 'endpoint-example',
version: '0.1.0',
});
server.registerTool(
'list_endpoints',
{
description: 'Find enrolled endpoints by platform.',
inputSchema: z.object({
platform: z.enum(['windows', 'macos', 'linux']).optional(),
limit: z.number().int().min(1).max(500).optional(),
}),
annotations: {
readOnlyHint: true,
destructiveHint: false,
idempotentHint: true,
},
},
async ({ platform, limit }) => {
const page = await client.endpoints({ platform, limit });
return {
content: [{
type: 'text',
text: `Showing ${page.endpoints.length} of ${page.total} endpoints.`,
}],
structuredContent: { ...page },
};
},
);
serveStdio(() => server);Illustrative excerpt using the repository’s SDK style. Client construction, configuration, and error handling are omitted; the complete implementation is in the repository.
The description should explain when to use the tool and what its result means. The schema should constrain inputs before the handler runs. Our full list_endpoints definition includes lifecycle states, hostname patterns, and pagination, with a maximum page size of 500.
Return enough context to support the next decision. The actual tool returns endpoint IDs, status, policy information, and pagination alongside readable text. A response that says only “found devices” forces the assistant to guess or ask again.
Make failures part of the design
Once the first read works, test the cases that break the happy path: missing scopes, an invalid ID, an empty page, rate limiting, a timeout, and malformed backend responses.
Our HTTP client applies request timeouts and response-size limits. It retries selected transient failures for GET requests. It does not automatically retry writes.
That last choice matters. If policy creation succeeds but its response is lost, a retry can create another policy. The creation and cloning tools tell the caller to inspect current state when the outcome is uncertain.
Also keep stdout clean when serving over stdio. It carries protocol messages. Diagnostic output belongs on stderr; an ordinary log line on stdout can break communication.
To explore the implementation:
git clone https://github.com/magicsword-io/magicsword-mcp.git
cd magicsword-mcp
npm ci
npm run build
npm run typecheck
npm testThe repository includes tests around tool calls over stdio, client behavior, policy workflows, and packaging. Test the packaged server through a client as well as testing handlers directly. Users need the launch configuration, transport, tool definitions, and backend access to work together.
Preview the change before committing it
Read access gets an assistant useful context. Write access gives it a way to change the environment. The implementation needs to make the proposed change concrete.
For policy assignments, MagicSword first requests a preview. The response identifies the computers, policy version, mode, and the effect of replacing their desired assignments. It also returns a confirmation token.
After the human approves that preview, a second call submits the token. The MCP handler rejects a commit that also supplies a new set of target selectors.

The assignment workflow uses a server token tied to the approved snapshot. The enforcement tool similarly separates readiness review from the enforcement request.
A token does not prove a human approved anything. The same API key can make both calls. The host must obtain that approval, and the API must enforce the credential’s permissions.
MCP safety annotations also help clients present operations appropriately, but they are hints. Authorization belongs in the backend. A read-scoped key should remain unable to write even if the assistant asks.
Connect it and verify actual access
MagicSword’s provides MCP and customer API access on Free and Enterprise plans, with scopes and entitlements determining which operations are available.
For terminal setup, use Node.js 22 or later:
npm install -g @magicsword-io/magicsword-mcp
magicsword-mcp configureSetup privately prompts for the API key and lets you select a supported local client. Start with read scopes. Keep the key out of assistant conversations.
For Claude Desktop, the repository also provides an .mcpb extension installer. That path uses Claude’s secure configuration field for the key. The terminal configuration path saves credentials in a local file; these are different setup methods.
Restart the client or start a new session, then ask:
Use MagicSword to call whoami, then list_endpoints. Show the connected organization, my approved permissions, and my devices. Do not make any changes.
A tool appearing in the list establishes discovery. These calls check authentication and endpoint read access.
From there, ask a question you care about. Review recent events. Inspect an endpoint. Build an audit policy from selected evidence. Add write permissions when you need a specific workflow and can review what it will change.
For me, that is the useful part of building this: shortening the path from “what happened?” to “what policy change should we review?” The API operations, platform rules, and endpoint verification still do their jobs. MCP makes those operations available in the conversation where the investigation is happening.
Explore MagicSword MCP and its setup guides.
MagicSword MCP is free. Sign up, grab your API key, and start investigating from the conversation.

Written by
Michael Haag
Threat Researcher
In the intricate chessboard of cybersecurity, my role oscillates between a master tactician and a relentless hunter. As an expert in detection engineering and threat hunting, I don't just respond to the digital threats, I anticipate them, ensuring that the digital realm remains sovereign.


