@kajidog/mcp-tts-voicevox 0.7.0 → 0.7.1

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/index.js CHANGED
@@ -620,6 +620,12 @@ function parseBaseCliArgs(argv = process.argv.slice(2)) {
620
620
  i++;
621
621
  }
622
622
  break;
623
+ case "--api-key":
624
+ if (nextArg && !nextArg.startsWith("-")) {
625
+ config2.apiKey = nextArg;
626
+ i++;
627
+ }
628
+ break;
623
629
  }
624
630
  }
625
631
  return config2;
@@ -641,6 +647,9 @@ function parseBaseEnvVars(env = process.env) {
641
647
  if (env.MCP_ALLOWED_ORIGINS) {
642
648
  config2.allowedOrigins = env.MCP_ALLOWED_ORIGINS.split(",").map((o) => o.trim());
643
649
  }
650
+ if (env.MCP_API_KEY) {
651
+ config2.apiKey = env.MCP_API_KEY;
652
+ }
644
653
  return config2;
645
654
  }
646
655
  function filterUndefined(obj) {
@@ -2805,6 +2814,13 @@ function forbiddenError(message) {
2805
2814
  id: null
2806
2815
  };
2807
2816
  }
2817
+ function unauthorizedError(message) {
2818
+ return {
2819
+ jsonrpc: "2.0",
2820
+ error: { code: -32001, message },
2821
+ id: null
2822
+ };
2823
+ }
2808
2824
  function validateOrigin(config2) {
2809
2825
  return async (c, next) => {
2810
2826
  const origin = c.req.header("Origin");
@@ -2847,6 +2863,22 @@ function validateHost(config2) {
2847
2863
  return next();
2848
2864
  };
2849
2865
  }
2866
+ function validateApiKey(config2) {
2867
+ return async (c, next) => {
2868
+ if (!config2.apiKey || c.req.method === "OPTIONS") {
2869
+ return next();
2870
+ }
2871
+ const xApiKey = c.req.header("X-API-Key");
2872
+ const authorization = c.req.header("Authorization");
2873
+ const bearerToken = authorization?.startsWith("Bearer ") ? authorization.slice(7).trim() : void 0;
2874
+ const providedKey = xApiKey ?? bearerToken;
2875
+ if (providedKey !== config2.apiKey) {
2876
+ console.log("Rejected request with invalid API key");
2877
+ return c.json(unauthorizedError("Unauthorized: Invalid API key"), { status: 401 });
2878
+ }
2879
+ return next();
2880
+ };
2881
+ }
2850
2882
  function createHttpApp(options) {
2851
2883
  const { server: server2, config: config2, serverFactory, extraCorsHeaders = [], onSessionInitialized, onSessionClosed } = options;
2852
2884
  const transports = /* @__PURE__ */ new Map();
@@ -2912,6 +2944,8 @@ function createHttpApp(options) {
2912
2944
  "mcp-session-id",
2913
2945
  "Last-Event-ID",
2914
2946
  "mcp-protocol-version",
2947
+ "X-API-Key",
2948
+ "Authorization",
2915
2949
  ...extraCorsHeaders
2916
2950
  ];
2917
2951
  app.use("/mcp", cors({
@@ -2922,6 +2956,7 @@ function createHttpApp(options) {
2922
2956
  }));
2923
2957
  app.use("/mcp", validateOrigin(config2));
2924
2958
  app.use("/mcp", validateHost(config2));
2959
+ app.use("/mcp", validateApiKey(config2));
2925
2960
  app.all("/mcp", handleMCP);
2926
2961
  app.get("/health", handleHealth);
2927
2962
  return app;
@@ -3029,6 +3064,7 @@ var defaultConfig = {
3029
3064
  restrictImmediate: false,
3030
3065
  restrictWaitForStart: false,
3031
3066
  restrictWaitForEnd: false,
3067
+ playerDomain: "",
3032
3068
  autoPlay: true,
3033
3069
  playerExportEnabled: true,
3034
3070
  playerExportDir: join(process.cwd(), "voicevox-player-exports"),
@@ -3188,6 +3224,9 @@ function parseEnvVars(env = process.env) {
3188
3224
  if (env.VOICEVOX_RESTRICT_WAIT_FOR_END === "true") {
3189
3225
  config2.restrictWaitForEnd = true;
3190
3226
  }
3227
+ if (env.VOICEVOX_PLAYER_DOMAIN) {
3228
+ config2.playerDomain = env.VOICEVOX_PLAYER_DOMAIN;
3229
+ }
3191
3230
  if (env.VOICEVOX_AUTO_PLAY !== void 0) {
3192
3231
  config2.autoPlay = env.VOICEVOX_AUTO_PLAY !== "false";
3193
3232
  }
@@ -4547,7 +4586,19 @@ function registerPlayerTools(deps) {
4547
4586
  mimeType: RESOURCE_MIME_TYPE
4548
4587
  },
4549
4588
  async () => ({
4550
- contents: [{ uri: playerResourceUri, mimeType: RESOURCE_MIME_TYPE, text: playerHtml }]
4589
+ contents: [
4590
+ {
4591
+ uri: playerResourceUri,
4592
+ mimeType: RESOURCE_MIME_TYPE,
4593
+ text: playerHtml,
4594
+ _meta: {
4595
+ ui: {
4596
+ csp: {},
4597
+ ...config2.playerDomain ? { domain: config2.playerDomain } : {}
4598
+ }
4599
+ }
4600
+ }
4601
+ ]
4551
4602
  })
4552
4603
  );
4553
4604
  registerAppToolIfEnabled(
@@ -4571,6 +4622,11 @@ function registerPlayerTools(deps) {
4571
4622
  const notice = "\u8F9E\u66F8\u5909\u66F4\u306F\u65E2\u5B58\u30C8\u30E9\u30C3\u30AF\u306B\u81EA\u52D5\u53CD\u6620\u3055\u308C\u307E\u305B\u3093\u3002Player\u3067\u518D\u751F\u6210\u3059\u308B\u3068\u53CD\u6620\u3055\u308C\u307E\u3059\u3002";
4572
4623
  return {
4573
4624
  content: [{ type: "text", text: `Dictionary manager opened. ${words.length} word(s).` }],
4625
+ structuredContent: {
4626
+ mode: "dictionary",
4627
+ dictionaryWords: words,
4628
+ dictionaryNotice: notice
4629
+ },
4574
4630
  _meta: {
4575
4631
  mode: "dictionary",
4576
4632
  dictionaryWords: words,
@@ -4648,6 +4704,11 @@ function registerPlayerTools(deps) {
4648
4704
  text: `Voicevox Player started. viewUUID: ${viewUUID} \u300C${textPreview}\u300D`
4649
4705
  }
4650
4706
  ],
4707
+ structuredContent: {
4708
+ viewUUID,
4709
+ autoPlay: config2.autoPlay,
4710
+ segments: uiSegments
4711
+ },
4651
4712
  _meta: {
4652
4713
  viewUUID,
4653
4714
  autoPlay: config2.autoPlay,
@@ -4773,6 +4834,11 @@ function registerPlayerTools(deps) {
4773
4834
  text: `Voicevox Player updated. viewUUID: ${viewUUID} (${segments.length} segment(s))`
4774
4835
  }
4775
4836
  ],
4837
+ structuredContent: {
4838
+ viewUUID,
4839
+ autoPlay: effectiveAutoPlay,
4840
+ segments: uiSegments
4841
+ },
4776
4842
  _meta: {
4777
4843
  viewUUID,
4778
4844
  autoPlay: effectiveAutoPlay,
@@ -5127,7 +5193,7 @@ var config = getConfig();
5127
5193
  function createServer() {
5128
5194
  const server2 = new McpServer({
5129
5195
  name: "mcp-tts-voicevox",
5130
- version: "0.7.0",
5196
+ version: "0.7.1",
5131
5197
  description: "A Voicevox server that converts text to speech for playback and saving."
5132
5198
  });
5133
5199
  const voicevoxClient = new VoicevoxClient({
@@ -5233,6 +5299,7 @@ Options:
5233
5299
  --host <host> HTTP server host (default: 0.0.0.0)
5234
5300
  --allowed-hosts <hosts> Comma-separated list of allowed hosts (default: localhost,127.0.0.1,[::1])
5235
5301
  --allowed-origins <origins> Comma-separated list of allowed origins
5302
+ --api-key <key> Require matching API key via X-API-Key or Authorization: Bearer
5236
5303
 
5237
5304
  Examples:
5238
5305
  npx @kajidog/mcp-tts-voicevox --url http://192.168.1.50:50021 --speaker 3