File size: 7,824 Bytes
0e5ccec
b753db1
 
 
0e5ccec
 
b753db1
 
 
0e5ccec
 
 
 
 
b753db1
 
 
 
 
0e5ccec
 
 
 
b753db1
 
 
0e5ccec
b753db1
 
 
0e5ccec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b753db1
 
 
 
0e5ccec
 
 
 
 
 
 
 
 
b753db1
0e5ccec
b753db1
0e5ccec
b753db1
0e5ccec
 
 
 
 
 
b753db1
 
 
0e5ccec
 
 
 
 
 
 
 
 
 
 
 
 
b753db1
 
 
0e5ccec
 
 
 
 
 
 
 
 
b753db1
0e5ccec
 
 
 
 
 
 
b753db1
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# **PRD – Dev A: Server Layer & Runner/Packaging**

---

## 1 β€’ Goal
As Dev A, your goal is to develop the **Server Layer** of the local Node.js application. This involves creating the MCP server, defining the resources and tools for interacting with the Codenames game, and handling communication with the Browser Layer via a defined interface (`ICodenamesBrowser`). You will also contribute to the top-level `runner.ts` script and the project's packaging configuration (`package.json`, `tsconfig.json`).

---

## 2 β€’ Key Technologies (Focus)
- **Node.js** & **npm**
- **`modelcontextprotocol` SDK** (TypeScript)
- **TypeScript**
- Understanding of `npm link` / `npx` for integration and testing

---

## 3 β€’ Responsibilities & Deliverables

| Module / Layer         | Responsibilities                                                                                               | Deliverables                      |
| :--------------------- | :------------------------------------------------------------------------------------------------------------- | :-------------------------------- |
| **Server Layer**       | Node.js MCP server logic:<br>β€’ Initialize MCP SDK<br>β€’ Define MCP resources & tools (e.g., `getBoardState`, `giveClue`)<br>β€’ Handle MCP requests<br>β€’ Call Browser Layer API (`ICodenamesBrowser`) | `server/server.ts`, `server/schemas.ts`, `server/tests/` |
| **Runner & Packaging** | Top-level script & setup contributions:<br>β€’ Implement relevant parts of `runner.ts` (initialize Server Layer, wire to Browser Layer)<br>β€’ **Drive definition** of `ICodenamesBrowser` interface<br>β€’ Configure `package.json` (`name`, `version`, `bin`, `files`, `scripts`)<br>β€’ Configure `tsconfig.json` | Contributions to: `runner.ts`, `package.json`, `tsconfig.json`, `shared/types.ts` |

---

## 4 β€’ Suggested Folder Structure (Focus)

```
spymaster/
β”œβ”€β”€ server/                # <-- Your primary focus
β”‚   β”œβ”€β”€ server.ts          # <-- MCP logic
β”‚   β”œβ”€β”€ schemas.ts         # <-- MCP resource/tool schemas
β”‚   └── tests/             # <-- Your unit tests
β”œβ”€β”€ browser/               # <-- Dev B's area (interact via ICodenamesBrowser)
β”‚   └── ...
β”œβ”€β”€ runner.ts              # <-- Collaborate on setup/wiring
β”œβ”€β”€ shared/                # <-- Define ICodenamesBrowser here
β”‚   └── types.ts
β”œβ”€β”€ package.json           # <-- Configure build, link, run
β”œβ”€β”€ tsconfig.json          # <-- Configure TS compilation
β”œβ”€β”€ README.md
└── docs/
    β”œβ”€β”€ overall_prd.md
    └── dev_a_prd.md       # <-- This document
```

---

## 5 β€’ Architecture & Execution Flow (Your Role)
1.  **Build:** Ensure `npm run build` (using `tsconfig.json` you configure) compiles `server/` and `runner.ts` correctly into `dist/`.
2.  **Linking:** Use `npm link` to make the package executable.
3.  **Execution:** `npx your-package-name` runs `dist/runner.js`.
4.  **Runner (`dist/runner.js`):**
    - Initializes the **Browser Layer** (handled by Dev B, provides `ICodenamesBrowser` instance).
    - You ensure `runner.ts` initializes your **Server Layer**, passing the `ICodenamesBrowser` instance to it.
    - Your Server Layer starts the MCP server.
5.  **Server Layer:** Your code handles incoming MCP requests, translates them into calls to the `ICodenamesBrowser` interface methods provided by the Browser Layer.

---

## 6 β€’ Development Steps (Your Flow)

| Phase                        | Your Actions (Dev A: Server Layer / Build / Runner)                                                                                              | Key Interaction / Synchronization Point                                                                         |
| :--------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------- |
| **1. Setup, Config & Contract** | Setup `server/`. Configure `package.json`, `tsconfig.json`. **Drive definition** of `ICodenamesBrowser` interface in `shared/types.ts`.           | **Critical Sync:** Agree with Dev B on `ICodenamesBrowser` interface & `package.json` structure (`bin`, `runner.ts`). |
| **2. Independent Implementation** | Implement Server Layer (`server/`) against a **mock** implementation of `ICodenamesBrowser`. Implement `runner.ts` wiring logic. Unit test `server/` logic using the mock. | **None.** Focus on your layer using the defined interface and mock.                               |
| **3. Build, Link & Smoke Test** | Run `npm run build`. Run `npm link`. Run `npx your-package-name` smoke test. Verify your server starts up correctly (even if browser part fails initially). | **Sync Point:** Verify successful build, link, basic `npx` execution. Inform Dev B.                           |
| **4. Integration Test & Debug** | **Lead** E2E testing using MCP Inspector connected to the `npx`-run process. Debug MCP request/response flow and issues related to interaction with the Browser Layer API. | **Sync Point:** Collaborative E2E testing & debugging using `npx`-launched app. You lead, Dev B supports.      |

---

## 7 β€’ Testing Approach (Your Responsibility)
-   **Unit Tests (`server/tests/`):**
    -   Thoroughly test your `server.ts` and `schemas.ts` logic.
    -   **Crucially, mock the `ICodenamesBrowser` interface.** Your unit tests should *not* depend on the actual Playwright implementation. Verify that your server logic correctly calls the mock interface methods based on MCP requests.
-   **E2E & Primary Validation:**
    -   After `npm run build` and `npm link`, you will primarily drive E2E testing.
    -   Run `npx your-package-name`.
    -   Connect MCP Inspector.
    -   Execute MCP commands (`getBoardState`, `giveClue`, `makeGuess`, etc.).
    -   Verify:
        -   Correct MCP responses are generated by your server.
        -   Expected actions occur in the browser (debugging with Dev B if browser actions fail).
        -   Your server correctly handles the data/responses received from the Browser Layer via the `ICodenamesBrowser` interface.

---

## 8 β€’ Key Risks (Focus)
-   **Interface Mismatch:** Your server code expects one thing from `ICodenamesBrowser`, but the Browser Layer implements it differently.
    -   **Mitigation:** Clear TypeScript interface definition (`shared/types.ts`), early integration testing via `npx` run, frequent communication with Dev B.
-   **Build/Link Issues:** Problems with `tsconfig.json`, `package.json` (`bin`, `files`), or `npm link`.
    -   **Mitigation:** Verify build output (`dist/`), check global links (`npm ls -g --depth=0 --link=true`), ensure `runner.ts` compiles correctly and `package.json` points to it.
-   **MCP Logic Errors:** Incorrectly handling MCP requests or formatting responses.
    -   **Mitigation:** Strong unit tests with mocked browser interface, thorough E2E testing with MCP Inspector.

---

## 9 β€’ Acceptance Criteria (Your Contribution)
-   `npm run build` successfully compiles `server/`, `shared/`, and `runner.ts` into `dist/`.
-   `npm link` successfully links the package defined in `package.json`.
-   `npx your-package-name` starts the `runner.ts` script, which successfully initializes and starts your MCP server.
-   MCP Inspector can connect to your server process.
-   MCP Inspector can invoke all defined MCP tools (`getBoardState`, `getTeamTurn`, `getClueLog`, `giveClue`, `makeGuess`, `endTurn`).
-   Your Server Layer correctly processes these requests, calls the appropriate methods on the (mocked or real) `ICodenamesBrowser` interface, and returns accurate responses based on the interface's return values.

---