@grebyn/toolflow-mcp-server
Version:
MCP server for managing other MCP servers - discover, install, organize into bundles, and automate with workflows. Uses StreamableHTTP transport with dual OAuth/API key authentication.
145 lines ⢠6.12 kB
JavaScript
/**
* Read Client Config Tool
* Read the current MCP configuration from a specific client using the toolflow CLI
*/
import { exec } from 'child_process';
import { promisify } from 'util';
const execAsync = promisify(exec);
export const readClientConfigTool = {
name: 'read_client_config',
description: 'Read the current MCP configuration from a client. Uses the CLIENT environment variable by default, or a custom path if provided. Shows all currently installed servers and their configurations.',
inputSchema: {
type: 'object',
properties: {
config_path: {
type: 'string',
description: 'Custom configuration file path (overrides CLIENT environment variable)'
}
}
},
async execute(args, context) {
try {
let command;
let configSource;
if (args.config_path) {
// Custom path override
command = `npx @grebyn/toolflow-cli@latest read --path "${args.config_path}"`;
configSource = `custom path: ${args.config_path}`;
}
else {
// Use CLIENT environment variable
const client = process.env.CLIENT;
if (!client) {
throw new Error('CLIENT environment variable not set. Please configure your MCP client connection with CLIENT environment variable.');
}
command = `npx @grebyn/toolflow-cli@latest read ${client}`;
configSource = `client: ${client}`;
}
// Execute the CLI command
const { stdout, stderr } = await execAsync(command, {
timeout: 30000, // 30 second timeout
maxBuffer: 1024 * 1024 // 1MB buffer
});
if (stderr && !stdout) {
throw new Error(`CLI error: ${stderr}`);
}
// Parse the JSON output from CLI
let config;
try {
config = JSON.parse(stdout);
}
catch (parseError) {
// If not JSON, return raw output
return {
content: [
{
type: 'text',
text: `š **MCP Configuration (${configSource})**\n\n${stdout}`
}
]
};
}
// Format the configuration for display
return {
content: [
{
type: 'text',
text: formatConfigResult(config, configSource)
}
]
};
}
catch (error) {
console.error(`Failed to read client config: ${error.message}`);
// Check for specific error types
const errorMessage = error.message;
let troubleshooting = '';
if (errorMessage.includes('CLIENT environment variable not set')) {
troubleshooting = `\n\n**Setup Required:**\n- Ensure your MCP client configuration includes: \`"env": { "CLIENT": "your-client-name" }\`\n- Supported clients: claude-desktop, vscode, cursor, and others`;
}
else if (errorMessage.includes('not found') || errorMessage.includes('ENOENT')) {
troubleshooting = `\n\n**Troubleshooting:**\n- Check if the configuration file exists\n- Verify the CLIENT environment variable is set correctly\n- For custom paths, ensure the file path is correct`;
}
return {
content: [
{
type: 'text',
text: `ā **Failed to Read Client Configuration**\n\nError: ${errorMessage}${troubleshooting}`
}
]
};
}
}
};
/**
* Format configuration result for display
*/
function formatConfigResult(config, configSource) {
let output = `š **MCP Configuration**\n\n`;
output += `**Source**: ${configSource}\n`;
// Count servers based on config format
let serverCount = 0;
let servers = {};
if (config.mcpServers) {
servers = config.mcpServers;
serverCount = Object.keys(servers).length;
}
else if (config.servers) {
servers = config.servers;
serverCount = Object.keys(servers).length;
}
else if (config.context_servers) {
servers = config.context_servers;
serverCount = Object.keys(servers).length;
}
output += `**Servers Found**: ${serverCount}\n\n`;
if (serverCount === 0) {
output += `š **No MCP servers currently configured**\n\n`;
output += `This client has an empty or default configuration. You can now install MCP servers using the write_client_config tool.\n\n`;
}
else {
output += `**MCP Servers:**\n`;
// List each server
Object.entries(servers).forEach(([serverName, serverConfig], index) => {
output += `\n${index + 1}. **${serverName}**\n`;
const cfg = serverConfig;
if (cfg.command && cfg.args) {
output += ` - Command: \`${cfg.command} ${Array.isArray(cfg.args) ? cfg.args.join(' ') : cfg.args}\`\n`;
}
if (cfg.transport && cfg.url) {
output += ` - Transport: ${cfg.transport}\n`;
output += ` - URL: ${cfg.url}\n`;
}
if (cfg.type) {
output += ` - Type: ${cfg.type}\n`;
}
if (cfg.env && Object.keys(cfg.env).length > 0) {
output += ` - Environment Variables: ${Object.keys(cfg.env).join(', ')}\n`;
}
});
}
output += `\n**Full Configuration:**\n\`\`\`json\n${JSON.stringify(config, null, 2)}\n\`\`\`\n`;
output += `\nš” **Next Steps**: Use \`write_client_config\` to modify this configuration, or \`test_mcp_server\` to test server functionality.\n`;
return output;
}
//# sourceMappingURL=read-client-config.js.map