Add configurable seal-home MCP toggle
This commit is contained in:
1 parent
883798b157
commit
8be627e1c6
9 files changed
+164
-79
No files matched your search
+43
-2
@@ -1,7 +1,13 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
||||
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
||||
import { createServer, SEAL_CLI_TOOL_NAME, tokenizeCommand } from "./server.js";
|
||||
import {
|
||||
createServer,
|
||||
resolveMcpEnabled,
|
||||
SEAL_CLI_TOOL_NAME,
|
||||
SEAL_MCP_ENABLED_ENV,
|
||||
tokenizeCommand
|
||||
} from "./server.js";
|
||||
|
||||
describe("seal-home MCP server", () => {
|
||||
test("tokenizes quoted JSON without invoking a shell", () => {
|
||||
@@ -18,8 +24,25 @@ describe("seal-home MCP server", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
test("defaults MCP tools to disabled and parses the plugin boolean setting", () => {
|
||||
const original = process.env[SEAL_MCP_ENABLED_ENV];
|
||||
delete process.env[SEAL_MCP_ENABLED_ENV];
|
||||
|
||||
try {
|
||||
expect(resolveMcpEnabled()).toBe(false);
|
||||
expect(resolveMcpEnabled("false")).toBe(false);
|
||||
expect(resolveMcpEnabled("0")).toBe(false);
|
||||
expect(resolveMcpEnabled("true")).toBe(true);
|
||||
expect(resolveMcpEnabled("1")).toBe(true);
|
||||
expect(resolveMcpEnabled("yes")).toBe(true);
|
||||
} finally {
|
||||
if (original === undefined) delete process.env[SEAL_MCP_ENABLED_ENV];
|
||||
else process.env[SEAL_MCP_ENABLED_ENV] = original;
|
||||
}
|
||||
});
|
||||
|
||||
test("advertises one tool and executes version through the CLI runner", async () => {
|
||||
const server = createServer();
|
||||
const server = createServer({ enableCli: true });
|
||||
const client = new Client({ name: "seal-home-test", version: "1.0.0" });
|
||||
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
||||
|
||||
@@ -64,4 +87,22 @@ describe("seal-home MCP server", () => {
|
||||
await Promise.allSettled([client.close(), server.close()]);
|
||||
}
|
||||
});
|
||||
|
||||
test("does not advertise tools when MCP is disabled", async () => {
|
||||
const server = createServer({ enableCli: false });
|
||||
const client = new Client({ name: "seal-home-disabled-test", version: "1.0.0" });
|
||||
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
||||
|
||||
try {
|
||||
await Promise.all([
|
||||
server.connect(serverTransport),
|
||||
client.connect(clientTransport)
|
||||
]);
|
||||
|
||||
const listed = await client.listTools();
|
||||
expect(listed.tools).toEqual([]);
|
||||
} finally {
|
||||
await Promise.allSettled([client.close(), server.close()]);
|
||||
}
|
||||
});
|
||||
});
|
||||
+34
-20
@@ -15,8 +15,15 @@ const pluginRoot = serverEntryFile.includes("/dist/mcp/") || serverEntryFile.inc
|
||||
: dirname(dirname(serverEntryFile));
|
||||
|
||||
export const SEAL_CLI_TOOL_NAME = "seal_cli";
|
||||
export const SEAL_MCP_ENABLED_ENV = "SEAL_HOME_MCP_ENABLED";
|
||||
|
||||
export function createServer() {
|
||||
export function resolveMcpEnabled(value = process.env[SEAL_MCP_ENABLED_ENV]): boolean {
|
||||
if (value === undefined) return false;
|
||||
return ["1", "true", "yes", "on"].includes(value.trim().toLowerCase());
|
||||
}
|
||||
|
||||
export function createServer(options: { enableCli?: boolean } = {}) {
|
||||
const enableCli = options.enableCli ?? true;
|
||||
const server = new Server(
|
||||
{
|
||||
name: "seal-home",
|
||||
@@ -30,26 +37,28 @@ export function createServer() {
|
||||
);
|
||||
|
||||
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
||||
tools: [
|
||||
{
|
||||
name: SEAL_CLI_TOOL_NAME,
|
||||
description: "Run seal-home CLI commands. See the seal-home skill for command reference.",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
command: {
|
||||
type: "string",
|
||||
description: "A seal-home CLI command, with or without the leading 'seal-home'."
|
||||
tools: enableCli
|
||||
? [
|
||||
{
|
||||
name: SEAL_CLI_TOOL_NAME,
|
||||
description: "Run seal-home CLI commands. See the seal-home skill for command reference.",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
command: {
|
||||
type: "string",
|
||||
description: "A seal-home CLI command, with or without the leading 'seal-home'."
|
||||
}
|
||||
},
|
||||
required: ["command"],
|
||||
additionalProperties: false
|
||||
}
|
||||
},
|
||||
required: ["command"],
|
||||
additionalProperties: false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
: []
|
||||
}));
|
||||
|
||||
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
||||
if (enableCli) server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
||||
const args = request.params.arguments;
|
||||
const command = args && typeof args.command === "string" ? args.command : undefined;
|
||||
if (!command?.trim()) {
|
||||
@@ -90,9 +99,14 @@ export function createServer() {
|
||||
}
|
||||
|
||||
export async function startServer() {
|
||||
const server = createServer();
|
||||
const enableCli = resolveMcpEnabled();
|
||||
const server = createServer({ enableCli });
|
||||
await server.connect(new StdioServerTransport());
|
||||
console.error("seal-home MCP server running on stdio");
|
||||
console.error(
|
||||
enableCli
|
||||
? "seal-home MCP server running on stdio"
|
||||
: "seal-home MCP server connected with seal_cli disabled by configuration"
|
||||
);
|
||||
}
|
||||
|
||||
export function tokenizeCommand(command: string): string[] {
|
||||
|
||||
Reference in new issue
Block a user