Improve MCP structured result visibility (#167)
This commit is contained in:
parent
2234cb54fc
commit
f58efea164
@ -44,4 +44,41 @@ describe("mcpResponse", () => {
|
||||
});
|
||||
expect(result.structuredContent).toEqual({ foo: "bar" });
|
||||
});
|
||||
|
||||
it("mirrors metadata into structuredContent for clients that hide _meta", () => {
|
||||
const result = mcpResponse({
|
||||
text: "hi",
|
||||
meta: {
|
||||
url: "https://app.openseo.so/p/1",
|
||||
projectId: "1",
|
||||
creditsRemaining: 100,
|
||||
},
|
||||
structuredContent: { foo: "bar" },
|
||||
});
|
||||
|
||||
expect(result.structuredContent).toEqual({
|
||||
foo: "bar",
|
||||
meta: {
|
||||
url: "https://app.openseo.so/p/1",
|
||||
projectId: "1",
|
||||
creditsRemaining: 100,
|
||||
},
|
||||
});
|
||||
expect(result._meta).toEqual({
|
||||
url: "https://app.openseo.so/p/1",
|
||||
projectId: "1",
|
||||
creditsRemaining: 100,
|
||||
});
|
||||
});
|
||||
|
||||
it("uses metadata as structuredContent when no data payload is provided", () => {
|
||||
const result = mcpResponse({
|
||||
text: "hi",
|
||||
meta: { url: "https://app.openseo.so" },
|
||||
});
|
||||
|
||||
expect(result.structuredContent).toEqual({
|
||||
meta: { url: "https://app.openseo.so" },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -17,15 +17,22 @@ export function mcpResponse(opts: {
|
||||
const result: CallToolResult = {
|
||||
content: [{ type: "text", text: opts.text }],
|
||||
};
|
||||
if (opts.structuredContent) {
|
||||
result.structuredContent = opts.structuredContent;
|
||||
}
|
||||
let meta: Record<string, unknown> | undefined;
|
||||
if (opts.meta) {
|
||||
// Drop undefined keys so the wire payload stays clean.
|
||||
const meta: Record<string, unknown> = {};
|
||||
meta = {};
|
||||
for (const [key, value] of Object.entries(opts.meta)) {
|
||||
if (value !== undefined) meta[key] = value;
|
||||
}
|
||||
}
|
||||
if (opts.structuredContent) {
|
||||
result.structuredContent =
|
||||
meta && Object.keys(meta).length > 0
|
||||
? { ...opts.structuredContent, meta }
|
||||
: opts.structuredContent;
|
||||
} else if (meta && Object.keys(meta).length > 0) {
|
||||
result.structuredContent = { meta };
|
||||
}
|
||||
if (meta) {
|
||||
if (Object.keys(meta).length > 0) {
|
||||
result._meta = meta;
|
||||
}
|
||||
|
||||
@ -46,6 +46,13 @@ export const saveKeywordsTool = {
|
||||
args.projectId,
|
||||
`/p/${args.projectId}/saved`,
|
||||
),
|
||||
structuredContent: {
|
||||
projectId: args.projectId,
|
||||
savedCount: args.keywords.length,
|
||||
keywords: args.keywords,
|
||||
locationCode: args.locationCode ?? DEFAULT_LOCATION_CODE,
|
||||
languageCode: args.languageCode ?? DEFAULT_LANGUAGE_CODE,
|
||||
},
|
||||
});
|
||||
}),
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user