Skip to content

fix(worker): dedupe MCP SDK + fix agent.ts type errors, add tsc gate to CI #238

Description

@liplus-lin-lay

purpose / 目的

worker の型チェック (tsc --noEmit) が CI で走っておらず, agent.ts に 2 件の型エラーが静かに蓄積していた (PR #237 のセルフレビュー中に発見). 2 件を修正し, 再発防止に tsc 型ゲートを CI に追加する.

premise / 前提

  • CI の test ジョブ = tsx --test test/*.test.ts && vitest runtsc --noEmit を一度も走らせていない. 型エラーは CI を素通りする (これが 2 件見逃された構造的原因).
  • tsc --noEmit の現状 = ちょうど 2 件 (全体確認済み), いずれも worker/src/agent.ts:
    • agent.ts:31 TS2344: TenantProps (interface) が Record<string, unknown> 制約を満たさない. TypeScript の interface は暗黙の index signature を持たないため, McpAgent<Env, unknown, TenantProps> の Props 制約に不適合.
    • agent.ts:32 TS2416: @modelcontextprotocol/sdk が依存ツリーに 2 コピー存在する (worker 直下 1.27.1 / agents@0.8.2 の nested 1.26.0). 別コピーのため McpServer の private フィールド _serverInfo が非互換となり, this.server が McpAgent の期待する型に代入できない. 版差ではなく「2 コピーある」こと自体が原因 (1.26/1.27 は実質互換).
  • @cloudflare/workers-types は既に worker/package.json overrides で pin 済み (同 family の transitive 重複問題). 今回は別パッケージ (@modelcontextprotocol/sdk) の同種ケース.

design / 設計・制約

  • (1) dedupe (error 2): worker/package.json の overrides@modelcontextprotocol/sdk を追加しツリーを単一版に寄せる. 既存の @cloudflare/workers-types override がテンプレート. agents@0.8.2 が要求する 1.26.0 に合わせる方向を優先 (安全側: より制約の強い consumer に合わせる). 適用後に tsc --noEmit クリア + 全テスト + Workers build 通過を必ず確認.
  • (2) type 化 (error 1): worker/src/agent.ts の interface TenantPropstype TenantProps = に変更.
  • (3) CI 型ゲート追加: worker に typecheck script ("typecheck": "tsc --noEmit") を追加し, .github/workflows/ci.yml の CI で実行. 型エラーで CI が fail するゲートにする.
  • 順序: (1)(2) を先に直し tsc を完全クリアにしてから (3) のゲートを有効化する (ゲートを先に入れると既存エラーで赤くなる). ゲート追加前に tsc --noEmit がエラーゼロであることを全体で再確認.
  • runtime 挙動は不変 (型/ビルド健全性のみ, 機能変更なし).

scope out / スコープ外

  • agent.ts の機能変更, MCP ツールの挙動変更.
  • 他パッケージ (mcp-server / local-mcp / shared) の typecheck ゲート化 (本 issue は worker 限定. 必要なら別 issue).

target files / 対象ファイル

  • worker/package.json (overrides + typecheck script)
  • worker/src/agent.ts
  • .github/workflows/ci.yml

completion conditions / 完了条件

  • cd worker && npx tsc --noEmit がエラーゼロ
  • @modelcontextprotocol/sdk が単一版に dedupe される (nested コピー解消)
  • TenantProps が type 化される
  • CI (ci.yml) が tsc --noEmit を実行し, 型エラーで fail するゲートになっている
  • 既存の全テスト + Workers build が green

Refs #237

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingreadybody converged for implementation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions