Skip to content

Commit a42b7cb

Browse files
Juan Pelaezclaude
andcommitted
fix(forms-app): Add CSP connectDomains to allow API fetches
The MCP App iframe was blocking fetch requests to external APIs due to Content Security Policy restrictions. Added CSP configuration with connectDomains to allow fetch/XHR to 23blocks API endpoints. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0841a58 commit a42b7cb

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

apps/forms-app/src/server/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ if (!API_URL || !API_KEY || !AUTH_URL) {
2121
process.exit(1);
2222
}
2323

24+
// Extract origins from URLs for CSP connect-src
25+
function getOrigin(url: string): string {
26+
try {
27+
const parsed = new URL(url);
28+
return `${parsed.protocol}//${parsed.host}`;
29+
} catch {
30+
return url;
31+
}
32+
}
33+
34+
const API_ORIGIN = getOrigin(API_URL);
35+
const AUTH_ORIGIN = getOrigin(AUTH_URL);
36+
const CSP_CONNECT_DOMAINS = [...new Set([API_ORIGIN, AUTH_ORIGIN])];
37+
2438
// Path to the built UI HTML file
2539
// Works both from source (server/index.ts) and compiled (dist/server/index.js)
2640
const DIST_DIR = import.meta.filename?.endsWith(".ts")
@@ -112,6 +126,7 @@ export function createServer(): McpServer {
112126
);
113127

114128
// Register the UI resource - serves the built HTML file
129+
// Include CSP configuration to allow fetch to 23blocks APIs
115130
registerAppResource(
116131
server,
117132
DASHBOARD_URI,
@@ -126,6 +141,14 @@ export function createServer(): McpServer {
126141
uri: DASHBOARD_URI,
127142
mimeType: RESOURCE_MIME_TYPE,
128143
text: html,
144+
_meta: {
145+
ui: {
146+
csp: {
147+
// Allow fetch/XHR to 23blocks APIs
148+
connectDomains: CSP_CONNECT_DOMAINS,
149+
},
150+
},
151+
},
129152
}],
130153
};
131154
} catch (err) {

0 commit comments

Comments
 (0)