Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,6 @@ superset plugins connect|connections # credentials
superset plugins marketplace list|add|remove # marketplace sources
superset plugins organization list|access # an organization's own plugins
superset plugins organization sources add|list|remove|sync # their GitHub sources
superset mcp tools|call-tool # call a plugin's tools through the proxy
superset mcp tools [tool]|call-tool <tool> # list a plugin's tools, read one's schema, call it
superset skills list
```
112 changes: 112 additions & 0 deletions packages/cli/src/commands/mcp/tools/command.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { afterAll, afterEach, beforeEach, expect, test } from "bun:test";
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
import { ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
import { env } from "../../../lib/env";
import { withTempSupersetHome } from "../../../lib/settings/test-helpers";
import toolsCommand from "./command";

const createIssue = {
name: "create_issue",
description: "Create an issue.",
inputSchema: {
type: "object" as const,
properties: {
title: { type: "string", description: "Issue title" },
labels: { type: "array", items: { type: "string" } },
priority: { enum: [1, 2, 3], default: 2 },
due: { anyOf: [{ type: "string" }, { type: "null" }] },
},
required: ["title"],
},
outputSchema: {
type: "object" as const,
properties: { id: { type: "string", description: "New issue id" } },
},
};

const proxy = Bun.serve({
port: 0,
async fetch(request) {
const transport = new WebStandardStreamableHTTPServerTransport({
enableJsonResponse: true,
});
const server = new Server(
{ name: "stub", version: "1.0.0" },
{ capabilities: { tools: {} } },
);
server.setRequestHandler(ListToolsRequestSchema, async () => ({
tools: [
createIssue,
{ name: "ping", inputSchema: { type: "object" as const } },
],
}));
await server.connect(transport);
return transport.handleRequest(request);
},
});
afterAll(() => proxy.stop(true));

withTempSupersetHome("superset-cli-mcp-tools-");
const originalApiUrl = env.SUPERSET_API_URL;
beforeEach(() => {
env.SUPERSET_API_URL = `http://localhost:${proxy.port}`;
});
afterEach(() => {
env.SUPERSET_API_URL = originalApiUrl;
});

async function listTools(tool?: string): Promise<{ data: unknown }> {
return (await toolsCommand.run({
ctx: { bearer: "test-key", config: {} },
args: { tool },
options: { plugin: "stub" },
signal: new AbortController().signal,
} as never)) as { data: unknown };
}

test("the list carries each tool's schemas as the server sent them", async () => {
const { data } = await listTools();

expect(data).toEqual([
{
plugin: "stub",
tool: "create_issue",
description: "Create an issue.",
inputSchema: createIssue.inputSchema,
outputSchema: createIssue.outputSchema,
},
{
plugin: "stub",
tool: "ping",
description: "",
inputSchema: { type: "object" },
outputSchema: undefined,
},
]);
});

test("one tool shows its arguments and output as fields", async () => {
const { data } = await listTools("create_issue");
const text = toolsCommand.display?.(data) ?? "";

expect(text).toContain("create_issue (stub)");
expect(text).toMatch(/title\s+string\s+yes\s+Issue title/);
expect(text).toMatch(/labels\s+string\[\]/);
expect(text).toMatch(/priority\s+1 \| 2 \| 3\s+2/);
expect(text).toMatch(/due\s+string \| null/);
expect(text).toMatch(/Output:\nNAME.*\nid\s+string\s+New issue id/);
});

test("a tool with no arguments and no output says so", async () => {
const text = toolsCommand.display?.((await listTools("ping")).data) ?? "";

expect(text).toContain("Arguments:\nNone.");
expect(text).toContain("Output:\nNot declared by the server.");
});

test("an unknown tool names the closest one", async () => {
await expect(listTools("create_isue")).rejects.toThrow(
expect.objectContaining({ suggestion: "Did you mean create_issue?" }),
);
});
100 changes: 82 additions & 18 deletions packages/cli/src/commands/mcp/tools/command.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,53 @@
import { string, table } from "@superset/cli-framework";
import type { Tool } from "@modelcontextprotocol/sdk/types.js";
import {
CLIError,
positional,
string,
suggestSimilar,
table,
} from "@superset/cli-framework";
import { command } from "../../../lib/command";
import { resolveOrganizationId } from "../../../lib/config";
import { resolvePluginName } from "../../../lib/plugins/connection-ref";
import { connectPluginMcp } from "../../../lib/plugins/mcp-client";
import { schemaFields } from "./schemaFields";

interface ToolRow {
plugin: string;
tool: string;
description: string;
inputSchema: Tool["inputSchema"];
outputSchema?: Tool["outputSchema"];
}

function fieldTable(schema: Tool["inputSchema"]): string {
const fields = schemaFields(schema);
if (fields.length === 0) return "None.";
return table(
fields as unknown as Record<string, unknown>[],
["name", "type", "required", "default", "description"],
["NAME", "TYPE", "REQUIRED", "DEFAULT", "DESCRIPTION"],
[30, 48, 8, 16, 400],
);
}

function describeTool(row: ToolRow): string {
return [
`${row.tool} (${row.plugin})`,
row.description,
`Arguments:\n${fieldTable(row.inputSchema)}`,
`Output:\n${row.outputSchema ? fieldTable(row.outputSchema) : "Not declared by the server."}`,
]
.filter(Boolean)
.join("\n\n");
}

export default command({
description: "List the tools a connected plugin exposes",
args: [],
description:
"List the tools a connected plugin exposes, or show one tool's arguments and output",
args: [
positional("tool").desc("Tool name, to show its arguments and output"),
],
options: {
plugin: string().desc("Plugin name from `paradev plugins list`"),
account: string().desc(
Expand All @@ -16,13 +57,15 @@ export default command({
pluginId: string().desc("Deprecated alias for --plugin"),
},
display: (data) =>
table(
(data ?? []) as Record<string, unknown>[],
["plugin", "tool", "description"],
["PLUGIN", "TOOL", "DESCRIPTION"],
[16, 30, 70],
),
run: async ({ ctx, options }) => {
Array.isArray(data)
? table(
data as Record<string, unknown>[],
["plugin", "tool", "description"],
["PLUGIN", "TOOL", "DESCRIPTION"],
[16, 30, 70],
)
: describeTool(data as ToolRow),
run: async ({ ctx, args, options }) => {
const pluginName = resolvePluginName({
plugin: options.plugin as string | undefined,
connection: options.connection as string | undefined,
Expand All @@ -39,14 +82,35 @@ export default command({
);
try {
const { tools } = await client.listTools();
return {
data: tools.map((tool) => ({
plugin: ref.plugin,
tool: tool.name,
description: tool.description ?? "",
})),
message: `${tools.length} tool${tools.length === 1 ? "" : "s"} on ${ref.plugin}.`,
};
const rows: ToolRow[] = tools.map((tool) => ({
plugin: ref.plugin,
tool: tool.name,
description: tool.description ?? "",
inputSchema: tool.inputSchema,
outputSchema: tool.outputSchema,
}));

const name = args.tool as string | undefined;
if (name === undefined) {
return {
data: rows,
message: `${rows.length} tool${rows.length === 1 ? "" : "s"} on ${ref.plugin}.`,
};
}
const row = rows.find((candidate) => candidate.tool === name);
if (!row) {
const similar = suggestSimilar(
name,
rows.map((candidate) => candidate.tool),
);
throw new CLIError(
`${ref.plugin} has no tool "${name}".`,
similar
? `Did you mean ${similar}?`
: `Run: paradev mcp tools --plugin ${pluginName}`,
);
}
return { data: row };
} finally {
await client.close();
}
Expand Down
45 changes: 45 additions & 0 deletions packages/cli/src/commands/mcp/tools/schemaFields.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
interface PropertySchema {
type?: string | string[];
enum?: unknown[];
items?: PropertySchema;
anyOf?: PropertySchema[];
oneOf?: PropertySchema[];
default?: unknown;
description?: string;
}

export interface SchemaField {
name: string;
type: string;
required: string;
default: string;
description: string;
}

function typeLabel(property: PropertySchema): string {
if (property.enum) return property.enum.map(String).join(" | ");
const union = property.anyOf ?? property.oneOf;
if (union) return union.map(typeLabel).join(" | ");
if (Array.isArray(property.type)) return property.type.join(" | ");
if (property.type === "array" && property.items) {
return `${typeLabel(property.items)}[]`;
}
return property.type ?? "any";
}

export function schemaFields(schema: {
properties?: Record<string, object>;
required?: string[];
}): SchemaField[] {
return Object.entries(schema.properties ?? {}).map(([name, value]) => {
const property = value as PropertySchema;
return {
name,
type: typeLabel(property),
required: schema.required?.includes(name) ? "yes" : "",
default:
property.default === undefined ? "" : JSON.stringify(property.default),
description: property.description ?? "",
};
});
}
4 changes: 1 addition & 3 deletions packages/cli/src/commands/plugins/install/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { command } from "../../../lib/command";
import { canReachDesktop, openUrl } from "../../../lib/open-url";
import { authorizeUrl, chooseAuthMethod } from "../../../lib/plugins/connect";
import { withPluginHints } from "../../../lib/plugins/errors";
import { resolvePluginRef } from "../../../lib/plugins/host";
import { ORGANIZATION, resolvePluginRef } from "../../../lib/plugins/host";
import {
type AuthInputSpec,
missingInputsError,
Expand All @@ -32,8 +32,6 @@ type ConnectFirst =
| { status: "ready"; connection: string }
| { status: "authorize"; url: string };

const ORGANIZATION = "organization";

async function organizationPlugin(
api: ApiClient,
name: string,
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/lib/plugins/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export {
DEFAULT_MARKETPLACE_REPO,
} from "@superset/shared/plugins";

/** What a user types after `@` to name their organization's marketplace. */
export const ORGANIZATION = "organization";

export function parsePluginRef(ref: string): {
name: string;
marketplace?: string;
Expand Down
67 changes: 67 additions & 0 deletions packages/cli/src/lib/plugins/mcp-client.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { describe, expect, test } from "bun:test";
import type { InstalledPlugin } from "./host";
import { resolveMcpPluginRef } from "./mcp-client";

const ORG = "organization-0f9c";

function install(name: string, marketplace: string): InstalledPlugin {
return {
name,
marketplace,
version: "1.0.0",
installedAt: "2026-11-24T00:00:00.000Z",
enabled: true,
};
}

describe("resolveMcpPluginRef", () => {
test("a bare name takes the marketplace of its one install", () => {
expect(
resolveMcpPluginRef("admin", "0f9c", [
install("linear", "superset"),
install("admin", ORG),
]),
).toEqual({ plugin: "admin", marketplace: ORG });
});

test("a bare name with no install asks the default marketplace", () => {
expect(resolveMcpPluginRef("linear", undefined, [])).toEqual({
plugin: "linear",
marketplace: "superset",
});
});

test("a bare name installed twice fails with both refs", () => {
expect(() =>
resolveMcpPluginRef("linear", undefined, [
install("linear", "superset"),
install("linear", ORG),
]),
).toThrow(
expect.objectContaining({
suggestion: `Name one: --plugin linear@superset or --plugin linear@${ORG}`,
}),
);
});

test("name@organization is the active organization's marketplace", () => {
expect(resolveMcpPluginRef("admin@organization", "0f9c", [])).toEqual({
plugin: "admin",
marketplace: ORG,
});
});

test("name@organization with no active organization fails", () => {
expect(() =>
resolveMcpPluginRef("admin@organization", undefined, []),
).toThrow("no organization is active");
});

test("a named marketplace is kept as given", () => {
expect(
resolveMcpPluginRef("linear@acme", undefined, [
install("linear", "superset"),
]),
).toEqual({ plugin: "linear", marketplace: "acme" });
});
});
Loading
Loading