Skip to content

Commit 9198fb5

Browse files
committed
Adds support to outputschema
Signed-off-by: Marcos Candeia <[email protected]>
1 parent 02e644c commit 9198fb5

File tree

4 files changed

+53
-16
lines changed

4 files changed

+53
-16
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ export default defineConfig({
6060
```
6161

6262
## Configuration
63-
Add the MCP server as a SSE endpoint using the production domain: https://sites-mcp.decocdn.com/mcp/sse
6463

64+
Add the MCP server as a SSE endpoint using the production domain:
65+
https://sites-mcp.decocdn.com/mcp/sse
6566

6667
<img width="1718" alt="image" src="https://github.com/user-attachments/assets/8a94dd3b-be41-48b5-98db-22ddae16391f" />
6768

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.1.9",
3+
"version": "0.1.10",
44
"exports": "./mod.ts",
55
"tasks": {
66
"check": "deno fmt && deno lint && deno check mod.ts"

mcp/server.ts

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ export interface Options<TManifest extends AppManifest> {
4747
include?: Array<keyof (TManifest["actions"] & TManifest["loaders"])>;
4848
exclude?: Array<keyof (TManifest["actions"] & TManifest["loaders"])>;
4949
}
50+
51+
interface RootSchema extends JSONSchema7 {
52+
inputSchema?: string;
53+
outputSchema?: string;
54+
}
55+
5056
function registerTools<TManifest extends AppManifest>(
5157
mcp: McpServer,
5258
deco: Deco<TManifest>,
@@ -73,7 +79,7 @@ function registerTools<TManifest extends AppManifest>(
7379

7480
const tools = [...availableLoaders, ...availableActions].map(
7581
(func) => {
76-
func = func as JSONSchema7;
82+
func = func as RootSchema;
7783
if (!func.$ref || func.$ref === RESOLVABLE_DEFINITION) return;
7884
const funcDefinition = schemas.definitions[idFromDefinition(func.$ref)];
7985
const resolveType =
@@ -94,9 +100,17 @@ function registerTools<TManifest extends AppManifest>(
94100
)
95101
) return;
96102

97-
const props = funcDefinition.allOf ?? [];
98-
const propsSchema = props[0];
99-
const ref = (propsSchema as JSONSchema7)?.$ref;
103+
const getInputSchemaId = () => {
104+
if ("inputSchema" in func) {
105+
return func.inputSchema as string;
106+
}
107+
const props = funcDefinition.allOf ?? [];
108+
const propsSchema = props[0];
109+
const ref = (propsSchema as JSONSchema7)?.$ref;
110+
return ref;
111+
};
112+
113+
const ref = getInputSchemaId();
100114
const rawInputSchema = ref
101115
? schemas.definitions[idFromDefinition(ref)]
102116
: undefined;
@@ -109,6 +123,23 @@ function registerTools<TManifest extends AppManifest>(
109123
)
110124
: undefined;
111125

126+
const outputSchemaId = "outputSchema" in func
127+
? func.outputSchema as string
128+
: undefined;
129+
130+
const rawOutputSchema = outputSchemaId
131+
? schemas.definitions[idFromDefinition(outputSchemaId)]
132+
: undefined;
133+
134+
const selfReference = (rawOutputSchema?.anyOf ?? [])[0];
135+
136+
const outputSchema = selfReference
137+
? dereferenceSchema(
138+
selfReference as JSONSchema7,
139+
schemas.definitions,
140+
)
141+
: undefined;
142+
112143
// Handle tool name slugification and clashes
113144
let toolName = (funcDefinition as { name?: string })?.name ??
114145
(inputSchema as { name?: string })?.name ?? slugify(resolveType);
@@ -122,17 +153,21 @@ function registerTools<TManifest extends AppManifest>(
122153
}
123154
toolNames.set(toolName, resolveType);
124155

156+
const normalizeSchema = (schema?: JSONSchema7) => {
157+
return schema && "type" in schema && schema.type === "object"
158+
? schema
159+
: {
160+
type: "object",
161+
additionalProperties: true,
162+
};
163+
};
125164
return {
126165
name: toolName,
166+
resolveType,
127167
description: funcDefinition.description ?? inputSchema?.description ??
128168
resolveType,
129-
inputSchema: inputSchema && "type" in inputSchema &&
130-
inputSchema.type === "object"
131-
? inputSchema
132-
: {
133-
type: "object",
134-
properties: {},
135-
},
169+
outputSchema: normalizeSchema(outputSchema),
170+
inputSchema: normalizeSchema(inputSchema),
136171
};
137172
},
138173
);

mcp/utils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// deno-lint-ignore-file no-explicit-any
12
import type { JSONSchema7 } from "@deco/deco";
23

34
export function dereferenceSchema(
@@ -27,7 +28,7 @@ export function dereferenceSchema(
2728

2829
// Handle allOf
2930
if (result.allOf) {
30-
result.allOf = result.allOf.map((subSchema) =>
31+
result.allOf = result.allOf.map((subSchema: any) =>
3132
dereferenceSchema(
3233
subSchema as JSONSchema7,
3334
definitions,
@@ -38,7 +39,7 @@ export function dereferenceSchema(
3839

3940
// Handle anyOf
4041
if (result.anyOf) {
41-
result.anyOf = result.anyOf.map((subSchema) =>
42+
result.anyOf = result.anyOf.map((subSchema: any) =>
4243
dereferenceSchema(
4344
subSchema as JSONSchema7,
4445
definitions,
@@ -49,7 +50,7 @@ export function dereferenceSchema(
4950

5051
// Handle oneOf
5152
if (result.oneOf) {
52-
result.oneOf = result.oneOf.map((subSchema) =>
53+
result.oneOf = result.oneOf.map((subSchema: any) =>
5354
dereferenceSchema(
5455
subSchema as JSONSchema7,
5556
definitions,

0 commit comments

Comments
 (0)