Skip to content

Commit 6f74483

Browse files
committed
fix: set typescript agent port to 8080
1 parent a03e095 commit 6f74483

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

  • src/cli/operations/dev/web-ui/handlers

src/cli/operations/dev/web-ui/handlers/start.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,29 +91,29 @@ async function doStartAgent(
9191
const agentIndex = ctx.options.agents.findIndex(a => a.name === agentName);
9292
const { onLog } = ctx.options;
9393

94-
// A2A agents use a fixed framework port (9000) that can't be overridden via env vars —
95-
// serve_a2a() accepts port as a function parameter, not from the environment.
96-
// MCP agents (FastMCP) also use a fixed port: FastMCP.__init__ passes port=8000 as a
97-
// pydantic BaseSettings init kwarg, which takes priority over the FASTMCP_PORT env var
98-
// we set. So MCP agents always bind to 8000 regardless of environment configuration.
94+
// Several frameworks bind to a fixed port that ignores the PORT env var:
95+
// - A2A: serve_a2a() accepts port as a function parameter, not from env → 9000
96+
// - MCP (FastMCP): pydantic BaseSettings init kwarg overrides env → 8000
97+
// - TS HTTP (BedrockAgentCoreApp): hardcodes `const PORT = 8080` in run() → 8080
98+
// For Python HTTP agents, uvicorn takes --port as a CLI arg so we can assign any port.
99+
// TODO: Remove isFixedPortTS once bedrock-agentcore respects the PORT env var.
99100
const isA2A = config.protocol === 'A2A';
100101
const isMCP = config.protocol === 'MCP';
101-
const targetPort = isA2A ? 9000 : isMCP ? 8000 : ctx.options.uiPort + 1 + (agentIndex >= 0 ? agentIndex : 0);
102+
const isFixedPortTS = !config.isPython && config.protocol === 'HTTP';
103+
const fixedPort = isA2A ? 9000 : isMCP ? 8000 : isFixedPortTS ? 8080 : undefined;
104+
const targetPort = fixedPort ?? ctx.options.uiPort + 1 + (agentIndex >= 0 ? agentIndex : 0);
102105
const agentPort = await findAvailablePort(targetPort);
103-
if (isA2A && agentPort !== 9000) {
106+
if (fixedPort && agentPort !== fixedPort) {
107+
const reason = isA2A
108+
? 'A2A agents require port 9000.'
109+
: isMCP
110+
? 'MCP agents require port 8000 (FastMCP default).'
111+
: 'TypeScript agents require port 8080 (BedrockAgentCoreApp default).';
104112
return {
105113
success: false,
106114
name: agentName,
107115
port: 0,
108-
error: `Port 9000 is in use. A2A agents require port 9000.`,
109-
};
110-
}
111-
if (isMCP && agentPort !== 8000) {
112-
return {
113-
success: false,
114-
name: agentName,
115-
port: 0,
116-
error: `Port 8000 is in use. MCP agents require port 8000 (FastMCP default).`,
116+
error: `Port ${fixedPort} is in use. ${reason}`,
117117
};
118118
}
119119
if (agentPort !== targetPort) {

0 commit comments

Comments
 (0)