@stabgan/openrouter-mcp-multimodal 4.0.1 → 4.5.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.
Files changed (49) hide show
  1. package/README.md +95 -8
  2. package/dist/errors.d.ts +26 -8
  3. package/dist/errors.js +17 -12
  4. package/dist/index.js +21 -5
  5. package/dist/logger.d.ts +11 -0
  6. package/dist/logger.js +26 -0
  7. package/dist/model-cache.d.ts +17 -0
  8. package/dist/model-cache.js +27 -1
  9. package/dist/openrouter-api.d.ts +22 -2
  10. package/dist/openrouter-api.js +21 -2
  11. package/dist/tool-handlers/analyze-audio.d.ts +9 -4
  12. package/dist/tool-handlers/analyze-audio.js +29 -15
  13. package/dist/tool-handlers/analyze-image.d.ts +10 -4
  14. package/dist/tool-handlers/analyze-image.js +37 -9
  15. package/dist/tool-handlers/analyze-video.d.ts +9 -4
  16. package/dist/tool-handlers/analyze-video.js +31 -19
  17. package/dist/tool-handlers/cache.d.ts +33 -0
  18. package/dist/tool-handlers/cache.js +54 -0
  19. package/dist/tool-handlers/chat-completion.d.ts +18 -4
  20. package/dist/tool-handlers/chat-completion.js +39 -11
  21. package/dist/tool-handlers/completion-utils.d.ts +29 -0
  22. package/dist/tool-handlers/completion-utils.js +76 -17
  23. package/dist/tool-handlers/generate-audio.d.ts +2 -0
  24. package/dist/tool-handlers/generate-audio.js +18 -1
  25. package/dist/tool-handlers/generate-image.d.ts +2 -0
  26. package/dist/tool-handlers/generate-image.js +15 -0
  27. package/dist/tool-handlers/generate-video.d.ts +43 -0
  28. package/dist/tool-handlers/generate-video.js +46 -3
  29. package/dist/tool-handlers/get-model-info.d.ts +1 -6
  30. package/dist/tool-handlers/get-model-info.js +2 -1
  31. package/dist/tool-handlers/health-check.d.ts +23 -0
  32. package/dist/tool-handlers/health-check.js +35 -0
  33. package/dist/tool-handlers/openai-withresponse.d.ts +16 -0
  34. package/dist/tool-handlers/openai-withresponse.js +16 -0
  35. package/dist/tool-handlers/openrouter-errors.d.ts +5 -1
  36. package/dist/tool-handlers/openrouter-errors.js +72 -11
  37. package/dist/tool-handlers/rerank.d.ts +17 -0
  38. package/dist/tool-handlers/rerank.js +52 -0
  39. package/dist/tool-handlers/search-models.d.ts +18 -7
  40. package/dist/tool-handlers/search-models.js +25 -2
  41. package/dist/tool-handlers/structured-output.d.ts +13 -0
  42. package/dist/tool-handlers/structured-output.js +24 -0
  43. package/dist/tool-handlers/validate-model.d.ts +4 -6
  44. package/dist/tool-handlers/validate-model.js +3 -8
  45. package/dist/tool-handlers.d.ts +1 -0
  46. package/dist/tool-handlers.js +435 -165
  47. package/dist/version.d.ts +16 -0
  48. package/dist/version.js +16 -0
  49. package/package.json +1 -1
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Helper for building MCP tool responses that carry structured data
3
+ * alongside the legacy text representation.
4
+ *
5
+ * Per MCP spec 2025-06-18 §5.2.6-7, when a tool has an `outputSchema`
6
+ * the response SHOULD include `structuredContent` (the typed object)
7
+ * AND, for backwards compatibility with clients that don't parse that
8
+ * field, `content` with a serialized JSON text block.
9
+ *
10
+ * Consumers use `buildStructuredResult(data, meta?)` and get back the
11
+ * full `{ content, structuredContent, _meta }` shape.
12
+ */
13
+ import { SERVER_VERSION } from '../version.js';
14
+ /**
15
+ * Wrap a JSON-serializable object in the MCP-spec dual-representation
16
+ * format. `meta` is merged on top of the default `server_version` stamp.
17
+ */
18
+ export function buildStructuredResult(data, meta = {}) {
19
+ return {
20
+ content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
21
+ structuredContent: data,
22
+ _meta: { server_version: SERVER_VERSION, ...meta },
23
+ };
24
+ }
@@ -6,9 +6,7 @@ export declare function handleValidateModel(request: {
6
6
  model: string;
7
7
  };
8
8
  };
9
- }, modelCache: ModelCache, apiClient?: OpenRouterAPIClient): Promise<import("../errors.js").ToolErrorResult | {
10
- content: {
11
- type: "text";
12
- text: string;
13
- }[];
14
- }>;
9
+ }, modelCache: ModelCache, apiClient?: OpenRouterAPIClient): Promise<import("../errors.js").ToolErrorResult | import("./structured-output.js").StructuredResult<{
10
+ valid: boolean;
11
+ model: string;
12
+ }>>;
@@ -1,5 +1,6 @@
1
1
  import { ErrorCode, toolError } from '../errors.js';
2
2
  import { classifyUpstreamError } from './openrouter-errors.js';
3
+ import { buildStructuredResult } from './structured-output.js';
3
4
  export async function handleValidateModel(request, modelCache, apiClient) {
4
5
  const { model } = request.params.arguments ?? { model: '' };
5
6
  if (!model || typeof model !== 'string') {
@@ -16,12 +17,6 @@ export async function handleValidateModel(request, modelCache, apiClient) {
16
17
  if (!modelCache.isValid()) {
17
18
  return toolError(ErrorCode.INTERNAL, 'No model data available.');
18
19
  }
19
- return {
20
- content: [
21
- {
22
- type: 'text',
23
- text: JSON.stringify({ valid: modelCache.has(model) }),
24
- },
25
- ],
26
- };
20
+ const valid = modelCache.has(model);
21
+ return buildStructuredResult({ valid, model });
27
22
  }
@@ -4,6 +4,7 @@ export declare class ToolHandlers {
4
4
  private modelCache;
5
5
  private apiClient;
6
6
  private defaultModel?;
7
+ private server;
7
8
  constructor(server: Server, apiKey: string, defaultModel?: string);
8
9
  private register;
9
10
  }