Skip to content

fix(typescript): compile MCP server when the document defines no servers - #216

Open
AshGodfrey wants to merge 1 commit into
mainfrom
claude/sharp-leavitt-6aec72
Open

AshGodfrey wants to merge 1 commit into
mainfrom
claude/sharp-leavitt-6aec72

Conversation

@AshGodfrey

@AshGodfrey AshGodfrey commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Why

With enableMCPServer: true, a TypeScript SDK generated from a document that defines no servers (or only relative ones) fails npm run build:

src/mcp-server/cli/start/impl.ts(23,40): error TS2339: Property 'serverIdx' does not exist on type 'SDKOptions'.
src/mcp-server/server.ts(25,26): error TS2339: Property 'serverIdx' does not exist on type 'SDKOptions'.
src/mcp-server/server.ts(34,5): error TS2353: Object literal may only specify known properties, and 'serverIdx' does not exist in type 'SDKOptions'.

src/lib/config.ts only declares SDKOptions.serverIdx (or SDKOptions.server for named servers) when the document has a server with an absolute URL. The MCP server templates emitted the --server-index flag and the serverIdx pass-through whenever any servers object existed, which is always the case because the generator injects an implicit / server.

What changed

templates/templates/typescriptv2/mcp-server/{cli/start/impl.ts,cli/start/command.ts,server.ts,create-mcp-server.ts}.stmpl now gate the server-selection flag, the serverIdx/server dependency field and its pass-through on the same $hasServers predicate config.ts.stmpl uses. create-mcp-server.ts.stmpl gains that predicate definition.

Generated output is unchanged for documents that define an absolute server. For documents with no servers or only relative servers the MCP server no longer emits the --server-index flag, which never had a valid value there, and compiles.

The mcp-typescript target is not affected: its config.ts always declares serverIdx, and its MCP templates already use the matching predicate.

Testing

  • Minimal document with one GET operation and no servers, enableMCPServer: true, zodVersion: v3: reproduced the three errors above on main; with this change npm run build passes and mcp start --help shows no --server-index.
  • Same document with servers: [/relative-url]: builds.
  • Same document with two absolute servers: generated output is byte-identical before and after this change (outside .speakeasy/), builds, and mcp start --help still lists --server-index.
  • npm run format, make check-template-typescriptv2, make lint: clean.
  • Review SDK not regenerated: the review configuration has enableMCPServer: false, so this path is not exercised there.

Public-safety check

  • This change contains no credentials, customer documents, private repository URLs, private filesystem paths, or unredacted private logs.
  • Title, body, comments, and commit messages name no customers or customer-derived identifiers, private paths or trackers, or workflow provenance, and are understandable without private context (.claude/skills/public-repo-communication/SKILL.md).
  • Generated fixtures and review SDK changes are public-safe.
  • I reviewed git diff --check.

Summary by cubic

Fixes TypeScript compilation of the generated MCP server when the OpenAPI document defines no servers or only relative ones. The MCP templates always emitted the --server-index flag and serverIdx/server pass-through whenever a servers object existed, but config.ts only declares those fields when a server has an absolute URL, so npm run build failed with TS2339/TS2353 errors.

  • MCP server templates now gate the server-selection flag and serverIdx/server pass-through on the same $hasServers predicate config.ts uses.
  • Generated output for documents with absolute servers is unchanged.
  • The mcp-typescript target already used the matching predicate and is unaffected.

Written for commit 6f47860. Summary will update on new commits.

View guided diff Turn on auto-fix

The generated src/lib/config.ts only declares SDKOptions.serverIdx (or
SDKOptions.server for named servers) when the document has a server with
an absolute URL. The MCP server templates emitted the server-index flag and
the serverIdx pass-through whenever any servers object existed, including
the implicit default or relative-only servers, which left the generated
MCP server referencing SDKOptions["serverIdx"] and failing to compile.

Gate those three places on the same predicate config.ts uses.
@AshGodfrey
AshGodfrey requested a review from a team as a code owner November 16, 2026 12:52
@github-actions github-actions Bot added the typescript Trigger (168) snapshot tests for typescript label Nov 16, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would auto-approve. Fixes generated TypeScript MCP server compilation when the OpenAPI document defines no absolute servers by gating serverIdx/server pass-through on the same HasAbsoluteURL predicate config.ts uses; output for absolute-server documents is unchanged.
Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack

View guided diff | Turn on auto-fix | Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

typescript Trigger (168) snapshot tests for typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant