mcp-speechmatics-transcribe 0.1.5 → 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
@@ -78,6 +78,19 @@ the adapter contains no transcription-specific schemas or execution logic.
78
78
 
79
79
  ## Configuration
80
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
+
81
94
  Invocation arguments override process environment, followed by the selected env file
82
95
  and built-in defaults. SPEECHMATICS_ENV_FILE or --env-file selects an env file.
83
96
  Source installations otherwise load .env from the package directory.
@@ -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.5",
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",