mcp-speechmatics-transcribe 0.1.4 → 0.1.6

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
@@ -42,8 +42,10 @@ For a local env file, append --env-file and its absolute path.
42
42
  With no file argument, the command starts the MCP server; the explicit mcp subcommand
43
43
  remains supported. MCP is a thin adapter: it obtains tool definitions from the CLI
44
44
  at startup and on every tools/list request, then forwards each tools/call to a
45
- separate CLI process. Both discovery and execution run through
46
- npx -y --prefer-online mcp-speechmatics-transcribe@latest, reusing npm's cache.
45
+ separate CLI process. An npx-managed installation resolves the latest published CLI
46
+ through npx, reusing npm's cache. Local launches, including npm scripts, use the CLI
47
+ from the same installation through the current Node.js executable. Ambiguous
48
+ launches use the same-installation CLI.
47
49
  Changes detected during discovery emit notifications/tools/list_changed. Clients
48
50
  must request the tool list to discover updates; no background polling is performed.
49
51
  In-flight calls continue with their starting version. The CLI inherits the
@@ -76,6 +78,19 @@ the adapter contains no transcription-specific schemas or execution logic.
76
78
 
77
79
  ## Configuration
78
80
 
81
+ The read-only `token_status` tool checks all configured tokens through the EU1
82
+ Batch usage endpoint. Optional `since` and `until` dates use YYYY-MM-DD; the default
83
+ start is the first day of the current UTC month. Results identify each key by its
84
+ configured login or a masked token. Excluded keys return `excluded` without an API
85
+ request. Successful requests return `active` and the API's usage fields directly;
86
+ failures return `error` with available HTTP details. Short anonymous tokens are fully
87
+ masked. No raw token or token hash is returned.
88
+
89
+ Usage reflects the scope reported by Speechmatics and is not attributed exclusively
90
+ to an individual key. Successful access does not guarantee funds for another job.
91
+ Credits are omitted because the public usage API does not provide a balance.
92
+ Status checks do not update logs, rotation, or exclusions.
93
+
79
94
  Invocation arguments override process environment, followed by the selected env file
80
95
  and built-in defaults. SPEECHMATICS_ENV_FILE or --env-file selects an env file.
81
96
  Source installations otherwise load .env from the package directory.
@@ -139,7 +154,7 @@ match the package version. npm publishing uses GitHub OIDC after a trusted
139
154
  publisher is configured for this repository and release.yml.
140
155
 
141
156
  For the first publication, authenticate with npm login and publish the checked archive
142
- from work/releases/ using npm publish with --access public.
157
+ from .tmp/releases/ using npm publish with --access public.
143
158
  The release workflow publishes stable versions under latest and prereleases under next.
144
159
 
145
160
  ## License
@@ -6,14 +6,24 @@ import { fileURLToPath } from "node:url";
6
6
  export function runCli(mode, request) {
7
7
  return new Promise((done, reject) => {
8
8
  if (!["--tool-manifest", "--execute-tool"].includes(mode)) throw new Error("Unsupported CLI mode.");
9
- const launchArgs = ["-y", "--prefer-online", "mcp-speechmatics-transcribe@latest", mode];
10
- const windows = process.platform === "win32";
11
- const child = spawn(windows ? "npx " + launchArgs.join(" ") : "npx", windows ? [] : launchArgs, {
12
- shell: windows,
9
+ const modulePath = fileURLToPath(import.meta.url);
10
+ const cachedPackage = /[\\/]_npx[\\/][^\\/]+[\\/]node_modules[\\/]mcp-speechmatics-transcribe[\\/]/i.test(modulePath);
11
+ const npmExec = process.env.npm_command === "exec"
12
+ || (!process.env.npm_command && process.env.npm_lifecycle_event === "npx");
13
+ const useNpx = cachedPackage && npmExec;
14
+ const launchArgs = useNpx
15
+ ? ["-y", "--prefer-online", "--package=mcp-speechmatics-transcribe@latest", "--", "mcp-speechmatics-transcribe", mode]
16
+ : [fileURLToPath(new URL("../cli.js", import.meta.url)), mode];
17
+ const windowsShell = useNpx && process.platform === "win32";
18
+ const environment = Object.fromEntries(Object.entries(process.env)
19
+ .filter(([key]) => !/^npm_config_(package|call)$/i.test(key)));
20
+ const command = useNpx ? "npx" : process.execPath;
21
+ const child = spawn(windowsShell ? command + " " + launchArgs.join(" ") : command, windowsShell ? [] : launchArgs, {
22
+ shell: windowsShell,
13
23
  windowsHide: true,
14
24
  stdio: ["pipe", "pipe", "inherit"],
15
25
  env: {
16
- ...process.env,
26
+ ...environment,
17
27
  SPEECHMATICS_ENV_FILE: process.env.SPEECHMATICS_ENV_FILE
18
28
  ? resolve(process.env.SPEECHMATICS_ENV_FILE)
19
29
  : fileURLToPath(new URL("../.env", import.meta.url)),
@@ -7,6 +7,16 @@ import lockfile from "proper-lockfile";
7
7
  export const outputRoot = join(tmpdir(), "transcription");
8
8
  export const logPath = join(outputRoot, "logs.json");
9
9
 
10
+ export async function readLog() {
11
+ const source = await readFile(logPath, "utf8").catch((error) => {
12
+ if (error.code === "ENOENT") return "[]";
13
+ throw error;
14
+ });
15
+ const entries = JSON.parse(source);
16
+ if (!Array.isArray(entries)) throw new Error("logs.json must contain an array of records.");
17
+ return entries;
18
+ }
19
+
10
20
  async function updateLog(update) {
11
21
  await mkdir(outputRoot, { recursive: true });
12
22
  const release = await lockfile.lock(logPath, {
@@ -14,12 +24,7 @@ async function updateLog(update) {
14
24
  retries: { retries: 60, minTimeout: 100, maxTimeout: 250 },
15
25
  });
16
26
  try {
17
- const source = await readFile(logPath, "utf8").catch((error) => {
18
- if (error.code === "ENOENT") return "[]";
19
- throw error;
20
- });
21
- const entries = JSON.parse(source);
22
- if (!Array.isArray(entries)) throw new Error("logs.json must contain an array of records.");
27
+ const entries = await readLog();
23
28
  const result = update(entries);
24
29
  const temporaryPath = join(outputRoot, `logs-${randomUUID()}.tmp`);
25
30
  try {
@@ -65,6 +65,12 @@ export async function submitJob(file, token, options, signal) {
65
65
  return id;
66
66
  }
67
67
 
68
+ export function getUsage(token, since, until, signal) {
69
+ const query = new URLSearchParams({ since });
70
+ if (until) query.set("until", until);
71
+ return request("/v2/usage?" + query, token, signal);
72
+ }
73
+
68
74
  export async function getTranscript(id, token, signal) {
69
75
  const jobPath = `/v2/jobs/${encodeURIComponent(id)}`;
70
76
  while (!signal.aborted) {
@@ -0,0 +1,38 @@
1
+ import { createHash } from "node:crypto";
2
+ import { loadConfig } from "./config.js";
3
+ import { readLog } from "./history.js";
4
+ import { ApiError, getUsage } from "./speechmatics.js";
5
+
6
+ export async function tokenStatus({ since = new Date().toISOString().slice(0, 7) + "-01", until } = {}) {
7
+ if (until && until < since) throw new Error("until must be on or after since.");
8
+ const { tokens } = await loadConfig();
9
+ const excluded = new Set((await readLog())
10
+ .filter((entry) => entry.tokenDisabled)
11
+ .map((entry) => entry.tokenSha256));
12
+ const results = [];
13
+ for (const { login, token } of tokens) {
14
+ const identity = login ? { login } : {
15
+ token: token.length > 12 ? token.slice(0, 4) + "****" + token.slice(-4) : "****",
16
+ };
17
+ const sha = createHash("sha256").update(token).digest("hex");
18
+ if (excluded.has(sha)) {
19
+ results.push({ ...identity, status: "excluded" });
20
+ continue;
21
+ }
22
+ try {
23
+ const { since: start, until: end, summary, details } = await getUsage(
24
+ token, since, until, AbortSignal.timeout(15000),
25
+ );
26
+ results.push({ ...identity, status: "active", usage: { since: start, until: end, summary, details } });
27
+ } catch (error) {
28
+ results.push({
29
+ ...identity, status: "error",
30
+ error: {
31
+ message: error.message.replaceAll(token, "[token]"),
32
+ ...(error instanceof ApiError && error.httpStatus !== null && { httpStatus: error.httpStatus }),
33
+ },
34
+ });
35
+ }
36
+ }
37
+ return { tokens: results };
38
+ }
package/modules/tools.js CHANGED
@@ -3,6 +3,7 @@ import { optionFields } from "./options.js";
3
3
  import { transcribe } from "./transcribe.js";
4
4
  import { loadConfig } from "./config.js";
5
5
  import { readFile } from "node:fs/promises";
6
+ import { tokenStatus } from "./token-status.js";
6
7
 
7
8
  export const description = "Transcribe local audio and video files through the Speechmatics Batch API.";
8
9
 
@@ -34,6 +35,24 @@ export function createTools(configuredDefaults) {
34
35
  }
35
36
  },
36
37
  },
38
+ token_status: {
39
+ definition: {
40
+ description: "Check configured tokens and read Batch usage from Speechmatics. Excluded tokens are reported without API requests. Identity is the configured login or a masked token. API access does not guarantee funds for transcription. Usage is returned in the API's scope, not attributed exclusively to a key. This read-only check does not change rotation, exclusions, or logs.",
41
+ inputSchema: z.strictObject({
42
+ since: z.iso.date().optional().describe("Inclusive start date YYYY-MM-DD. Defaults to the first day of the current UTC month."),
43
+ until: z.iso.date().optional().describe("Inclusive end date YYYY-MM-DD. Omit to use the API's current end date."),
44
+ }),
45
+ annotations: { readOnlyHint: true },
46
+ },
47
+ execute: async (options) => {
48
+ try {
49
+ const result = await tokenStatus(options);
50
+ return { content: [{ type: "text", text: JSON.stringify(result) }], structuredContent: result };
51
+ } catch (error) {
52
+ return { isError: true, content: [{ type: "text", text: JSON.stringify({ message: error.message }) }] };
53
+ }
54
+ },
55
+ },
37
56
  };
38
57
  }
39
58
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-speechmatics-transcribe",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Transcribe audio and video files with Speechmatics through a CLI and MCP server.",
5
5
  "type": "module",
6
6
  "license": "MIT",