@daileyos/mcp-server 1.21.2 → 1.21.4
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.js +1 -1
- 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 +7 -1
- 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 +3 -1
- 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 +4 -1
- 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,66 +0,0 @@
|
|
|
1
|
-
# Remote MCP endpoint — mcp.dailey.cloud (design)
|
|
2
|
-
|
|
3
|
-
Approved by Jonny 2026-08-09 (brainstorm in ops session). v1 = bearer-token auth; Core OAuth 2.1 is phase 2, out of scope here.
|
|
4
|
-
|
|
5
|
-
## Goal
|
|
6
|
-
Expose the existing DOS MCP tools over streamable HTTP at `https://mcp.dailey.cloud` so remote-capable clients (Cursor, claude.ai, ChatGPT connectors) attach with a URL + DOS API token — no local install. The npm stdio package (`@daileyos/mcp-server`) keeps working unchanged.
|
|
7
|
-
|
|
8
|
-
## Decisions (locked)
|
|
9
|
-
- **Tool surface:** everything except `registerAdminTools` and the account-SWITCH tool. **AMENDED during implementation (2026-08-09):** `registerAuthTools` was originally excluded on the premise it held device-login/config flows — inspection shows its three tools (`dailey_whoami`, `dailey_auth_status`, `dailey_auth_enable`) are pure API calls, so they SHIP remotely (whoami/auth_status are how a remote user verifies their connection). The `includeLocalAuth` build flag remains for any future genuinely-local tool. Project-transfer tools also ship remotely (customer capability; capi-authorized consent flow). capi remains the sole authorizer.
|
|
10
|
-
- **Tokens:** existing DOS API tokens (same value `DAILEY_API_TOKEN` takes today; users copy from the dashboard). No new token type in v1.
|
|
11
|
-
- **Hosting:** normal DOS project (internal account), repo-first from this repo, domain `mcp.dailey.cloud`, 1 replica.
|
|
12
|
-
- **Transport:** streamable HTTP, **stateless mode** (`sessionIdGenerator: undefined`) — all tools are request/response; restarts invisible; no session store.
|
|
13
|
-
|
|
14
|
-
## Architecture
|
|
15
|
-
One repo (`dailey-mcp`), two entries sharing one assembly:
|
|
16
|
-
|
|
17
|
-
- `src/server.ts` (new): `buildServer(opts: { includeAdmin: boolean, includeLocalAuth: boolean }): McpServer` — moves the register-call block out of `index.ts` verbatim; gates `registerAdminTools` on `includeAdmin` and `registerAuthTools` on `includeLocalAuth`. `index.ts` keeps its version-check/active-account behavior and calls `buildServer({ includeAdmin: true, includeLocalAuth: true })` — stdio behavior byte-identical.
|
|
18
|
-
- `src/http.ts` (new): node `http` server.
|
|
19
|
-
- `POST /mcp` → SDK `StreamableHTTPServerTransport` (stateless), one `buildServer({ includeAdmin: false, includeLocalAuth: false })` + transport per request (stateless pattern), request handling wrapped in the token context (below).
|
|
20
|
-
- `GET /` → minimal HTML: what this is, how to attach (Cursor/claude.ai snippets), link to docs.
|
|
21
|
-
- `GET /healthz` → 200 `ok`.
|
|
22
|
-
- `GET /.well-known/oauth-protected-resource` → static JSON naming `https://core.dailey.cloud` as the (future) authorization server; contract-correct stub so OAuth-capable clients discover cleanly in phase 2.
|
|
23
|
-
- CORS: `Access-Control-Allow-Origin: *`, allow `Authorization, Content-Type, Mcp-Session-Id, MCP-Protocol-Version`; handle `OPTIONS`.
|
|
24
|
-
- `DELETE /mcp` and `GET /mcp` → 405 (stateless mode has no sessions / no server-push stream).
|
|
25
|
-
|
|
26
|
-
## Per-request auth (the one real mechanism)
|
|
27
|
-
`src/api.ts` gains an `AsyncLocalStorage<{ token: string }>` exported as `tokenContext`. `resolveToken()` checks `tokenContext.getStore()?.token` FIRST, then falls back to today's env/config chain. `http.ts`:
|
|
28
|
-
1. Reads `Authorization: Bearer <token>`; missing/malformed → HTTP 401, `WWW-Authenticate: Bearer resource_metadata="https://mcp.dailey.cloud/.well-known/oauth-protected-resource"`, JSON-RPC error body.
|
|
29
|
-
2. Valid shape → `tokenContext.run({ token }, () => transport.handleRequest(...))`.
|
|
30
|
-
3. No token validation at the MCP layer — a bad token surfaces as capi's 401 through the existing `formatError` path on first tool call.
|
|
31
|
-
Zero changes to the 41 tool modules.
|
|
32
|
-
|
|
33
|
-
## Security (v1 posture — reviewed and expanded 2026-08-09 at Jonny's direction)
|
|
34
|
-
**Core property: the server is credential-free.** It holds no API keys, no DB creds, no service tokens — bearer tokens arrive per-request, live only in the request's AsyncLocalStorage, and die with it. A fully compromised pod yields no standing secrets. Preserve this property in all future changes (nothing secret in env/ConfigMap/Secret for this workload).
|
|
35
|
-
|
|
36
|
-
- Admin, account-switch, and project-transfer tools never registered on the remote surface (auth tools SHIP per the amended Decisions — pure API calls).
|
|
37
|
-
- In-process per-token rate limit: 60 requests/min (fixed window, `Map<tokenHash, {count, windowStart}>`); over-limit → HTTP 429. Token keys are sha256 truncations — raw tokens never held beyond the request, never logged.
|
|
38
|
-
- No request-body logging; access log line = method, path, status, duration, token hash prefix (8 chars), and tool name when the request is a tools/call (NEVER tool arguments — they can contain user secrets). Errors returned to clients never echo the token.
|
|
39
|
-
- Request body cap: 1 MiB (413 above). Server timeouts: headersTimeout 10s, requestTimeout 120s (long tool calls allowed; slowloris not).
|
|
40
|
-
- Global ceiling in addition to per-token: 600 req/min process-wide → 429 + `Retry-After` (protects capi from a runaway or distributed client).
|
|
41
|
-
- CORS `*` is safe here BECAUSE auth is an explicit header (no cookies → no CSRF); revisit if cookie auth ever appears. Validate `Content-Type: application/json` on POST /mcp.
|
|
42
|
-
- Container hardening: non-root `USER node`, `readOnlyRootFilesystem: true` in the deployment (SDK needs no disk writes), no added capabilities, `NODE_ENV=production`.
|
|
43
|
-
- Dependency hygiene: `@modelcontextprotocol/sdk` pinned exact (no `^`); `npm audit --omit=dev` in the build (fail on critical).
|
|
44
|
-
- Tool OUTPUTS are untrusted data to the calling model (they can contain customer-authored content from capi); nothing in this server treats them as instructions — inherent MCP posture, noted so future middleware doesn't.
|
|
45
|
-
- **Active-account state (three moves, decided 2026-08-09 after review):**
|
|
46
|
-
1. Remote surface registers the account-LIST tool but NOT the account-SWITCH tool (stateless mode has no session to remember it; a manager with two connectors could otherwise cross-wire accounts with valid creds). The list tool's remote description instructs "pass `account:` per call" (supported on every tool since v1.21.0).
|
|
47
|
-
2. The AsyncLocalStorage store is `{ token: string, account?: string }`. `setActiveAccount()`/`getActiveAccount()` consult the ALS store FIRST (write/read request-scoped state when present) and fall through to the module global only when no store exists (stdio). Cross-user bleed becomes impossible by construction — any code path that "sets the account" inside a remote request affects only that request.
|
|
48
|
-
3. Fix `wordpress-live-edit.ts:62`, which mutates the global as a side effect of its per-call `account` param — route it through the same mechanism (this is a latent stdio bug too: a per-call param permanently switching the session's account).
|
|
49
|
-
|
|
50
|
-
## Deployment
|
|
51
|
-
- `Dockerfile` (new, repo root): node:22-alpine, `npm ci && npm run build`, `CMD ["node", "dist/http.js"]`, `EXPOSE 8080` (`PORT` env honored, default 8080).
|
|
52
|
-
- DOS project `dailey-mcp-remote` (internal account) built from this repo's main; domain `mcp.dailey.cloud`; resources 100m/128Mi req, 500m/512Mi lim.
|
|
53
|
-
- The container reaches capi via the public `https://os.dailey.cloud/api` (default `DAILEY_API_URL`) — no in-cluster coupling, no netpol work (customer-ns egress to public IPs is allowed).
|
|
54
|
-
|
|
55
|
-
## Error handling
|
|
56
|
-
- 401 (no/malformed bearer) and 429 (rate limit) at HTTP layer with JSON-RPC-shaped bodies.
|
|
57
|
-
- Everything else flows through the SDK transport; tool errors keep the existing `formatError`/`remediationFor` copy (already plain-language).
|
|
58
|
-
- Uncaught handler errors → 500 JSON-RPC internal error; process stays up (per-request try/catch).
|
|
59
|
-
|
|
60
|
-
## Testing
|
|
61
|
-
1. **Unit** (`test/`): `resolveToken()` prefers tokenContext over env; `buildServer({includeAdmin:false})` registers no `dailey_admin_*` and no login tools; rate limiter windows.
|
|
62
|
-
2. **Integration** (local): start `dist/http.js`, connect with `@modelcontextprotocol/sdk` `StreamableHTTPClientTransport` + `Authorization` header, `tools/list` (assert no admin tools, count > 40), call `dailey_whoami` with a real token (env-gated test), assert identity echo.
|
|
63
|
-
3. **Live**: deploy → `curl /healthz` → attach from Cursor by URL → tool list + `dailey_whoami` + one read tool (`dailey_list_projects`).
|
|
64
|
-
|
|
65
|
-
## Out of scope (phase 2+)
|
|
66
|
-
Core OAuth 2.1 (authorization-server work in dailey-core, dynamic client registration, PKCE); scoped MCP-specific tokens + revocation UI; docs-site "Add to Cursor" deep-link buttons; MCP registry listings.
|
package/src/api.ts
DELETED
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
import { homedir } from 'node:os';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { readFileSync } from 'node:fs';
|
|
4
|
-
import { OWN_VERSION } from './version.js';
|
|
5
|
-
import { requestContext } from './context.js';
|
|
6
|
-
|
|
7
|
-
const API_URL = process.env.DAILEY_API_URL || 'https://os.dailey.cloud/api';
|
|
8
|
-
const DAILEY_EMAIL = process.env.DAILEY_EMAIL;
|
|
9
|
-
const DAILEY_PASSWORD = process.env.DAILEY_PASSWORD;
|
|
10
|
-
|
|
11
|
-
// Read the token the Dailey CLI stores after `dailey auth login`. The CLI uses
|
|
12
|
-
// `conf` ({ projectName: 'dailey' }), which writes <config>/dailey-nodejs/config.json
|
|
13
|
-
// (env-paths layout). Reusing it means anyone already logged into the CLI (their
|
|
14
|
-
// `dailey whoami` works) gets a working MCP server with NO credentials in the
|
|
15
|
-
// client config — the installer's generated config only sets DAILEY_API_URL, so
|
|
16
|
-
// without this the server has no auth and exits, surfacing as "Connection closed".
|
|
17
|
-
function readCliStoredToken(): string | undefined {
|
|
18
|
-
try {
|
|
19
|
-
const name = 'dailey-nodejs';
|
|
20
|
-
let dir: string;
|
|
21
|
-
if (process.platform === 'darwin') {
|
|
22
|
-
dir = join(homedir(), 'Library', 'Preferences', name);
|
|
23
|
-
} else if (process.platform === 'win32') {
|
|
24
|
-
dir = join(process.env.APPDATA || join(homedir(), 'AppData', 'Roaming'), name, 'Config');
|
|
25
|
-
} else {
|
|
26
|
-
dir = join(process.env.XDG_CONFIG_HOME || join(homedir(), '.config'), name);
|
|
27
|
-
}
|
|
28
|
-
const cfg = JSON.parse(readFileSync(join(dir, 'config.json'), 'utf8'));
|
|
29
|
-
const tok = typeof cfg?.token === 'string' ? cfg.token.trim() : '';
|
|
30
|
-
return tok || undefined;
|
|
31
|
-
} catch {
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// An explicit env token (headless/CI) takes precedence and is fixed for the
|
|
37
|
-
// process lifetime. Otherwise the token is resolved DYNAMICALLY on every request
|
|
38
|
-
// (resolveToken below): the email/password refresh token if present, else the
|
|
39
|
-
// active CLI login — re-read from disk each call so a `dailey login` account
|
|
40
|
-
// switch is picked up live, without restarting the MCP server. This is what
|
|
41
|
-
// keeps multi-account users in sync (no token is baked into the client config).
|
|
42
|
-
const ENV_TOKEN = process.env.DAILEY_API_TOKEN || '';
|
|
43
|
-
let refreshedToken = '';
|
|
44
|
-
|
|
45
|
-
export function resolveToken(): string {
|
|
46
|
-
const ctx = requestContext.getStore();
|
|
47
|
-
if (ctx) return ctx.token;
|
|
48
|
-
if (ENV_TOKEN) return ENV_TOKEN;
|
|
49
|
-
if (refreshedToken) return refreshedToken;
|
|
50
|
-
return readCliStoredToken() || '';
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Active managed-account context for the "manager / managed-accounts" capability.
|
|
54
|
-
// A manager (a Dailey account) can operate inside other accounts that granted
|
|
55
|
-
// them a consent-based grant by sending header `X-Dailey-Account: <slug|id>`;
|
|
56
|
-
// the server verifies a LIVE grant and scopes the request to that account (no
|
|
57
|
-
// re-login). This is SESSION-SCOPED: it persists for the MCP server process
|
|
58
|
-
// lifetime, which is what we want — an agent calls `dailey_use_account` once and
|
|
59
|
-
// every subsequent tool call operates within that account until it clears or
|
|
60
|
-
// switches. When unset, no header is sent (normal self-scoped behavior).
|
|
61
|
-
let activeAccount: string | undefined;
|
|
62
|
-
|
|
63
|
-
export function setActiveAccount(slugOrId: string | undefined): void {
|
|
64
|
-
const v = slugOrId && slugOrId.trim() ? slugOrId.trim() : undefined;
|
|
65
|
-
const ctx = requestContext.getStore();
|
|
66
|
-
if (ctx) { ctx.account = v; return; } // request-scoped: dies with the request
|
|
67
|
-
activeAccount = v;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function getActiveAccount(): string | undefined {
|
|
71
|
-
const ctx = requestContext.getStore();
|
|
72
|
-
if (ctx) return ctx.account;
|
|
73
|
-
return activeAccount;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Credential preflight lives in index.ts so it can distinguish TTY vs
|
|
77
|
-
// MCP-stdio invocation and emit a JSON-RPC-shaped error instead of just
|
|
78
|
-
// dying with a stderr line that Claude Code doesn't surface.
|
|
79
|
-
export function hasCredentials(): boolean {
|
|
80
|
-
return Boolean(resolveToken() || DAILEY_EMAIL);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
async function refreshToken(): Promise<string> {
|
|
84
|
-
if (!DAILEY_EMAIL || !DAILEY_PASSWORD) {
|
|
85
|
-
throw new Error('Cannot refresh token: DAILEY_EMAIL and DAILEY_PASSWORD not set');
|
|
86
|
-
}
|
|
87
|
-
const res = await fetch(`${API_URL}/customers/login`, {
|
|
88
|
-
method: 'POST',
|
|
89
|
-
headers: { 'Content-Type': 'application/json', 'X-Dailey-Source': 'mcp' },
|
|
90
|
-
body: JSON.stringify({ email: DAILEY_EMAIL, password: DAILEY_PASSWORD }),
|
|
91
|
-
});
|
|
92
|
-
if (!res.ok) {
|
|
93
|
-
throw new Error(`Token refresh failed (${res.status}): ${await res.text()}`);
|
|
94
|
-
}
|
|
95
|
-
const data = await res.json() as { access_token?: string };
|
|
96
|
-
if (!data.access_token) {
|
|
97
|
-
throw new Error('Token refresh: no access_token in response');
|
|
98
|
-
}
|
|
99
|
-
refreshedToken = data.access_token;
|
|
100
|
-
return refreshedToken;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
interface ApiResponse<T = unknown> {
|
|
104
|
-
ok: boolean;
|
|
105
|
-
status: number;
|
|
106
|
-
data: T;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export async function apiRequest<T = unknown>(
|
|
110
|
-
method: string,
|
|
111
|
-
path: string,
|
|
112
|
-
body?: Record<string, unknown>,
|
|
113
|
-
): Promise<ApiResponse<T>> {
|
|
114
|
-
const makeRequest = async (token: string): Promise<Response> => {
|
|
115
|
-
const url = `${API_URL}${path}`;
|
|
116
|
-
const headers: Record<string, string> = {
|
|
117
|
-
'Authorization': `Bearer ${token}`,
|
|
118
|
-
'Content-Type': 'application/json',
|
|
119
|
-
// Identify MCP-originated traffic so the platform can record a customer's
|
|
120
|
-
// first successful MCP connection (onboarding progress).
|
|
121
|
-
'X-Dailey-Source': 'mcp',
|
|
122
|
-
// Version fingerprint (2026-07-13 stale-client incident): lets the
|
|
123
|
-
// platform see which MCP versions are live in the field. A request with
|
|
124
|
-
// X-Dailey-Source: mcp but NO version header is a pre-1.20.7 client.
|
|
125
|
-
'X-Dailey-Client-Version': OWN_VERSION,
|
|
126
|
-
};
|
|
127
|
-
// Manager / managed-accounts: when an active account is set, scope every
|
|
128
|
-
// request to it. The server verifies a live consent grant; absent header =
|
|
129
|
-
// normal self-scoped behavior.
|
|
130
|
-
const acct = getActiveAccount();
|
|
131
|
-
if (acct) headers['X-Dailey-Account'] = acct;
|
|
132
|
-
const options: RequestInit = { method, headers };
|
|
133
|
-
if (body && (method === 'POST' || method === 'PUT' || method === 'PATCH')) {
|
|
134
|
-
options.body = JSON.stringify(body);
|
|
135
|
-
}
|
|
136
|
-
return fetch(url, options);
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
let res = await makeRequest(resolveToken());
|
|
140
|
-
|
|
141
|
-
// Auto-refresh on 401 if credentials are configured
|
|
142
|
-
if (res.status === 401 && DAILEY_EMAIL) {
|
|
143
|
-
try {
|
|
144
|
-
await refreshToken();
|
|
145
|
-
res = await makeRequest(resolveToken());
|
|
146
|
-
} catch {
|
|
147
|
-
// refresh failed, return the original 401
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const text = await res.text();
|
|
152
|
-
let data: T;
|
|
153
|
-
try {
|
|
154
|
-
data = JSON.parse(text) as T;
|
|
155
|
-
} catch {
|
|
156
|
-
data = text as unknown as T;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return { ok: res.ok, status: res.status, data };
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export function formatError(res: ApiResponse): string {
|
|
163
|
-
// 401/403 always returns a structured auth error object as JSON text so MCP
|
|
164
|
-
// clients (and agents reading tool output) get a machine-readable signal with
|
|
165
|
-
// a clear remediation path rather than a generic "Error (401): ..." string.
|
|
166
|
-
if (res.status === 401 || res.status === 403) {
|
|
167
|
-
return JSON.stringify({
|
|
168
|
-
error_code: 'DAILEY_AUTH_REQUIRED',
|
|
169
|
-
message: 'Not authenticated',
|
|
170
|
-
remediation: 'Run `dailey auth setup` in your terminal',
|
|
171
|
-
help_url: 'https://docs.dailey.cloud/auth',
|
|
172
|
-
}, null, 2);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const data = res.data;
|
|
176
|
-
let baseMessage: string;
|
|
177
|
-
if (typeof data === 'object' && data !== null && 'error' in data) {
|
|
178
|
-
baseMessage = `Error (${res.status}): ${(data as { error: string }).error}`;
|
|
179
|
-
} else if (typeof data === 'object' && data !== null && 'message' in data) {
|
|
180
|
-
baseMessage = `Error (${res.status}): ${(data as { message: string }).message}`;
|
|
181
|
-
} else {
|
|
182
|
-
baseMessage = `Error (${res.status}): ${JSON.stringify(data)}`;
|
|
183
|
-
}
|
|
184
|
-
const hint = remediationFor(res.status, data);
|
|
185
|
-
return hint ? `${baseMessage}\n→ Remediation: ${hint}` : baseMessage;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Remediation hints for common error patterns. Customer-feedback Scott Waters
|
|
190
|
-
* platform-wishlist 2026-04-25, section 8: "MCP tool errors should include
|
|
191
|
-
* remediation hints. The agent can show this verbatim to the user."
|
|
192
|
-
*
|
|
193
|
-
* Match order matters — most-specific first. Returns null when nothing maps.
|
|
194
|
-
*/
|
|
195
|
-
export function remediationFor(status: number, data: unknown): string | null {
|
|
196
|
-
// Extract a searchable message regardless of the body shape.
|
|
197
|
-
const messageParts: string[] = [];
|
|
198
|
-
if (typeof data === 'string') messageParts.push(data);
|
|
199
|
-
if (typeof data === 'object' && data !== null) {
|
|
200
|
-
const d = data as Record<string, unknown>;
|
|
201
|
-
if (typeof d.error === 'string') messageParts.push(d.error);
|
|
202
|
-
if (typeof d.message === 'string') messageParts.push(d.message);
|
|
203
|
-
if (typeof d.detail === 'string') messageParts.push(d.detail);
|
|
204
|
-
if (typeof d.code === 'string') messageParts.push(d.code);
|
|
205
|
-
}
|
|
206
|
-
const haystack = messageParts.join(' ').toLowerCase();
|
|
207
|
-
|
|
208
|
-
// ── Pattern-driven hints (more specific) — checked first so that an
|
|
209
|
-
// AWS-style "SignatureDoesNotMatch" carrying a 403 status maps to the
|
|
210
|
-
// storage-creds advice, not the generic "token expired" advice. ──
|
|
211
|
-
if (haystack.includes('alreadyexists') && haystack.includes('registry')) {
|
|
212
|
-
return 'Usually transient — retry `dailey_deploy`. The build worker also auto-retries this now.';
|
|
213
|
-
}
|
|
214
|
-
if (haystack.includes('alreadyexists') && (haystack.includes('push') || haystack.includes('blob'))) {
|
|
215
|
-
return 'Usually transient — retry `dailey_deploy`. The build worker also auto-retries this now.';
|
|
216
|
-
}
|
|
217
|
-
if (haystack.includes('signaturedoesnotmatch')) {
|
|
218
|
-
return 'Storage creds may be stale; run `dailey_storage_refresh` or wait for the 24h auto-refresh.';
|
|
219
|
-
}
|
|
220
|
-
if (haystack.includes('containercreating') && (haystack.includes('4 min') || haystack.includes('stuck'))) {
|
|
221
|
-
return 'Image pull or PVC mount; check `dailey_app_logs`.';
|
|
222
|
-
}
|
|
223
|
-
if (haystack.includes('crashloopbackoff')) {
|
|
224
|
-
return 'App is failing on startup; check `dailey_app_logs` for the error, then redeploy.';
|
|
225
|
-
}
|
|
226
|
-
if (haystack.includes('enotfound') || haystack.includes('econnrefused') || haystack.includes('etimedout')) {
|
|
227
|
-
return 'Dailey API may be temporarily unreachable; retry in a minute.';
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// ── Status-code-driven hints (generic fallback) ─────────────────────
|
|
231
|
-
if (status === 423) {
|
|
232
|
-
return 'Account locked. Wait the duration in the message; the platform now sends Retry-After.';
|
|
233
|
-
}
|
|
234
|
-
if (status === 429) {
|
|
235
|
-
return 'Rate limited. Wait the duration; CLI/API auto-honor Retry-After.';
|
|
236
|
-
}
|
|
237
|
-
if (status === 401 || status === 403) {
|
|
238
|
-
return 'Token expired or scope mismatch. Run `dailey login` (CLI) or refresh DAILEY_API_TOKEN.';
|
|
239
|
-
}
|
|
240
|
-
if (status === 502 || status === 503 || status === 504) {
|
|
241
|
-
return 'Dailey API may be temporarily unreachable; retry in a minute.';
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return null;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Wrap a thrown error with remediation hints when possible. Used for fetch-
|
|
249
|
-
* level failures (DNS, connection refused) that never reach formatError.
|
|
250
|
-
*/
|
|
251
|
-
export function formatThrownError(err: unknown): string {
|
|
252
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
253
|
-
const hint = remediationFor(0, message);
|
|
254
|
-
return hint ? `Error: ${message}\n→ Remediation: ${hint}` : `Error: ${message}`;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
export function textResult(text: string) {
|
|
258
|
-
return { content: [{ type: 'text' as const, text }] };
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
export function jsonResult(data: unknown) {
|
|
262
|
-
return textResult(JSON.stringify(data, null, 2));
|
|
263
|
-
}
|
package/src/context.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// Request-scoped identity for the remote (HTTP) entry. The stdio entry never
|
|
2
|
-
// enters this context, so api.ts falls through to its module-global/env logic
|
|
3
|
-
// there — stdio behavior is unchanged by construction.
|
|
4
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
5
|
-
|
|
6
|
-
export interface RequestIdentity {
|
|
7
|
-
token: string;
|
|
8
|
-
/** Managed-account scope for THIS request only (X-Dailey-Account). */
|
|
9
|
-
account?: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const requestContext = new AsyncLocalStorage<RequestIdentity>();
|
package/src/http.ts
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import http from 'node:http';
|
|
2
|
-
import { createHash } from 'node:crypto';
|
|
3
|
-
import { pathToFileURL } from 'node:url';
|
|
4
|
-
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
5
|
-
import { buildServer } from './server.js';
|
|
6
|
-
import { requestContext } from './context.js';
|
|
7
|
-
|
|
8
|
-
const PORT = Number(process.env.PORT || 8080);
|
|
9
|
-
const BODY_LIMIT = 1024 * 1024; // 1 MiB
|
|
10
|
-
const PER_TOKEN_LIMIT = 60; // req/min
|
|
11
|
-
const GLOBAL_LIMIT = 600; // req/min
|
|
12
|
-
const RESOURCE = 'https://mcp.dailey.cloud';
|
|
13
|
-
const AUTH_SERVER = 'https://core.dailey.cloud';
|
|
14
|
-
|
|
15
|
-
// In-flight cap: each request retains a ~1.2MB McpServer until close; 50 × ~1.2MB bounds worst-case heap under slow tool calls (512Mi pod). Security-review dissent 2026-08-09.
|
|
16
|
-
export const MAX_INFLIGHT = 50;
|
|
17
|
-
let inflight = 0;
|
|
18
|
-
|
|
19
|
-
// ── fixed-window rate limiting ──────────────────────────────────────────────
|
|
20
|
-
const tokenWindows = new Map<string, { count: number; windowStart: number }>();
|
|
21
|
-
let globalWindow = { count: 0, windowStart: Date.now() };
|
|
22
|
-
function allow(tokenHash: string): 'ok' | 'token' | 'global' {
|
|
23
|
-
const now = Date.now();
|
|
24
|
-
if (now - globalWindow.windowStart >= 60_000) globalWindow = { count: 0, windowStart: now };
|
|
25
|
-
if (++globalWindow.count > GLOBAL_LIMIT) return 'global';
|
|
26
|
-
const w = tokenWindows.get(tokenHash);
|
|
27
|
-
if (!w || now - w.windowStart >= 60_000) { tokenWindows.set(tokenHash, { count: 1, windowStart: now }); return 'ok'; }
|
|
28
|
-
return ++w.count <= PER_TOKEN_LIMIT ? 'ok' : 'token';
|
|
29
|
-
}
|
|
30
|
-
setInterval(() => { // stop the map growing forever
|
|
31
|
-
const cutoff = Date.now() - 120_000;
|
|
32
|
-
for (const [k, w] of tokenWindows) if (w.windowStart < cutoff) tokenWindows.delete(k);
|
|
33
|
-
}, 60_000).unref();
|
|
34
|
-
|
|
35
|
-
function hashToken(token: string): string {
|
|
36
|
-
return createHash('sha256').update(token).digest('hex');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function cors(res: http.ServerResponse): void {
|
|
40
|
-
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
41
|
-
res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');
|
|
42
|
-
res.setHeader('Access-Control-Allow-Headers', 'Authorization, Content-Type, Mcp-Session-Id, MCP-Protocol-Version');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function json(res: http.ServerResponse, status: number, body: unknown, headers: Record<string, string> = {}): void {
|
|
46
|
-
cors(res);
|
|
47
|
-
res.writeHead(status, { 'Content-Type': 'application/json', ...headers });
|
|
48
|
-
res.end(JSON.stringify(body));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function rpcError(res: http.ServerResponse, status: number, code: number, message: string, headers: Record<string, string> = {}): void {
|
|
52
|
-
json(res, status, { jsonrpc: '2.0', error: { code, message }, id: null }, headers);
|
|
53
|
-
res.destroy();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function readBody(req: http.IncomingMessage): Promise<string | null> {
|
|
57
|
-
return new Promise((resolve) => {
|
|
58
|
-
let size = 0; const chunks: Buffer[] = [];
|
|
59
|
-
req.on('data', (c: Buffer) => {
|
|
60
|
-
size += c.length;
|
|
61
|
-
if (size > BODY_LIMIT) { resolve(null); req.destroy(); return; }
|
|
62
|
-
chunks.push(c);
|
|
63
|
-
});
|
|
64
|
-
req.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
|
|
65
|
-
req.on('error', () => resolve(null));
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const LANDING = `<!doctype html><title>Dailey OS MCP</title>
|
|
70
|
-
<h1>Dailey OS remote MCP endpoint</h1>
|
|
71
|
-
<p>Point your MCP client at <code>${RESOURCE}/mcp</code> with header
|
|
72
|
-
<code>Authorization: Bearer <your DOS API token></code> (copy the token from the
|
|
73
|
-
<a href="https://os.dailey.cloud">dashboard</a>). Docs: <a href="https://docs.dailey.cloud">docs.dailey.cloud</a>.</p>`;
|
|
74
|
-
|
|
75
|
-
export function createHttpServer(): http.Server {
|
|
76
|
-
const server = http.createServer(async (req, res) => {
|
|
77
|
-
const started = Date.now();
|
|
78
|
-
const url = (req.url || '/').split('?')[0];
|
|
79
|
-
let logSuffix = '';
|
|
80
|
-
const finish = (status: number) => {
|
|
81
|
-
// access log: method path status duration token-hash tool — never bodies/args
|
|
82
|
-
console.log(`${req.method} ${url} ${status} ${Date.now() - started}ms${logSuffix}`);
|
|
83
|
-
};
|
|
84
|
-
res.on('finish', () => finish(res.statusCode));
|
|
85
|
-
try {
|
|
86
|
-
if (req.method === 'OPTIONS') { cors(res); res.writeHead(204); res.end(); return; }
|
|
87
|
-
if (url === '/healthz') { cors(res); res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('ok'); return; }
|
|
88
|
-
if (url === '/' && req.method === 'GET') { cors(res); res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(LANDING); return; }
|
|
89
|
-
if (url === '/.well-known/oauth-protected-resource') {
|
|
90
|
-
json(res, 200, { resource: RESOURCE, authorization_servers: [AUTH_SERVER], bearer_methods_supported: ['header'] });
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
if (url !== '/mcp') { rpcError(res, 404, -32601, 'Not found'); return; }
|
|
94
|
-
if (req.method !== 'POST') { rpcError(res, 405, -32601, 'Stateless server: only POST /mcp is supported'); return; }
|
|
95
|
-
|
|
96
|
-
const auth = req.headers.authorization || '';
|
|
97
|
-
const m = /^Bearer\s+(\S+)$/i.exec(auth);
|
|
98
|
-
if (!m) {
|
|
99
|
-
rpcError(res, 401, -32001, 'Missing bearer token. Get a DOS API token from https://os.dailey.cloud and send Authorization: Bearer <token>.',
|
|
100
|
-
{ 'WWW-Authenticate': `Bearer resource_metadata="${RESOURCE}/.well-known/oauth-protected-resource"` });
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const token = m[1];
|
|
104
|
-
const tokenHash = hashToken(token);
|
|
105
|
-
logSuffix = ` tok=${tokenHash.slice(0, 8)}`;
|
|
106
|
-
|
|
107
|
-
const verdict = allow(tokenHash);
|
|
108
|
-
if (verdict !== 'ok') {
|
|
109
|
-
const message = verdict === 'token'
|
|
110
|
-
? 'Rate limit exceeded (60/min per token). Slow down.'
|
|
111
|
-
: 'Server-wide rate limit exceeded. Retry shortly.';
|
|
112
|
-
rpcError(res, 429, -32000, message, { 'Retry-After': '30' }); return;
|
|
113
|
-
}
|
|
114
|
-
if (inflight >= MAX_INFLIGHT) {
|
|
115
|
-
rpcError(res, 503, -32000, 'Server busy (too many concurrent requests). Retry shortly.', { 'Retry-After': '5' });
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
inflight++;
|
|
119
|
-
const done = () => { inflight = Math.max(0, inflight - 1); };
|
|
120
|
-
res.once('close', done);
|
|
121
|
-
if (!/^application\/json/i.test(req.headers['content-type'] || '')) {
|
|
122
|
-
rpcError(res, 415, -32600, 'Content-Type must be application/json'); return;
|
|
123
|
-
}
|
|
124
|
-
const raw = await readBody(req);
|
|
125
|
-
if (raw === null) { rpcError(res, 413, -32600, 'Body too large (limit 1 MiB)'); return; }
|
|
126
|
-
let parsed: unknown;
|
|
127
|
-
try { parsed = JSON.parse(raw); } catch { rpcError(res, 400, -32700, 'Parse error'); return; }
|
|
128
|
-
const toolName = ((parsed as any)?.method === 'tools/call' ? String((parsed as any)?.params?.name ?? '') : '').replace(/[^\w.-]/g, '').slice(0, 64);
|
|
129
|
-
if (toolName) logSuffix += ` tool=${toolName}`;
|
|
130
|
-
|
|
131
|
-
// Stateless: fresh server+transport per request; identity lives in ALS.
|
|
132
|
-
const mcp = buildServer({ includeAdmin: false, includeLocalAuth: true, includeAccountSwitch: false });
|
|
133
|
-
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
|
|
134
|
-
cors(res);
|
|
135
|
-
res.on('error', () => {});
|
|
136
|
-
res.on('close', () => { transport.close().catch(() => {}); mcp.close().catch(() => {}); });
|
|
137
|
-
await requestContext.run({ token }, async () => {
|
|
138
|
-
await mcp.connect(transport);
|
|
139
|
-
await transport.handleRequest(req, res, parsed);
|
|
140
|
-
});
|
|
141
|
-
} catch (err) {
|
|
142
|
-
console.error('handler error:', (err as Error).message);
|
|
143
|
-
if (!res.headersSent) rpcError(res, 500, -32603, 'Internal error');
|
|
144
|
-
else res.end();
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
server.headersTimeout = 10_000;
|
|
148
|
-
server.requestTimeout = 120_000;
|
|
149
|
-
server.keepAliveTimeout = 65_000;
|
|
150
|
-
server.maxConnections = 1000;
|
|
151
|
-
return server;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export function getInflight(): number {
|
|
155
|
-
return inflight;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
159
|
-
createHttpServer().listen(PORT, () => console.log(`dailey-mcp http listening on :${PORT} (stateless streamable HTTP)`));
|
|
160
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
-
|
|
5
|
-
import { hasCredentials } from './api.js';
|
|
6
|
-
import { OWN_VERSION, checkForNewerVersion, outdatedNotice } from './version.js';
|
|
7
|
-
import { buildServer } from './server.js';
|
|
8
|
-
|
|
9
|
-
function writeStream(stream: NodeJS.WriteStream, text: string): Promise<void> {
|
|
10
|
-
return new Promise((resolve) => {
|
|
11
|
-
stream.write(text, () => resolve());
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async function preflight(): Promise<void> {
|
|
16
|
-
const isInteractive = Boolean(process.stdin.isTTY);
|
|
17
|
-
|
|
18
|
-
if (!hasCredentials()) {
|
|
19
|
-
const msg =
|
|
20
|
-
'Missing credentials. Set DAILEY_API_TOKEN, or DAILEY_EMAIL + DAILEY_PASSWORD.';
|
|
21
|
-
|
|
22
|
-
if (isInteractive) {
|
|
23
|
-
await writeStream(
|
|
24
|
-
process.stderr,
|
|
25
|
-
'\n' +
|
|
26
|
-
'dailey-mcp: ' + msg + '\n\n' +
|
|
27
|
-
'This is an MCP stdio server — it is meant to be spawned by an MCP client\n' +
|
|
28
|
-
'(Claude Code, Cursor, etc.) which will send JSON-RPC messages on stdin.\n' +
|
|
29
|
-
'Running it directly in a shell is not how you use it.\n\n' +
|
|
30
|
-
'Add it to your client config like this:\n' +
|
|
31
|
-
' {\n' +
|
|
32
|
-
' "mcpServers": {\n' +
|
|
33
|
-
' "dailey-os": {\n' +
|
|
34
|
-
' "command": "npx",\n' +
|
|
35
|
-
' "args": ["-y", "@daileyos/mcp-server"],\n' +
|
|
36
|
-
' "env": { "DAILEY_API_TOKEN": "..." }\n' +
|
|
37
|
-
' }\n' +
|
|
38
|
-
' }\n' +
|
|
39
|
-
' }\n\n' +
|
|
40
|
-
'Docs: https://docs.dailey.cloud/mcp/getting-started\n\n'
|
|
41
|
-
);
|
|
42
|
-
} else {
|
|
43
|
-
// Best-effort: some MCP clients surface unsolicited log notifications
|
|
44
|
-
// that arrive before the initialize handshake. Emit a structured JSON-RPC
|
|
45
|
-
// message so the client has something to render other than "process exited".
|
|
46
|
-
const note = {
|
|
47
|
-
jsonrpc: '2.0',
|
|
48
|
-
method: 'notifications/message',
|
|
49
|
-
params: {
|
|
50
|
-
level: 'error',
|
|
51
|
-
logger: 'dailey-mcp',
|
|
52
|
-
data: msg + ' See https://docs.dailey.cloud/mcp/getting-started',
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
await writeStream(process.stdout, JSON.stringify(note) + '\n');
|
|
56
|
-
await writeStream(process.stderr, 'dailey-mcp: ' + msg + '\n');
|
|
57
|
-
}
|
|
58
|
-
process.exit(1);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (isInteractive) {
|
|
62
|
-
await writeStream(
|
|
63
|
-
process.stderr,
|
|
64
|
-
'\n' +
|
|
65
|
-
'dailey-mcp: MCP stdio server running.\n' +
|
|
66
|
-
'This server speaks JSON-RPC 2.0 on stdin/stdout — it is driven by an MCP\n' +
|
|
67
|
-
'client (Claude Code, Cursor, etc.), not typed into directly. If you were\n' +
|
|
68
|
-
'trying to update it, you do not need to — `npx @daileyos/mcp-server` in\n' +
|
|
69
|
-
'your client config pulls latest at each session start.\n' +
|
|
70
|
-
'Press Ctrl+C to exit.\n\n'
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
await preflight();
|
|
76
|
-
|
|
77
|
-
// Staleness self-check (2026-07-13 incident: sessions silently ran a months-old
|
|
78
|
-
// MCP and the agent concluded platform features didn't exist). Fail-open + hard
|
|
79
|
-
// timeout; when outdated, the notice rides the server instructions so the AGENT
|
|
80
|
-
// itself tells the user to update instead of silently missing tools.
|
|
81
|
-
const newerVersion = await checkForNewerVersion();
|
|
82
|
-
if (newerVersion) {
|
|
83
|
-
process.stderr.write(`dailey-mcp: v${OWN_VERSION} is outdated (latest v${newerVersion})\n`);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const server = buildServer({
|
|
87
|
-
includeAdmin: true,
|
|
88
|
-
includeLocalAuth: true,
|
|
89
|
-
includeAccountSwitch: true,
|
|
90
|
-
instructions: newerVersion ? outdatedNotice(newerVersion) : undefined,
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
const transport = new StdioServerTransport();
|
|
94
|
-
await server.connect(transport);
|