Petra Security MCP Server
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Petra Security MCP Server show my recent M365 breach incidents from the last 7 days"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Petra Security MCP Server
Read-only MCP server for Petra Security's public REST API, for AI assistants and the WYRE Conduit gateway. Petra detects and investigates Microsoft 365 account compromises (BEC, session hijacks). This server exposes its incidents, failed attacks, posture reports, tenants, usage and billable users.
Authentication
A Petra Admin creates an API key at app.petrasecurity.com under Settings > API Keys. The full key is shown only once, so store it in a secrets manager immediately. Full Members can see the key list but cannot create keys.
Every request goes to https://api.petrasecurity.com with Authorization: Bearer <key> and a User-Agent header (Petra returns 403 without one). The host is fixed and cannot be changed by request headers or tool arguments.
Petra rate-limits each route to 10 requests per minute. A 429 comes back as a tool error that names the Retry-After-public-api wait. To spare that budget, successful responses are cached in memory per API key (keyed by a SHA-256 of the key) for 60 seconds, and /v1/failed-attacks for 5 minutes. Identical concurrent requests share one upstream call.
Related MCP server: Cisco Umbrella MCP Server
Configuration
Copy .env.example and set the variables below. The stdio transport reads PETRA_API_KEY and does not use CONDUIT_S2S_SECRET.
Env var | Description |
| Petra API key. Required for stdio and |
|
|
|
|
| Required for HTTP. HMAC secret checked against |
| Set to exactly |
| Bind address when |
| HTTP port. Defaults to |
|
|
/health and /healthz stay unauthenticated and do not read credentials.
HTTP authentication
With MCP_TRANSPORT=http and CONDUIT_S2S_SECRET set, every /mcp request must include X-Gateway-S2S. The check is verifyS2sHeader in src/s2s-verify.ts: the header value is t=<unix seconds>,v1=<hex>, where the hex is HMAC-SHA256 of the literal string t=<unix seconds> keyed with CONDUIT_S2S_SECRET (64 lowercase hex characters). The timestamp must be within 300 seconds of the server clock. A missing or invalid header is HTTP 401, before vendor credentials are read. An empty secret refuses to start unless MCP_ALLOW_INSECURE_DEV=1. A known placeholder (replace-with-a-real-secret, your-s2s-secret, changeme, change-me, placeholder, secret, example, replace-me, s2s-secret, any case) refuses to start even with that flag, so a copied example cannot forge the header.
TS=$(date +%s)
SIG=$(printf 't=%s' "$TS" | openssl dgst -sha256 -hmac "$CONDUIT_S2S_SECRET" -hex | awk '{print $NF}')
curl -sS http://127.0.0.1:8080/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-H "X-Gateway-S2S: t=${TS},v1=${SIG}" \
-H "X-Petra-Api-Key: $PETRA_API_KEY" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'In AUTH_MODE=gateway, /mcp also requires X-Petra-Api-Key. That header is the only credential source for the request. A request without it returns 401 and does not fall back to PETRA_API_KEY in the process environment.
AUTH_MODE=env still requires a valid X-Gateway-S2S header, then uses PETRA_API_KEY from the environment.
Request limits
HTTP request bodies are capped at 256 KiB (262144 bytes). After the
X-Gateway-S2Scheck (and, withAUTH_MODE=gateway, theX-Petra-Api-Keypresence check) passes, aContent-Lengthabove the cap returns 413 with a JSON-RPC error; bodies withoutContent-Lengthare capped by the MCP SDK transport. Unauthenticated requests still get 401 first.tools/callarguments are capped at 10,000 elements (every array item and object key at any depth). Larger inputs return anisErrortool result and are never dispatched.
These limits address CVE-2026-111768 / GHSA-46jr-4wx8-v453 (memory exhaustion during validation) and GHSA-f897-62hf-6gxq (no request body / batch cap).
Tools
Every tool is a GET, annotated readOnlyHint: true and destructiveHint: false. Where a tool takes tenantId, either the Petra tenant ID (e.g. ZZk90t, from petra_list_tenants or the app.petrasecurity.com/tenant/<id> URL) or the Microsoft tenant ID works.
Tenants and billing
petra_list_tenants- every client tenant with Petra and Microsoft tenant IDs, onboarding date and paused flag (GET /v1/tenants). OptionalnameContainsandincludePausedfilters.petra_get_usage- organization-wide billing snapshot per tenant: service, billable status, licensed and billable users, prorating, first billable date, plus totals (GET /v1/usage). OptionalasOf,includePaused(setfalseso paused tenants don't inflate counts) andbillableStatus.petra_list_billable_users- billable users for one tenant with UPN, mail, enabled flag and license SKUs (GET /v1/billable-users). Petra documents only the Petra tenant ID here, so a Microsoft tenant ID is resolved through/v1/tenantsfirst. OptionalenabledOnly.
Security events
petra_list_incidents- M365 compromise incidents, newest first, with user, remediation status, live flag, dwell time and phishing email (GET /v1/incidents). OmittenantIdfor all tenants.startDateandlimit(1-500) go to Petra;remediationStatus,liveOnly,userPrincipalNameandincludePhishingEmailare applied locally after the limit.petra_get_incident- one incident by ID. Petra has no single-incident route, so this searches the newest 500 (passtenantIdto reach older ones in a tenant).petra_get_failed_attacks- blocked-attack summary for one tenant: total, by country, daily by attack type, and most-targeted users (GET /v1/failed-attacks). Defaults to the last 30 days.petra_list_posture_reports- M365 posture reports: score and grade, control rollup, Global Admin review, top risks and every check with its suggested fix (GET /v1/posture-reports). Latest per tenant by default. OptionalincludeChecks: falsefor a compact view.
Scope
This server covers the first five tools StackJack ships for Petra (petra_list_tenants, petra_get_usage, petra_list_billable_users, petra_list_incidents, petra_get_failed_attacks), with the same names, and adds petra_get_incident and petra_list_posture_reports.
Petra's public API has no write, remediation, pause or scan-trigger routes, so there is nothing to gate. GET /v1/usage-xlsx is left out on purpose: it returns a binary spreadsheet and needs a separate Multi-MSP API key.
The request and response shapes come from Petra's published OpenAPI spec (/docs/api-reference/openapi.json). Tests mock the API, and nothing has been tested against a live Petra key yet.
Development
npm install
npm run build
npm test
npm run lint # tsc --noEmitDocker
The image listens on 0.0.0.0 inside the container (MCP_HTTP_HOST) and defaults to AUTH_MODE=gateway. Startup still refuses to run without a real CONDUIT_S2S_SECRET. Publish the port on loopback. In gateway mode, the Petra key arrives on each request as a header and is not read from the environment.
docker build -t petra-mcp .
docker run \
-e CONDUIT_S2S_SECRET="$CONDUIT_S2S_SECRET" \
-p 127.0.0.1:8080:8080 \
petra-mcpCompose refuses to start when CONDUIT_S2S_SECRET is unset, defaults AUTH_MODE to gateway, publishes 127.0.0.1:8080:8080, and does not set PETRA_API_KEY or env_file:
CONDUIT_S2S_SECRET="$CONDUIT_S2S_SECRET" docker compose upSingle-tenant HTTP (AUTH_MODE=env) still requires the S2S secret, then uses PETRA_API_KEY:
docker run \
-e CONDUIT_S2S_SECRET="$CONDUIT_S2S_SECRET" \
-e AUTH_MODE=env \
-e PETRA_API_KEY=... \
-p 127.0.0.1:8080:8080 \
petra-mcpLocal HTTP without a secret is development-only. It binds 127.0.0.1 (including when MCP_HTTP_HOST is localhost or ::1) and logs a warning. A non-loopback MCP_HTTP_HOST makes startup exit. The container image sets MCP_HTTP_HOST=0.0.0.0, so the bypass inside Docker also needs -e MCP_HTTP_HOST=127.0.0.1. Do not publish that port off loopback.
MCP_TRANSPORT=http MCP_ALLOW_INSECURE_DEV=1 npm run start:httpAvailable Tools
7 toolspetra_get_failed_attacksARead-onlyIdempotent
Get the BLOCKED (failed) attack summary for one tenant: total count, counts by origin country, a daily breakdown by attack type (e.g. PASSWORD_SPRAY, LEGACY_AUTH), and the most-targeted users with the countries their attackers came from. Defaults to the last 30 days. Petra rate-limits this route heavily, so results are cached for 5 minutes.
Inputs: tenantId (required), endDate, startDate.
petra_get_incidentARead-onlyIdempotent
Get one Petra incident by its ID, with full user and phishing-email detail. Petra has no single-incident route, so this searches the newest 500 incidents (pass tenantId to reach older ones).
Inputs: incidentId (required), tenantId, startDate.
petra_get_usageARead-onlyIdempotent
Get the whole-organization Petra billing snapshot in one call: for every tenant, the service (Monitoring or Autopsy), billableStatus (Trial, Active, NFR, Deleted), totalLicensedUsers, billableUsersThisMonth, proratingPercentageThisMonth and firstBillableDate, plus totals across the returned tenants. Use for invoice reconciliation against the PSA.
Inputs: asOf, includePaused, billableStatus.
petra_list_billable_usersARead-onlyIdempotent
List the individual billable users for ONE tenant (users with an assigned Microsoft license that are not deleted), with display name, UPN, mail, enabled flag and license SKU IDs, plus totalBillableUsers and projectedBillableUnitsThisMonth. This is the user-level detail behind petra_get_usage. A Microsoft tenant ID is resolved to the Petra tenant ID automatically.
Inputs: tenantId (required), enabledOnly.
petra_list_incidentsARead-onlyIdempotent
List Microsoft 365 identity-compromise incidents Petra detected (account takeovers, BEC), newest first: compromised user, occurred/created time, remediation status, whether the attacker is still live, dwell time, and the phishing email that led to it. Omit tenantId to search every tenant in the organization. Petra only alerts on real compromises.
Inputs: limit, liveOnly, tenantId, startDate, +3 more.
petra_list_posture_reportsARead-onlyIdempotent
Get completed Microsoft 365 security posture reports: score and grade (with previous score/grade on follow-ups), control rollup (secure, fixed, open, drifted), the Global Administrators review (count, MFA strength, password age), top risks, and every check with its status, severity, current state and suggested fix. By default returns the latest report per tenant.
Inputs: limit, tenantId, startDate, latestOnly, +1 more.
petra_list_tenantsARead-onlyIdempotent
List every client tenant (Microsoft 365 customer) in the Petra organization, alphabetically, with its Petra tenant ID, Microsoft tenant ID, onboarding date and paused flag. Start here to find the tenantId other petra_* tools take. Removed tenants are excluded; paused tenants are included unless includePaused is false.
Inputs: nameContains, includePaused.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 7 tools
Each tool targets a clearly distinct resource or action: tenants, org-level usage, per-tenant billable users, incidents, incident detail, failed attacks, and posture reports. The billing-related tools overlap conceptually but are clearly separated by aggregate vs. user-level scope, and list vs. get incident tools have an explicit summary/detail boundary.
All tools use a consistent snake_case verb_noun pattern with the same petra_ prefix. The verbs are predictable list/get pairs, and no mixed naming conventions appear.
Seven tools is well-scoped for a read-only security and billing reporting server. Each tool covers a meaningful surface area without excessive fragmentation.
The surface covers the core reporting lifecycle: tenant discovery, usage, user-level billing, incidents, blocked attacks, and posture reports. Minor gaps exist around per-tenant aggregate usage, explicit report retrieval beyond defaults, and remediation/write operations, but agents can largely work around these.
Maintenance
Related MCP Connectors
Query your team's drift, vulnerability, and upgrade data from any AI assistant. OAuth 2.1, 51 tools.
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Connect AI agents to 580+ APIs with OAuth or API-key auth. Hosted gateway; API pricing varies.
Pay-per-call cybersecurity for AI agents: vuln scans, threat intel, compliance, code security.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceEnables AI assistants to query and manage OpenCTI threat intelligence data, including indicators, observables, reports, malware, and more, with read-only and optional write operations.1MIT
- AlicenseBqualityBmaintenanceProvides AI assistants with read-only access to Cisco Umbrella's NextGen REST API for deployment, admin, policy, reporting, and investigate visibility, enabling DNS and cloud security monitoring through natural language.31Apache 2.0
- AlicenseAqualityBmaintenanceEnables AI assistants to query RoboShadow's Rubicon Platform Data API for read-only endpoint security, asset inventory, applications, users, vulnerabilities, and remediation status data.401Apache 2.0
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to read and act on managed security data from the Huntress API, covering accounts, organizations, protected endpoints, incident reports and their remediations, escalations, signals, users, invoices and summary reports. Read operations are safe by default, while data-changing actions such as resolving incidents, approving remediations, and managing organizations or users require explicit write and confirm flags.Apache 2.0