sonance-brand-mcp 1.3.86 → 1.3.87
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.
|
@@ -94,22 +94,36 @@ function debugLog(message: string, data?: unknown) {
|
|
|
94
94
|
/**
|
|
95
95
|
* Extract JSON from LLM response that may contain preamble text
|
|
96
96
|
* Handles: pure JSON, markdown code fences, and text with embedded JSON
|
|
97
|
+
*
|
|
98
|
+
* PRIORITY ORDER:
|
|
99
|
+
* 1. Direct JSON (starts with {)
|
|
100
|
+
* 2. Explicit ```json fence (most reliable)
|
|
101
|
+
* 3. Raw JSON object in text (handles prose + JSON responses)
|
|
102
|
+
* 4. Generic code fence (last resort, may match tsx/js fences incorrectly)
|
|
97
103
|
*/
|
|
98
104
|
function extractJsonFromResponse(text: string): string {
|
|
99
105
|
// Try direct parse first - if it starts with {, it's likely pure JSON
|
|
100
106
|
const trimmed = text.trim();
|
|
101
107
|
if (trimmed.startsWith('{')) return trimmed;
|
|
102
108
|
|
|
103
|
-
//
|
|
104
|
-
const
|
|
105
|
-
if (
|
|
106
|
-
const extracted =
|
|
107
|
-
debugLog("Extracted JSON from
|
|
109
|
+
// PRIORITY 1: Look specifically for ```json fence (most reliable)
|
|
110
|
+
const jsonFenceMatch = text.match(/```json\s*([\s\S]*?)```/);
|
|
111
|
+
if (jsonFenceMatch) {
|
|
112
|
+
const extracted = jsonFenceMatch[1].trim();
|
|
113
|
+
debugLog("Extracted JSON from explicit json fence", { previewLength: extracted.length });
|
|
108
114
|
return extracted;
|
|
109
115
|
}
|
|
110
116
|
|
|
111
|
-
// Find
|
|
112
|
-
|
|
117
|
+
// PRIORITY 2: Find raw JSON object in text (handles prose + JSON at end)
|
|
118
|
+
// Look for {"modifications" pattern which is our expected response format
|
|
119
|
+
const modMatch = text.match(/(\{"modifications"\s*:\s*\[[\s\S]*\](?:\s*,\s*"explanation"\s*:\s*"[^"]*")?\s*\})/);
|
|
120
|
+
if (modMatch) {
|
|
121
|
+
debugLog("Extracted JSON via modifications pattern", { length: modMatch[1].length });
|
|
122
|
+
return modMatch[1];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// PRIORITY 3: Find any JSON object starting with {"
|
|
126
|
+
const jsonStart = text.indexOf('{"');
|
|
113
127
|
const jsonEnd = text.lastIndexOf('}');
|
|
114
128
|
if (jsonStart !== -1 && jsonEnd > jsonStart) {
|
|
115
129
|
const extracted = text.slice(jsonStart, jsonEnd + 1);
|
|
@@ -120,6 +134,18 @@ function extractJsonFromResponse(text: string): string {
|
|
|
120
134
|
return extracted;
|
|
121
135
|
}
|
|
122
136
|
|
|
137
|
+
// PRIORITY 4 (last resort): Try generic code fence
|
|
138
|
+
// This may incorrectly match tsx/js fences, so it's lowest priority
|
|
139
|
+
const fenceMatch = text.match(/```\s*([\s\S]*?)```/);
|
|
140
|
+
if (fenceMatch) {
|
|
141
|
+
const extracted = fenceMatch[1].trim();
|
|
142
|
+
// Only use if it looks like JSON
|
|
143
|
+
if (extracted.startsWith('{')) {
|
|
144
|
+
debugLog("Extracted JSON from generic fence", { previewLength: extracted.length });
|
|
145
|
+
return extracted;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
123
149
|
// Return as-is if no JSON structure found
|
|
124
150
|
return text;
|
|
125
151
|
}
|
|
@@ -90,22 +90,36 @@ function debugLog(message: string, data?: unknown) {
|
|
|
90
90
|
/**
|
|
91
91
|
* Extract JSON from LLM response that may contain preamble text
|
|
92
92
|
* Handles: pure JSON, markdown code fences, and text with embedded JSON
|
|
93
|
+
*
|
|
94
|
+
* PRIORITY ORDER:
|
|
95
|
+
* 1. Direct JSON (starts with {)
|
|
96
|
+
* 2. Explicit ```json fence (most reliable)
|
|
97
|
+
* 3. Raw JSON object in text (handles prose + JSON responses)
|
|
98
|
+
* 4. Generic code fence (last resort, may match tsx/js fences incorrectly)
|
|
93
99
|
*/
|
|
94
100
|
function extractJsonFromResponse(text: string): string {
|
|
95
101
|
// Try direct parse first - if it starts with {, it's likely pure JSON
|
|
96
102
|
const trimmed = text.trim();
|
|
97
103
|
if (trimmed.startsWith('{')) return trimmed;
|
|
98
104
|
|
|
99
|
-
//
|
|
100
|
-
const
|
|
101
|
-
if (
|
|
102
|
-
const extracted =
|
|
103
|
-
debugLog("Extracted JSON from
|
|
105
|
+
// PRIORITY 1: Look specifically for ```json fence (most reliable)
|
|
106
|
+
const jsonFenceMatch = text.match(/```json\s*([\s\S]*?)```/);
|
|
107
|
+
if (jsonFenceMatch) {
|
|
108
|
+
const extracted = jsonFenceMatch[1].trim();
|
|
109
|
+
debugLog("Extracted JSON from explicit json fence", { previewLength: extracted.length });
|
|
104
110
|
return extracted;
|
|
105
111
|
}
|
|
106
112
|
|
|
107
|
-
// Find
|
|
108
|
-
|
|
113
|
+
// PRIORITY 2: Find raw JSON object in text (handles prose + JSON at end)
|
|
114
|
+
// Look for {"modifications" pattern which is our expected response format
|
|
115
|
+
const modMatch = text.match(/(\{"modifications"\s*:\s*\[[\s\S]*\](?:\s*,\s*"explanation"\s*:\s*"[^"]*")?\s*\})/);
|
|
116
|
+
if (modMatch) {
|
|
117
|
+
debugLog("Extracted JSON via modifications pattern", { length: modMatch[1].length });
|
|
118
|
+
return modMatch[1];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// PRIORITY 3: Find any JSON object starting with {"
|
|
122
|
+
const jsonStart = text.indexOf('{"');
|
|
109
123
|
const jsonEnd = text.lastIndexOf('}');
|
|
110
124
|
if (jsonStart !== -1 && jsonEnd > jsonStart) {
|
|
111
125
|
const extracted = text.slice(jsonStart, jsonEnd + 1);
|
|
@@ -116,6 +130,18 @@ function extractJsonFromResponse(text: string): string {
|
|
|
116
130
|
return extracted;
|
|
117
131
|
}
|
|
118
132
|
|
|
133
|
+
// PRIORITY 4 (last resort): Try generic code fence
|
|
134
|
+
// This may incorrectly match tsx/js fences, so it's lowest priority
|
|
135
|
+
const fenceMatch = text.match(/```\s*([\s\S]*?)```/);
|
|
136
|
+
if (fenceMatch) {
|
|
137
|
+
const extracted = fenceMatch[1].trim();
|
|
138
|
+
// Only use if it looks like JSON
|
|
139
|
+
if (extracted.startsWith('{')) {
|
|
140
|
+
debugLog("Extracted JSON from generic fence", { previewLength: extracted.length });
|
|
141
|
+
return extracted;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
119
145
|
// Return as-is if no JSON structure found
|
|
120
146
|
return text;
|
|
121
147
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sonance-brand-mcp",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.87",
|
|
4
4
|
"description": "MCP Server for Sonance Brand Guidelines and Component Library - gives Claude instant access to brand colors, typography, and UI components.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|