@yoonion/mimi-seed-mcp 0.25.2 → 0.25.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/README.md +6 -5
- package/assets/agent-guide.md +29 -5
- package/dist/auth/cli.js +2 -2
- package/dist/auth/constants.d.ts +5 -2
- package/dist/auth/constants.js +17 -10
- package/dist/auth/errors.js +8 -5
- package/dist/auth/google-auth.d.ts +27 -0
- package/dist/auth/google-auth.js +39 -3
- package/dist/core/console-url.d.ts +19 -0
- package/dist/core/console-url.js +61 -0
- package/dist/core/credential-store.js +2 -0
- package/dist/drive/tools.d.ts +0 -1
- package/dist/drive/tools.js +19 -1
- package/dist/i18n/tools-en/android.d.ts +2 -2
- package/dist/i18n/tools-en/android.js +2 -2
- package/dist/i18n/tools-en/jenkins.d.ts +4 -4
- package/dist/i18n/tools-en/jenkins.js +4 -4
- package/dist/instagram/browser-login.js +4 -3
- package/dist/jenkins/credentials.d.ts +7 -3
- package/dist/jenkins/credentials.js +4 -0
- package/dist/jenkins/messages.d.ts +2 -0
- package/dist/jenkins/messages.js +15 -0
- package/dist/lib/human-approval.d.ts +49 -0
- package/dist/lib/human-approval.js +143 -0
- package/dist/lib/package-root.d.ts +5 -0
- package/dist/lib/tool-registrar.d.ts +31 -0
- package/dist/lib/tool-registrar.js +80 -3
- package/dist/registers/android.js +10 -7
- package/dist/registers/auth.js +16 -7
- package/dist/registers/jenkins.js +20 -8
- package/dist/remote-sync.js +13 -4
- package/dist/server.js +2 -1
- package/dist/social/broker-base.d.ts +7 -0
- package/dist/social/broker-base.js +11 -0
- package/dist/social/meta-app-config.d.ts +19 -0
- package/dist/social/meta-app-config.js +83 -0
- package/dist/social/meta-direct-login.d.ts +45 -0
- package/dist/social/meta-direct-login.js +307 -0
- package/dist/social/setup-cli.js +231 -22
- package/dist/threads/browser-login.js +4 -3
- package/npm-shrinkwrap.json +1985 -0
- package/package.json +6 -3
- package/tool-manifest.json +26 -0
|
@@ -5,19 +5,19 @@ export default {
|
|
|
5
5
|
'Jenkins 기본 URL (예: https://jenkins.company.com)': 'Jenkins base URL (e.g. https://jenkins.company.com)',
|
|
6
6
|
'Jenkins 사용자 ID': 'Jenkins user ID',
|
|
7
7
|
'Jenkins에 등록된 credential 목록을 조회합니다 (id / displayName / type). 설정이 없으면 jenkins_status를 먼저 호출해 연결 정보를 확인하세요.': 'Lists the credentials registered in Jenkins (id / displayName / type). If there is no config, call jenkins_status first to check the connection info.',
|
|
8
|
-
'Jenkins에 Secret Text credential을 생성하거나 업데이트합니다. 비밀번호, API 키, 앱 시크릿 등 문자열 값에 사용하세요.
|
|
8
|
+
'Jenkins에 Secret Text credential을 생성하거나 업데이트합니다. 비밀번호, API 키, 앱 시크릿 등 문자열 값에 사용하세요. confirm 생략/false 면 아무것도 보내지 않고 dry-run 만 반환한다 — 새 id 면 "생성 예정", 같은 id 가 있으면 "이미 존재"(교체하면 되돌릴 수 없음). 사용자 승인 후 같은 인자에 confirm: true 로 재호출. 설정이 없으면 jenkins_status를 먼저 호출하세요.': 'Creates or updates a Secret Text credential in Jenkins. Use it for string values such as passwords, API keys, and app secrets. With confirm omitted/false nothing is sent and only a dry-run is returned — "will create" for a new id, "already exists" for an existing one (replacing it cannot be undone). Call again with the same arguments plus confirm: true after the user approves. If there is no config, call jenkins_status first.',
|
|
9
9
|
'Credential ID (예: my-app-android-key-password)': 'Credential ID (e.g. my-app-android-key-password)',
|
|
10
10
|
'저장할 비밀값. secret_file 과 둘 중 하나': 'Secret value to store. Exactly one of this or secret_file',
|
|
11
11
|
'권장 — android_generate_keystore 가 만든 signing.json 절대경로 (~/.mimi-seed/keystores/ 안만 허용). 비밀값이 대화에 남지 않음': 'Recommended — absolute path to the signing.json created by android_generate_keystore (only paths inside ~/.mimi-seed/keystores/ are allowed). The secret value never appears in the conversation',
|
|
12
12
|
'secret_file 에서 꺼낼 필드 (storePassword / keyPassword / keyAlias)': 'Field to read from secret_file (storePassword / keyPassword / keyAlias)',
|
|
13
13
|
'설명 (선택)': 'Description (optional)',
|
|
14
|
-
'
|
|
15
|
-
'Jenkins에 Android keystore 파일을 Secret File credential로 업로드합니다. keystore_base64에 .jks/.p12 파일을 base64로 인코딩한 값을 전달하세요.
|
|
14
|
+
'true 일 때만 Jenkins 로 보낸다 (새 id 생성 또는 기존 값 교체). 생략/false 면 dry-run': 'Sends to Jenkins only when true (creates a new id or replaces the existing value). Omitted/false is a dry-run',
|
|
15
|
+
'Jenkins에 Android keystore 파일을 Secret File credential로 업로드합니다. keystore_base64에 .jks/.p12 파일을 base64로 인코딩한 값을 전달하세요. confirm 생략/false 면 아무것도 보내지 않고 dry-run 만 반환한다 — 새 id 면 "생성 예정", 같은 id 가 있으면 "이미 존재"(기존 keystore 를 교체하면 되돌릴 수 없음). 사용자 승인 후 같은 인자에 confirm: true 로 재호출. 설정이 없으면 jenkins_status를 먼저 호출하세요.': 'Uploads an Android keystore file to Jenkins as a Secret File credential. Pass the .jks/.p12 file base64-encoded in keystore_base64. With confirm omitted/false nothing is sent and only a dry-run is returned — "will create" for a new id, "already exists" for an existing one (replacing the existing keystore cannot be undone). Call again with the same arguments plus confirm: true after the user approves. If there is no config, call jenkins_status first.',
|
|
16
16
|
'Credential ID (예: my-app-android-keystore)': 'Credential ID (e.g. my-app-android-keystore)',
|
|
17
17
|
'keystore 파일 내용을 base64로 인코딩한 값. keystore_path 와 둘 중 하나': 'The keystore file contents, base64-encoded. Exactly one of this or keystore_path',
|
|
18
18
|
'권장 — android_generate_keystore 가 만든 keystore 절대경로 (~/.mimi-seed/keystores/ 안만 허용)': 'Recommended — absolute path to the keystore created by android_generate_keystore (only paths inside ~/.mimi-seed/keystores/ are allowed)',
|
|
19
19
|
'파일명 (기본: keystore.jks)': 'File name (default: keystore.jks)',
|
|
20
|
-
'
|
|
20
|
+
'true 일 때만 Jenkins 로 보낸다 (새 id 생성 또는 기존 keystore 교체). 생략/false 면 dry-run': 'Sends to Jenkins only when true (creates a new id or replaces the existing keystore). Omitted/false is a dry-run',
|
|
21
21
|
'Jenkins credential을 삭제합니다. 비가역 작업입니다. 설정이 없으면 jenkins_status를 먼저 호출하세요.': 'Deletes a Jenkins credential. This is irreversible. If there is no config, call jenkins_status first.',
|
|
22
22
|
'삭제할 Credential ID': 'Credential ID to delete',
|
|
23
23
|
'Jenkins 잡 목록을 조회합니다 (이름 / URL / 상태색). folder를 주면 그 폴더 안만 조회합니다. 재귀하지 않고 한 단계만 봅니다. 설정이 없으면 jenkins_status를 먼저 호출하세요.': 'Lists Jenkins jobs (name / URL / status color). When folder is given, lists only inside that folder. Does not recurse; looks one level deep only. If there is no config, call jenkins_status first.',
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { socialBrokerBase } from '../social/broker-base.js';
|
|
1
2
|
import { createServer } from 'node:http';
|
|
2
3
|
import { randomBytes, createHash, timingSafeEqual } from 'node:crypto';
|
|
3
4
|
import { fetchWithTimeout } from '../lib/http.js';
|
|
@@ -16,10 +17,10 @@ export async function connectInstagramInBrowser(options = {}) {
|
|
|
16
17
|
// Freeze the selected profile before any asynchronous work / directory changes.
|
|
17
18
|
const target = resolveSocialConfigTarget('instagram', options);
|
|
18
19
|
const saveOptions = { ...options, profile: target.profile ?? undefined, startDir: options.startDir ?? process.cwd() };
|
|
19
|
-
const
|
|
20
|
-
if (
|
|
20
|
+
const url = socialBrokerBase(options.webBase ?? process.env.MIMI_SEED_WEB_BASE);
|
|
21
|
+
if (!url)
|
|
21
22
|
throw new InstagramLoginError('configuration');
|
|
22
|
-
|
|
23
|
+
const base = new URL(url);
|
|
23
24
|
const state = randomBytes(32).toString('hex');
|
|
24
25
|
const verifier = randomBytes(32).toString('base64url');
|
|
25
26
|
const codeChallenge = createHash('sha256').update(verifier).digest('base64url');
|
|
@@ -35,13 +35,17 @@ export declare function inspectCredential(cfg: JenkinsConfig, id: string): Promi
|
|
|
35
35
|
} | null>;
|
|
36
36
|
/**
|
|
37
37
|
* allowReplace=false 면 같은 id 가 이미 있을 때 **아무것도 쓰지 않고** 'exists' 를 돌려준다.
|
|
38
|
-
* 같은 종류의 기존 값(예: 서명 keystore)을 조용히 갈아끼우면 되돌릴 수
|
|
39
|
-
*
|
|
38
|
+
* 같은 종류의 기존 값(예: 서명 keystore)을 조용히 갈아끼우면 되돌릴 수 없으므로 교체에는 확인이 필요하다.
|
|
39
|
+
*
|
|
40
|
+
* dryRun=true 면 존재·종류만 확인하고 **아무것도 보내지 않는다** — 새 id 면 'new', 있으면 'exists'.
|
|
41
|
+
* MCP 도구는 confirm 전에 이 모드로 부른다: 새 id 도 비밀을 외부(Jenkins)로 내보내는 작업이라, 확인 없이
|
|
42
|
+
* 바로 올리던 시절엔 confirm 플래그가 없는 그 경로를 사람 승인 게이트가 잡지 못했다.
|
|
40
43
|
*/
|
|
41
44
|
export interface UpsertOptions {
|
|
42
45
|
allowReplace?: boolean;
|
|
46
|
+
dryRun?: boolean;
|
|
43
47
|
}
|
|
44
|
-
export type UpsertResult = 'created' | 'updated' | 'exists';
|
|
48
|
+
export type UpsertResult = 'created' | 'updated' | 'exists' | 'new';
|
|
45
49
|
export declare function listCredentials(cfg: JenkinsConfig): Promise<JenkinsCredentialSummary[]>;
|
|
46
50
|
export declare function upsertSecretText(cfg: JenkinsConfig, id: string, secret: string, description?: string, options?: UpsertOptions): Promise<UpsertResult>;
|
|
47
51
|
/**
|
|
@@ -183,6 +183,8 @@ export async function upsertSecretText(cfg, id, secret, description = '', option
|
|
|
183
183
|
if (existing)
|
|
184
184
|
assertSameKind(id, existing.info, existing.kind, KIND_STRING);
|
|
185
185
|
const exists = existing !== null;
|
|
186
|
+
if (options.dryRun)
|
|
187
|
+
return exists ? 'exists' : 'new';
|
|
186
188
|
if (exists && options.allowReplace === false)
|
|
187
189
|
return 'exists';
|
|
188
190
|
const payload = {
|
|
@@ -222,6 +224,8 @@ export async function upsertSecretFile(cfg, id, fileBase64, fileName, descriptio
|
|
|
222
224
|
if (existing)
|
|
223
225
|
assertSameKind(id, existing.info, existing.kind, KIND_FILE);
|
|
224
226
|
const exists = existing !== null;
|
|
227
|
+
if (options.dryRun)
|
|
228
|
+
return exists ? 'exists' : 'new';
|
|
225
229
|
if (exists && options.allowReplace === false)
|
|
226
230
|
return 'exists';
|
|
227
231
|
const payload = {
|
|
@@ -13,6 +13,8 @@ export declare function existingCredentialPreview(id: string, inspected: {
|
|
|
13
13
|
info: ExistingCredential;
|
|
14
14
|
kind: CredentialKind | null;
|
|
15
15
|
} | null, requested: CredentialKind, notes?: string[]): string;
|
|
16
|
+
/** 새 id dry-run — 무엇을 어디로 보낼지 (비밀값은 싣지 않는다). */
|
|
17
|
+
export declare function newCredentialPreview(id: string, jenkinsUrl: string, requested: CredentialKind, notes?: string[]): string;
|
|
16
18
|
/** 기본 id 접두사(패키지 마지막 세그먼트 slug)가 여러 앱에서 흔히 겹치는 이름인가. */
|
|
17
19
|
export declare function isGenericCredentialPrefix(prefix: string): boolean;
|
|
18
20
|
/** 기본 id 모양인데 접두사가 흔한 이름이면 경고 한 줄, 아니면 null. */
|
package/dist/jenkins/messages.js
CHANGED
|
@@ -4,6 +4,8 @@ import { catalog } from '#core/lang.js';
|
|
|
4
4
|
import { kindLabel } from './credentials.js';
|
|
5
5
|
const M = catalog({
|
|
6
6
|
exists: (id) => `🛑 dry-run — Jenkins credential \`${id}\` 가 이미 존재해 아직 바꾸지 않았다.`,
|
|
7
|
+
willCreate: (id, kind) => `🛑 dry-run — Jenkins credential \`${id}\` (${kind}) 는 아직 없다. 아무것도 보내지 않았다.`,
|
|
8
|
+
createNext: '비밀값을 Jenkins 로 보내는 작업이다. 대상 Jenkins·id 가 맞는지 사용자에게 확인받은 뒤 같은 인자에 confirm: true 를 추가해 다시 호출하세요.',
|
|
7
9
|
existingHeader: '기존 credential:',
|
|
8
10
|
kind: '종류: ',
|
|
9
11
|
name: '이름: ',
|
|
@@ -42,6 +44,8 @@ const M = catalog({
|
|
|
42
44
|
],
|
|
43
45
|
}, {
|
|
44
46
|
exists: (id) => `🛑 dry-run — Jenkins credential \`${id}\` already exists, so nothing has changed yet.`,
|
|
47
|
+
willCreate: (id, kind) => `🛑 dry-run — Jenkins credential \`${id}\` (${kind}) does not exist yet. Nothing was sent.`,
|
|
48
|
+
createNext: 'This sends a secret to Jenkins. Confirm the target Jenkins and id with the user, then call again with the same arguments plus confirm: true.',
|
|
45
49
|
existingHeader: 'Existing credential:',
|
|
46
50
|
kind: 'kind: ',
|
|
47
51
|
name: 'name: ',
|
|
@@ -115,6 +119,17 @@ export function existingCredentialPreview(id, inspected, requested, notes = [])
|
|
|
115
119
|
m.confirmNext,
|
|
116
120
|
].join('\n');
|
|
117
121
|
}
|
|
122
|
+
/** 새 id dry-run — 무엇을 어디로 보낼지 (비밀값은 싣지 않는다). */
|
|
123
|
+
export function newCredentialPreview(id, jenkinsUrl, requested, notes = []) {
|
|
124
|
+
const m = M();
|
|
125
|
+
return [
|
|
126
|
+
m.willCreate(id, kindLabel(requested)),
|
|
127
|
+
` Jenkins: ${jenkinsUrl}`,
|
|
128
|
+
...(notes.length ? ['', ...notes] : []),
|
|
129
|
+
'',
|
|
130
|
+
m.createNext,
|
|
131
|
+
].join('\n');
|
|
132
|
+
}
|
|
118
133
|
/**
|
|
119
134
|
* android_signing_setup / android_generate_keystore / jenkins_upload_playstore_sa 가 만드는 기본 id 는
|
|
120
135
|
* `<패키지 마지막 세그먼트>-<접미사>` 다. 기존 사용자의 id 가 바뀌므로 파생 규칙은 그대로 두고,
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* 사람 승인 게이트 — 위험한 호출을 **실행 직전에 사용자에게 직접** 묻는다 (MCP form elicitation).
|
|
5
|
+
*
|
|
6
|
+
* 왜: `confirm: true` 는 모델이 채우는 인자다. 스토어 리뷰·SNS 댓글·Drive 문서처럼 도구가 읽어 온 외부 텍스트에
|
|
7
|
+
* 숨은 지시(프롬프트 인젝션)를 모델이 따르면, 사람이 보지 않은 채 preview → confirm 두 번 호출로 출시·IAM 키
|
|
8
|
+
* 생성·공개 게시가 나간다. elicitation 은 서버가 클라이언트 UI 에 직접 띄우는 대화상자라 모델이 대신 답할 수 없다.
|
|
9
|
+
* 무엇을 묻는지는 레지스트라가 정한다 (확인 플래그가 true 인 호출 + manifest `approval` 도구의 모든 호출).
|
|
10
|
+
*
|
|
11
|
+
* 모드 (`MIMI_SEED_APPROVAL`):
|
|
12
|
+
* - `auto` (기본) — 클라이언트가 form elicitation 을 지원하면 묻고, 지원하지 않으면 예전처럼 실행한다.
|
|
13
|
+
* - `required` — 물을 수 없는 클라이언트에서는 실행을 거부한다. **알 수 없는 값도 이것** — 보안 설정의 오타가
|
|
14
|
+
* 조용히 느슨한 쪽으로 풀리면 안 된다.
|
|
15
|
+
* - `off` — 묻지 않는다. 사람이 없는 자동화(예약 실행·헤드리스)용 — 그 대가로 이 게이트도 없다.
|
|
16
|
+
*/
|
|
17
|
+
export type ApprovalMode = 'auto' | 'required' | 'off';
|
|
18
|
+
export declare const APPROVAL_ENV = "MIMI_SEED_APPROVAL";
|
|
19
|
+
/** 사용자가 답할 시간. SDK 기본 60초는 미리보기를 읽고 판단하기엔 짧다. */
|
|
20
|
+
export declare const APPROVAL_TIMEOUT_MS: number;
|
|
21
|
+
/**
|
|
22
|
+
* 사용자가 거절·취소한 **같은 호출**(도구 + 인자)은 이 시간 동안 대화상자 없이 거부한다 (시간 초과·중단·오류는 거절이 아니라 제외). 인젝션된 에이전트가
|
|
23
|
+
* 같은 요청을 반복해 사용자가 지쳐 승인하게 만드는 것(approval fatigue)을 막는다. 인자를 바꾼 호출은 다시 묻는다.
|
|
24
|
+
*/
|
|
25
|
+
export declare const DECLINE_COOLDOWN_MS: number;
|
|
26
|
+
export declare function approvalMode(env?: NodeJS.ProcessEnv): ApprovalMode;
|
|
27
|
+
/** `mimi_seed_status` 한 줄 — 팀이 게이트가 실제로 살아 있는지 확인할 수 있게. */
|
|
28
|
+
export declare function describeApproval(status: {
|
|
29
|
+
mode: ApprovalMode;
|
|
30
|
+
clientCanElicit: boolean;
|
|
31
|
+
}): string;
|
|
32
|
+
/** 클라이언트가 form elicitation 을 선언했는가. SDK 가 빈 `elicitation: {}` 를 `{ form: {} }` 로 정규화한다. */
|
|
33
|
+
export declare function clientCanElicit(server: McpServer): boolean;
|
|
34
|
+
export interface ApprovalCall {
|
|
35
|
+
name: string;
|
|
36
|
+
title: string;
|
|
37
|
+
/** 실행 인자 원본 — 쿨다운 키에만 쓴다 (화면에는 argLines). */
|
|
38
|
+
args: Record<string, unknown>;
|
|
39
|
+
/** 비밀을 가리고 이스케이프한 인자 줄 (tool-registrar 의 approvalArgLines). */
|
|
40
|
+
argLines: string[];
|
|
41
|
+
/** 어떤 값의 가운데를 생략했는가. */
|
|
42
|
+
truncated: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** 승인되면 `null`, 아니면 실행 대신 돌려줄 결과. */
|
|
45
|
+
export declare function requestHumanApproval(server: McpServer, call: ApprovalCall, options?: {
|
|
46
|
+
signal?: AbortSignal;
|
|
47
|
+
mode?: ApprovalMode;
|
|
48
|
+
now?: () => number;
|
|
49
|
+
}): Promise<CallToolResult | null>;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { catalog } from '#core/lang.js';
|
|
3
|
+
export const APPROVAL_ENV = 'MIMI_SEED_APPROVAL';
|
|
4
|
+
/** 사용자가 답할 시간. SDK 기본 60초는 미리보기를 읽고 판단하기엔 짧다. */
|
|
5
|
+
export const APPROVAL_TIMEOUT_MS = 10 * 60 * 1000;
|
|
6
|
+
/**
|
|
7
|
+
* 사용자가 거절·취소한 **같은 호출**(도구 + 인자)은 이 시간 동안 대화상자 없이 거부한다 (시간 초과·중단·오류는 거절이 아니라 제외). 인젝션된 에이전트가
|
|
8
|
+
* 같은 요청을 반복해 사용자가 지쳐 승인하게 만드는 것(approval fatigue)을 막는다. 인자를 바꾼 호출은 다시 묻는다.
|
|
9
|
+
*/
|
|
10
|
+
export const DECLINE_COOLDOWN_MS = 5 * 60 * 1000;
|
|
11
|
+
const A = catalog({
|
|
12
|
+
title: (title) => `⚠️ 실행 승인 요청 — ${title}`,
|
|
13
|
+
intro: 'AI 에이전트가 되돌리기 어렵거나 외부에 공개되거나 자격증명을 다루는 작업을 실행하려 한다. 아래 인자가 의도한 것과 같을 때만 승인한다.',
|
|
14
|
+
args: '실행 인자 (문자열은 따옴표·이스케이프 그대로 표시):',
|
|
15
|
+
none: '(없음)',
|
|
16
|
+
truncated: '⚠️ 일부 값이 너무 길어 가운데를 생략했다. 생략된 부분을 확인할 수 없다면 거절한다.',
|
|
17
|
+
approveTitle: '이 작업 실행을 승인합니다',
|
|
18
|
+
approveDescription: '체크하고 확인을 눌러야 실행된다. 거절·취소·체크 해제면 아무것도 바뀌지 않는다.',
|
|
19
|
+
declined: (name) => `⛔ 사용자가 \`${name}\` 실행을 승인하지 않아 아무것도 바꾸지 않았다. 자동으로 다시 시도하지 말고, 사용자에게 어떻게 할지 물을 것.`,
|
|
20
|
+
failed: (name, reason) => `⛔ \`${name}\` 실행 승인을 받지 못해 아무것도 바꾸지 않았다 (${reason}). 자동으로 다시 시도하지 말 것.`,
|
|
21
|
+
cooldown: (name, minutes) => `⛔ 같은 \`${name}\` 요청을 사용자가 방금 승인하지 않아 다시 묻지 않고 거부했다 (${minutes}분 후 다시 물을 수 있다). 다시 시도하지 말고 사용자에게 물을 것.`,
|
|
22
|
+
busy: (name) => `⛔ 다른 승인 요청이 이미 사용자 앞에 열려 있어 \`${name}\` 은(는) 실행하지 않았다. 앞의 요청이 끝난 뒤 사용자에게 물을 것.`,
|
|
23
|
+
unsupported: (name, env) => `⛔ \`${name}\` 은(는) 사용자 직접 승인이 필요한데, 이 MCP 클라이언트는 승인 대화상자(elicitation)를 지원하지 않는다 (${env}=required). ` +
|
|
24
|
+
`아무것도 바꾸지 않았다. 지원하는 클라이언트에서 실행하거나, 사용자가 ${env} 설정을 바꿔야 한다.`,
|
|
25
|
+
badMode: (env, value) => `[mimi-seed] ${env}="${value}" 은(는) 알 수 없는 값이라 가장 엄격한 required 로 동작한다 (auto · required · off).`,
|
|
26
|
+
status: (mode, can) => mode === 'off'
|
|
27
|
+
? 'off — 확정 작업도 묻지 않는다 (무인 실행 설정)'
|
|
28
|
+
: can
|
|
29
|
+
? `${mode} — 확정 작업마다 이 클라이언트에서 승인 대화상자를 띄운다`
|
|
30
|
+
: mode === 'required'
|
|
31
|
+
? 'required — 이 클라이언트는 승인 대화상자를 지원하지 않아 확정 작업을 거부한다'
|
|
32
|
+
: 'auto — 이 클라이언트는 승인 대화상자를 지원하지 않아 에이전트의 confirm 만으로 실행한다 (사람 확인 없음)',
|
|
33
|
+
}, {
|
|
34
|
+
title: (title) => `⚠️ Approval needed — ${title}`,
|
|
35
|
+
intro: 'An AI agent is about to run an action that is hard to undo, publishes externally, or handles credentials. Approve only if the arguments below are what you intended.',
|
|
36
|
+
args: 'Arguments (strings shown quoted and escaped):',
|
|
37
|
+
none: '(none)',
|
|
38
|
+
truncated: '⚠️ Some values were too long and their middle is omitted. Decline if you cannot check the omitted part.',
|
|
39
|
+
approveTitle: 'I approve running this action',
|
|
40
|
+
approveDescription: 'It runs only if this is checked and you confirm. Declining, cancelling, or leaving it unchecked changes nothing.',
|
|
41
|
+
declined: (name) => `⛔ The user did not approve \`${name}\`, so nothing was changed. Do not retry automatically — ask the user how to proceed.`,
|
|
42
|
+
failed: (name, reason) => `⛔ Could not get approval for \`${name}\`, so nothing was changed (${reason}). Do not retry automatically.`,
|
|
43
|
+
cooldown: (name, minutes) => `⛔ The user just did not approve this same \`${name}\` request, so it was refused without asking again (it can be asked again in ${minutes} min). Do not retry — ask the user.`,
|
|
44
|
+
busy: (name) => `⛔ Another approval request is already open in front of the user, so \`${name}\` did not run. Ask the user after that one is answered.`,
|
|
45
|
+
unsupported: (name, env) => `⛔ \`${name}\` needs the user's direct approval, but this MCP client does not support approval dialogs (elicitation) (${env}=required). ` +
|
|
46
|
+
`Nothing was changed. Run it from a client that supports them, or the user must change ${env}.`,
|
|
47
|
+
badMode: (env, value) => `[mimi-seed] Unknown ${env}="${value}"; using the strictest mode, required (auto · required · off).`,
|
|
48
|
+
status: (mode, can) => mode === 'off'
|
|
49
|
+
? 'off — confirmed actions are not asked about (unattended setting)'
|
|
50
|
+
: can
|
|
51
|
+
? `${mode} — every confirmed action opens an approval dialog in this client`
|
|
52
|
+
: mode === 'required'
|
|
53
|
+
? 'required — this client has no approval dialog, so confirmed actions are refused'
|
|
54
|
+
: 'auto — this client has no approval dialog, so the agent’s confirm alone runs them (no human check)',
|
|
55
|
+
});
|
|
56
|
+
let warnedValue;
|
|
57
|
+
export function approvalMode(env = process.env) {
|
|
58
|
+
const raw = env[APPROVAL_ENV]?.trim().toLowerCase();
|
|
59
|
+
if (!raw)
|
|
60
|
+
return 'auto';
|
|
61
|
+
if (raw === 'auto' || raw === 'required' || raw === 'off')
|
|
62
|
+
return raw;
|
|
63
|
+
if (warnedValue !== raw) {
|
|
64
|
+
warnedValue = raw;
|
|
65
|
+
// stdout 은 MCP 프로토콜 전용 — 진단은 stderr.
|
|
66
|
+
process.stderr.write(`${A().badMode(APPROVAL_ENV, raw)}\n`);
|
|
67
|
+
}
|
|
68
|
+
return 'required';
|
|
69
|
+
}
|
|
70
|
+
/** `mimi_seed_status` 한 줄 — 팀이 게이트가 실제로 살아 있는지 확인할 수 있게. */
|
|
71
|
+
export function describeApproval(status) {
|
|
72
|
+
return A().status(status.mode, status.clientCanElicit);
|
|
73
|
+
}
|
|
74
|
+
/** 클라이언트가 form elicitation 을 선언했는가. SDK 가 빈 `elicitation: {}` 를 `{ form: {} }` 로 정규화한다. */
|
|
75
|
+
export function clientCanElicit(server) {
|
|
76
|
+
return Boolean(server.server.getClientCapabilities()?.elicitation?.form);
|
|
77
|
+
}
|
|
78
|
+
const refuse = (text) => ({ isError: true, content: [{ type: 'text', text }] });
|
|
79
|
+
const states = new WeakMap();
|
|
80
|
+
const stateOf = (server) => {
|
|
81
|
+
let s = states.get(server);
|
|
82
|
+
if (!s)
|
|
83
|
+
states.set(server, (s = { pending: false, refusedUntil: new Map() }));
|
|
84
|
+
return s;
|
|
85
|
+
};
|
|
86
|
+
const callKey = (name, args) => createHash('sha256').update(name).update('\0').update(JSON.stringify(args)).digest('hex');
|
|
87
|
+
/** 승인되면 `null`, 아니면 실행 대신 돌려줄 결과. */
|
|
88
|
+
export async function requestHumanApproval(server, call, options = {}) {
|
|
89
|
+
const mode = options.mode ?? approvalMode();
|
|
90
|
+
if (mode === 'off')
|
|
91
|
+
return null;
|
|
92
|
+
if (!clientCanElicit(server)) {
|
|
93
|
+
return mode === 'required' ? refuse(A().unsupported(call.name, APPROVAL_ENV)) : null;
|
|
94
|
+
}
|
|
95
|
+
const m = A();
|
|
96
|
+
const now = options.now ?? Date.now;
|
|
97
|
+
const state = stateOf(server);
|
|
98
|
+
const key = callKey(call.name, call.args);
|
|
99
|
+
const until = state.refusedUntil.get(key);
|
|
100
|
+
if (until !== undefined && until > now()) {
|
|
101
|
+
return refuse(m.cooldown(call.name, Math.ceil((until - now()) / 60_000)));
|
|
102
|
+
}
|
|
103
|
+
// 대화상자는 한 번에 하나 — 동시에 여러 개를 띄워 하나쯤 승인되길 노리는 호출을 막는다.
|
|
104
|
+
if (state.pending)
|
|
105
|
+
return refuse(m.busy(call.name));
|
|
106
|
+
const message = [
|
|
107
|
+
m.title(call.title),
|
|
108
|
+
'',
|
|
109
|
+
m.intro,
|
|
110
|
+
...(call.truncated ? ['', m.truncated] : []),
|
|
111
|
+
'',
|
|
112
|
+
m.args,
|
|
113
|
+
...(call.argLines.length ? call.argLines : [` ${m.none}`]),
|
|
114
|
+
].join('\n');
|
|
115
|
+
state.pending = true;
|
|
116
|
+
try {
|
|
117
|
+
const result = await server.server.elicitInput({
|
|
118
|
+
mode: 'form',
|
|
119
|
+
message,
|
|
120
|
+
requestedSchema: {
|
|
121
|
+
type: 'object',
|
|
122
|
+
properties: { approve: { type: 'boolean', title: m.approveTitle, description: m.approveDescription } },
|
|
123
|
+
required: ['approve'],
|
|
124
|
+
},
|
|
125
|
+
}, { timeout: APPROVAL_TIMEOUT_MS, signal: options.signal });
|
|
126
|
+
// accept 만으로는 부족하다 — 체크박스까지 true 여야 한다 (엔터 한 번에 실행되지 않게).
|
|
127
|
+
if (result.action === 'accept' && result.content?.approve === true) {
|
|
128
|
+
state.refusedUntil.delete(key);
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
state.refusedUntil.set(key, now() + DECLINE_COOLDOWN_MS);
|
|
132
|
+
return refuse(m.declined(call.name));
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
// 지원을 선언한 클라이언트에서의 실패(타임아웃·중단·응답 오류)는 모드와 무관하게 거부한다 — 실패를 승인으로 치지 않는다.
|
|
136
|
+
// 다만 쿨다운은 걸지 않는다: 사용자가 거절한 게 아니다. 클라이언트의 tools/call 타임아웃(SDK 기본 60초)이나
|
|
137
|
+
// 사용자가 턴을 중단(Esc)한 경우를 거절로 기록하면, "응, 실행해" 라고 한 뒤의 같은 호출이 5분간 막혔다.
|
|
138
|
+
return refuse(m.failed(call.name, e instanceof Error ? e.message : String(e)));
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
state.pending = false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -31,6 +31,11 @@ export type DomainEntry = {
|
|
|
31
31
|
* 막는 도구. 레지스트라는 이 도구들에만 confirm 가드 주입을 생략한다.
|
|
32
32
|
*/
|
|
33
33
|
ownGate?: string[];
|
|
34
|
+
/**
|
|
35
|
+
* 확인 플래그와 무관하게 **매 호출** 사용자 승인(elicitation)을 받는 쓰기 도구 — 플래그 없이도 위험한 경로가 있는 것:
|
|
36
|
+
* 자격증명이 나갈 목적지를 바꾸거나(`*_save_config`), 새 id 로 비밀을 바로 올리거나, 배포 워크플로를 시작한다.
|
|
37
|
+
*/
|
|
38
|
+
approval?: string[];
|
|
34
39
|
/** 같은 인자로 반복 호출해도 추가 효과가 없는 **쓰기** 도구. 읽기 도구는 자동으로 idempotent. */
|
|
35
40
|
idempotent?: string[];
|
|
36
41
|
};
|
|
@@ -3,6 +3,7 @@ import type { ZodRawShapeCompat } from '@modelcontextprotocol/sdk/server/zod-com
|
|
|
3
3
|
import type { CallToolResult, ToolAnnotations } from '@modelcontextprotocol/sdk/types.js';
|
|
4
4
|
import type { ToolManifest } from './package-root.js';
|
|
5
5
|
import type { ToolsetSelection } from './toolsets.js';
|
|
6
|
+
import { type ApprovalMode } from './human-approval.js';
|
|
6
7
|
/**
|
|
7
8
|
* 도구 등록의 단일 관문.
|
|
8
9
|
*
|
|
@@ -17,6 +18,9 @@ import type { ToolsetSelection } from './toolsets.js';
|
|
|
17
18
|
* "자기 confirm 이 모든 파괴적 경로를 막는다" 고 선언한 도구만 주입을 생략하고, 선언과 스키마가
|
|
18
19
|
* 어긋나면 throw — 파괴적 도구가 가드 없이 등록되는 경로를 구조적으로 없앤다.
|
|
19
20
|
* 3. **toolset 필터** — MIMI_SEED_TOOLSETS 로 꺼진 도구는 등록하지 않는다 (도메인 + alsoInToolsets 소속 기준).
|
|
21
|
+
* 3b. **사람 승인** — 확인 플래그(`confirm`, `confirm<Xxx>`)가 true 로 온 호출과 manifest `approval` 도구의 모든 호출은
|
|
22
|
+
* 실행 직전에 MCP elicitation 으로 사용자에게 직접 묻는다 (lib/human-approval.ts). 모델이 채운 confirm 만으로는
|
|
23
|
+
* 실행되지 않는다.
|
|
20
24
|
* 4. **폐기 예정 별칭** — manifest `deprecated` 의 옛 이름을 정식 도구의 스키마·핸들러로
|
|
21
25
|
* 함께 등록한다 (설명에 [DEPRECATED …] 접두).
|
|
22
26
|
*
|
|
@@ -35,6 +39,8 @@ export interface ToolMeta {
|
|
|
35
39
|
* 레지스트라는 이런 도구에만 가드 주입을 생략한다 — 선언 없이 confirm 파라미터만 있으면 throw.
|
|
36
40
|
*/
|
|
37
41
|
ownGate: boolean;
|
|
42
|
+
/** 확인 플래그와 무관하게 매 호출 사용자 승인을 받는다 (manifest `approval`). */
|
|
43
|
+
approval: boolean;
|
|
38
44
|
/** 이 이름이 폐기 예정 별칭이면 정식 도구 이름. */
|
|
39
45
|
deprecatedFor?: string;
|
|
40
46
|
/** 이 도구를 가리키는 폐기 예정 별칭들. */
|
|
@@ -58,6 +64,24 @@ export declare function annotationsFor(meta: ToolMeta): ToolAnnotations & {
|
|
|
58
64
|
/** 생략된 힌트를 명세 기본값으로 채운 실효값 — 테스트·카탈로그가 "이 도구는 읽기 전용인가"를 물을 때 쓴다. */
|
|
59
65
|
export declare function effectiveHints(annotations: ToolAnnotations | undefined): Required<Omit<ToolAnnotations, 'title'>>;
|
|
60
66
|
export declare function previewValue(key: string, value: unknown): string;
|
|
67
|
+
/**
|
|
68
|
+
* 확인 플래그인가 — `confirm` 또는 `confirm` + 대문자로 시작하는 이름 (`confirmPublish`, `confirmCreate` …).
|
|
69
|
+
* 세 이름만 보던 시절 `confirmCreate` 같은 새 플래그가 승인 게이트를 조용히 비껴갔다. ownGate 선언 검사는
|
|
70
|
+
* 여전히 CONFIRM_KEYS 로 한다 (그 규칙은 파괴적 도구의 가드 모양에 대한 것).
|
|
71
|
+
*/
|
|
72
|
+
export declare function isConfirmKey(key: string): boolean;
|
|
73
|
+
/** 인자 → ` key: value` 줄 (비밀 키는 가리고, 확인 플래그 자체는 뺀다). 비면 빈 배열. */
|
|
74
|
+
export declare function previewArgLines(args: Record<string, unknown>): string[];
|
|
75
|
+
/**
|
|
76
|
+
* 승인 대화상자용 인자 줄. dry-run preview 와 달리 **사람이 마지막으로 보는 화면**이라 모델이 고른 값으로
|
|
77
|
+
* 화면을 위조할 수 없어야 한다: 문자열은 JSON 리터럴로(따옴표 + `\n` 이스케이프 — 값 안의 줄바꿈으로 가짜
|
|
78
|
+
* `key: value` 줄이나 "검증됨" 문구를 만들 수 없다), 보이지 않는 문자는 `\uXXXX` 로, 긴 값은 앞뒤를 보이고
|
|
79
|
+
* 생략 사실과 길이를 밝힌다 (200자에서 자르던 시절엔 뒤쪽에 숨긴 URL·명령이 안 보였다).
|
|
80
|
+
*/
|
|
81
|
+
export declare function approvalArgLines(args: Record<string, unknown>): {
|
|
82
|
+
lines: string[];
|
|
83
|
+
truncated: boolean;
|
|
84
|
+
};
|
|
61
85
|
export declare function confirmPreview(name: string, args: Record<string, unknown>): CallToolResult;
|
|
62
86
|
/** 레지스트라 가드를 받는 파괴적 도구의 설명 끝에 붙는 문구. 영어 번역은 i18n/tools-en/registrar.ts. */
|
|
63
87
|
export declare const GUARD_DESCRIPTION = "\u26A0\uFE0F \uC548\uC804 \uAC00\uB4DC: confirm \uC0DD\uB7B5/false \uBA74 \uC544\uBB34\uAC83\uB3C4 \uBC14\uAFB8\uC9C0 \uC54A\uACE0 dry-run preview \uB9CC \uBC18\uD658\uD55C\uB2E4. \uC0AC\uC6A9\uC790 \uBA85\uC2DC \uC2B9\uC778 \uD6C4 confirm: true \uB85C \uC7AC\uD638\uCD9C.";
|
|
@@ -69,6 +93,11 @@ export interface ToolRegistrar {
|
|
|
69
93
|
/** 이 서버에서 켜진 toolset (mimi_seed_status 가 보고한다). */
|
|
70
94
|
readonly toolsets: ToolsetSelection;
|
|
71
95
|
readonly manifest: ToolManifest;
|
|
96
|
+
/** 승인 게이트가 지금 살아 있는가 — 모드 + 연결된 클라이언트의 elicitation 지원 (mimi_seed_status 가 보고한다). */
|
|
97
|
+
approvalStatus(): {
|
|
98
|
+
mode: ApprovalMode;
|
|
99
|
+
clientCanElicit: boolean;
|
|
100
|
+
};
|
|
72
101
|
}
|
|
73
102
|
export declare function createToolRegistrar(server: McpServer, options: {
|
|
74
103
|
manifest: ToolManifest;
|
|
@@ -78,4 +107,6 @@ export declare function createToolRegistrar(server: McpServer, options: {
|
|
|
78
107
|
* 번역표의 키와 맞지 않는다. 파라미터 설명은 buildServer 가 tools/list 응답에서 바꾼다. 생략하면 원문 그대로.
|
|
79
108
|
*/
|
|
80
109
|
translate?: (text: string) => string;
|
|
110
|
+
/** `MIMI_SEED_APPROVAL` 을 읽을 환경 (buildServer({ env }) 와 같은 것). 생략하면 process.env. */
|
|
111
|
+
env?: NodeJS.ProcessEnv;
|
|
81
112
|
}): ToolRegistrar;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { catalog } from '#core/lang.js';
|
|
3
|
+
import { approvalMode, clientCanElicit, requestHumanApproval } from './human-approval.js';
|
|
3
4
|
/** 자체 확인 파라미터 이름 — manifest `ownGate` 도구는 이 중 하나를 스키마에 가져야 한다. */
|
|
4
5
|
export const CONFIRM_KEYS = ['confirm', 'confirmPublish', 'confirmVisible'];
|
|
5
6
|
/** 레지스트라가 주입한 가드의 preview 첫 줄. 테스트와 에이전트가 이 문자열로 dry-run 을 식별한다. */
|
|
@@ -16,6 +17,7 @@ export function buildToolIndex(manifest) {
|
|
|
16
17
|
const local = new Set(entry.local ?? []);
|
|
17
18
|
const idempotent = new Set(entry.idempotent ?? []);
|
|
18
19
|
const ownGate = new Set(entry.ownGate ?? []);
|
|
20
|
+
const approval = new Set(entry.approval ?? []);
|
|
19
21
|
for (const name of entry.tools) {
|
|
20
22
|
const kind = destructive.has(name) ? 'destructive' : write.has(name) ? 'write' : 'read';
|
|
21
23
|
index.set(name, {
|
|
@@ -25,6 +27,7 @@ export function buildToolIndex(manifest) {
|
|
|
25
27
|
local: local.has(name),
|
|
26
28
|
idempotent: kind === 'read' || idempotent.has(name),
|
|
27
29
|
ownGate: ownGate.has(name),
|
|
30
|
+
approval: approval.has(name),
|
|
28
31
|
deprecatedFor: manifest.deprecated?.[name],
|
|
29
32
|
aliases: aliasesOf.get(name) ?? [],
|
|
30
33
|
});
|
|
@@ -94,7 +97,9 @@ export function effectiveHints(annotations) {
|
|
|
94
97
|
};
|
|
95
98
|
}
|
|
96
99
|
// ── confirm guard ──────────────────────────────────────────────────────────
|
|
97
|
-
|
|
100
|
+
// 키 이름으로 비밀을 가린다 (값은 모른다). `API_KEY`·`SIGNING_KEY`·`STORE_PASS`·`pwd` 같은 흔한 CI 파라미터 이름도 포함 —
|
|
101
|
+
// 빠져 있던 시절엔 ci_trigger_build 의 inputs 가 승인 대화상자에 그대로 보였다. `keystore_path` 같은 경로 이름은 걸리지 않는다.
|
|
102
|
+
const SECRET_KEY = /secret|token|passw(or)?d|passphrase|(^|_)pass$|pwd|private|base64|credential_json|serviceAccountJson|api_?key|signing_?key|access_?key|client_?key/i;
|
|
98
103
|
/**
|
|
99
104
|
* 중첩된 객체·배열 안의 비밀처럼 보이는 키도 가린다 — 예: jenkins_trigger_build 의
|
|
100
105
|
* `parameters: { DEPLOY_TOKEN: … }`. 최상위 키만 보던 시절엔 값이 preview 에 그대로 찍혔다.
|
|
@@ -129,13 +134,66 @@ export function previewValue(key, value) {
|
|
|
129
134
|
return 'undefined';
|
|
130
135
|
return raw.length > 200 ? `${raw.slice(0, 200)}… (${P().chars(raw.length)})` : raw;
|
|
131
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* 확인 플래그인가 — `confirm` 또는 `confirm` + 대문자로 시작하는 이름 (`confirmPublish`, `confirmCreate` …).
|
|
139
|
+
* 세 이름만 보던 시절 `confirmCreate` 같은 새 플래그가 승인 게이트를 조용히 비껴갔다. ownGate 선언 검사는
|
|
140
|
+
* 여전히 CONFIRM_KEYS 로 한다 (그 규칙은 파괴적 도구의 가드 모양에 대한 것).
|
|
141
|
+
*/
|
|
142
|
+
export function isConfirmKey(key) {
|
|
143
|
+
return /^confirm(?:[A-Z]\w*)?$/.test(key);
|
|
144
|
+
}
|
|
145
|
+
/** 인자 → ` key: value` 줄 (비밀 키는 가리고, 확인 플래그 자체는 뺀다). 비면 빈 배열. */
|
|
146
|
+
export function previewArgLines(args) {
|
|
147
|
+
return Object.entries(args)
|
|
148
|
+
.filter(([k, v]) => !isConfirmKey(k) && v !== undefined)
|
|
149
|
+
.map(([k, v]) => ` ${k}: ${previewValue(k, v)}`);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* 줄바꿈·제어 문자에 더해, 화면에서 안 보이거나 글자 순서를 뒤집는 문자를 `\uXXXX` / `\u{XXXXX}` 로 보이게 만든다:
|
|
153
|
+
* 형식 문자(Cf — zero-width, bidi override/isolate, BOM, soft hyphen, **태그 문자 U+E0000–E007F**)와 기본 무시 문자
|
|
154
|
+
* (Default_Ignorable — 한글 채움 문자 U+3164, 변형 선택자). 태그 문자·변형 선택자는 보이지 않는 ASCII 를 실어 나를 수
|
|
155
|
+
* 있어(“ASCII smuggling”), 사용자가 “Hellox” 를 승인했는데 숨은 지시가 함께 게시될 수 있었다. 코드포인트 단위로
|
|
156
|
+
* 매칭해야(u 플래그) BMP 밖 문자도 잡힌다. JSON.stringify 는 U+0020 미만만 이스케이프한다.
|
|
157
|
+
*/
|
|
158
|
+
const INVISIBLE = /[\p{Default_Ignorable_Code_Point}\p{Cf}\u007F-\u009F\u2028\u2029]/gu;
|
|
159
|
+
const showInvisible = (s) => s.replace(INVISIBLE, (c) => {
|
|
160
|
+
const cp = c.codePointAt(0) ?? 0;
|
|
161
|
+
return cp > 0xffff ? `\\u{${cp.toString(16)}}` : `\\u${cp.toString(16).padStart(4, '0')}`;
|
|
162
|
+
});
|
|
163
|
+
/** 승인 대화상자의 값 하나가 넘으면 가운데를 생략한다 — 앞 HEAD + 뒤 TAIL 은 항상 보인다. */
|
|
164
|
+
const APPROVAL_VALUE_MAX = 1500;
|
|
165
|
+
const APPROVAL_VALUE_HEAD = 1000;
|
|
166
|
+
const APPROVAL_VALUE_TAIL = 300;
|
|
167
|
+
/**
|
|
168
|
+
* 승인 대화상자용 인자 줄. dry-run preview 와 달리 **사람이 마지막으로 보는 화면**이라 모델이 고른 값으로
|
|
169
|
+
* 화면을 위조할 수 없어야 한다: 문자열은 JSON 리터럴로(따옴표 + `\n` 이스케이프 — 값 안의 줄바꿈으로 가짜
|
|
170
|
+
* `key: value` 줄이나 "검증됨" 문구를 만들 수 없다), 보이지 않는 문자는 `\uXXXX` 로, 긴 값은 앞뒤를 보이고
|
|
171
|
+
* 생략 사실과 길이를 밝힌다 (200자에서 자르던 시절엔 뒤쪽에 숨긴 URL·명령이 안 보였다).
|
|
172
|
+
*/
|
|
173
|
+
export function approvalArgLines(args) {
|
|
174
|
+
let truncated = false;
|
|
175
|
+
const lines = Object.entries(args)
|
|
176
|
+
.filter(([k, v]) => !isConfirmKey(k) && v !== undefined)
|
|
177
|
+
.map(([k, v]) => {
|
|
178
|
+
if (SECRET_KEY.test(k))
|
|
179
|
+
return ` ${k}: (redacted)`;
|
|
180
|
+
let shown = showInvisible(JSON.stringify(redactNested(v)) ?? 'undefined');
|
|
181
|
+
if (shown.length > APPROVAL_VALUE_MAX) {
|
|
182
|
+
truncated = true;
|
|
183
|
+
const hidden = shown.length - APPROVAL_VALUE_HEAD - APPROVAL_VALUE_TAIL;
|
|
184
|
+
shown = `${shown.slice(0, APPROVAL_VALUE_HEAD)} …[${hidden}/${shown.length}]… ${shown.slice(-APPROVAL_VALUE_TAIL)}`;
|
|
185
|
+
}
|
|
186
|
+
return ` ${k}: ${shown}`;
|
|
187
|
+
});
|
|
188
|
+
return { lines, truncated };
|
|
189
|
+
}
|
|
132
190
|
export function confirmPreview(name, args) {
|
|
133
|
-
const
|
|
191
|
+
const argLines = previewArgLines(args);
|
|
134
192
|
const lines = [
|
|
135
193
|
`${CONFIRM_PREVIEW_MARKER} — ${P().notRun(name)}`,
|
|
136
194
|
'',
|
|
137
195
|
P().args,
|
|
138
|
-
...(
|
|
196
|
+
...(argLines.length ? argLines : [` ${P().none}`]),
|
|
139
197
|
'',
|
|
140
198
|
P().next,
|
|
141
199
|
];
|
|
@@ -147,6 +205,7 @@ export const GUARD_DESCRIPTION = '⚠️ 안전 가드: confirm 생략/false 면
|
|
|
147
205
|
export const CONFIRM_PARAM_DESCRIPTION = 'true 명시 시에만 실제 실행. 생략/false 면 dry-run preview 만 반환 (비가역·공개 사고 차단).';
|
|
148
206
|
export function createToolRegistrar(server, options) {
|
|
149
207
|
const { manifest, toolsets } = options;
|
|
208
|
+
const env = options.env ?? process.env;
|
|
150
209
|
const t = options.translate ?? ((text) => text);
|
|
151
210
|
const index = buildToolIndex(manifest);
|
|
152
211
|
const metaOf = (name) => {
|
|
@@ -164,6 +223,7 @@ export function createToolRegistrar(server, options) {
|
|
|
164
223
|
return {
|
|
165
224
|
toolsets,
|
|
166
225
|
manifest,
|
|
226
|
+
approvalStatus: () => ({ mode: approvalMode(env), clientCanElicit: clientCanElicit(server) }),
|
|
167
227
|
tool(name, description, shape, handler, outputSchema) {
|
|
168
228
|
const meta = metaOf(name);
|
|
169
229
|
if (meta.deprecatedFor) {
|
|
@@ -199,6 +259,23 @@ export function createToolRegistrar(server, options) {
|
|
|
199
259
|
return run(args, extra);
|
|
200
260
|
};
|
|
201
261
|
}
|
|
262
|
+
// 사람 승인 게이트 — 확인 플래그(confirm* — isConfirmKey)를 가진 **모든** 도구(레지스트라 가드 · ownGate · 자체 확인을
|
|
263
|
+
// 가진 쓰기 도구)에서, 플래그가 true 로 온 호출만 실행 직전에 사용자에게 직접 묻는다. 플래그 없는 호출은 그대로.
|
|
264
|
+
// manifest `approval` 도구는 플래그와 무관하게 매 호출 묻는다 — 플래그 없는 경로가 위험한 도구
|
|
265
|
+
// (자격증명 목적지 변경 `*_save_config`, 새 id 로 비밀 업로드, 배포 워크플로 시작).
|
|
266
|
+
const confirmKeys = Object.keys(finalShape).filter(isConfirmKey);
|
|
267
|
+
if (meta.approval || confirmKeys.length > 0) {
|
|
268
|
+
const gated = finalHandler;
|
|
269
|
+
const title = annotationsFor(meta).title;
|
|
270
|
+
finalHandler = async (args, extra) => {
|
|
271
|
+
if (!meta.approval && !confirmKeys.some((k) => args[k] === true))
|
|
272
|
+
return gated(args, extra);
|
|
273
|
+
const signal = extra?.signal;
|
|
274
|
+
const { lines, truncated } = approvalArgLines(args);
|
|
275
|
+
const refusal = await requestHumanApproval(server, { name, title, args, argLines: lines, truncated }, { signal, mode: approvalMode(env) });
|
|
276
|
+
return refusal ?? gated(args, extra);
|
|
277
|
+
};
|
|
278
|
+
}
|
|
202
279
|
register(meta, finalDescription, finalShape, finalHandler, outputSchema);
|
|
203
280
|
for (const alias of meta.aliases) {
|
|
204
281
|
const aliasMeta = metaOf(alias);
|
|
@@ -8,7 +8,7 @@ import { generateKeystore, isKeytoolAvailable } from '../android/keystore.js';
|
|
|
8
8
|
import { keystoresDir, persistGeneratedKeystore } from '../android/keystore-store.js';
|
|
9
9
|
import { loadJenkinsConfig, requireJenkinsConfig } from '../jenkins/config.js';
|
|
10
10
|
import { inspectCredential, KIND_FILE, upsertSecretFile } from '../jenkins/credentials.js';
|
|
11
|
-
import { ambiguousDefaultIdNote, existingCredentialPreview } from '../jenkins/messages.js';
|
|
11
|
+
import { ambiguousDefaultIdNote, existingCredentialPreview, newCredentialPreview } from '../jenkins/messages.js';
|
|
12
12
|
import { loadPlayServiceAccountForUpload } from '../android/playstore-sa.js';
|
|
13
13
|
import { existingAppSigningPlanLines, newAppSigningPlanLines, keytoolMissingLines, keystoreGeneratedLines, playServiceAccountMissingLines, playServiceAccountUploadedLines, } from '../android/messages.js';
|
|
14
14
|
import { textResult } from '../lib/mcp-response.js';
|
|
@@ -124,8 +124,8 @@ export function registerAndroidTools(server) {
|
|
|
124
124
|
'~/.mimi-seed/play-service-accounts/{package_name}.json 을 읽어 base64로 변환 후 등록합니다.',
|
|
125
125
|
'iam_create_key 로 막 발급한 키를 올리려면 service_account_json_path 에 그 경로(~/.mimi-seed/keys/ 안)를 넘기세요.',
|
|
126
126
|
'setup_playstore_connection 실행 후 반드시 이 도구를 호출하세요.',
|
|
127
|
-
'
|
|
128
|
-
'
|
|
127
|
+
'confirm 생략/false 면 아무것도 보내지 않고 dry-run 만 반환한다 — 새 id 면 "생성 예정", 같은 id 가 있으면',
|
|
128
|
+
'"이미 존재"(기존 SA JSON 을 교체하면 되돌릴 수 없음). 사용자 승인 후 같은 인자에 confirm: true 로 재호출.',
|
|
129
129
|
].join(' '), {
|
|
130
130
|
package_name: androidPackageName.describe('Android 패키지명 (예: com.example.app)'),
|
|
131
131
|
// 기본값을 하드코딩 문자열에서 패키지명 파생으로 바꿨다 — 예전 기본값은 한 사설 앱
|
|
@@ -135,7 +135,7 @@ export function registerAndroidTools(server) {
|
|
|
135
135
|
.string()
|
|
136
136
|
.optional()
|
|
137
137
|
.describe('선택 — iam_create_key 가 저장한 키 파일 절대경로 (~/.mimi-seed/keys/ 안만 허용). 생략하면 패키지별 등록 SA 사용'),
|
|
138
|
-
confirm: z.boolean().optional().describe('
|
|
138
|
+
confirm: z.boolean().optional().describe('true 일 때만 Jenkins 로 보낸다 (새 id 생성 또는 기존 SA JSON 교체). 생략/false 면 dry-run'),
|
|
139
139
|
}, async ({ package_name, credential_id: credentialIdInput, service_account_json_path, confirm }) => {
|
|
140
140
|
const credential_id = credentialIdInput ?? `${credentialPrefix(package_name)}-playstore-sa`;
|
|
141
141
|
const sa = loadPlayServiceAccountForUpload(package_name, service_account_json_path);
|
|
@@ -143,19 +143,22 @@ export function registerAndroidTools(server) {
|
|
|
143
143
|
return textResult(playServiceAccountMissingLines(package_name, sa.path));
|
|
144
144
|
const saBase64 = Buffer.from(sa.raw, 'utf-8').toString('base64');
|
|
145
145
|
const cfg = requireJenkinsConfig();
|
|
146
|
-
// jenkins_upload_keystore / jenkins_create_credential 와 같은 규칙:
|
|
147
|
-
//
|
|
146
|
+
// jenkins_upload_keystore / jenkins_create_credential 와 같은 규칙: confirm 전에는 아무것도 보내지 않는다.
|
|
147
|
+
// 새 id 도 SA 키를 외부로 내보내는 작업이라 dry-run 을 거친다 (예전엔 새 id 는 바로, 기존 id 는 말없이 덮어썼다).
|
|
148
148
|
// 설명에 패키지명을 남긴다 — 기본 id 가 마지막 세그먼트만 써서 다른 앱과 겹쳐도 다음 dry-run 이 누구 것인지 보여준다.
|
|
149
149
|
const description = `Play Store service account for ${package_name}`;
|
|
150
150
|
const result = await upsertSecretFile(cfg, credential_id, saBase64, `${package_name}-sa.json`, description, {
|
|
151
151
|
allowReplace: confirm === true,
|
|
152
|
+
dryRun: confirm !== true,
|
|
152
153
|
});
|
|
153
|
-
if (result === 'exists') {
|
|
154
|
+
if (result === 'exists' || result === 'new') {
|
|
154
155
|
const notes = [];
|
|
155
156
|
if (credentialIdInput === undefined) {
|
|
156
157
|
notes.push(ambiguousDefaultIdNote(credential_id) ??
|
|
157
158
|
M().defaultIdNote(credential_id, package_name));
|
|
158
159
|
}
|
|
160
|
+
if (result === 'new')
|
|
161
|
+
return textResult(newCredentialPreview(credential_id, cfg.url, KIND_FILE, notes));
|
|
159
162
|
return textResult(existingCredentialPreview(credential_id, await inspectCredential(cfg, credential_id), KIND_FILE, notes));
|
|
160
163
|
}
|
|
161
164
|
return textResult(playServiceAccountUploadedLines({
|