Skip to content

Commit d00a2b4

Browse files
committed
Fixes dereference arrays
Signed-off-by: Marcos Candeia <[email protected]>
1 parent a56cfed commit d00a2b4

File tree

3 files changed

+39
-18
lines changed

3 files changed

+39
-18
lines changed

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@deco/mcp",
3-
"version": "0.7.1",
3+
"version": "0.7.2",
44
"exports": {
55
".": "./mod.ts",
66
"./http": "./mcp/http.ts"

mcp/server.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,22 +339,33 @@ export function mcpServer<TManifest extends AppManifest>(
339339
// Check if this is a browser request (HTML acceptance)
340340
const acceptHeader = c.req.header("accept") || "";
341341
const isHTMLRequest = acceptHeader.includes("text/html");
342-
342+
343343
if (isHTMLRequest) {
344344
// Return HTML page for browser requests
345-
const currentUrl = c.req.url.replace(/^http:/, 'https:');
346-
345+
const currentUrl = c.req.url.replace(/^http:/, "https:");
346+
347347
// Get tools data directly
348348
const meta = await deco.meta().then((v) => v?.value);
349-
const tools = meta ? getTools(new Map<string, string>(), meta.schema, options, meta?.manifest?.blocks?.apps) : [];
350-
const toolsHtml = tools.length > 0
349+
const tools = meta
350+
? getTools(
351+
new Map<string, string>(),
352+
meta.schema,
353+
options,
354+
meta?.manifest?.blocks?.apps,
355+
)
356+
: [];
357+
const toolsHtml = tools.length > 0
351358
? tools.map((tool: Tool) => `
352359
<div class="tool-card">
353360
<div class="tool-name">${tool.name}</div>
354-
<div class="tool-description">${tool.description || 'No description available'}</div>
355-
${tool.appName ? `<div class="tool-app">${tool.appName}</div>` : ''}
361+
<div class="tool-description">${
362+
tool.description || "No description available"
363+
}</div>
364+
${
365+
tool.appName ? `<div class="tool-app">${tool.appName}</div>` : ""
366+
}
356367
</div>
357-
`).join('')
368+
`).join("")
358369
: '<div class="no-tools">No tools available</div>';
359370
const htmlResponse = `
360371
<!DOCTYPE html>
@@ -763,7 +774,7 @@ export function mcpServer<TManifest extends AppManifest>(
763774
</script>
764775
</body>
765776
</html>`;
766-
777+
767778
return new Response(htmlResponse, {
768779
headers: {
769780
"Content-Type": "text/html; charset=utf-8",

mcp/utils.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,21 @@ export function dereferenceSchema(
4444

4545
const result: JSONSchema7 = { ...schema };
4646

47-
// Handle arrays with items
47+
// Handle arrays with items (including tuple types)
4848
if (result.type === "array" && result.items) {
49-
result.items = dereferenceSchema(
50-
result.items as JSONSchema7,
51-
definitions,
52-
visited,
53-
) as JSONSchema7;
49+
if (Array.isArray(result.items)) {
50+
// Handle tuple types
51+
result.items = result.items.map((item) =>
52+
dereferenceSchema(item as JSONSchema7, definitions, visited)
53+
).filter(Boolean) as JSONSchema7[];
54+
} else {
55+
// Handle single item schema
56+
result.items = dereferenceSchema(
57+
result.items as JSONSchema7,
58+
definitions,
59+
visited,
60+
) as JSONSchema7;
61+
}
5462
}
5563

5664
// Handle and merge allOf into the main schema
@@ -141,6 +149,8 @@ export function dereferenceSchema(
141149
}
142150

143151
function idFromDefinition(definition: string): string {
144-
const [_, __, id] = definition.split("/");
145-
return id;
152+
// Handle complex definition patterns like:
153+
// "#/definitions/ZmlsZTovLy9hcHAvZGVjby9jbGllbnRzL3BsYXVzaWJsZS52Mi50cw==@FilterOperator"
154+
// Just remove the "#/definitions/" prefix and return the rest
155+
return definition.replace("#/definitions/", "");
146156
}

0 commit comments

Comments
 (0)