openwire 0.0.0-stage → 1.2.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.
Files changed (75) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +281 -2
  3. package/dist/config.d.ts +31 -0
  4. package/dist/config.js +97 -0
  5. package/dist/config.js.map +1 -0
  6. package/dist/errors.d.ts +17 -0
  7. package/dist/errors.js +22 -0
  8. package/dist/errors.js.map +1 -0
  9. package/dist/http/executor.d.ts +2 -0
  10. package/dist/http/executor.js +53 -0
  11. package/dist/http/executor.js.map +1 -0
  12. package/dist/http/index.d.ts +2 -0
  13. package/dist/http/index.js +3 -0
  14. package/dist/http/index.js.map +1 -0
  15. package/dist/http/request.d.ts +2 -0
  16. package/dist/http/request.js +75 -0
  17. package/dist/http/request.js.map +1 -0
  18. package/dist/index.d.ts +9 -0
  19. package/dist/index.js +111 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/loader/index.d.ts +2 -0
  22. package/dist/loader/index.js +2 -0
  23. package/dist/loader/index.js.map +1 -0
  24. package/dist/loader/specLoader.d.ts +17 -0
  25. package/dist/loader/specLoader.js +78 -0
  26. package/dist/loader/specLoader.js.map +1 -0
  27. package/dist/logger.d.ts +16 -0
  28. package/dist/logger.js +65 -0
  29. package/dist/logger.js.map +1 -0
  30. package/dist/metadata.d.ts +4 -0
  31. package/dist/metadata.js +4 -0
  32. package/dist/metadata.js.map +1 -0
  33. package/dist/parser/index.d.ts +1 -0
  34. package/dist/parser/index.js +2 -0
  35. package/dist/parser/index.js.map +1 -0
  36. package/dist/parser/parser.d.ts +12 -0
  37. package/dist/parser/parser.js +423 -0
  38. package/dist/parser/parser.js.map +1 -0
  39. package/dist/pipeline.d.ts +4 -0
  40. package/dist/pipeline.js +29 -0
  41. package/dist/pipeline.js.map +1 -0
  42. package/dist/sanitizer/index.d.ts +2 -0
  43. package/dist/sanitizer/index.js +2 -0
  44. package/dist/sanitizer/index.js.map +1 -0
  45. package/dist/sanitizer/sanitizer.d.ts +12 -0
  46. package/dist/sanitizer/sanitizer.js +88 -0
  47. package/dist/sanitizer/sanitizer.js.map +1 -0
  48. package/dist/schema/builder.d.ts +10 -0
  49. package/dist/schema/builder.js +36 -0
  50. package/dist/schema/builder.js.map +1 -0
  51. package/dist/schema/index.d.ts +2 -0
  52. package/dist/schema/index.js +3 -0
  53. package/dist/schema/index.js.map +1 -0
  54. package/dist/schema/normalize.d.ts +14 -0
  55. package/dist/schema/normalize.js +79 -0
  56. package/dist/schema/normalize.js.map +1 -0
  57. package/dist/server/handler.d.ts +11 -0
  58. package/dist/server/handler.js +56 -0
  59. package/dist/server/handler.js.map +1 -0
  60. package/dist/server/index.d.ts +4 -0
  61. package/dist/server/index.js +3 -0
  62. package/dist/server/index.js.map +1 -0
  63. package/dist/server/server.d.ts +7 -0
  64. package/dist/server/server.js +50 -0
  65. package/dist/server/server.js.map +1 -0
  66. package/dist/types.d.ts +87 -0
  67. package/dist/types.js +2 -0
  68. package/dist/types.js.map +1 -0
  69. package/dist/validator/index.d.ts +2 -0
  70. package/dist/validator/index.js +2 -0
  71. package/dist/validator/index.js.map +1 -0
  72. package/dist/validator/validator.d.ts +9 -0
  73. package/dist/validator/validator.js +46 -0
  74. package/dist/validator/validator.js.map +1 -0
  75. package/package.json +74 -4
@@ -0,0 +1,2 @@
1
+ export { normalizeOpenApiSchema } from "./normalize.js";
2
+ export { buildInputSchema } from "./builder.js";
@@ -0,0 +1,3 @@
1
+ export { normalizeOpenApiSchema } from "./normalize.js";
2
+ export { buildInputSchema } from "./builder.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { JsonSchema } from "../types.js";
2
+ /**
3
+ * Normalizes an OpenAPI schema so it can be consumed by an Ajv draft-07
4
+ * validator:
5
+ *
6
+ * - OpenAPI 3.0 `nullable: true` becomes a `["<type>", "null"]` union.
7
+ * - OpenAPI 3.0 boolean `exclusiveMinimum`/`exclusiveMaximum` markers are
8
+ * folded into the numeric draft-07 form.
9
+ *
10
+ * Sub-schemas in every schema-position keyword are normalized recursively,
11
+ * including `additionalProperties`, `patternProperties`, `$defs` and
12
+ * `if`/`then`/`else`.
13
+ */
14
+ export declare function normalizeOpenApiSchema(schema: JsonSchema): JsonSchema;
@@ -0,0 +1,79 @@
1
+ const SCHEMA_MAP_KEYWORDS = ["properties", "patternProperties", "$defs", "definitions"];
2
+ const SCHEMA_ARRAY_KEYWORDS = ["allOf", "anyOf", "oneOf", "prefixItems", "items"];
3
+ const SCHEMA_KEYWORDS = [
4
+ "items",
5
+ "additionalProperties",
6
+ "unevaluatedProperties",
7
+ "additionalItems",
8
+ "unevaluatedItems",
9
+ "propertyNames",
10
+ "contains",
11
+ "not",
12
+ "if",
13
+ "then",
14
+ "else",
15
+ ];
16
+ /**
17
+ * Normalizes an OpenAPI schema so it can be consumed by an Ajv draft-07
18
+ * validator:
19
+ *
20
+ * - OpenAPI 3.0 `nullable: true` becomes a `["<type>", "null"]` union.
21
+ * - OpenAPI 3.0 boolean `exclusiveMinimum`/`exclusiveMaximum` markers are
22
+ * folded into the numeric draft-07 form.
23
+ *
24
+ * Sub-schemas in every schema-position keyword are normalized recursively,
25
+ * including `additionalProperties`, `patternProperties`, `$defs` and
26
+ * `if`/`then`/`else`.
27
+ */
28
+ export function normalizeOpenApiSchema(schema) {
29
+ const copy = { ...schema };
30
+ if (copy.nullable === true && copy.type) {
31
+ const type = copy.type;
32
+ const types = Array.isArray(type) ? [...type] : [type];
33
+ if (!types.includes("null")) {
34
+ types.push("null");
35
+ }
36
+ copy.type = types;
37
+ }
38
+ delete copy.nullable;
39
+ if (copy.exclusiveMinimum === true && typeof copy.minimum === "number") {
40
+ copy.exclusiveMinimum = copy.minimum;
41
+ delete copy.minimum;
42
+ }
43
+ else if (typeof copy.exclusiveMinimum !== "number") {
44
+ delete copy.exclusiveMinimum;
45
+ }
46
+ if (copy.exclusiveMaximum === true && typeof copy.maximum === "number") {
47
+ copy.exclusiveMaximum = copy.maximum;
48
+ delete copy.maximum;
49
+ }
50
+ else if (typeof copy.exclusiveMaximum !== "number") {
51
+ delete copy.exclusiveMaximum;
52
+ }
53
+ for (const keyword of SCHEMA_MAP_KEYWORDS) {
54
+ const map = copy[keyword];
55
+ if (map && typeof map === "object" && !Array.isArray(map)) {
56
+ copy[keyword] = Object.fromEntries(Object.entries(map).map(([key, value]) => [
57
+ key,
58
+ isSchema(value) ? normalizeOpenApiSchema(value) : value,
59
+ ]));
60
+ }
61
+ }
62
+ for (const keyword of SCHEMA_ARRAY_KEYWORDS) {
63
+ const list = copy[keyword];
64
+ if (Array.isArray(list)) {
65
+ copy[keyword] = list.map((sub) => (isSchema(sub) ? normalizeOpenApiSchema(sub) : sub));
66
+ }
67
+ }
68
+ for (const keyword of SCHEMA_KEYWORDS) {
69
+ const value = copy[keyword];
70
+ if (isSchema(value)) {
71
+ copy[keyword] = normalizeOpenApiSchema(value);
72
+ }
73
+ }
74
+ return copy;
75
+ }
76
+ function isSchema(value) {
77
+ return typeof value === "object" && value !== null && !Array.isArray(value);
78
+ }
79
+ //# sourceMappingURL=normalize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../src/schema/normalize.ts"],"names":[],"mappings":"AAEA,MAAM,mBAAmB,GAAG,CAAC,YAAY,EAAE,mBAAmB,EAAE,OAAO,EAAE,aAAa,CAAU,CAAC;AAEjG,MAAM,qBAAqB,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,CAAU,CAAC;AAE3F,MAAM,eAAe,GAAG;IACtB,OAAO;IACP,sBAAsB;IACtB,uBAAuB;IAC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AO,CAAC,GAAG,sBAAsB,CAAC,KAAK,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { CallToolResult } from "@modelcontextprotocol/server";
2
+ import type { HttpResult, JsonSchema, ParsedOperation, RuntimeContext } from "../types.js";
3
+ import type { ValidationOutcome } from "../validator/index.js";
4
+ import type { SanitizeOptions, SanitizeResult } from "../sanitizer/index.js";
5
+ export declare const healthSchema: JsonSchema;
6
+ export interface ToolDeps {
7
+ validate: (schema: JsonSchema, value: unknown) => ValidationOutcome;
8
+ execute: (runtime: RuntimeContext, operation: ParsedOperation, args: Record<string, unknown>) => Promise<HttpResult>;
9
+ sanitize: (text: string, options: SanitizeOptions) => SanitizeResult;
10
+ }
11
+ export declare function createToolHandler(operation: ParsedOperation, inputSchema: JsonSchema, runtime: RuntimeContext, deps: ToolDeps): (args: unknown) => Promise<CallToolResult>;
@@ -0,0 +1,56 @@
1
+ import { HttpExecutionError, ValidationError } from "../errors.js";
2
+ export const healthSchema = {
3
+ type: "object",
4
+ properties: {
5
+ echo: { type: "string" },
6
+ },
7
+ additionalProperties: false,
8
+ };
9
+ export function createToolHandler(operation, inputSchema, runtime, deps) {
10
+ return async (args) => {
11
+ const input = (args ?? {});
12
+ const outcome = deps.validate(inputSchema, input);
13
+ if (!outcome.ok) {
14
+ const text = `Input validation error: Invalid arguments for tool ${operation.toolName}:\n${outcome.errors.join("\n")}`;
15
+ return { content: [{ type: "text", text }], isError: true };
16
+ }
17
+ try {
18
+ const http = await deps.execute(runtime, operation, input);
19
+ const sanitized = deps.sanitize(http.bodyText, {
20
+ maxChars: runtime.config.maxResponseChars,
21
+ maxDepth: runtime.config.maxDepth,
22
+ maxArrayLength: runtime.config.maxArrayLength,
23
+ maxStringLength: runtime.config.maxStringLength,
24
+ });
25
+ const content = [
26
+ `HTTP ${http.status} ${http.statusText}`,
27
+ sanitized.text,
28
+ sanitized.truncated ? "[response truncated]" : "",
29
+ ]
30
+ .filter(Boolean)
31
+ .join("\n");
32
+ runtime.logger.debug(`Tool ${operation.toolName} returned HTTP ${http.status}`, {
33
+ url: http.url,
34
+ truncated: sanitized.truncated,
35
+ });
36
+ return { content: [{ type: "text", text: content }], isError: http.status >= 400 };
37
+ }
38
+ catch (err) {
39
+ if (err instanceof HttpExecutionError) {
40
+ return textResult(`Execution error for tool ${operation.toolName}: ${err.message}`, true);
41
+ }
42
+ if (err instanceof ValidationError) {
43
+ return textResult(`Invalid arguments for tool ${operation.toolName}: ${err.message}`, true);
44
+ }
45
+ runtime.logger.error(`Tool ${operation.toolName} failed`, err);
46
+ return textResult(`Unexpected error in tool ${operation.toolName}: ${messageOf(err)}`, true);
47
+ }
48
+ };
49
+ }
50
+ function textResult(text, isError) {
51
+ return { content: [{ type: "text", text }], isError };
52
+ }
53
+ function messageOf(err) {
54
+ return err instanceof Error ? err.message : String(err);
55
+ }
56
+ //# sourceMappingURL=handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/server/handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAKnE,MAAM,CAAC,MAAM,YAAY,GAAe;IACtC,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KACzB;IACD,oBAAoB,EAAE,KAAK;CAC5B,CAAC;AAYF,MAAM,UAAU,iBAAiB,CAC/B,SAA0B,EAC1B,WAAuB,EACvB,OAAuB,EACvB,IAAc;IAEd,OAAO,KAAK,EAAE,IAAa,EAA2B,EAAE;QACtD,MAAM,KAAK,GA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ToolHandler, healthSchema } from "./handler.js";
4
+ export type { ToolDeps } from "./handler.js";
@@ -0,0 +1,3 @@
1
+ export { createMcpServer } from "./server.js";
2
+ export { createToolHandler, healthSchema } from "./handler.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { McpServer } from "@modelcontextprotocol/server";
2
+ import type { ParsedSpec, RuntimeContext } from "../types.js";
3
+ export interface BridgeContext {
4
+ runtime: RuntimeContext;
5
+ parsedSpec: ParsedSpec;
6
+ }
7
+ export declare function createMcpServer(context: BridgeContext): McpServer;
@@ -0,0 +1,50 @@
1
+ import { McpServer, fromJsonSchema } from "@modelcontextprotocol/server";
2
+ import { SpecParseError } from "../errors.js";
3
+ import { buildInputSchema } from "../schema/index.js";
4
+ import { validateData } from "../validator/index.js";
5
+ import { executeOperation } from "../http/index.js";
6
+ import { sanitizeResponse } from "../sanitizer/index.js";
7
+ import { createToolHandler, healthSchema } from "./handler.js";
8
+ const defaultDeps = {
9
+ validate: validateData,
10
+ execute: executeOperation,
11
+ sanitize: sanitizeResponse,
12
+ };
13
+ export function createMcpServer(context) {
14
+ const { runtime, parsedSpec } = context;
15
+ const server = new McpServer({
16
+ name: runtime.config.serverName,
17
+ version: runtime.config.serverVersion,
18
+ });
19
+ if (parsedSpec.operations.length > runtime.config.maxTools) {
20
+ const msg = `OpenAPI spec has ${parsedSpec.operations.length} operations, exceeding the maximum supported limit of ${runtime.config.maxTools}. Massive APIs with hundreds of endpoints are not supported yet to prevent LLM context overflow.`;
21
+ runtime.logger.error(msg);
22
+ throw new SpecParseError(msg);
23
+ }
24
+ server.registerTool("health", {
25
+ description: "Health check for the OpenAPI bridge server.",
26
+ inputSchema: fromJsonSchema(healthSchema),
27
+ }, async (args) => {
28
+ const echo = args?.echo;
29
+ const text = typeof echo === "string" && echo !== "" ? `ok: ${echo}` : "ok";
30
+ return { content: [{ type: "text", text }] };
31
+ });
32
+ for (const operation of parsedSpec.operations) {
33
+ const inputSchema = buildInputSchema(operation);
34
+ server.registerTool(operation.toolName, {
35
+ description: describeOperation(operation),
36
+ inputSchema: fromJsonSchema(inputSchema),
37
+ }, createToolHandler(operation, inputSchema, runtime, defaultDeps));
38
+ }
39
+ runtime.logger.info(`Registered ${parsedSpec.operations.length} tools from "${parsedSpec.title}" v${parsedSpec.version}`);
40
+ return server;
41
+ }
42
+ function describeOperation(operation) {
43
+ const parts = [
44
+ `HTTP ${operation.method.toUpperCase()} ${operation.path}`,
45
+ operation.summary,
46
+ operation.description,
47
+ ].filter((part) => Boolean(part));
48
+ return parts.join("\n");
49
+ }
50
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAuB,MAAM,8BAA8B,CAAC;AAE9F,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAiB,MAAM,cAAc,CAAC;AAO9E,MAAM,WAAW,GAAa;IAC5B,QAAQ,EAAE,YAAY;IACtB,OAAO,EAAE,gBAAgB;IACzB,QAAQ,EAAE,gBAAgB;CAC3B,CAAC;AAEF,MAAM,UAAU,eAAe,CAAC,OAAsB;IACpD,MAAM,EAAE,OAAO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AC,WAAwC,CAAC;SACtE,EACD,iBAAiB,CAAC,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,CAAC,CAChE,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,MAAM,CAAC,IAAI,CACjB,cAAc,UAAU,CAAC,UAAU,CAAC,MAAM,gBAAgB,UAAU,CAAC,KAAK,MAAM,UAAU,CAAC,OAAO,EAAE,CACrG,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,iBAAiB,CAAC,SAA0B;IACnD,MAAM,KAAK,GAAG;QACZ,QAAQ,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,SAAS,CAAC,IAAI,EAAE;QAC1D,SAAS,CAAC,OAAO;QACjB,SAAS,CAAC,WAAW;KACtB,CAAC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAClD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,87 @@
1
+ import type { BridgeConfig } from "./config.js";
2
+ import type { Logger } from "./logger.js";
3
+ export type HttpMethod = "get" | "post" | "put" | "delete" | "patch" | "head" | "options" | "trace";
4
+ export type ParameterLocation = "query" | "header" | "path" | "cookie";
5
+ export interface JsonSchema {
6
+ type?: string | string[];
7
+ properties?: Record<string, JsonSchema>;
8
+ items?: JsonSchema | JsonSchema[];
9
+ required?: string[];
10
+ enum?: unknown[];
11
+ nullable?: boolean;
12
+ additionalProperties?: boolean | JsonSchema;
13
+ format?: string;
14
+ description?: string;
15
+ $ref?: string;
16
+ $defs?: Record<string, JsonSchema>;
17
+ definitions?: Record<string, JsonSchema>;
18
+ allOf?: JsonSchema[];
19
+ oneOf?: JsonSchema[];
20
+ anyOf?: JsonSchema[];
21
+ minimum?: number;
22
+ maximum?: number;
23
+ exclusiveMinimum?: number | boolean;
24
+ exclusiveMaximum?: number | boolean;
25
+ [key: string]: unknown;
26
+ }
27
+ export interface OperationParameter {
28
+ name: string;
29
+ in: ParameterLocation;
30
+ required: boolean;
31
+ description?: string;
32
+ schema?: JsonSchema;
33
+ }
34
+ export interface OperationRequestBody {
35
+ required: boolean;
36
+ contentType: string;
37
+ schema?: JsonSchema;
38
+ }
39
+ export type SecurityScheme = {
40
+ type: "apiKey";
41
+ name: string;
42
+ in: "header" | "query" | "cookie";
43
+ } | {
44
+ type: "http";
45
+ scheme: string;
46
+ } | {
47
+ type: "oauth2";
48
+ } | {
49
+ type: "openIdConnect";
50
+ };
51
+ export interface ParsedOperation {
52
+ toolName: string;
53
+ method: HttpMethod;
54
+ path: string;
55
+ summary?: string;
56
+ description?: string;
57
+ parameters: OperationParameter[];
58
+ requestBody?: OperationRequestBody;
59
+ baseUrl: string;
60
+ /** Security schemes this operation requires. Empty for public operations. */
61
+ security: SecurityScheme[];
62
+ }
63
+ export interface ParsedSpec {
64
+ title: string;
65
+ version: string;
66
+ operations: ParsedOperation[];
67
+ }
68
+ export interface RuntimeContext {
69
+ config: BridgeConfig;
70
+ logger: Logger;
71
+ fetchImpl: typeof fetch;
72
+ }
73
+ export interface HttpRequestContext {
74
+ url: string;
75
+ method: HttpMethod;
76
+ headers: Record<string, string>;
77
+ body?: unknown;
78
+ timeoutMs: number;
79
+ }
80
+ export interface HttpResult {
81
+ url: string;
82
+ method: HttpMethod;
83
+ status: number;
84
+ statusText: string;
85
+ headers: Record<string, string>;
86
+ bodyText: string;
87
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export { validateData } from "./validator.js";
2
+ export type { ValidationOutcome } from "./validator.js";
@@ -0,0 +1,2 @@
1
+ export { validateData } from "./validator.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validator/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { JsonSchema } from "../types.js";
2
+ export type ValidationOutcome = {
3
+ ok: true;
4
+ value: unknown;
5
+ } | {
6
+ ok: false;
7
+ errors: string[];
8
+ };
9
+ export declare function validateData(schema: JsonSchema, value: unknown): ValidationOutcome;
@@ -0,0 +1,46 @@
1
+ import { Ajv } from "ajv";
2
+ import addFormatsModule from "ajv-formats";
3
+ const addFormats = addFormatsModule;
4
+ const ajv = new Ajv({
5
+ allErrors: true,
6
+ strict: false,
7
+ allowUnionTypes: true,
8
+ validateFormats: true,
9
+ });
10
+ addFormats(ajv);
11
+ const cache = new WeakMap();
12
+ export function validateData(schema, value) {
13
+ const validate = getValidator(schema);
14
+ const valid = validate(value);
15
+ if (valid) {
16
+ return { ok: true, value };
17
+ }
18
+ return { ok: false, errors: formatErrors(validate.errors ?? []) };
19
+ }
20
+ function getValidator(schema) {
21
+ const cached = cache.get(schema);
22
+ if (cached) {
23
+ return cached;
24
+ }
25
+ const validate = ajv.compile(schema);
26
+ cache.set(schema, validate);
27
+ return validate;
28
+ }
29
+ function formatErrors(errors) {
30
+ return errors.map((error) => {
31
+ const path = error.instancePath || "/";
32
+ const params = describeParams(error);
33
+ return `${path} ${error.message}${params ? ` (${params})` : ""}`;
34
+ });
35
+ }
36
+ function describeParams(error) {
37
+ const params = error.params;
38
+ if (!params) {
39
+ return "";
40
+ }
41
+ const parts = Object.entries(params)
42
+ .filter(([key]) => key !== "type")
43
+ .map(([key, value]) => `${key}=${JSON.stringify(value)}`);
44
+ return parts.join(", ");
45
+ }
46
+ //# sourceMappingURL=validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/validator/validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAA2C,MAAM,KAAK,C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AK,CAAC,CAAC;QACrC,OAAO,GAAG,IAAI,IAAI,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IACnE,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,cAAc,CAAC,KAAkB;IACxC,MAAM,MAAM,GAAG,KAAK,CAAC,MAA6C,CAAC;IACnE,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;SACjC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,MAAM,CAAC;SACjC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC5D,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,76 @@
1
1
  {
2
2
  "name": "openwire",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.2.0",
4
+ "description": "OpenAPI-to-MCP server: turn API specifications into validated tools for AI clients.",
5
+ "author": "Moad Tellami",
6
+ "license": "MIT",
7
+ "keywords": [
8
+ "mcp",
9
+ "model-context-protocol",
10
+ "openapi",
11
+ "openapi3",
12
+ "swagger",
13
+ "llm",
14
+ "ai",
15
+ "bridge",
16
+ "api",
17
+ "tools"
18
+ ],
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/mtellami/openwire.git"
22
+ },
23
+ "homepage": "https://github.com/mtellami/openwire#readme",
24
+ "bugs": {
25
+ "url": "https://github.com/mtellami/openwire/issues"
26
+ },
27
+ "type": "module",
28
+ "engines": {
29
+ "node": ">=20.19"
30
+ },
31
+ "main": "./dist/index.js",
32
+ "types": "./dist/index.d.ts",
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist/index.d.ts",
36
+ "import": "./dist/index.js"
37
+ },
38
+ "./package.json": "./package.json"
39
+ },
40
+ "bin": {
41
+ "openwire": "dist/index.js",
42
+ "api-mcp-bridge": "dist/index.js"
43
+ },
44
+ "files": [
45
+ "dist"
46
+ ],
47
+ "scripts": {
48
+ "dev": "tsx watch src/index.ts",
49
+ "build": "tsc -p tsconfig.build.json",
50
+ "start": "node dist/index.js",
51
+ "test": "tsx --test test/*.test.ts",
52
+ "typecheck": "tsc -p tsconfig.json --noEmit",
53
+ "lint": "oxlint src",
54
+ "fmt": "prettier --write .",
55
+ "format:check": "prettier --check .",
56
+ "prepack": "npm run build",
57
+ "prepublishOnly": "npm run typecheck && npm run lint && npm run format:check && npm test && npm run test:package",
58
+ "test:package": "npm run build && node scripts/verify-package.mjs"
59
+ },
60
+ "dependencies": {
61
+ "@modelcontextprotocol/server": "^2.4.0",
62
+ "ajv": "^8.20.0",
63
+ "ajv-formats": "^3.0.1",
64
+ "openapi-types": "^12.1.3",
65
+ "yaml": "^2.9.0",
66
+ "zod": "^4.6.7"
67
+ },
68
+ "devDependencies": {
69
+ "@modelcontextprotocol/client": "^2.4.0",
70
+ "@types/node": "^26.1.2",
71
+ "oxlint": "^1.78.0",
72
+ "prettier": "^3.6.0",
73
+ "tsx": "^4.23.9",
74
+ "typescript": "~5.9.3"
75
+ }
76
+ }