@rog0x/mcp-json-tools 1.0.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.
- package/README.md +111 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/csv-to-json.d.ts +3 -0
- package/dist/tools/csv-to-json.d.ts.map +1 -0
- package/dist/tools/csv-to-json.js +69 -0
- package/dist/tools/csv-to-json.js.map +1 -0
- package/dist/tools/json-diff.d.ts +3 -0
- package/dist/tools/json-diff.d.ts.map +1 -0
- package/dist/tools/json-diff.js +123 -0
- package/dist/tools/json-diff.js.map +1 -0
- package/dist/tools/json-to-csv.d.ts +3 -0
- package/dist/tools/json-to-csv.d.ts.map +1 -0
- package/dist/tools/json-to-csv.js +97 -0
- package/dist/tools/json-to-csv.js.map +1 -0
- package/dist/tools/json-transform.d.ts +3 -0
- package/dist/tools/json-transform.d.ts.map +1 -0
- package/dist/tools/json-transform.js +176 -0
- package/dist/tools/json-transform.js.map +1 -0
- package/dist/tools/json-validator.d.ts +3 -0
- package/dist/tools/json-validator.d.ts.map +1 -0
- package/dist/tools/json-validator.js +68 -0
- package/dist/tools/json-validator.js.map +1 -0
- package/dist/tools/yaml-json.d.ts +3 -0
- package/dist/tools/yaml-json.d.ts.map +1 -0
- package/dist/tools/yaml-json.js +75 -0
- package/dist/tools/yaml-json.js.map +1 -0
- package/package.json +35 -0
- package/src/index.ts +32 -0
- package/src/tools/csv-to-json.ts +74 -0
- package/src/tools/json-diff.ts +151 -0
- package/src/tools/json-to-csv.ts +116 -0
- package/src/tools/json-transform.ts +223 -0
- package/src/tools/json-validator.ts +91 -0
- package/src/tools/yaml-json.ts +83 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
function escapeCell(value: string, delimiter: string): string {
|
|
5
|
+
if (
|
|
6
|
+
value.includes(delimiter) ||
|
|
7
|
+
value.includes('"') ||
|
|
8
|
+
value.includes("\n") ||
|
|
9
|
+
value.includes("\r")
|
|
10
|
+
) {
|
|
11
|
+
return `"${value.replace(/"/g, '""')}"`;
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function toCsvValue(value: unknown): string {
|
|
17
|
+
if (value === null || value === undefined) {
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
if (typeof value === "object") {
|
|
21
|
+
return JSON.stringify(value);
|
|
22
|
+
}
|
|
23
|
+
return String(value);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function registerJsonToCsv(server: McpServer): void {
|
|
27
|
+
server.tool(
|
|
28
|
+
"json_to_csv",
|
|
29
|
+
"Convert a JSON array of objects to CSV text. Automatically extracts headers from object keys.",
|
|
30
|
+
{
|
|
31
|
+
data: z
|
|
32
|
+
.string()
|
|
33
|
+
.describe("The JSON array to convert (as a JSON string)"),
|
|
34
|
+
delimiter: z
|
|
35
|
+
.string()
|
|
36
|
+
.optional()
|
|
37
|
+
.describe("Column delimiter character (default: ',')"),
|
|
38
|
+
includeHeaders: z
|
|
39
|
+
.boolean()
|
|
40
|
+
.optional()
|
|
41
|
+
.describe("Whether to include a header row (default: true)"),
|
|
42
|
+
},
|
|
43
|
+
async ({ data, delimiter, includeHeaders }) => {
|
|
44
|
+
try {
|
|
45
|
+
const parsed = JSON.parse(data);
|
|
46
|
+
|
|
47
|
+
if (!Array.isArray(parsed)) {
|
|
48
|
+
throw new Error("Input must be a JSON array");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (parsed.length === 0) {
|
|
52
|
+
return {
|
|
53
|
+
content: [
|
|
54
|
+
{
|
|
55
|
+
type: "text" as const,
|
|
56
|
+
text: "",
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const delim = delimiter || ",";
|
|
63
|
+
const withHeaders = includeHeaders !== false;
|
|
64
|
+
|
|
65
|
+
const headerSet = new Set<string>();
|
|
66
|
+
for (const row of parsed) {
|
|
67
|
+
if (typeof row === "object" && row !== null && !Array.isArray(row)) {
|
|
68
|
+
for (const key of Object.keys(row as Record<string, unknown>)) {
|
|
69
|
+
headerSet.add(key);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const headers = Array.from(headerSet);
|
|
74
|
+
|
|
75
|
+
const lines: string[] = [];
|
|
76
|
+
|
|
77
|
+
if (withHeaders) {
|
|
78
|
+
lines.push(
|
|
79
|
+
headers.map((h) => escapeCell(h, delim)).join(delim)
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
for (const row of parsed) {
|
|
84
|
+
if (typeof row === "object" && row !== null && !Array.isArray(row)) {
|
|
85
|
+
const record = row as Record<string, unknown>;
|
|
86
|
+
const cells = headers.map((h) =>
|
|
87
|
+
escapeCell(toCsvValue(record[h]), delim)
|
|
88
|
+
);
|
|
89
|
+
lines.push(cells.join(delim));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
content: [
|
|
95
|
+
{
|
|
96
|
+
type: "text" as const,
|
|
97
|
+
text: lines.join("\n"),
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
};
|
|
101
|
+
} catch (error) {
|
|
102
|
+
const message =
|
|
103
|
+
error instanceof Error ? error.message : String(error);
|
|
104
|
+
return {
|
|
105
|
+
content: [
|
|
106
|
+
{
|
|
107
|
+
type: "text" as const,
|
|
108
|
+
text: `Error converting JSON to CSV: ${message}`,
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
isError: true,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
function getNestedValue(obj: unknown, path: string): unknown {
|
|
5
|
+
const parts = path.split(".");
|
|
6
|
+
let current: unknown = obj;
|
|
7
|
+
for (const part of parts) {
|
|
8
|
+
if (current === null || current === undefined || typeof current !== "object") {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
current = (current as Record<string, unknown>)[part];
|
|
12
|
+
}
|
|
13
|
+
return current;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function setNestedValue(
|
|
17
|
+
obj: Record<string, unknown>,
|
|
18
|
+
path: string,
|
|
19
|
+
value: unknown
|
|
20
|
+
): void {
|
|
21
|
+
const parts = path.split(".");
|
|
22
|
+
let current: Record<string, unknown> = obj;
|
|
23
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
24
|
+
const part = parts[i];
|
|
25
|
+
if (!(part in current) || typeof current[part] !== "object" || current[part] === null) {
|
|
26
|
+
current[part] = {};
|
|
27
|
+
}
|
|
28
|
+
current = current[part] as Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
current[parts[parts.length - 1]] = value;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function pickFields(
|
|
34
|
+
data: unknown,
|
|
35
|
+
fields: string[]
|
|
36
|
+
): Record<string, unknown> {
|
|
37
|
+
const result: Record<string, unknown> = {};
|
|
38
|
+
for (const field of fields) {
|
|
39
|
+
const value = getNestedValue(data, field);
|
|
40
|
+
if (value !== undefined) {
|
|
41
|
+
result[field] = value;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function renameFields(
|
|
48
|
+
data: Record<string, unknown>,
|
|
49
|
+
mapping: Readonly<Record<string, string>>
|
|
50
|
+
): Record<string, unknown> {
|
|
51
|
+
const result: Record<string, unknown> = {};
|
|
52
|
+
for (const [key, value] of Object.entries(data)) {
|
|
53
|
+
const newKey = mapping[key] || key;
|
|
54
|
+
result[newKey] = value;
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function flattenObject(
|
|
60
|
+
obj: unknown,
|
|
61
|
+
prefix: string = "",
|
|
62
|
+
separator: string = "."
|
|
63
|
+
): Record<string, unknown> {
|
|
64
|
+
const result: Record<string, unknown> = {};
|
|
65
|
+
|
|
66
|
+
if (obj === null || obj === undefined || typeof obj !== "object") {
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (Array.isArray(obj)) {
|
|
71
|
+
for (let i = 0; i < obj.length; i++) {
|
|
72
|
+
const newKey = prefix ? `${prefix}${separator}${i}` : String(i);
|
|
73
|
+
const val = obj[i];
|
|
74
|
+
if (typeof val === "object" && val !== null) {
|
|
75
|
+
Object.assign(result, flattenObject(val, newKey, separator));
|
|
76
|
+
} else {
|
|
77
|
+
result[newKey] = val;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
for (const [key, value] of Object.entries(obj as Record<string, unknown>)) {
|
|
84
|
+
const newKey = prefix ? `${prefix}${separator}${key}` : key;
|
|
85
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
86
|
+
Object.assign(result, flattenObject(value, newKey, separator));
|
|
87
|
+
} else if (Array.isArray(value)) {
|
|
88
|
+
Object.assign(result, flattenObject(value, newKey, separator));
|
|
89
|
+
} else {
|
|
90
|
+
result[newKey] = value;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function unflattenObject(
|
|
98
|
+
obj: Record<string, unknown>,
|
|
99
|
+
separator: string = "."
|
|
100
|
+
): Record<string, unknown> {
|
|
101
|
+
const result: Record<string, unknown> = {};
|
|
102
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
103
|
+
const parts = key.split(separator);
|
|
104
|
+
setNestedValue(result, parts.join("."), value);
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function registerJsonTransform(server: McpServer): void {
|
|
110
|
+
server.tool(
|
|
111
|
+
"json_transform",
|
|
112
|
+
"Apply transformations to a JSON object: pick specific fields, rename keys, flatten nested objects, or unflatten dot-notation keys.",
|
|
113
|
+
{
|
|
114
|
+
data: z.string().describe("The JSON data to transform (as a JSON string)"),
|
|
115
|
+
operation: z
|
|
116
|
+
.enum(["pick", "rename", "flatten", "unflatten"])
|
|
117
|
+
.describe("The transformation operation to apply"),
|
|
118
|
+
fields: z
|
|
119
|
+
.array(z.string())
|
|
120
|
+
.optional()
|
|
121
|
+
.describe(
|
|
122
|
+
"For 'pick': array of field paths to extract (supports dot notation like 'user.name')"
|
|
123
|
+
),
|
|
124
|
+
mapping: z
|
|
125
|
+
.record(z.string(), z.string())
|
|
126
|
+
.optional()
|
|
127
|
+
.describe(
|
|
128
|
+
"For 'rename': object mapping old key names to new key names"
|
|
129
|
+
),
|
|
130
|
+
separator: z
|
|
131
|
+
.string()
|
|
132
|
+
.optional()
|
|
133
|
+
.describe(
|
|
134
|
+
"For 'flatten'/'unflatten': separator character (default: '.')"
|
|
135
|
+
),
|
|
136
|
+
},
|
|
137
|
+
async ({ data, operation, fields, mapping, separator }) => {
|
|
138
|
+
try {
|
|
139
|
+
const parsed = JSON.parse(data);
|
|
140
|
+
let result: unknown;
|
|
141
|
+
const sep = separator || ".";
|
|
142
|
+
|
|
143
|
+
switch (operation) {
|
|
144
|
+
case "pick": {
|
|
145
|
+
if (!fields || fields.length === 0) {
|
|
146
|
+
throw new Error(
|
|
147
|
+
"The 'fields' parameter is required for the 'pick' operation"
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
if (Array.isArray(parsed)) {
|
|
151
|
+
result = parsed.map((item: unknown) => pickFields(item, fields));
|
|
152
|
+
} else {
|
|
153
|
+
result = pickFields(parsed, fields);
|
|
154
|
+
}
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
case "rename": {
|
|
158
|
+
if (!mapping || Object.keys(mapping).length === 0) {
|
|
159
|
+
throw new Error(
|
|
160
|
+
"The 'mapping' parameter is required for the 'rename' operation"
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
if (Array.isArray(parsed)) {
|
|
164
|
+
result = parsed.map((item: unknown) =>
|
|
165
|
+
renameFields(item as Record<string, unknown>, mapping)
|
|
166
|
+
);
|
|
167
|
+
} else {
|
|
168
|
+
result = renameFields(
|
|
169
|
+
parsed as Record<string, unknown>,
|
|
170
|
+
mapping
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
case "flatten": {
|
|
176
|
+
if (Array.isArray(parsed)) {
|
|
177
|
+
result = parsed.map((item: unknown) =>
|
|
178
|
+
flattenObject(item, "", sep)
|
|
179
|
+
);
|
|
180
|
+
} else {
|
|
181
|
+
result = flattenObject(parsed, "", sep);
|
|
182
|
+
}
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
case "unflatten": {
|
|
186
|
+
if (Array.isArray(parsed)) {
|
|
187
|
+
result = parsed.map((item: unknown) =>
|
|
188
|
+
unflattenObject(item as Record<string, unknown>, sep)
|
|
189
|
+
);
|
|
190
|
+
} else {
|
|
191
|
+
result = unflattenObject(
|
|
192
|
+
parsed as Record<string, unknown>,
|
|
193
|
+
sep
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return {
|
|
201
|
+
content: [
|
|
202
|
+
{
|
|
203
|
+
type: "text" as const,
|
|
204
|
+
text: JSON.stringify(result, null, 2),
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
};
|
|
208
|
+
} catch (error) {
|
|
209
|
+
const message =
|
|
210
|
+
error instanceof Error ? error.message : String(error);
|
|
211
|
+
return {
|
|
212
|
+
content: [
|
|
213
|
+
{
|
|
214
|
+
type: "text" as const,
|
|
215
|
+
text: `Error transforming JSON: ${message}`,
|
|
216
|
+
},
|
|
217
|
+
],
|
|
218
|
+
isError: true,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
);
|
|
223
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import Ajv, { ErrorObject } from "ajv";
|
|
4
|
+
|
|
5
|
+
interface ValidationResult {
|
|
6
|
+
valid: boolean;
|
|
7
|
+
errors: Array<{
|
|
8
|
+
path: string;
|
|
9
|
+
message: string;
|
|
10
|
+
keyword: string;
|
|
11
|
+
params: Record<string, unknown>;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function validateJsonAgainstSchema(
|
|
16
|
+
data: unknown,
|
|
17
|
+
schema: Record<string, unknown>
|
|
18
|
+
): ValidationResult {
|
|
19
|
+
const ajv = new Ajv({ allErrors: true, verbose: true });
|
|
20
|
+
const validate = ajv.compile(schema);
|
|
21
|
+
const valid = validate(data);
|
|
22
|
+
|
|
23
|
+
if (valid) {
|
|
24
|
+
return { valid: true, errors: [] };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const errors = (validate.errors || []).map((err: ErrorObject) => ({
|
|
28
|
+
path: err.instancePath || "/",
|
|
29
|
+
message: err.message || "Unknown validation error",
|
|
30
|
+
keyword: err.keyword,
|
|
31
|
+
params: err.params as Record<string, unknown>,
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
return { valid: false, errors };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function registerJsonValidator(server: McpServer): void {
|
|
38
|
+
server.tool(
|
|
39
|
+
"json_validate",
|
|
40
|
+
"Validate a JSON object against a JSON Schema. Returns whether the data is valid and a list of errors with their paths.",
|
|
41
|
+
{
|
|
42
|
+
data: z.string().describe("The JSON data to validate (as a JSON string)"),
|
|
43
|
+
schema: z
|
|
44
|
+
.string()
|
|
45
|
+
.describe("The JSON Schema to validate against (as a JSON string)"),
|
|
46
|
+
},
|
|
47
|
+
async ({ data, schema }) => {
|
|
48
|
+
try {
|
|
49
|
+
const parsedData = JSON.parse(data);
|
|
50
|
+
const parsedSchema = JSON.parse(schema);
|
|
51
|
+
|
|
52
|
+
const result = validateJsonAgainstSchema(parsedData, parsedSchema);
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
content: [
|
|
56
|
+
{
|
|
57
|
+
type: "text" as const,
|
|
58
|
+
text: JSON.stringify(result, null, 2),
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
} catch (error) {
|
|
63
|
+
const message =
|
|
64
|
+
error instanceof Error ? error.message : String(error);
|
|
65
|
+
return {
|
|
66
|
+
content: [
|
|
67
|
+
{
|
|
68
|
+
type: "text" as const,
|
|
69
|
+
text: JSON.stringify(
|
|
70
|
+
{
|
|
71
|
+
valid: false,
|
|
72
|
+
errors: [
|
|
73
|
+
{
|
|
74
|
+
path: "/",
|
|
75
|
+
message: `Parse error: ${message}`,
|
|
76
|
+
keyword: "parse",
|
|
77
|
+
params: {},
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
null,
|
|
82
|
+
2
|
|
83
|
+
),
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
isError: true,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import YAML from "yaml";
|
|
4
|
+
|
|
5
|
+
export function registerYamlJson(server: McpServer): void {
|
|
6
|
+
server.tool(
|
|
7
|
+
"yaml_to_json",
|
|
8
|
+
"Convert YAML text to a JSON string.",
|
|
9
|
+
{
|
|
10
|
+
yamlText: z.string().describe("The YAML text to convert to JSON"),
|
|
11
|
+
indent: z
|
|
12
|
+
.number()
|
|
13
|
+
.optional()
|
|
14
|
+
.describe("JSON indentation spaces (default: 2)"),
|
|
15
|
+
},
|
|
16
|
+
async ({ yamlText, indent }) => {
|
|
17
|
+
try {
|
|
18
|
+
const parsed = YAML.parse(yamlText);
|
|
19
|
+
const spaces = indent ?? 2;
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
content: [
|
|
23
|
+
{
|
|
24
|
+
type: "text" as const,
|
|
25
|
+
text: JSON.stringify(parsed, null, spaces),
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
} catch (error) {
|
|
30
|
+
const message =
|
|
31
|
+
error instanceof Error ? error.message : String(error);
|
|
32
|
+
return {
|
|
33
|
+
content: [
|
|
34
|
+
{
|
|
35
|
+
type: "text" as const,
|
|
36
|
+
text: `Error converting YAML to JSON: ${message}`,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
isError: true,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
server.tool(
|
|
46
|
+
"json_to_yaml",
|
|
47
|
+
"Convert a JSON string to YAML text.",
|
|
48
|
+
{
|
|
49
|
+
jsonText: z.string().describe("The JSON text to convert to YAML"),
|
|
50
|
+
indent: z
|
|
51
|
+
.number()
|
|
52
|
+
.optional()
|
|
53
|
+
.describe("YAML indentation spaces (default: 2)"),
|
|
54
|
+
},
|
|
55
|
+
async ({ jsonText, indent }) => {
|
|
56
|
+
try {
|
|
57
|
+
const parsed = JSON.parse(jsonText);
|
|
58
|
+
const spaces = indent ?? 2;
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
content: [
|
|
62
|
+
{
|
|
63
|
+
type: "text" as const,
|
|
64
|
+
text: YAML.stringify(parsed, { indent: spaces }),
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
};
|
|
68
|
+
} catch (error) {
|
|
69
|
+
const message =
|
|
70
|
+
error instanceof Error ? error.message : String(error);
|
|
71
|
+
return {
|
|
72
|
+
content: [
|
|
73
|
+
{
|
|
74
|
+
type: "text" as const,
|
|
75
|
+
text: `Error converting JSON to YAML: ${message}`,
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
isError: true,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "Node16",
|
|
5
|
+
"moduleResolution": "Node16",
|
|
6
|
+
"outDir": "dist",
|
|
7
|
+
"rootDir": "src",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"declaration": true,
|
|
14
|
+
"declarationMap": true,
|
|
15
|
+
"sourceMap": true
|
|
16
|
+
},
|
|
17
|
+
"include": ["src/**/*"],
|
|
18
|
+
"exclude": ["node_modules", "dist"]
|
|
19
|
+
}
|