Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mcp-default-user-agent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"executor": patch
---

Send a default User-Agent on remote MCP requests so servers that reject requests without one accept the connection. A configured User-Agent header still wins.
15 changes: 13 additions & 2 deletions packages/plugins/mcp/src/sdk/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ const buildEndpointUrl = (endpoint: string, queryParams: Record<string, string>)
return url;
};

// Some upstreams (Cloudflare bot rules among them) reject requests without a
// User-Agent, and Workers' fetch adds none. Both remote SDK transports apply
// `requestInit.headers` to every request they send, including OAuth metadata
// discovery, so the default goes there. A configured User-Agent wins.
const DEFAULT_USER_AGENT = "executor";

const withDefaultUserAgent = (headers: Record<string, string>): Record<string, string> =>
Object.keys(headers).some((name) => name.toLowerCase() === "user-agent")
? headers
: { "User-Agent": DEFAULT_USER_AGENT, ...headers };

type HttpMethod = Parameters<typeof HttpClientRequest.make>[0];
const HTTP_METHODS = new Set<HttpMethod>([
"DELETE",
Expand Down Expand Up @@ -626,9 +637,9 @@ export const createMcpConnector = (input: ConnectorInput): McpConnector => {
}

// Remote transport
const headers = input.headers ?? {};
const headers = withDefaultUserAgent(input.headers ?? {});
const remoteTransport = input.remoteTransport ?? "auto";
const requestInit = Object.keys(headers).length > 0 ? { headers } : undefined;
const requestInit = { headers };
const fetch = input.httpClientLayer
? fetchFromHttpClientLayer(input.httpClientLayer, input.staticOAuthBearer === true)
: undefined;
Expand Down
Loading