@poai/mcpm-aider
Version:
Your MCP CLI Manager for aider(forked from @mcpm/cli). Helps you install/remove/search your MCP projects. You can also manage your MCP in Claude App with natural language.
40 lines (39 loc) • 1.4 kB
JavaScript
/**
* Copyright (C) 2024 PoAI (Lutz Leonhardt)
* This file is part of mcpm, based on work by MCP Club
* Licensed under the GNU AGPL v3.0
* See LICENSE file for details
*/
import { StdioClientTransport, getDefaultEnvironment } from '@modelcontextprotocol/sdk/client/stdio.js';
/**
* Replace placeholders in an argument using the provided arguments object.
*/
export function replacePlaceholders(arg, argumentsObj) {
const placeholderMatch = arg.match(/^\*\*(.+)\*\*$/);
return placeholderMatch ? argumentsObj[placeholderMatch[1]] ?? arg : arg;
}
/**
* Provides fallback arguments from the server configuration.
*/
export function getArgumentsWithFallback(server) {
return server.info.arguments ?? {};
}
/**
* Builds and returns a configured StdioClientTransport instance for the given MCPServerWithStatus.
*/
export function buildTransportForServer(server) {
const args = getArgumentsWithFallback(server);
const rawEnv = server.info.appConfig?.env || {};
const env = {};
for (const [key, value] of Object.entries(rawEnv)) {
env[key] = replacePlaceholders(value, args);
}
return new StdioClientTransport({
command: server.info.appConfig.command,
args: (server.info.appConfig.args || []).map(arg => replacePlaceholders(arg, args)),
env: {
...getDefaultEnvironment(),
...env
},
});
}