@daileyos/mcp-server 1.21.2 → 1.21.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +7 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +23 -2
- package/dist/api.js.map +1 -1
- package/dist/index.js +24 -17
- package/dist/index.js.map +1 -1
- package/dist/tools/accounts.d.ts.map +1 -1
- package/dist/tools/accounts.js +3 -2
- package/dist/tools/accounts.js.map +1 -1
- package/dist/tools/ai.d.ts.map +1 -1
- package/dist/tools/ai.js +7 -1
- package/dist/tools/ai.js.map +1 -1
- package/dist/tools/auth.d.ts.map +1 -1
- package/dist/tools/auth.js +25 -6
- package/dist/tools/auth.js.map +1 -1
- package/dist/tools/backups.d.ts.map +1 -1
- package/dist/tools/backups.js +3 -1
- package/dist/tools/backups.js.map +1 -1
- package/dist/tools/build-logs.d.ts.map +1 -1
- package/dist/tools/build-logs.js +3 -1
- package/dist/tools/build-logs.js.map +1 -1
- package/dist/tools/credentials-reveal.d.ts.map +1 -1
- package/dist/tools/credentials-reveal.js +3 -1
- package/dist/tools/credentials-reveal.js.map +1 -1
- package/dist/tools/dailey-images.js +3 -3
- package/dist/tools/dailey-images.js.map +1 -1
- package/dist/tools/db-migrate.js +5 -5
- package/dist/tools/db-migrate.js.map +1 -1
- package/dist/tools/db.d.ts.map +1 -1
- package/dist/tools/db.js +17 -1
- package/dist/tools/db.js.map +1 -1
- package/dist/tools/deploy-status.d.ts.map +1 -1
- package/dist/tools/deploy-status.js +3 -1
- package/dist/tools/deploy-status.js.map +1 -1
- package/dist/tools/deploy.d.ts.map +1 -1
- package/dist/tools/deploy.js +9 -1
- package/dist/tools/deploy.js.map +1 -1
- package/dist/tools/domains.d.ts.map +1 -1
- package/dist/tools/domains.js +3 -1
- package/dist/tools/domains.js.map +1 -1
- package/dist/tools/email.d.ts.map +1 -1
- package/dist/tools/email.js +8 -2
- package/dist/tools/email.js.map +1 -1
- package/dist/tools/env.d.ts.map +1 -1
- package/dist/tools/env.js +5 -1
- package/dist/tools/env.js.map +1 -1
- package/dist/tools/environments.js +3 -3
- package/dist/tools/environments.js.map +1 -1
- package/dist/tools/exec-run.d.ts.map +1 -1
- package/dist/tools/exec-run.js +7 -1
- package/dist/tools/exec-run.js.map +1 -1
- package/dist/tools/images.d.ts.map +1 -1
- package/dist/tools/images.js +5 -1
- package/dist/tools/images.js.map +1 -1
- package/dist/tools/lifecycle.d.ts.map +1 -1
- package/dist/tools/lifecycle.js +5 -1
- package/dist/tools/lifecycle.js.map +1 -1
- package/dist/tools/links.d.ts.map +1 -1
- package/dist/tools/links.js +3 -1
- package/dist/tools/links.js.map +1 -1
- package/dist/tools/platform.d.ts.map +1 -1
- package/dist/tools/platform.js +5 -3
- package/dist/tools/platform.js.map +1 -1
- package/dist/tools/processes.d.ts.map +1 -1
- package/dist/tools/processes.js +11 -1
- package/dist/tools/processes.js.map +1 -1
- package/dist/tools/projects.d.ts.map +1 -1
- package/dist/tools/projects.js +36 -12
- package/dist/tools/projects.js.map +1 -1
- package/dist/tools/resource-config.d.ts.map +1 -1
- package/dist/tools/resource-config.js +3 -1
- package/dist/tools/resource-config.js.map +1 -1
- package/dist/tools/scale.d.ts.map +1 -1
- package/dist/tools/scale.js +3 -1
- package/dist/tools/scale.js.map +1 -1
- package/dist/tools/storage.d.ts.map +1 -1
- package/dist/tools/storage.js +11 -1
- package/dist/tools/storage.js.map +1 -1
- package/dist/tools/support.d.ts.map +1 -1
- package/dist/tools/support.js +3 -1
- package/dist/tools/support.js.map +1 -1
- package/dist/tools/usage.d.ts.map +1 -1
- package/dist/tools/usage.js +3 -1
- package/dist/tools/usage.js.map +1 -1
- package/dist/tools/wordpress-import.d.ts.map +1 -1
- package/dist/tools/wordpress-import.js +3 -1
- package/dist/tools/wordpress-import.js.map +1 -1
- package/dist/tools/wordpress-migrate.d.ts.map +1 -1
- package/dist/tools/wordpress-migrate.js +3 -1
- package/dist/tools/wordpress-migrate.js.map +1 -1
- package/dist/tools/wordpress-snapshot.d.ts.map +1 -1
- package/dist/tools/wordpress-snapshot.js +9 -1
- package/dist/tools/wordpress-snapshot.js.map +1 -1
- package/package.json +10 -2
- package/.dockerignore +0 -6
- package/.github/workflows/publish.yml +0 -120
- package/Dockerfile +0 -19
- package/claude-config.json +0 -13
- package/docs/superpowers/plans/2026-08-09-remote-mcp-endpoint.md +0 -663
- package/docs/superpowers/specs/2026-08-09-remote-mcp-endpoint-design.md +0 -66
- package/src/api.ts +0 -263
- package/src/context.ts +0 -12
- package/src/http.ts +0 -160
- package/src/index.ts +0 -94
- package/src/server.ts +0 -188
- package/src/tools/accounts.ts +0 -119
- package/src/tools/addons.ts +0 -124
- package/src/tools/admin.ts +0 -42
- package/src/tools/ai.ts +0 -83
- package/src/tools/analyze.ts +0 -108
- package/src/tools/auth.ts +0 -177
- package/src/tools/backups.ts +0 -84
- package/src/tools/billing.ts +0 -34
- package/src/tools/build-logs.ts +0 -65
- package/src/tools/bundle.ts +0 -129
- package/src/tools/cli.ts +0 -76
- package/src/tools/credentials-reveal.ts +0 -64
- package/src/tools/credits.ts +0 -97
- package/src/tools/dailey-images.ts +0 -151
- package/src/tools/db-migrate.ts +0 -211
- package/src/tools/db.ts +0 -391
- package/src/tools/deploy-status.ts +0 -247
- package/src/tools/deploy.ts +0 -101
- package/src/tools/diagnose.ts +0 -567
- package/src/tools/domains.ts +0 -156
- package/src/tools/email.ts +0 -101
- package/src/tools/env.ts +0 -205
- package/src/tools/environments.ts +0 -138
- package/src/tools/exec-run.ts +0 -91
- package/src/tools/images.ts +0 -221
- package/src/tools/lifecycle.ts +0 -75
- package/src/tools/links.ts +0 -69
- package/src/tools/platform.ts +0 -209
- package/src/tools/processes.ts +0 -182
- package/src/tools/project-transfer.ts +0 -129
- package/src/tools/projects.ts +0 -287
- package/src/tools/resource-config.ts +0 -84
- package/src/tools/scale.ts +0 -33
- package/src/tools/storage.ts +0 -281
- package/src/tools/support.ts +0 -42
- package/src/tools/usage.ts +0 -128
- package/src/tools/wordpress-import.ts +0 -174
- package/src/tools/wordpress-live-edit.ts +0 -250
- package/src/tools/wordpress-migrate.ts +0 -104
- package/src/tools/wordpress-snapshot.ts +0 -225
- package/src/tools/wordpress-targeting.ts +0 -188
- package/src/upload.ts +0 -35
- package/src/version.ts +0 -70
- package/test/context.test.ts +0 -36
- package/test/http.test.ts +0 -103
- package/test/server-surface.test.ts +0 -36
- package/test/use-account-sticky.test.ts +0 -28
- package/test/wordpress-import.test.ts +0 -223
- package/test/wordpress-live-edit.test.ts +0 -159
- package/test/wordpress-targeting.test.ts +0 -162
- package/tests/dailey-images.test.mjs +0 -156
- package/tests/environments.test.mjs +0 -230
- package/tests/mcp-protocol-smoke.mjs +0 -149
- package/tests/new-tools-smoke.mjs +0 -217
- package/tests/pack1-mcp-preflight.test.mjs +0 -184
- package/tests/pack6-smoke.mjs +0 -222
- package/tests/wp-snapshot-labels.test.mjs +0 -21
- package/tests/wp-snapshot.test.mjs +0 -261
- package/tsconfig.json +0 -19
|
@@ -1,663 +0,0 @@
|
|
|
1
|
-
# Remote MCP Endpoint (mcp.dailey.cloud) Implementation Plan
|
|
2
|
-
|
|
3
|
-
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
|
4
|
-
|
|
5
|
-
**Goal:** Serve the existing DOS MCP tools over hardened streamable HTTP at `https://mcp.dailey.cloud` (bearer-token auth) without changing the stdio npm package's behavior.
|
|
6
|
-
|
|
7
|
-
**Architecture:** One repo (`dailey-mcp`), two entries sharing one tool assembly: `src/server.ts` builds an `McpServer` with surface flags; `src/index.ts` (stdio) keeps today's behavior; new `src/http.ts` serves stateless streamable HTTP with per-request AsyncLocalStorage carrying `{token, account?}` so `api.ts` token/account resolution becomes request-scoped remotely and unchanged locally.
|
|
8
|
-
|
|
9
|
-
**Tech Stack:** TypeScript (existing tsconfig), `@modelcontextprotocol/sdk` (pin exact `1.27.1`), node `http` (no express), node:22-alpine container, `tsx --test` for tests (repo standard).
|
|
10
|
-
|
|
11
|
-
## Global Constraints (from the spec — verbatim where quoted)
|
|
12
|
-
|
|
13
|
-
- The server is **credential-free**: no secrets in env/ConfigMap/Secret for this workload; tokens exist only inside a request's ALS store. Never log tokens or tool arguments.
|
|
14
|
-
- Remote surface: NO `registerAdminTools`, NO account-SWITCH tool; `registerAuthTools` SHIPS remotely (amended — pure API tools incl. dailey_whoami); account-LIST tool stays and its remote description says to pass `account:` per call.
|
|
15
|
-
- Transport: streamable HTTP **stateless** (`sessionIdGenerator: undefined`); `GET /mcp` and `DELETE /mcp` → 405.
|
|
16
|
-
- HTTP hardening: body cap 1 MiB → 413; `headersTimeout` 10s; `requestTimeout` 120s; per-token limit 60 req/min → 429; global 600 req/min → 429 + `Retry-After`; POST /mcp requires `Content-Type: application/json`.
|
|
17
|
-
- 401 body is JSON-RPC-shaped with header `WWW-Authenticate: Bearer resource_metadata="https://mcp.dailey.cloud/.well-known/oauth-protected-resource"`.
|
|
18
|
-
- CORS: `Access-Control-Allow-Origin: *`; allow headers `Authorization, Content-Type, Mcp-Session-Id, MCP-Protocol-Version`; handle `OPTIONS` with 204.
|
|
19
|
-
- Access log line: method, path, status, duration ms, sha256(token) first 8 hex chars, tool name for tools/call. Never arguments.
|
|
20
|
-
- Dockerfile: node:22-alpine, `USER node`, `npm ci` + `npm audit --omit=dev --audit-level=critical` (build fails on critical), `NODE_ENV=production`, default `PORT=8080`.
|
|
21
|
-
- stdio behavior byte-identical: `src/index.ts` still registers everything (admin, auth, account switch) and keeps preflight/version-check logic.
|
|
22
|
-
- Commits go to `main` of `jonndailey/dailey-mcp` (repo has no CI deploy; npm publish is manual and NOT part of this plan).
|
|
23
|
-
|
|
24
|
-
## File Structure
|
|
25
|
-
|
|
26
|
-
- `src/context.ts` (new) — the ALS store: type, export, helpers. Single responsibility: request-scoped identity.
|
|
27
|
-
- `src/api.ts` (modify ~lines 44–66) — `resolveToken`/`setActiveAccount`/`getActiveAccount` consult the ALS store first.
|
|
28
|
-
- `src/server.ts` (new) — `buildServer(opts)`: constructs `McpServer` + all registrations, gated.
|
|
29
|
-
- `src/index.ts` (modify) — delete its inline construction/registration block; call `buildServer` with all-true flags. No other changes.
|
|
30
|
-
- `src/tools/accounts.ts` (modify) — `registerAccountTools(server, opts?)` gains `{ includeSwitch?: boolean; remoteHint?: boolean }` (defaults preserve today's behavior).
|
|
31
|
-
- `src/http.ts` (new) — the hardened HTTP entry.
|
|
32
|
-
- `test/context.test.ts`, `test/server-surface.test.ts`, `test/http.test.ts` (new).
|
|
33
|
-
- `Dockerfile`, `.dockerignore` (new, repo root).
|
|
34
|
-
|
|
35
|
-
---
|
|
36
|
-
|
|
37
|
-
### Task 1: Request-scoped identity context (`src/context.ts` + `api.ts` integration)
|
|
38
|
-
|
|
39
|
-
**Files:**
|
|
40
|
-
- Create: `src/context.ts`
|
|
41
|
-
- Modify: `src/api.ts` (the `resolveToken`, `setActiveAccount`, `getActiveAccount` bodies, ~lines 44–66)
|
|
42
|
-
- Test: `test/context.test.ts`
|
|
43
|
-
|
|
44
|
-
**Interfaces:**
|
|
45
|
-
- Consumes: nothing new.
|
|
46
|
-
- Produces: `requestContext: AsyncLocalStorage<RequestIdentity>` and `interface RequestIdentity { token: string; account?: string }` from `src/context.ts`. Later tasks import `requestContext` and run handlers inside `requestContext.run({ token }, fn)`.
|
|
47
|
-
|
|
48
|
-
- [ ] **Step 1: Write the failing test**
|
|
49
|
-
|
|
50
|
-
```ts
|
|
51
|
-
// test/context.test.ts
|
|
52
|
-
import { test } from 'node:test';
|
|
53
|
-
import assert from 'node:assert/strict';
|
|
54
|
-
import { requestContext } from '../src/context.js';
|
|
55
|
-
import { resolveToken, setActiveAccount, getActiveAccount } from '../src/api.js';
|
|
56
|
-
|
|
57
|
-
test('resolveToken prefers the ALS store token over env/config', () => {
|
|
58
|
-
requestContext.run({ token: 'tok-from-request' }, () => {
|
|
59
|
-
assert.equal(resolveToken(), 'tok-from-request');
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('setActiveAccount inside a request scopes to that request only', () => {
|
|
64
|
-
// Outside any request: module-global behavior (stdio path).
|
|
65
|
-
setActiveAccount(undefined);
|
|
66
|
-
requestContext.run({ token: 't1' }, () => {
|
|
67
|
-
setActiveAccount('acme');
|
|
68
|
-
assert.equal(getActiveAccount(), 'acme');
|
|
69
|
-
});
|
|
70
|
-
// The write above must NOT have leaked to the module global.
|
|
71
|
-
assert.equal(getActiveAccount(), undefined);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test('two concurrent request contexts never see each other', async () => {
|
|
75
|
-
const seen: Array<string | undefined> = [];
|
|
76
|
-
await Promise.all([
|
|
77
|
-
new Promise<void>((res) => requestContext.run({ token: 'a' }, () => {
|
|
78
|
-
setActiveAccount('acct-a');
|
|
79
|
-
setTimeout(() => { seen.push(getActiveAccount()); res(); }, 20);
|
|
80
|
-
})),
|
|
81
|
-
new Promise<void>((res) => requestContext.run({ token: 'b' }, () => {
|
|
82
|
-
setActiveAccount('acct-b');
|
|
83
|
-
setTimeout(() => { seen.push(getActiveAccount()); res(); }, 10);
|
|
84
|
-
})),
|
|
85
|
-
]);
|
|
86
|
-
assert.deepEqual(seen.sort(), ['acct-a', 'acct-b']);
|
|
87
|
-
});
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
- [ ] **Step 2: Run test to verify it fails**
|
|
91
|
-
|
|
92
|
-
Run: `npx tsx --test --experimental-test-module-mocks test/context.test.ts`
|
|
93
|
-
Expected: FAIL — `Cannot find module '../src/context.js'`.
|
|
94
|
-
|
|
95
|
-
- [ ] **Step 3: Create `src/context.ts`**
|
|
96
|
-
|
|
97
|
-
```ts
|
|
98
|
-
// Request-scoped identity for the remote (HTTP) entry. The stdio entry never
|
|
99
|
-
// enters this context, so api.ts falls through to its module-global/env logic
|
|
100
|
-
// there — stdio behavior is unchanged by construction.
|
|
101
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
102
|
-
|
|
103
|
-
export interface RequestIdentity {
|
|
104
|
-
token: string;
|
|
105
|
-
/** Managed-account scope for THIS request only (X-Dailey-Account). */
|
|
106
|
-
account?: string;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export const requestContext = new AsyncLocalStorage<RequestIdentity>();
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
- [ ] **Step 4: Integrate in `src/api.ts`**
|
|
113
|
-
|
|
114
|
-
Add the import at the top of `src/api.ts`:
|
|
115
|
-
|
|
116
|
-
```ts
|
|
117
|
-
import { requestContext } from './context.js';
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
Replace the three function bodies (keep the existing comments above them):
|
|
121
|
-
|
|
122
|
-
```ts
|
|
123
|
-
export function resolveToken(): string {
|
|
124
|
-
const ctx = requestContext.getStore();
|
|
125
|
-
if (ctx) return ctx.token;
|
|
126
|
-
if (ENV_TOKEN) return ENV_TOKEN;
|
|
127
|
-
if (refreshedToken) return refreshedToken;
|
|
128
|
-
return readCliStoredToken() || '';
|
|
129
|
-
}
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
```ts
|
|
133
|
-
export function setActiveAccount(slugOrId: string | undefined): void {
|
|
134
|
-
const v = slugOrId && slugOrId.trim() ? slugOrId.trim() : undefined;
|
|
135
|
-
const ctx = requestContext.getStore();
|
|
136
|
-
if (ctx) { ctx.account = v; return; } // request-scoped: dies with the request
|
|
137
|
-
activeAccount = v;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export function getActiveAccount(): string | undefined {
|
|
141
|
-
const ctx = requestContext.getStore();
|
|
142
|
-
if (ctx) return ctx.account;
|
|
143
|
-
return activeAccount;
|
|
144
|
-
}
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
- [ ] **Step 5: Run test to verify it passes**
|
|
148
|
-
|
|
149
|
-
Run: `npx tsx --test --experimental-test-module-mocks test/context.test.ts`
|
|
150
|
-
Expected: PASS (3/3). Note: this also satisfies the spec's `wordpress-live-edit.ts` item with zero edits there — its `setActiveAccount` call now lands in ALS during remote requests.
|
|
151
|
-
|
|
152
|
-
- [ ] **Step 6: Run the full existing suite to prove stdio semantics unchanged**
|
|
153
|
-
|
|
154
|
-
Run: `npm test`
|
|
155
|
-
Expected: same pass/fail set as before this task (compare against a pre-change run of `npm test`).
|
|
156
|
-
|
|
157
|
-
- [ ] **Step 7: Commit**
|
|
158
|
-
|
|
159
|
-
```bash
|
|
160
|
-
git add src/context.ts src/api.ts test/context.test.ts
|
|
161
|
-
git commit -m "feat(context): request-scoped token/account via AsyncLocalStorage"
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
### Task 2: Extract `buildServer` + surface flags
|
|
165
|
-
|
|
166
|
-
**Files:**
|
|
167
|
-
- Create: `src/server.ts`
|
|
168
|
-
- Modify: `src/index.ts` (remove inline `new McpServer(...)` at ~line 128 and the registration block ~lines 179–244; replace with a `buildServer` call)
|
|
169
|
-
- Modify: `src/tools/accounts.ts` (add opts param)
|
|
170
|
-
- Test: `test/server-surface.test.ts`
|
|
171
|
-
|
|
172
|
-
**Interfaces:**
|
|
173
|
-
- Consumes: all existing `registerXxxTools(server)` functions; `OWN_VERSION` from `./version.js`.
|
|
174
|
-
- Produces: `buildServer(opts: BuildOptions): McpServer` and `interface BuildOptions { includeAdmin: boolean; includeLocalAuth: boolean; includeAccountSwitch: boolean; instructions?: string }` from `src/server.ts`. Task 3 calls `buildServer({ includeAdmin: false, includeLocalAuth: true, includeAccountSwitch: false })` (AMENDED: auth.ts tools are pure API calls and ship remotely — see spec amendment).
|
|
175
|
-
|
|
176
|
-
- [ ] **Step 1: Write the failing test**
|
|
177
|
-
|
|
178
|
-
```ts
|
|
179
|
-
// test/server-surface.test.ts
|
|
180
|
-
import { test } from 'node:test';
|
|
181
|
-
import assert from 'node:assert/strict';
|
|
182
|
-
import { buildServer } from '../src/server.js';
|
|
183
|
-
|
|
184
|
-
async function toolNames(opts: Parameters<typeof buildServer>[0]): Promise<string[]> {
|
|
185
|
-
const server = buildServer(opts);
|
|
186
|
-
// McpServer keeps registrations in a private map; list via the underlying
|
|
187
|
-
// server's request handler is heavyweight, so use the public accessor
|
|
188
|
-
// pattern the SDK supports: (server as any)._registeredTools.
|
|
189
|
-
return Object.keys((server as any)._registeredTools ?? {});
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
test('remote surface excludes admin, local-auth, and account-switch tools', async () => {
|
|
193
|
-
const names = await toolNames({ includeAdmin: false, includeLocalAuth: false, includeAccountSwitch: false });
|
|
194
|
-
assert.ok(names.length > 40, `expected >40 tools, got ${names.length}`);
|
|
195
|
-
for (const n of names) {
|
|
196
|
-
assert.ok(!n.startsWith('dailey_admin'), `admin tool leaked: ${n}`);
|
|
197
|
-
}
|
|
198
|
-
assert.ok(!names.includes('dailey_login'), 'local auth tool leaked');
|
|
199
|
-
assert.ok(!names.includes('dailey_use_account'), 'account switch tool leaked');
|
|
200
|
-
assert.ok(names.some((n) => n.includes('account')), 'account LIST tool should remain');
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
test('stdio surface includes everything', async () => {
|
|
204
|
-
const names = await toolNames({ includeAdmin: true, includeLocalAuth: true, includeAccountSwitch: true });
|
|
205
|
-
assert.ok(names.some((n) => n.startsWith('dailey_admin')), 'admin tools missing on stdio surface');
|
|
206
|
-
assert.ok(names.includes('dailey_use_account') || names.some((n) => n.includes('use_account')), 'switch tool missing on stdio surface');
|
|
207
|
-
});
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
Before finalizing assertions, verify the actual tool names: `grep -n "'dailey_" src/tools/auth.ts src/tools/accounts.ts src/tools/admin.ts | head -20` and adjust the exact strings (`dailey_login`, `dailey_use_account`, `dailey_admin*`) to what is registered. If `(server as any)._registeredTools` is not present in SDK 1.27.1, use the documented alternative: call `server.tool` count via a wrapper — wrap registration by passing a Proxy'd server that records `tool()` names into an array, and assert on that array instead (the Proxy approach works regardless of SDK internals; prefer it if the private map is absent).
|
|
211
|
-
|
|
212
|
-
- [ ] **Step 2: Run test to verify it fails**
|
|
213
|
-
|
|
214
|
-
Run: `npx tsx --test --experimental-test-module-mocks test/server-surface.test.ts`
|
|
215
|
-
Expected: FAIL — `Cannot find module '../src/server.js'`.
|
|
216
|
-
|
|
217
|
-
- [ ] **Step 3: Create `src/server.ts`**
|
|
218
|
-
|
|
219
|
-
Move VERBATIM from `src/index.ts`: the whole import block for `register*` functions (index.ts lines 9–49), the `new McpServer(...)` expression (index.ts ~line 128, including its `name: 'dailey-os', version: OWN_VERSION` args), and the full registration call sequence (~lines 179–244, keeping every comment). Shape:
|
|
220
|
-
|
|
221
|
-
```ts
|
|
222
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
223
|
-
import { OWN_VERSION } from './version.js';
|
|
224
|
-
// ... all registerXxxTools imports moved verbatim from index.ts ...
|
|
225
|
-
|
|
226
|
-
export interface BuildOptions {
|
|
227
|
-
includeAdmin: boolean;
|
|
228
|
-
includeLocalAuth: boolean;
|
|
229
|
-
includeAccountSwitch: boolean;
|
|
230
|
-
instructions?: string;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export function buildServer(opts: BuildOptions): McpServer {
|
|
234
|
-
const server = new McpServer(
|
|
235
|
-
{ name: 'dailey-os', version: OWN_VERSION },
|
|
236
|
-
opts.instructions ? { instructions: opts.instructions } : undefined,
|
|
237
|
-
);
|
|
238
|
-
|
|
239
|
-
if (opts.includeLocalAuth) registerAuthTools(server);
|
|
240
|
-
registerAccountTools(server, {
|
|
241
|
-
includeSwitch: opts.includeAccountSwitch,
|
|
242
|
-
remoteHint: !opts.includeAccountSwitch,
|
|
243
|
-
});
|
|
244
|
-
// ... every other register call moved verbatim, in the same order ...
|
|
245
|
-
if (opts.includeAdmin) registerAdminTools(server);
|
|
246
|
-
// ... remainder verbatim ...
|
|
247
|
-
return server;
|
|
248
|
-
}
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
- [ ] **Step 4: Add opts to `src/tools/accounts.ts`**
|
|
252
|
-
|
|
253
|
-
Change the signature (line ~20) to:
|
|
254
|
-
|
|
255
|
-
```ts
|
|
256
|
-
export function registerAccountTools(
|
|
257
|
-
server: McpServer,
|
|
258
|
-
opts: { includeSwitch?: boolean; remoteHint?: boolean } = {},
|
|
259
|
-
): void {
|
|
260
|
-
const { includeSwitch = true, remoteHint = false } = opts;
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
Wrap the SECOND `server.tool(` block (the switch tool at ~line 47) in `if (includeSwitch) { ... }`. On the FIRST (list) tool, append to its description string when `remoteHint` is true:
|
|
264
|
-
|
|
265
|
-
```ts
|
|
266
|
-
(remoteHint ? ' NOTE: this server is remote and stateless — there is no session account switching. Pass `account: "<slug>"` on each tool call to operate in a managed account.' : '')
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
- [ ] **Step 5: Rewire `src/index.ts`**
|
|
270
|
-
|
|
271
|
-
Delete the moved code; in its place:
|
|
272
|
-
|
|
273
|
-
```ts
|
|
274
|
-
import { buildServer } from './server.js';
|
|
275
|
-
// ... existing preflight/version-check code stays exactly as-is ...
|
|
276
|
-
const server = buildServer({
|
|
277
|
-
includeAdmin: true,
|
|
278
|
-
includeLocalAuth: true,
|
|
279
|
-
includeAccountSwitch: true,
|
|
280
|
-
instructions: newerVersion ? outdatedNotice(newerVersion) : undefined,
|
|
281
|
-
});
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
The `hasCredentials`/`getActiveAccount`/`setActiveAccount` imports index.ts still uses for preflight stay.
|
|
285
|
-
|
|
286
|
-
- [ ] **Step 6: Run tests**
|
|
287
|
-
|
|
288
|
-
Run: `npx tsx --test --experimental-test-module-mocks test/server-surface.test.ts && npm test`
|
|
289
|
-
Expected: new test PASS; full suite unchanged vs baseline.
|
|
290
|
-
|
|
291
|
-
- [ ] **Step 7: Build + stdio smoke**
|
|
292
|
-
|
|
293
|
-
Run: `npm run build && printf '' | DAILEY_API_TOKEN=x node dist/index.js` (should start and exit cleanly on stdin EOF, no stack trace).
|
|
294
|
-
|
|
295
|
-
- [ ] **Step 8: Commit**
|
|
296
|
-
|
|
297
|
-
```bash
|
|
298
|
-
git add src/server.ts src/index.ts src/tools/accounts.ts test/server-surface.test.ts
|
|
299
|
-
git commit -m "refactor(server): buildServer with surface flags; account tools gain switch/remote opts"
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
### Task 3: Hardened HTTP entry (`src/http.ts`)
|
|
303
|
-
|
|
304
|
-
**Files:**
|
|
305
|
-
- Create: `src/http.ts`
|
|
306
|
-
- Test: `test/http.test.ts`
|
|
307
|
-
|
|
308
|
-
**Interfaces:**
|
|
309
|
-
- Consumes: `buildServer` (Task 2), `requestContext` (Task 1), `StreamableHTTPServerTransport` from `@modelcontextprotocol/sdk/server/streamableHttp.js`.
|
|
310
|
-
- Produces: a runnable `dist/http.js` honoring `PORT` (default 8080). Exports `createHttpServer(): http.Server` for tests; `if (import.meta.url === pathToFileURL(process.argv[1]).href)` guard starts listening.
|
|
311
|
-
|
|
312
|
-
- [ ] **Step 1: Write the failing test**
|
|
313
|
-
|
|
314
|
-
```ts
|
|
315
|
-
// test/http.test.ts
|
|
316
|
-
import { test, before, after } from 'node:test';
|
|
317
|
-
import assert from 'node:assert/strict';
|
|
318
|
-
import type { Server } from 'node:http';
|
|
319
|
-
import { createHttpServer } from '../src/http.js';
|
|
320
|
-
|
|
321
|
-
let server: Server; let base: string;
|
|
322
|
-
before(async () => {
|
|
323
|
-
server = createHttpServer();
|
|
324
|
-
await new Promise<void>((r) => server.listen(0, () => r()));
|
|
325
|
-
const addr = server.address() as { port: number };
|
|
326
|
-
base = `http://127.0.0.1:${addr.port}`;
|
|
327
|
-
});
|
|
328
|
-
after(() => server.close());
|
|
329
|
-
|
|
330
|
-
test('healthz is open', async () => {
|
|
331
|
-
const r = await fetch(`${base}/healthz`);
|
|
332
|
-
assert.equal(r.status, 200);
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
test('POST /mcp without bearer → 401 with WWW-Authenticate', async () => {
|
|
336
|
-
const r = await fetch(`${base}/mcp`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{}' });
|
|
337
|
-
assert.equal(r.status, 401);
|
|
338
|
-
assert.match(r.headers.get('www-authenticate') ?? '', /resource_metadata=/);
|
|
339
|
-
const body = await r.json();
|
|
340
|
-
assert.equal(body.jsonrpc, '2.0');
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
test('GET /mcp → 405 (stateless)', async () => {
|
|
344
|
-
const r = await fetch(`${base}/mcp`, { headers: { Authorization: 'Bearer x' } });
|
|
345
|
-
assert.equal(r.status, 405);
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
test('wrong content-type → 415', async () => {
|
|
349
|
-
const r = await fetch(`${base}/mcp`, { method: 'POST', headers: { Authorization: 'Bearer x', 'Content-Type': 'text/plain' }, body: '{}' });
|
|
350
|
-
assert.equal(r.status, 415);
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
test('oauth-protected-resource metadata served', async () => {
|
|
354
|
-
const r = await fetch(`${base}/.well-known/oauth-protected-resource`);
|
|
355
|
-
assert.equal(r.status, 200);
|
|
356
|
-
const j = await r.json();
|
|
357
|
-
assert.equal(j.resource, 'https://mcp.dailey.cloud');
|
|
358
|
-
assert.deepEqual(j.authorization_servers, ['https://core.dailey.cloud']);
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
test('tools/list works with any bearer (no capi call) and excludes admin', async () => {
|
|
362
|
-
const { Client } = await import('@modelcontextprotocol/sdk/client/index.js');
|
|
363
|
-
const { StreamableHTTPClientTransport } = await import('@modelcontextprotocol/sdk/client/streamableHttp.js');
|
|
364
|
-
const client = new Client({ name: 'test', version: '0' });
|
|
365
|
-
const transport = new StreamableHTTPClientTransport(new URL(`${base}/mcp`), {
|
|
366
|
-
requestInit: { headers: { Authorization: 'Bearer dummy-token' } },
|
|
367
|
-
});
|
|
368
|
-
await client.connect(transport);
|
|
369
|
-
const tools = await client.listTools();
|
|
370
|
-
assert.ok(tools.tools.length > 40);
|
|
371
|
-
assert.ok(tools.tools.every((t) => !t.name.startsWith('dailey_admin')));
|
|
372
|
-
await client.close();
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
test('per-token rate limit trips at 61st request in a minute', async () => {
|
|
376
|
-
let last = 0;
|
|
377
|
-
for (let i = 0; i < 61; i++) {
|
|
378
|
-
const r = await fetch(`${base}/healthz-limited-probe`, { method: 'POST', headers: { Authorization: 'Bearer ratelimit-test', 'Content-Type': 'application/json' }, body: '{}' }).catch(() => null);
|
|
379
|
-
// use /mcp for the real limiter:
|
|
380
|
-
const r2 = await fetch(`${base}/mcp`, { method: 'POST', headers: { Authorization: 'Bearer ratelimit-test', 'Content-Type': 'application/json' }, body: JSON.stringify({ jsonrpc: '2.0', id: i, method: 'ping' }) });
|
|
381
|
-
last = r2.status;
|
|
382
|
-
if (last === 429) break;
|
|
383
|
-
}
|
|
384
|
-
assert.equal(last, 429);
|
|
385
|
-
});
|
|
386
|
-
```
|
|
387
|
-
|
|
388
|
-
(Trim the stray `healthz-limited-probe` fetch when writing — the real assertions are on `/mcp`.)
|
|
389
|
-
|
|
390
|
-
- [ ] **Step 2: Run test to verify it fails**
|
|
391
|
-
|
|
392
|
-
Run: `npx tsx --test --experimental-test-module-mocks test/http.test.ts`
|
|
393
|
-
Expected: FAIL — `Cannot find module '../src/http.js'`.
|
|
394
|
-
|
|
395
|
-
- [ ] **Step 3: Implement `src/http.ts`**
|
|
396
|
-
|
|
397
|
-
```ts
|
|
398
|
-
import http from 'node:http';
|
|
399
|
-
import { createHash } from 'node:crypto';
|
|
400
|
-
import { pathToFileURL } from 'node:url';
|
|
401
|
-
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
402
|
-
import { buildServer } from './server.js';
|
|
403
|
-
import { requestContext } from './context.js';
|
|
404
|
-
|
|
405
|
-
const PORT = Number(process.env.PORT || 8080);
|
|
406
|
-
const BODY_LIMIT = 1024 * 1024; // 1 MiB
|
|
407
|
-
const PER_TOKEN_LIMIT = 60; // req/min
|
|
408
|
-
const GLOBAL_LIMIT = 600; // req/min
|
|
409
|
-
const RESOURCE = 'https://mcp.dailey.cloud';
|
|
410
|
-
const AUTH_SERVER = 'https://core.dailey.cloud';
|
|
411
|
-
|
|
412
|
-
// ── fixed-window rate limiting ──────────────────────────────────────────────
|
|
413
|
-
const tokenWindows = new Map<string, { count: number; windowStart: number }>();
|
|
414
|
-
let globalWindow = { count: 0, windowStart: Date.now() };
|
|
415
|
-
function allow(tokenHash: string): boolean {
|
|
416
|
-
const now = Date.now();
|
|
417
|
-
if (now - globalWindow.windowStart >= 60_000) globalWindow = { count: 0, windowStart: now };
|
|
418
|
-
if (++globalWindow.count > GLOBAL_LIMIT) return false;
|
|
419
|
-
const w = tokenWindows.get(tokenHash);
|
|
420
|
-
if (!w || now - w.windowStart >= 60_000) { tokenWindows.set(tokenHash, { count: 1, windowStart: now }); return true; }
|
|
421
|
-
return ++w.count <= PER_TOKEN_LIMIT;
|
|
422
|
-
}
|
|
423
|
-
setInterval(() => { // stop the map growing forever
|
|
424
|
-
const cutoff = Date.now() - 120_000;
|
|
425
|
-
for (const [k, w] of tokenWindows) if (w.windowStart < cutoff) tokenWindows.delete(k);
|
|
426
|
-
}, 60_000).unref();
|
|
427
|
-
|
|
428
|
-
function hashToken(token: string): string {
|
|
429
|
-
return createHash('sha256').update(token).digest('hex').slice(0, 8);
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
function cors(res: http.ServerResponse): void {
|
|
433
|
-
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
434
|
-
res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');
|
|
435
|
-
res.setHeader('Access-Control-Allow-Headers', 'Authorization, Content-Type, Mcp-Session-Id, MCP-Protocol-Version');
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
function json(res: http.ServerResponse, status: number, body: unknown, headers: Record<string, string> = {}): void {
|
|
439
|
-
cors(res);
|
|
440
|
-
res.writeHead(status, { 'Content-Type': 'application/json', ...headers });
|
|
441
|
-
res.end(JSON.stringify(body));
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
function rpcError(res: http.ServerResponse, status: number, code: number, message: string, headers: Record<string, string> = {}): void {
|
|
445
|
-
json(res, status, { jsonrpc: '2.0', error: { code, message }, id: null }, headers);
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
function readBody(req: http.IncomingMessage): Promise<string | null> {
|
|
449
|
-
return new Promise((resolve) => {
|
|
450
|
-
let size = 0; const chunks: Buffer[] = [];
|
|
451
|
-
req.on('data', (c: Buffer) => {
|
|
452
|
-
size += c.length;
|
|
453
|
-
if (size > BODY_LIMIT) { resolve(null); req.destroy(); return; }
|
|
454
|
-
chunks.push(c);
|
|
455
|
-
});
|
|
456
|
-
req.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
|
|
457
|
-
req.on('error', () => resolve(null));
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
const LANDING = `<!doctype html><title>Dailey OS MCP</title>
|
|
462
|
-
<h1>Dailey OS remote MCP endpoint</h1>
|
|
463
|
-
<p>Point your MCP client at <code>${RESOURCE}/mcp</code> with header
|
|
464
|
-
<code>Authorization: Bearer <your DOS API token></code> (copy the token from the
|
|
465
|
-
<a href="https://os.dailey.cloud">dashboard</a>). Docs: <a href="https://docs.dailey.cloud">docs.dailey.cloud</a>.</p>`;
|
|
466
|
-
|
|
467
|
-
export function createHttpServer(): http.Server {
|
|
468
|
-
const server = http.createServer(async (req, res) => {
|
|
469
|
-
const started = Date.now();
|
|
470
|
-
const url = (req.url || '/').split('?')[0];
|
|
471
|
-
let logSuffix = '';
|
|
472
|
-
const finish = (status: number) => {
|
|
473
|
-
// access log: method path status duration token-hash tool — never bodies/args
|
|
474
|
-
console.log(`${req.method} ${url} ${status} ${Date.now() - started}ms${logSuffix}`);
|
|
475
|
-
};
|
|
476
|
-
res.on('finish', () => finish(res.statusCode));
|
|
477
|
-
try {
|
|
478
|
-
if (req.method === 'OPTIONS') { cors(res); res.writeHead(204); res.end(); return; }
|
|
479
|
-
if (url === '/healthz') { cors(res); res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('ok'); return; }
|
|
480
|
-
if (url === '/' && req.method === 'GET') { cors(res); res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(LANDING); return; }
|
|
481
|
-
if (url === '/.well-known/oauth-protected-resource') {
|
|
482
|
-
json(res, 200, { resource: RESOURCE, authorization_servers: [AUTH_SERVER], bearer_methods_supported: ['header'] });
|
|
483
|
-
return;
|
|
484
|
-
}
|
|
485
|
-
if (url !== '/mcp') { rpcError(res, 404, -32601, 'Not found'); return; }
|
|
486
|
-
if (req.method !== 'POST') { rpcError(res, 405, -32601, 'Stateless server: only POST /mcp is supported'); return; }
|
|
487
|
-
|
|
488
|
-
const auth = req.headers.authorization || '';
|
|
489
|
-
const m = /^Bearer\s+(\S+)$/i.exec(auth);
|
|
490
|
-
if (!m) {
|
|
491
|
-
rpcError(res, 401, -32001, 'Missing bearer token. Get a DOS API token from https://os.dailey.cloud and send Authorization: Bearer <token>.',
|
|
492
|
-
{ 'WWW-Authenticate': `Bearer resource_metadata="${RESOURCE}/.well-known/oauth-protected-resource"` });
|
|
493
|
-
return;
|
|
494
|
-
}
|
|
495
|
-
const token = m[1];
|
|
496
|
-
const tokenHash = hashToken(token);
|
|
497
|
-
logSuffix = ` tok=${tokenHash}`;
|
|
498
|
-
|
|
499
|
-
if (!/^application\/json/.test(req.headers['content-type'] || '')) {
|
|
500
|
-
rpcError(res, 415, -32600, 'Content-Type must be application/json'); return;
|
|
501
|
-
}
|
|
502
|
-
if (!allow(tokenHash)) {
|
|
503
|
-
rpcError(res, 429, -32000, 'Rate limit exceeded (60/min per token). Slow down.', { 'Retry-After': '30' }); return;
|
|
504
|
-
}
|
|
505
|
-
const raw = await readBody(req);
|
|
506
|
-
if (raw === null) { rpcError(res, 413, -32600, 'Body too large (limit 1 MiB)'); return; }
|
|
507
|
-
let parsed: unknown;
|
|
508
|
-
try { parsed = JSON.parse(raw); } catch { rpcError(res, 400, -32700, 'Parse error'); return; }
|
|
509
|
-
const toolName = (parsed as any)?.method === 'tools/call' ? String((parsed as any)?.params?.name ?? '') : '';
|
|
510
|
-
if (toolName) logSuffix += ` tool=${toolName}`;
|
|
511
|
-
|
|
512
|
-
// Stateless: fresh server+transport per request; identity lives in ALS.
|
|
513
|
-
const mcp = buildServer({ includeAdmin: false, includeLocalAuth: true, includeAccountSwitch: false });
|
|
514
|
-
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
|
|
515
|
-
cors(res);
|
|
516
|
-
res.on('close', () => { transport.close().catch(() => {}); mcp.close().catch(() => {}); });
|
|
517
|
-
await requestContext.run({ token }, async () => {
|
|
518
|
-
await mcp.connect(transport);
|
|
519
|
-
await transport.handleRequest(req, res, parsed);
|
|
520
|
-
});
|
|
521
|
-
} catch (err) {
|
|
522
|
-
console.error('handler error:', (err as Error).message);
|
|
523
|
-
if (!res.headersSent) rpcError(res, 500, -32603, 'Internal error');
|
|
524
|
-
else res.end();
|
|
525
|
-
}
|
|
526
|
-
});
|
|
527
|
-
server.headersTimeout = 10_000;
|
|
528
|
-
server.requestTimeout = 120_000;
|
|
529
|
-
return server;
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
533
|
-
createHttpServer().listen(PORT, () => console.log(`dailey-mcp http listening on :${PORT} (stateless streamable HTTP)`));
|
|
534
|
-
}
|
|
535
|
-
```
|
|
536
|
-
|
|
537
|
-
Note for the implementer: SDK 1.27.1's `StreamableHTTPServerTransport.handleRequest(req, res, parsedBody)` accepts the pre-parsed body as the third argument — check `node_modules/@modelcontextprotocol/sdk/dist/esm/server/streamableHttp.d.ts` and, if the signature differs (some versions read the stream themselves), pass the raw body through instead per its actual signature. Do not guess: read the .d.ts.
|
|
538
|
-
|
|
539
|
-
- [ ] **Step 4: Run tests**
|
|
540
|
-
|
|
541
|
-
Run: `npx tsx --test --experimental-test-module-mocks test/http.test.ts`
|
|
542
|
-
Expected: PASS (7/7).
|
|
543
|
-
|
|
544
|
-
- [ ] **Step 5: Env-gated live-token integration test (append to `test/http.test.ts`)**
|
|
545
|
-
|
|
546
|
-
```ts
|
|
547
|
-
test('whoami round-trip with a real token', { skip: !process.env.DAILEY_TEST_TOKEN }, async () => {
|
|
548
|
-
const { Client } = await import('@modelcontextprotocol/sdk/client/index.js');
|
|
549
|
-
const { StreamableHTTPClientTransport } = await import('@modelcontextprotocol/sdk/client/streamableHttp.js');
|
|
550
|
-
const client = new Client({ name: 'test', version: '0' });
|
|
551
|
-
const transport = new StreamableHTTPClientTransport(new URL(`${base}/mcp`), {
|
|
552
|
-
requestInit: { headers: { Authorization: `Bearer ${process.env.DAILEY_TEST_TOKEN}` } },
|
|
553
|
-
});
|
|
554
|
-
await client.connect(transport);
|
|
555
|
-
const out = await client.callTool({ name: 'dailey_whoami', arguments: {} });
|
|
556
|
-
assert.ok(JSON.stringify(out).length > 0);
|
|
557
|
-
await client.close();
|
|
558
|
-
});
|
|
559
|
-
```
|
|
560
|
-
|
|
561
|
-
Run once with a real token from the operator: `DAILEY_TEST_TOKEN=... npx tsx --test --experimental-test-module-mocks test/http.test.ts` → the extra test passes. (Verify the whoami tool's registered name with `grep -rn "dailey_whoami" src/tools/ | head -1` and adjust if it differs.)
|
|
562
|
-
|
|
563
|
-
- [ ] **Step 6: Full suite + build**
|
|
564
|
-
|
|
565
|
-
Run: `npm test && npm run build && node -e "import('./dist/http.js')" & sleep 2 && curl -s localhost:8080/healthz && kill %1`
|
|
566
|
-
Expected: suite baseline-clean; healthz prints `ok`.
|
|
567
|
-
|
|
568
|
-
- [ ] **Step 7: Commit**
|
|
569
|
-
|
|
570
|
-
```bash
|
|
571
|
-
git add src/http.ts test/http.test.ts
|
|
572
|
-
git commit -m "feat(http): hardened stateless streamable-HTTP entry (bearer auth, rate limits, CORS, PRM stub)"
|
|
573
|
-
```
|
|
574
|
-
|
|
575
|
-
### Task 4: Container + package plumbing
|
|
576
|
-
|
|
577
|
-
**Files:**
|
|
578
|
-
- Create: `Dockerfile`, `.dockerignore`
|
|
579
|
-
- Modify: `package.json` (pin SDK exact; add `start:http`; extend `build`)
|
|
580
|
-
|
|
581
|
-
- [ ] **Step 1: Pin the SDK and add scripts**
|
|
582
|
-
|
|
583
|
-
```bash
|
|
584
|
-
npm pkg set 'dependencies.@modelcontextprotocol/sdk=1.27.1'
|
|
585
|
-
npm pkg set 'scripts.start:http=node dist/http.js'
|
|
586
|
-
npm install
|
|
587
|
-
git diff package.json # confirm only those changes + lockfile
|
|
588
|
-
```
|
|
589
|
-
|
|
590
|
-
- [ ] **Step 2: Write `Dockerfile`**
|
|
591
|
-
|
|
592
|
-
```dockerfile
|
|
593
|
-
FROM node:22-alpine AS build
|
|
594
|
-
WORKDIR /app
|
|
595
|
-
COPY package.json package-lock.json ./
|
|
596
|
-
RUN npm ci
|
|
597
|
-
# Security gate: fail the build on critical advisories in prod deps.
|
|
598
|
-
RUN npm audit --omit=dev --audit-level=critical
|
|
599
|
-
COPY tsconfig.json ./
|
|
600
|
-
COPY src ./src
|
|
601
|
-
RUN npm run build && npm prune --omit=dev
|
|
602
|
-
|
|
603
|
-
FROM node:22-alpine
|
|
604
|
-
ENV NODE_ENV=production PORT=8080
|
|
605
|
-
WORKDIR /app
|
|
606
|
-
COPY --from=build /app/node_modules ./node_modules
|
|
607
|
-
COPY --from=build /app/dist ./dist
|
|
608
|
-
COPY --from=build /app/package.json ./package.json
|
|
609
|
-
USER node
|
|
610
|
-
EXPOSE 8080
|
|
611
|
-
CMD ["node", "dist/http.js"]
|
|
612
|
-
```
|
|
613
|
-
|
|
614
|
-
- [ ] **Step 3: Write `.dockerignore`**
|
|
615
|
-
|
|
616
|
-
```
|
|
617
|
-
node_modules
|
|
618
|
-
dist
|
|
619
|
-
docs
|
|
620
|
-
test
|
|
621
|
-
.git
|
|
622
|
-
*.md
|
|
623
|
-
```
|
|
624
|
-
|
|
625
|
-
- [ ] **Step 4: Local container smoke**
|
|
626
|
-
|
|
627
|
-
```bash
|
|
628
|
-
docker build -t dailey-mcp-http:dev .
|
|
629
|
-
docker run --rm -d -p 18080:8080 --name mcp-smoke dailey-mcp-http:dev
|
|
630
|
-
sleep 2
|
|
631
|
-
curl -s localhost:18080/healthz # expect: ok
|
|
632
|
-
curl -s -o /dev/null -w '%{http_code}\n' -X POST localhost:18080/mcp -H 'Content-Type: application/json' -d '{}' # expect: 401
|
|
633
|
-
docker rm -f mcp-smoke
|
|
634
|
-
```
|
|
635
|
-
|
|
636
|
-
- [ ] **Step 5: Commit**
|
|
637
|
-
|
|
638
|
-
```bash
|
|
639
|
-
git add Dockerfile .dockerignore package.json package-lock.json
|
|
640
|
-
git commit -m "build(docker): hardened non-root image for the http entry; pin SDK exact"
|
|
641
|
-
```
|
|
642
|
-
|
|
643
|
-
### Task 5: Deploy to DOS + live verification (operator task — runs on King, not a code subagent)
|
|
644
|
-
|
|
645
|
-
**Files:** none in this repo (uses the DOS dashboard/MCP tooling + this repo's main).
|
|
646
|
-
|
|
647
|
-
- [ ] **Step 1: Push main** — `git push origin main` (repo `jonndailey/dailey-mcp`; no CI publishes npm from this — verified, publish is manual).
|
|
648
|
-
- [ ] **Step 2: Create the DOS project** via `dailey_create_project` (internal account): name `dailey-mcp-remote`, repo `https://github.com/jonndailey/dailey-mcp`, branch `main` (Dockerfile auto-detected). Resources: 0.1 CPU / 128 MB request, 0.5 / 512 limit.
|
|
649
|
-
- [ ] **Step 3: Domain** — attach `mcp.dailey.cloud` via `dailey_domains`; wait for cert.
|
|
650
|
-
- [ ] **Step 4: Verify security posture live:**
|
|
651
|
-
- `curl -s https://mcp.dailey.cloud/healthz` → `ok`
|
|
652
|
-
- `curl -s -o /dev/null -w '%{http_code}' -X POST https://mcp.dailey.cloud/mcp -H 'Content-Type: application/json' -d '{}'` → `401` with `WWW-Authenticate` header present (`curl -sI` variant)
|
|
653
|
-
- `curl -s https://mcp.dailey.cloud/.well-known/oauth-protected-resource` → the PRM JSON
|
|
654
|
-
- Confirm the deployment has NO secret envFrom carrying credentials (`kubectl -n <ns> get deploy dailey-mcp-remote -o yaml | grep -A5 envFrom` — only optional platform mounts; the credential-free property).
|
|
655
|
-
- `readOnlyRootFilesystem`: check whether the deploy-service template supports it; if not, record the gap in the EOS note (accepted for v1) rather than hand-editing the live object.
|
|
656
|
-
- [ ] **Step 5: Real-client verification** — attach from Cursor (Settings → MCP → URL `https://mcp.dailey.cloud/mcp`, header `Authorization: Bearer <token>`): tool list loads (>40 tools, no admin), `dailey_whoami` returns identity, `dailey_list_projects` returns projects.
|
|
657
|
-
- [ ] **Step 6: Documentation** — EOS release note (what shipped, security posture, the credential-free property, phase-2 OAuth pointer) + memory update; add the endpoint to the registry of public surfaces in `Dailey OS Operations.md`.
|
|
658
|
-
|
|
659
|
-
## Self-review (done at write time)
|
|
660
|
-
|
|
661
|
-
- **Spec coverage:** every spec section maps: architecture→T2/T3, auth/ALS→T1/T3, security items→T3 (limits/CORS/log/timeouts) + T4 (container/audit/pin) + T5.4 (credential-free check, readOnly gap), hosting→T5, stub PRM→T3, testing→T1/T2/T3 tests + T5 live. Out-of-scope items stay out.
|
|
662
|
-
- **Placeholders:** none; the two "verify against actual" notes (tool names, SDK handleRequest signature) instruct reading real files, with exact commands — deliberate anti-guessing guards, not gaps.
|
|
663
|
-
- **Type consistency:** `RequestIdentity`/`requestContext` (T1) used in T3; `BuildOptions`/`buildServer` (T2) used in T3; `createHttpServer` (T3) used in its own tests. Names match throughout.
|