You can add Model Context Protocol (MCP) servers as tool sources using sdk.sources.add. MCP servers can be connected via remote (SSE/HTTP) or stdio (local process) transports.
Requirements:
- For
transport: "remote", you must provide an endpoint. - For
transport: "stdio", you must provide a command and args. - You must install
@executor-js/plugin-mcp alongside @executor-js/sdk.
Tool Path Mapping:
Tools are accessed via <namespace>.<server-tool-name>. Server tool names (often snake_case) are preserved verbatim in the tool path.
const executor = await createExecutor({
setup: async (sdk) => {
// Remote (SSE / HTTP)
await sdk.sources.add({
kind: "mcp",
transport: "remote",
endpoint: "https://mcp.example.com/sse",
name: "docs",
});
// Stdio (local process)
await sdk.sources.add({
kind: "mcp",
transport: "stdio",
command: "npx",
args: ["-y", "@modelcontextprotocol/server-filesystem", "/data"],
env: { LOG_LEVEL: "info" },
cwd: "/work",
name: "fs",
});
},
onToolApproval: async (req) => {
// Gate destructive tools
if (req.toolPath.endsWith(".write_file")) {
return { approved: false, reason: "writes need review" };
}
return { approved: true };
},
onElicitation: async (ctx) => {
// Handle interactive flows (forms, OAuth)
return { action: "decline" };
},
});