Skip to content

MCP Tools

CSP Analyser exposes 12 tools through its MCP server. This page documents each tool with its parameters, types, and example usage.

start_session

Start a new CSP analysis session: crawl a website with a deny-all report-only CSP and capture all violations.

ParameterTypeRequiredDefaultDescription
targetUrlstring (URL)Yes--The URL to analyse
depthinteger (0-10)No1Crawl depth
maxPagesinteger (1-1000)No10Maximum pages to crawl
settlementDelayinteger (0-10000)No2000Milliseconds to wait after page load for late violations
storageStatePathstringNo--Path to Playwright storageState JSON for authenticated sessions
cookiesCookieParam[]No--Cookies to inject before crawling
violationLimitinteger (0+)No10000Maximum violations to accept per session (0 for unlimited)

Example:

json
{
  "targetUrl": "https://example.com",
  "depth": 2,
  "maxPages": 20
}

Response includes: sessionId, targetUrl, pagesVisited, violationsFound, errors


crawl_url

Analyse a single page for CSP violations. Convenience wrapper that sets depth=0 and maxPages=1.

ParameterTypeRequiredDefaultDescription
urlstring (URL)Yes--The URL to analyse
storageStatePathstringNo--Path to Playwright storageState JSON
cookiesCookieParam[]No--Cookies to inject before crawling

Example:

json
{
  "url": "https://example.com/login"
}

Response includes: sessionId, targetUrl, pagesVisited, violationsFound, errors


get_violations

Get CSP violations captured during a session, optionally filtered by directive, page URL, or origin.

ParameterTypeRequiredDefaultDescription
sessionIdstring (UUID)Yes--The session ID
directivestringNo--Filter by CSP directive (e.g., script-src)
pageUrlstringNo--Filter by page URL
originstringNo--Filter by blocked resource origin

Example:

json
{
  "sessionId": "a1b2c3d4-...",
  "directive": "script-src"
}

Response includes: sessionId, count, and a violations array with id, documentUri, blockedUri, effectiveDirective, violatedDirective, sourceFile, lineNumber, sample, capturedVia


generate_policy

Generate an optimised CSP policy from violations captured in a session.

ParameterTypeRequiredDefaultDescription
sessionIdstring (UUID)Yes--The session ID
strictness"strict" | "moderate" | "permissive"No"moderate"Policy strictness
includeHashesbooleanNofalseInclude SHA-256 hashes for inline scripts/styles (from violation samples and full DOM extraction)
useHashesbooleanNofalseRemove 'unsafe-inline' from directives that have hash sources (implies includeHashes)
stripUnsafeEvalbooleanNofalseRemove 'unsafe-eval' from the generated policy
useNoncesbooleanNofalseReplace 'unsafe-inline' in script/style directives with 'nonce-' placeholders
useStrictDynamicbooleanNofalseAdd 'strict-dynamic' alongside script nonces; implies nonce mode when useNonces is not set
collapseHashThresholdinteger (0+)NodisabledCollapse hashes to 'unsafe-inline' when a directive exceeds this many hashes
staticSiteModebooleanNofalseTarget is a static site — skips nonce suggestions and enables hash collapsing recommendations
staticProfile"react-expo"No--Keep script hashes strict while collapsing excessive style-src-attr hashes for static React/Expo-style apps

Example:

json
{
  "sessionId": "a1b2c3d4-...",
  "strictness": "strict",
  "useHashes": true,
  "useStrictDynamic": true
}

Response includes: sessionId, strictness, directives (map), policyString. May also include:

  • evalSources — when 'unsafe-eval' is in the policy, lists the source files and line numbers that triggered it (for identifying which dependencies call eval())
  • hashStability — warnings when hashes are likely build-specific and impractical to maintain (high count, large content, bundler patterns like webpack/Expo/Next.js)
  • staticSiteAnalysis — when the site is detected as static, includes confidence level, reasons, and whether nonces are feasible

export_policy

Export a CSP policy in a deployment-ready format.

ParameterTypeRequiredDefaultDescription
sessionIdstring (UUID)Yes--The session ID
format"header" | "meta" | "nginx" | "apache" | "cloudflare" | "cloudflare-pages" | "azure-frontdoor" | "helmet" | "json"Yes--Output format
strictness"strict" | "moderate" | "permissive"No"moderate"Policy strictness
isReportOnlybooleanNofalseUse Content-Security-Policy-Report-Only header
useHashesbooleanNofalseRemove 'unsafe-inline' from directives that have hash sources
stripUnsafeEvalbooleanNofalseRemove 'unsafe-eval' from the generated policy
useNoncesbooleanNofalseReplace 'unsafe-inline' in script/style directives with 'nonce-' placeholders
useStrictDynamicbooleanNofalseAdd 'strict-dynamic' alongside script nonces; implies nonce mode when useNonces is not set
collapseHashThresholdinteger (0+)NodisabledCollapse hashes to 'unsafe-inline' when a directive exceeds this many hashes
staticSiteModebooleanNofalseTarget is a static site — skips nonce suggestions
staticProfile"react-expo"No--Keep script hashes strict while collapsing excessive style-src-attr hashes for static React/Expo-style apps

Example:

json
{
  "sessionId": "a1b2c3d4-...",
  "format": "nginx",
  "useHashes": true,
  "useNonces": true
}

Response includes: sessionId, format, isReportOnly, policy (formatted string)


hash_static

Generate a CSP by scanning project-local static HTML files without launching a browser. This mirrors the CLI hash-static pipeline and can optionally inject the generated policy into each scanned HTML file as a CSP <meta> tag.

All paths and mergeJsonPaths entries must resolve under the MCP server's current working directory; paths outside the project are rejected.

ParameterTypeRequiredDefaultDescription
pathsstring[]Yes--Project-local HTML files or directories to scan. Directories are walked recursively for *.html files
format"header" | "meta" | "nginx" | "apache" | "cloudflare" | "cloudflare-pages" | "azure-frontdoor" | "helmet" | "json"No"meta"Output format
isReportOnlybooleanNofalseUse Content-Security-Policy-Report-Only where the selected format supports it
injectbooleanNofalseWrite the CSP into scanned HTML files as a <meta http-equiv="Content-Security-Policy"> tag
extraDirectivesRecord<string, string[]>No--Additional sources for known CSP fetch/navigation directives
mergeJsonPathsstring[]No--Project-local JSON policy files exported by this tool or the CLI. Accepts { directives: ... } or a bare directive map
policyDirectivesRecord<string, string[]>No--Document directives appended verbatim, such as report-uri, sandbox, or upgrade-insecure-requests
collapseHashThresholdinteger (0+)NodisabledCollapse hashes to 'unsafe-inline' when an eligible directive exceeds this count
staticProfile"react-expo"No--Keep scripts hash-strict while allowing scoped style-src-attr fallback for hash-heavy React/Expo exports

Example:

json
{
  "paths": ["dist"],
  "inject": true,
  "extraDirectives": {
    "connect-src": ["https://api.example.com"]
  },
  "policyDirectives": {
    "report-uri": ["/csp-report"]
  }
}

Response includes: format, isReportOnly, policy (formatted string), directives (map), filesScanned, counts (scriptElemHashes, styleElemHashes, styleAttrHashes, scriptAttrHashes), and injected.

When inject is true, report-uri and report-to are stripped from the injected meta policy because browsers ignore reporting directives delivered via CSP meta tags. They remain present in the returned directives and formatted policy unless the selected format strips them.


score_policy

Score a CSP policy against best practices on a 0-100 scale with A-F grading.

ParameterTypeRequiredDefaultDescription
sessionIdstring (UUID)Yes--The session ID
strictness"strict" | "moderate" | "permissive"No"moderate"Policy strictness
useHashesbooleanNofalseScore the hash-optimized policy
stripUnsafeEvalbooleanNofalseScore with 'unsafe-eval' removed
useNoncesbooleanNofalseScore the nonce-optimized policy
useStrictDynamicbooleanNofalseScore the strict-dynamic policy; implies nonce mode when useNonces is not set
collapseHashThresholdinteger (0+)NodisabledCollapse hashes before scoring when a directive exceeds this many hashes
staticSiteModebooleanNofalseScore with static-site nonce skipping behavior
staticProfile"react-expo"No--Score with the static React/Expo style-attribute collapse profile

Example:

json
{
  "sessionId": "a1b2c3d4-...",
  "useStrictDynamic": true
}

Response includes: overall (score), grade, findings (array of issues and strengths), formatted (human-readable summary)


compare_sessions

Compare two CSP analysis sessions and show policy/violation differences.

ParameterTypeRequiredDefaultDescription
sessionIdAstring (UUID)Yes--First session ID (baseline)
sessionIdBstring (UUID)Yes--Second session ID (comparison)
strictness"strict" | "moderate" | "permissive"No"moderate"Policy strictness
allProjectsbooleanNofalseAllow comparing sessions from any project instead of only the current one

Example:

json
{
  "sessionIdA": "a1b2c3d4-...",
  "sessionIdB": "e5f6g7h8-...",
  "strictness": "moderate",
  "allProjects": true
}

Response includes: Diff of added, removed, and changed directives, plus a formatted human-readable summary


get_session

Get details and violation summary for a CSP analysis session. By default, only sessions belonging to the current project, plus legacy unscoped sessions, are accessible.

ParameterTypeRequiredDefaultDescription
sessionIdstring (UUID)Yes--The session ID
allProjectsbooleanNofalseAllow accessing sessions from any project instead of only the current one

Example:

json
{
  "sessionId": "a1b2c3d4-...",
  "allProjects": true
}

Response includes: session (id, targetUrl, status, createdAt, updatedAt, project), pagesVisited, pages (array of url + statusCode), violationSummary


list_sessions

List CSP analysis sessions. By default, only sessions for the current project are returned.

ParameterTypeRequiredDefaultDescription
allProjectsbooleanNofalseReturn sessions from all projects instead of only the current one

Example:

json
{
  "allProjects": true
}

Response includes: count, sessions (array of id, targetUrl, status, createdAt, project)


get_permissions_policy

Get Permissions-Policy and Feature-Policy headers captured during a session.

ParameterTypeRequiredDefaultDescription
sessionIdstring (UUID)Yes--The session ID
directivestringNo--Filter by directive name (e.g., camera, geolocation)

Example:

json
{
  "sessionId": "a1b2c3d4-...",
  "directive": "camera"
}

Response includes: sessionId, count, policies (array of id, directive, allowlist, headerType, sourceUrl)

CookieParam

Cookie injection is supported by start_session, crawl_url, and audit_policy. Cookie values are used only for the browser context and are not persisted in session configuration.

FieldTypeRequiredDefaultDescription
namestringYes--Cookie name
valuestringYes--Cookie value
domainstringNoTarget hostnameCookie domain
pathstringNo/Cookie path
httpOnlybooleanNo--Whether the cookie is HTTP-only
securebooleanNo--Whether the cookie is restricted to secure requests
sameSite"Strict" | "Lax" | "None"No--SameSite policy, matching Playwright cookie option names

audit_policy

Audit an existing CSP: crawl a website preserving its current CSP, capture violations, and produce a diff plus merged policy. In strict mode, 'unsafe-inline' is stripped and replaced with hashes.

ParameterTypeRequiredDefaultDescription
targetUrlstring (URL)Yes--The URL to audit
depthinteger (0-10)No1Crawl depth
maxPagesinteger (1-1000)No10Maximum pages to crawl
settlementDelayinteger (0-10000)No2000Milliseconds to wait after page load for late violations
storageStatePathstringNo--Path to Playwright storageState JSON for authenticated sessions
cookiesCookieParam[]No--Cookies to inject before crawling
strictness"strict" | "moderate" | "permissive"No"moderate"Policy strictness. Strict mode strips 'unsafe-inline' and generates hashes.
violationLimitinteger (0+)No10000Maximum violations to accept per session (0 for unlimited)

Example:

json
{
  "targetUrl": "https://example.com",
  "depth": 2,
  "strictness": "strict"
}

Response includes: sessionId, pagesVisited, violationsFound, errors (array of { url, error } entries for pages that failed to load), enforced (existing + merged directives, diff, violation count), reportOnly (same structure), formatted (human-readable summary). enforced and reportOnly are null when the site has no corresponding CSP header.


Error handling

All tools return errors in a consistent format:

json
{
  "content": [{ "type": "text", "text": "Failed to start session: ..." }],
  "isError": true
}

Error messages are sanitized to remove internal file paths. Session IDs are validated as UUIDs. Target URLs are validated before crawling.


Released under the MIT License.