smedc-mcp-launcher 0.5.2 → 0.7.0

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 CHANGED
@@ -1,16 +1,16 @@
1
1
  # SMEDC MCP Launcher
2
2
 
3
3
  Official stdio MCP launcher for SMEDC. It reads only `SMEDC_BASE_URL`, which must
4
- be a canonical HTTPS origin. Browser sign-in uses OAuth Authorization Code with PKCE; credentials
5
- are never accepted through command arguments, environment variables, or MCP tool inputs.
4
+ be a canonical HTTPS origin. Browser sign-in uses OAuth Device Authorization; credentials are
5
+ never accepted through command arguments, environment variables, or MCP tool inputs.
6
6
 
7
7
  Commands: `serve`, `self-check`, `logout`, and `--version`.
8
8
 
9
- Release: `smedc-mcp-launcher@0.5.2` (`smedc-mcp-launcher --version` reports `0.5.2`).
9
+ Release target: `smedc-mcp-launcher@0.7.0` (`smedc-mcp-launcher --version` reports `0.7.0`).
10
10
 
11
11
  All three file-upload tools remain discoverable and require the admin role. The launcher
12
12
  rejects cached employee-role uploads before reading a local file or processing upload input.
13
- For an unknown or legacy profile, it first queries authenticated `/me` and securely caches
13
+ For a newly established session without a cached profile, it first queries authenticated `/me` and securely caches
14
14
  only display name, email, role, clearance, and organization name with the credential. Profile
15
15
  lookup failures stop the upload. Logout clears the cached profile. The service remains the
16
16
  authority for upload authorization, including when a local cache has been modified.
@@ -26,3 +26,31 @@ This tool always reads the live service profile; `smedc_auth_status` does not re
26
26
  credential contents.
27
27
 
28
28
  This public package has no npm provenance because the source repository is private.
29
+
30
+ Ledger PDF tools in 0.7.0:
31
+
32
+ - `describe_ledger_pdf_coverage`: select real `YYYY-MM-DD` dates or an inclusive
33
+ `startDate`/`endDate` range, with optional exact `storeNames` and opaque `cursor`.
34
+ Pages contain at most 200 facts.
35
+ - `prepare_ledger_pdf_download`: submit explicit stores/dates and `idempotencyKey`
36
+ to bundle existing authorized PDFs. Missing or stale PDFs await the service's daily
37
+ 03:00 Asia/Shanghai generation; employee agents cannot trigger generation.
38
+ - `get_ledger_pdf_request_status`: poll the returned `requestId` to terminal status;
39
+ optional `cursor` reads the next page. A queued 202 response is not completion.
40
+ - `get_ledger_pdf_download_url`: after ZIP readiness, exchange `requestId` for a
41
+ service-signed short-lived ZIP URL. The service reauthorizes each issuance.
42
+
43
+ Public scopes accept at most 50 exact stores, 366 dates, and 5,000 actual partitions
44
+ counted by the service. They reject organization selectors and render/download flags.
45
+ The launcher returns service JSON and signed links; it does not generate ledger files
46
+ or return base64 PDF contents. Coverage, status, and link issuance have read-only
47
+ annotations; ZIP preparation advertises idempotent side effects. Uploads and photo
48
+ changes record changed dates for scheduled generation; they do not generate PDFs immediately.
49
+
50
+ This version requires a coordinated service rollout for the ledger PDF endpoints.
51
+ An older service may reject the new tools or return `LEDGER_PDF_NOT_ENABLED` (503).
52
+ `LEDGER_DETAIL_DISABLED` directs clients to the PDF workflow. For
53
+ `LEDGER_PDF_NOT_READY`, wait for scheduled service generation, then recheck coverage;
54
+ `LEDGER_PDF_BUNDLE_STALE` requires a new preparation request. Existing validation,
55
+ permission, and idempotency errors retain their service semantics. The release target
56
+ above does not indicate that 0.7.0 has been published.
package/dist/index.d.ts CHANGED
@@ -14,7 +14,7 @@ declare function createLauncherRuntimeConfig(input: LauncherRuntimeConfigInput):
14
14
  declare function loadLauncherRuntimeConfig(env?: LauncherRuntimeEnv): LauncherRuntimeConfig;
15
15
 
16
16
  declare const MCP_LAUNCHER_SERVER_NAME = "smedc-mcp-launcher";
17
- declare const MCP_LAUNCHER_SERVER_VERSION = "0.5.2";
17
+ declare const MCP_LAUNCHER_SERVER_VERSION = "0.7.0";
18
18
  declare function createSmedcMcpLauncherServer(config: LauncherRuntimeConfig): McpServer;
19
19
  declare function runMcpLauncherStdioServer(config: LauncherRuntimeConfig): Promise<void>;
20
20
 
@@ -23,28 +23,6 @@ interface SecureCredentialStore {
23
23
  set(credential: string): Promise<void>;
24
24
  delete(): Promise<void>;
25
25
  }
26
- interface AuthorizationRequest {
27
- url: URL;
28
- state: string;
29
- verifier: string;
30
- }
31
- interface LoopbackCallbackServer {
32
- redirectUri: URL;
33
- waitForResult(): Promise<{
34
- received: true;
35
- }>;
36
- close(): Promise<void>;
37
- }
38
- declare function createAuthorizationRequest(input: {
39
- authorizationEndpoint: URL;
40
- redirectUri: URL;
41
- state?: string;
42
- verifier?: string;
43
- }): Promise<AuthorizationRequest>;
44
- declare function createLoopbackCallbackServer(input: {
45
- state: string;
46
- timeoutMs?: number;
47
- }): Promise<LoopbackCallbackServer>;
48
26
  declare function redactSecrets(value: unknown): unknown;
49
27
 
50
28
  interface CachedUserProfile {
@@ -118,7 +96,7 @@ declare class LauncherSession {
118
96
 
119
97
  declare const LAUNCHER_BOOTSTRAP_TOOL_NAMES: readonly ["smedc_login", "smedc_logout", "smedc_auth_status"];
120
98
  type LauncherBootstrapToolName = (typeof LAUNCHER_BOOTSTRAP_TOOL_NAMES)[number];
121
- type LauncherBusinessToolName = "smedc_get_current_user" | "smedc_list_skills" | "search_document_evidence" | "list_structured_datasets" | "query_structured_dataset" | "describe_structured_dataset_coverage" | "upload_structured_dataset" | "upload_evidence_document" | "upload_quarantine_certificate" | "query_quarantine_certificates" | "archive_quarantine_certificates" | "get_source_document_download_url" | "get_evidence_document_status" | "get_import_status" | "get_partition_import_status" | "download_structured_partitions";
99
+ type LauncherBusinessToolName = "smedc_get_current_user" | "smedc_list_skills" | "search_document_evidence" | "list_structured_datasets" | "query_structured_dataset" | "describe_structured_dataset_coverage" | "upload_structured_dataset" | "upload_evidence_document" | "upload_quarantine_certificate" | "query_quarantine_certificates" | "archive_quarantine_certificates" | "get_source_document_download_url" | "get_evidence_document_status" | "get_import_status" | "get_partition_import_status" | "download_structured_partitions" | "describe_ledger_pdf_coverage" | "get_ledger_pdf_request_status" | "prepare_ledger_pdf_download" | "get_ledger_pdf_download_url";
122
100
  type LauncherToolName = LauncherBootstrapToolName | LauncherBusinessToolName;
123
101
  interface LauncherToolResult {
124
102
  [key: string]: unknown;
@@ -184,7 +162,12 @@ interface LauncherToolRegistrar {
184
162
  registerTool(name: string, options: {
185
163
  title: string;
186
164
  description: string;
187
- inputSchema: z.ZodRawShape;
165
+ inputSchema: z.ZodRawShape | z.ZodObject<z.ZodRawShape>;
166
+ annotations?: {
167
+ readOnlyHint: boolean;
168
+ destructiveHint: boolean;
169
+ idempotentHint: boolean;
170
+ };
188
171
  }, handler: (input: unknown) => Promise<LauncherToolResult>): void;
189
172
  }
190
173
  declare function createLauncherToolDependencies(input: {
@@ -198,4 +181,4 @@ declare function createOfficialLauncherAuthentication(config: LauncherRuntimeCon
198
181
 
199
182
  declare function runCommand(): Promise<void>;
200
183
 
201
- export { type CachedUserProfile, LAUNCHER_BOOTSTRAP_TOOL_NAMES, type LauncherAuthentication, type LauncherBootstrapToolName, type LauncherBusinessToolName, type LauncherErrorCode, type LauncherRuntimeConfig, type LauncherRuntimeConfigInput, LauncherSession, type LauncherToolDependencies, type LauncherToolName, type LauncherToolRegistrar, type LauncherToolResult, LauncherTypedError, MCP_LAUNCHER_SERVER_NAME, MCP_LAUNCHER_SERVER_VERSION, cachedUserProfileSchema, createAuthorizationRequest, createLauncherRuntimeConfig, createLauncherToolDependencies, createLauncherToolHandler, createLoopbackCallbackServer, createOfficialLauncherAuthentication, createSmedcMcpLauncherServer, loadLauncherRuntimeConfig, parseCurrentUserProfileResponse, redactSecrets, registerLauncherTools, runCommand, runMcpLauncherStdioServer };
184
+ export { type CachedUserProfile, LAUNCHER_BOOTSTRAP_TOOL_NAMES, type LauncherAuthentication, type LauncherBootstrapToolName, type LauncherBusinessToolName, type LauncherErrorCode, type LauncherRuntimeConfig, type LauncherRuntimeConfigInput, LauncherSession, type LauncherToolDependencies, type LauncherToolName, type LauncherToolRegistrar, type LauncherToolResult, LauncherTypedError, MCP_LAUNCHER_SERVER_NAME, MCP_LAUNCHER_SERVER_VERSION, cachedUserProfileSchema, createLauncherRuntimeConfig, createLauncherToolDependencies, createLauncherToolHandler, createOfficialLauncherAuthentication, createSmedcMcpLauncherServer, loadLauncherRuntimeConfig, parseCurrentUserProfileResponse, redactSecrets, registerLauncherTools, runCommand, runMcpLauncherStdioServer };
package/dist/index.js CHANGED
@@ -1460,6 +1460,85 @@ var archiveQuarantineCertificatesInputSchema = z.object({
1460
1460
  var sourceDocumentDownloadUrlInputSchema = z.object({
1461
1461
  sourceDocumentId: z.string().min(1).describe("Source document ID to download.")
1462
1462
  }).strict();
1463
+ var ledgerPdfDate = z.string().regex(/^\d{4}-\d{2}-\d{2}$/).refine((value) => {
1464
+ const date = /* @__PURE__ */ new Date(`${value}T00:00:00.000Z`);
1465
+ return value >= "1000-01-01" && value <= "9999-12-31" && !Number.isNaN(date.getTime()) && date.toISOString().slice(0, 10) === value;
1466
+ }, "Use a real YYYY-MM-DD calendar date.");
1467
+ var ledgerPdfStoreNames = z.array(
1468
+ z.string().min(1).max(512).refine((name) => name.trim().length > 0)
1469
+ ).min(1).max(50).describe("1-50 exact store names, preserved without trimming.");
1470
+ var ledgerPdfScopeShape = {
1471
+ storeNames: ledgerPdfStoreNames,
1472
+ dates: z.array(ledgerPdfDate).min(1).max(366).optional().describe("1-366 explicit dates; exclusive with the date range."),
1473
+ startDate: ledgerPdfDate.optional().describe("Inclusive range start; requires endDate and excludes dates."),
1474
+ endDate: ledgerPdfDate.optional().describe("Inclusive range end; requires startDate and excludes dates.")
1475
+ };
1476
+ var ledgerPdfCursor = z.string().min(1).max(PUBLIC_INPUT_LIMITS.cursorChars).optional().describe("Opaque service cursor; pages contain at most 200 items.");
1477
+ var ledgerPdfRequestId = z.string().min(1).max(128).describe("Service-issued ledger PDF request ID.");
1478
+ var ledgerPdfCoverageInputSchema = z.object({
1479
+ ...ledgerPdfScopeShape,
1480
+ storeNames: ledgerPdfStoreNames.optional(),
1481
+ cursor: ledgerPdfCursor
1482
+ }).strict().superRefine(validateLedgerPdfDateSelection);
1483
+ var ledgerPdfActionInputSchema = z.object({
1484
+ ...ledgerPdfScopeShape,
1485
+ idempotencyKey: z.string().min(1).max(PUBLIC_INPUT_LIMITS.idempotencyKeyChars).describe("Client-generated retry/idempotency key.")
1486
+ }).strict().superRefine(validateLedgerPdfDateSelection);
1487
+ var ledgerPdfRequestStatusInputSchema = z.object({ requestId: ledgerPdfRequestId, cursor: ledgerPdfCursor }).strict();
1488
+ var ledgerPdfDownloadUrlInputSchema = z.object({ requestId: ledgerPdfRequestId }).strict();
1489
+ var ledgerPdfScopeFields = [
1490
+ { name: "storeNames", required: true, description: "1-50 exact store names." },
1491
+ {
1492
+ name: "dates",
1493
+ required: false,
1494
+ description: "1-366 real YYYY-MM-DD dates, exclusive with startDate/endDate."
1495
+ },
1496
+ {
1497
+ name: "startDate",
1498
+ required: false,
1499
+ description: "Inclusive YYYY-MM-DD range start, paired with endDate."
1500
+ },
1501
+ {
1502
+ name: "endDate",
1503
+ required: false,
1504
+ description: "Inclusive YYYY-MM-DD range end, at most 366 days."
1505
+ }
1506
+ ];
1507
+ var ledgerPdfReadAnnotations = {
1508
+ readOnlyHint: true,
1509
+ destructiveHint: false,
1510
+ idempotentHint: true
1511
+ };
1512
+ var ledgerPdfActionAnnotations = {
1513
+ readOnlyHint: false,
1514
+ destructiveHint: false,
1515
+ idempotentHint: true
1516
+ };
1517
+ function validateLedgerPdfDateSelection(input, context) {
1518
+ if (input.dates !== void 0) {
1519
+ if (input.startDate !== void 0 || input.endDate !== void 0)
1520
+ context.addIssue({
1521
+ code: "custom",
1522
+ path: ["dates"],
1523
+ message: "Provide dates or startDate/endDate, never both."
1524
+ });
1525
+ return;
1526
+ }
1527
+ if (input.startDate === void 0 || input.endDate === void 0) {
1528
+ context.addIssue({
1529
+ code: "custom",
1530
+ path: ["startDate"],
1531
+ message: "Provide dates or both startDate and endDate."
1532
+ });
1533
+ return;
1534
+ }
1535
+ if (input.startDate > input.endDate || (Date.parse(input.endDate) - Date.parse(input.startDate)) / 864e5 + 1 > 366)
1536
+ context.addIssue({
1537
+ code: "custom",
1538
+ path: ["endDate"],
1539
+ message: "Date range must be ordered and contain at most 366 days."
1540
+ });
1541
+ }
1463
1542
  var SMEDC_MCP_TOOL_NAMES = [
1464
1543
  "smedc_get_current_user",
1465
1544
  "smedc_list_skills",
@@ -1476,7 +1555,11 @@ var SMEDC_MCP_TOOL_NAMES = [
1476
1555
  "get_evidence_document_status",
1477
1556
  "get_import_status",
1478
1557
  "get_partition_import_status",
1479
- "download_structured_partitions"
1558
+ "download_structured_partitions",
1559
+ "describe_ledger_pdf_coverage",
1560
+ "get_ledger_pdf_request_status",
1561
+ "prepare_ledger_pdf_download",
1562
+ "get_ledger_pdf_download_url"
1480
1563
  ];
1481
1564
  var SMEDC_MCP_TOOL_CONTRACTS = [
1482
1565
  defineToolContract({
@@ -1744,6 +1827,58 @@ var SMEDC_MCP_TOOL_CONTRACTS = [
1744
1827
  { name: "importBatchId", required: true, description: "Structured import batch id." }
1745
1828
  ],
1746
1829
  resultShape: ["document", "processing", "importBatch"]
1830
+ }),
1831
+ defineToolContract({
1832
+ name: "describe_ledger_pdf_coverage",
1833
+ title: "Describe ledger PDF coverage",
1834
+ description: "Query authorized ledger PDF coverage using POST /v1/ledger-pdfs/coverage. Dates are required; stores may be omitted. Pages contain at most 200 scope facts. The service limits each scope to 5,000 actual partitions, independent of the store/date Cartesian product.",
1835
+ inputSchema: ledgerPdfCoverageInputSchema,
1836
+ inputFields: [
1837
+ ...ledgerPdfScopeFields.map(
1838
+ (field) => field.name === "storeNames" ? { ...field, required: false } : field
1839
+ ),
1840
+ { name: "cursor", required: false, description: "Opaque service pagination cursor." }
1841
+ ],
1842
+ resultShape: ["scope", "partitions[]: authorized scope coverage facts", "nextCursor"],
1843
+ annotations: ledgerPdfReadAnnotations
1844
+ }),
1845
+ defineToolContract({
1846
+ name: "get_ledger_pdf_request_status",
1847
+ title: "Get ledger PDF request status",
1848
+ description: "Read an authorized request using GET /v1/ledger-pdfs/requests/:requestId. Poll queued requests to a terminal status; cursor pages contain at most 200 scope facts. This tool never issues download URLs.",
1849
+ inputSchema: ledgerPdfRequestStatusInputSchema,
1850
+ inputFields: [
1851
+ { name: "requestId", required: true, description: "Service-issued ledger PDF request ID." },
1852
+ { name: "cursor", required: false, description: "Opaque service pagination cursor." }
1853
+ ],
1854
+ resultShape: [
1855
+ "requestId",
1856
+ "status",
1857
+ "partitions[]: authorized request scope facts",
1858
+ "nextCursor"
1859
+ ],
1860
+ annotations: ledgerPdfReadAnnotations
1861
+ }),
1862
+ defineToolContract({
1863
+ name: "prepare_ledger_pdf_download",
1864
+ title: "Prepare ledger PDF ZIP download",
1865
+ description: "Submit an idempotent ZIP request using POST /v1/ledger-pdfs/downloads for existing authorized PDFs in explicit stores/dates, at most 5,000 actual partitions. A 202 queued requestId must be polled with get_ledger_pdf_request_status. Preparation never invokes the renderer. Missing or stale PDFs must wait for the service's daily 03:00 Asia/Shanghai generation; employee agents cannot trigger generation. After ready, call get_ledger_pdf_download_url.",
1866
+ inputSchema: ledgerPdfActionInputSchema,
1867
+ inputFields: [
1868
+ ...ledgerPdfScopeFields,
1869
+ { name: "idempotencyKey", required: true, description: "Retry/idempotency key." }
1870
+ ],
1871
+ resultShape: ["requestId", "status: queued; poll get_ledger_pdf_request_status"],
1872
+ annotations: ledgerPdfActionAnnotations
1873
+ }),
1874
+ defineToolContract({
1875
+ name: "get_ledger_pdf_download_url",
1876
+ title: "Get ledger PDF ZIP download URL",
1877
+ description: "Get a short-lived service-signed ZIP link using POST /v1/ledger-pdfs/requests/:requestId/download-url. The service reauthorizes current access on every call. Returns a link only; no PDF base64, binary content, local file generation, or renderer invocation.",
1878
+ inputSchema: ledgerPdfDownloadUrlInputSchema,
1879
+ inputFields: [{ name: "requestId", required: true, description: "Ready ZIP request ID." }],
1880
+ resultShape: ["requestId", "downloadUrl", "expiresAt"],
1881
+ annotations: ledgerPdfReadAnnotations
1747
1882
  })
1748
1883
  ];
1749
1884
  var mcpToolContractSchema = z.object({
@@ -1759,7 +1894,12 @@ var mcpToolContractSchema = z.object({
1759
1894
  description: z.string().min(1)
1760
1895
  }).strict()
1761
1896
  ),
1762
- resultShape: z.array(z.string().min(1)).min(1)
1897
+ resultShape: z.array(z.string().min(1)).min(1),
1898
+ annotations: z.object({
1899
+ readOnlyHint: z.boolean(),
1900
+ destructiveHint: z.boolean(),
1901
+ idempotentHint: z.boolean()
1902
+ }).strict().optional()
1763
1903
  }).strict().superRefine((contract, context) => {
1764
1904
  const shapeNames = Object.keys(contract.inputShape);
1765
1905
  const fieldNames = contract.inputFields.map((field) => field.name);
@@ -2183,9 +2323,9 @@ var LauncherSession = class {
2183
2323
  if (!record) return null;
2184
2324
  try {
2185
2325
  const value = JSON.parse(record);
2186
- if (value === null || value.schemaVersion !== 1 && value.schemaVersion !== 2 || value.origin !== this.dependencies.origin || typeof value.durableCredential !== "string" || !value.durableCredential)
2326
+ if (value === null || value.schemaVersion !== 2 || value.origin !== this.dependencies.origin || typeof value.durableCredential !== "string" || !value.durableCredential)
2187
2327
  return null;
2188
- const profile = value.schemaVersion === 1 || value.profile === null ? null : cachedUserProfileSchema.parse(value.profile);
2328
+ const profile = value.profile === null ? null : cachedUserProfileSchema.parse(value.profile);
2189
2329
  return {
2190
2330
  schemaVersion: 2,
2191
2331
  origin: this.dependencies.origin,
@@ -2261,7 +2401,7 @@ function messageFor(code) {
2261
2401
  }
2262
2402
 
2263
2403
  // src/oauth-client.ts
2264
- var LAUNCHER_VERSION = "0.5.2";
2404
+ var LAUNCHER_VERSION = "0.7.0";
2265
2405
  var CLIENT = { client_id: "smedc-desktop-launcher" };
2266
2406
  var VERSION_HEADER = { "x-smedc-launcher-version": LAUNCHER_VERSION };
2267
2407
  var REQUEST_TIMEOUT_MS = 1e4;
@@ -2275,7 +2415,7 @@ var SmedcOAuthClient = class {
2275
2415
  #server = null;
2276
2416
  async metadata(force = false, enforce = true) {
2277
2417
  const server = await this.discovery(force);
2278
- if (!server.authorization_endpoint || !server.token_endpoint) {
2418
+ if (!server.device_authorization_endpoint || !server.token_endpoint) {
2279
2419
  throw new LauncherTypedError("SERVICE_UNAVAILABLE");
2280
2420
  }
2281
2421
  const extensions = server;
@@ -2287,35 +2427,13 @@ var SmedcOAuthClient = class {
2287
2427
  throw new LauncherTypedError("LAUNCHER_UPGRADE_REQUIRED");
2288
2428
  }
2289
2429
  return {
2290
- authorizationEndpoint: new URL(server.authorization_endpoint),
2291
- deviceAuthorizationEndpoint: server.device_authorization_endpoint ? new URL(server.device_authorization_endpoint) : null,
2430
+ deviceAuthorizationEndpoint: new URL(server.device_authorization_endpoint),
2292
2431
  minimumVersion,
2293
2432
  recommendedVersion,
2294
2433
  recommendedUpdateAvailable: semver.lt(LAUNCHER_VERSION, recommendedVersion),
2295
2434
  compatible
2296
2435
  };
2297
2436
  }
2298
- async exchange(callbackParameters, redirectUri, verifier) {
2299
- const server = await this.discovery();
2300
- try {
2301
- const response = await oauth.authorizationCodeGrantRequest(
2302
- server,
2303
- CLIENT,
2304
- oauth.None(),
2305
- callbackParameters,
2306
- redirectUri.toString(),
2307
- verifier,
2308
- requestOptions(this.fetchImplementation)
2309
- );
2310
- return readToken(await oauth.processAuthorizationCodeResponse(server, CLIENT, response));
2311
- } catch (error) {
2312
- throw mapOAuthError(error);
2313
- }
2314
- }
2315
- validateCallback(callbackUrl, expectedState) {
2316
- if (!this.#server) throw new LauncherTypedError("SERVICE_UNAVAILABLE");
2317
- return validateAuthorizationCallback(this.#server, callbackUrl, expectedState);
2318
- }
2319
2437
  async requestDeviceAuthorization(input) {
2320
2438
  const server = await this.discovery();
2321
2439
  if (!server.device_authorization_endpoint) {
@@ -2426,18 +2544,6 @@ var SmedcOAuthClient = class {
2426
2544
  }
2427
2545
  }
2428
2546
  };
2429
- function validateAuthorizationCallback(server, callbackUrl, expectedState) {
2430
- try {
2431
- for (const name of ["code", "state", "error", "iss"]) {
2432
- if (callbackUrl.searchParams.getAll(name).length > 1) {
2433
- throw new LauncherTypedError("AUTHENTICATION_REQUIRED");
2434
- }
2435
- }
2436
- return oauth.validateAuthResponse(server, CLIENT, callbackUrl, expectedState);
2437
- } catch (error) {
2438
- throw mapOAuthError(error);
2439
- }
2440
- }
2441
2547
  function readToken(response) {
2442
2548
  if (!response.access_token || !response.refresh_token)
2443
2549
  throw new LauncherTypedError("AUTHENTICATION_REQUIRED");
@@ -2974,6 +3080,12 @@ var LAUNCHER_BOOTSTRAP_TOOL_NAMES = [
2974
3080
  "smedc_logout",
2975
3081
  "smedc_auth_status"
2976
3082
  ];
3083
+ var LEDGER_PDF_TOOL_NAMES = /* @__PURE__ */ new Set([
3084
+ "describe_ledger_pdf_coverage",
3085
+ "get_ledger_pdf_request_status",
3086
+ "prepare_ledger_pdf_download",
3087
+ "get_ledger_pdf_download_url"
3088
+ ]);
2977
3089
  var LOCAL_PATH_UPLOAD_TOOL_NAMES = /* @__PURE__ */ new Set([
2978
3090
  "upload_structured_dataset",
2979
3091
  "upload_evidence_document",
@@ -3016,7 +3128,10 @@ function createLauncherToolDependencies(input) {
3016
3128
  function registerLauncherTools(registrar, dependencies) {
3017
3129
  const registered = /* @__PURE__ */ new Map();
3018
3130
  const registerTool = (name, options, handler) => {
3019
- registered.set(name, { inputSchema: z3.object(options.inputSchema), handler });
3131
+ registered.set(name, {
3132
+ inputSchema: options.inputSchema instanceof z3.ZodObject ? options.inputSchema : z3.object(options.inputSchema),
3133
+ handler
3134
+ });
3020
3135
  registrar.registerTool(name, options, handler);
3021
3136
  };
3022
3137
  for (const tool of bootstrapTools)
@@ -3031,7 +3146,8 @@ function registerLauncherTools(registrar, dependencies) {
3031
3146
  {
3032
3147
  title: tool.title,
3033
3148
  description: tool.description,
3034
- inputSchema: LOCAL_PATH_UPLOAD_TOOL_NAMES.has(tool.name) ? launcherUploadToolInputShape(tool) : tool.inputShape
3149
+ annotations: tool.annotations,
3150
+ inputSchema: LOCAL_PATH_UPLOAD_TOOL_NAMES.has(tool.name) ? launcherUploadToolInputShape(tool) : LEDGER_PDF_TOOL_NAMES.has(tool.name) ? tool.inputSchema : tool.inputShape
3035
3151
  },
3036
3152
  createLauncherToolHandler(tool.name, dependencies)
3037
3153
  );
@@ -3521,7 +3637,7 @@ function errorCode2(error) {
3521
3637
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3522
3638
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3523
3639
  var MCP_LAUNCHER_SERVER_NAME = "smedc-mcp-launcher";
3524
- var MCP_LAUNCHER_SERVER_VERSION = "0.5.2";
3640
+ var MCP_LAUNCHER_SERVER_VERSION = "0.7.0";
3525
3641
  function createSmedcMcpLauncherServer(config) {
3526
3642
  const server = new McpServer({
3527
3643
  name: MCP_LAUNCHER_SERVER_NAME,
@@ -3537,36 +3653,6 @@ async function runMcpLauncherStdioServer(config) {
3537
3653
  }
3538
3654
 
3539
3655
  // src/auth.ts
3540
- import { createHash as createHash3, randomBytes } from "crypto";
3541
- import http from "http";
3542
- var OAUTH_CLIENT_ID = "smedc-desktop-launcher";
3543
- var CALLBACK_PATH = "/oauth/callback";
3544
- var CALLBACK_TIMEOUT_MS = 5 * 60 * 1e3;
3545
- async function createAuthorizationRequest(input) {
3546
- const state = input.state ?? randomBase64Url(32);
3547
- const verifier = input.verifier ?? randomBase64Url(64);
3548
- const challenge = createHash3("sha256").update(verifier).digest("base64url");
3549
- const url = new URL(input.authorizationEndpoint);
3550
- url.searchParams.set("client_id", OAUTH_CLIENT_ID);
3551
- url.searchParams.set("response_type", "code");
3552
- url.searchParams.set("redirect_uri", input.redirectUri.toString());
3553
- url.searchParams.set("code_challenge", challenge);
3554
- url.searchParams.set("code_challenge_method", "S256");
3555
- url.searchParams.set("state", state);
3556
- return { url, state, verifier };
3557
- }
3558
- async function createLoopbackCallbackServer(input) {
3559
- for (let attempt = 0; attempt < 2; attempt += 1) {
3560
- try {
3561
- return await listenForCallback(input);
3562
- } catch (error) {
3563
- if (attempt === 1 || !isBindFailure(error)) {
3564
- throw new Error("Unable to start the secure browser callback.");
3565
- }
3566
- }
3567
- }
3568
- throw new Error("Unable to start the secure browser callback.");
3569
- }
3570
3656
  function redactSecrets(value) {
3571
3657
  if (Array.isArray(value)) {
3572
3658
  return value.map(redactSecrets);
@@ -3581,86 +3667,6 @@ function redactSecrets(value) {
3581
3667
  ])
3582
3668
  );
3583
3669
  }
3584
- function listenForCallback(input) {
3585
- return new Promise((resolve, reject) => {
3586
- let complete = false;
3587
- let resolveUrl;
3588
- let rejectUrl;
3589
- const urlPromise = new Promise((resolveUrlPromise, rejectUrlPromise) => {
3590
- resolveUrl = resolveUrlPromise;
3591
- rejectUrl = rejectUrlPromise;
3592
- });
3593
- const server = http.createServer((request, response) => {
3594
- const requestUrl = new URL(request.url ?? "/", "http://127.0.0.1");
3595
- if (request.method !== "GET" || requestUrl.pathname !== CALLBACK_PATH || complete) {
3596
- sendCallbackResponse(response, 400, "The sign-in callback is invalid.");
3597
- return;
3598
- }
3599
- complete = true;
3600
- clearTimeout(timeout);
3601
- sendCallbackResponse(response, 200, "Sign-in completed. You can return to SMEDC.");
3602
- resolveUrl?.(
3603
- new URL(requestUrl.pathname + requestUrl.search, `http://${request.headers.host}`)
3604
- );
3605
- });
3606
- const timeout = setTimeout(() => {
3607
- if (!complete) {
3608
- complete = true;
3609
- rejectUrl?.(new Error("Browser sign-in timed out."));
3610
- void closeServer(server);
3611
- }
3612
- }, input.timeoutMs ?? CALLBACK_TIMEOUT_MS);
3613
- server.once("error", (error) => {
3614
- clearTimeout(timeout);
3615
- reject(error);
3616
- });
3617
- server.listen(0, "127.0.0.1", () => {
3618
- const address = server.address();
3619
- if (address === null || typeof address === "string") {
3620
- clearTimeout(timeout);
3621
- void closeServer(server);
3622
- reject(new Error("Loopback callback did not bind to IPv4."));
3623
- return;
3624
- }
3625
- const callback = {
3626
- redirectUri: new URL(`http://127.0.0.1:${address.port}${CALLBACK_PATH}`),
3627
- waitForResult: async () => {
3628
- await urlPromise;
3629
- return { received: true };
3630
- },
3631
- waitForUrl: () => urlPromise,
3632
- close: async () => {
3633
- clearTimeout(timeout);
3634
- if (!complete) {
3635
- complete = true;
3636
- rejectUrl?.(new Error("Browser sign-in was cancelled."));
3637
- }
3638
- await closeServer(server);
3639
- }
3640
- };
3641
- resolve(callback);
3642
- });
3643
- });
3644
- }
3645
- function sendCallbackResponse(response, status2, message) {
3646
- response.writeHead(status2, {
3647
- "content-type": "text/html; charset=utf-8",
3648
- "cache-control": "no-store"
3649
- });
3650
- response.end(`<!doctype html><title>SMEDC</title><p>${message}</p>`);
3651
- }
3652
- async function closeServer(server) {
3653
- if (!server.listening) {
3654
- return;
3655
- }
3656
- await new Promise((resolve) => server.close(() => resolve()));
3657
- }
3658
- function randomBase64Url(bytes) {
3659
- return randomBytes(bytes).toString("base64url");
3660
- }
3661
- function isBindFailure(error) {
3662
- return typeof error === "object" && error !== null && "code" in error && ["EADDRINUSE", "EACCES"].includes(String(error.code));
3663
- }
3664
3670
  function isSecretKey(key) {
3665
3671
  return /(?:token|authorization|cookie|password|credential|code|secret)/i.test(key);
3666
3672
  }
@@ -3707,11 +3713,9 @@ export {
3707
3713
  MCP_LAUNCHER_SERVER_NAME,
3708
3714
  MCP_LAUNCHER_SERVER_VERSION,
3709
3715
  cachedUserProfileSchema,
3710
- createAuthorizationRequest,
3711
3716
  createLauncherRuntimeConfig,
3712
3717
  createLauncherToolDependencies,
3713
3718
  createLauncherToolHandler,
3714
- createLoopbackCallbackServer,
3715
3719
  createOfficialLauncherAuthentication,
3716
3720
  createSmedcMcpLauncherServer,
3717
3721
  loadLauncherRuntimeConfig,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smedc-mcp-launcher",
3
- "version": "0.5.2",
3
+ "version": "0.7.0",
4
4
  "description": "Official desktop stdio MCP launcher for SMEDC",
5
5
  "license": "MIT",
6
6
  "repository": {