UNPKG

@nanocollective/nanocoder

Version:

A local-first CLI coding agent that brings the power of agentic coding tools like Claude Code and Gemini CLI to local models or controlled APIs like OpenRouter

59 lines 4.12 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import { Box, Text } from 'ink'; import React from 'react'; import { TitledBoxWithPreferences } from '../components/ui/titled-box.js'; import { useTerminalWidth } from '../hooks/useTerminalWidth.js'; import { useTheme } from '../hooks/useTheme.js'; import { getToolManager } from '../message-handler.js'; // Helper function to get transport icons function getTransportIcon(transportType) { switch (transportType.toLowerCase()) { case 'stdio': return '💻'; case 'websocket': return '🔄'; case 'http': return '🌐'; default: return '❓'; } } export function MCP({ toolManager }) { const boxWidth = useTerminalWidth(); const { colors } = useTheme(); const connectedServers = toolManager?.getConnectedServers() || []; return (_jsx(TitledBoxWithPreferences, { title: "Model Context Protocol Servers", width: boxWidth, borderColor: colors.primary, paddingX: 2, paddingY: 1, flexDirection: "column", marginBottom: 1, children: connectedServers.length === 0 ? (_jsxs(_Fragment, { children: [_jsx(Box, { marginBottom: 1, children: _jsx(Text, { color: colors.text, bold: true, children: "No MCP servers connected" }) }), _jsxs(Text, { color: colors.text, children: ["To connect MCP servers, add them to your", ' ', _jsx(Text, { color: colors.primary, children: ".mcp.json" }), " file:"] }), _jsx(Box, { marginTop: 1, marginBottom: 1, children: _jsx(Text, { color: colors.secondary, children: `{ "mcpServers": { "filesystem": { "transport": "stdio", "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "."], "description": "Project filesystem access", "alwaysAllow": ["list_directory", "file_info"] }, "http-server": { "transport": "http", "url": "http://localhost:3000/mcp" } } }` }) }), _jsxs(Text, { color: colors.secondary, children: ["Use ", _jsx(Text, { color: colors.primary, children: "/setup-providers" }), " to configure servers interactively."] })] })) : (_jsxs(_Fragment, { children: [_jsx(Box, { marginBottom: 1, children: _jsxs(Text, { color: colors.primary, children: ["Connected MCP Servers (", connectedServers.length, "):"] }) }), connectedServers.map((serverName, index) => { const serverTools = toolManager?.getServerTools(serverName) || []; const serverInfo = toolManager?.getServerInfo(serverName); const transportIcon = getTransportIcon(serverInfo?.transport || 'stdio'); return (_jsx(Box, { marginBottom: 1, children: _jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { color: colors.text, children: ["\u2022 ", transportIcon, ' ', _jsx(Text, { color: colors.primary, children: serverName }), ":", ' ', _jsxs(Text, { color: colors.secondary, children: ["(", serverInfo?.transport?.toUpperCase() || 'STDIO', ")"] }), ' ', "\u2022 ", serverTools.length, " tool", serverTools.length !== 1 ? 's' : ''] }), serverInfo?.url && (_jsxs(Text, { color: colors.info, children: ["URL: ", serverInfo.url] })), serverInfo?.description && (_jsx(Text, { color: colors.success, children: serverInfo.description })), !!serverInfo?.autoApprovedCommands?.length && (_jsxs(Text, { color: colors.secondary, children: ["Auto-approved tools:", ' ', serverInfo.autoApprovedCommands.join(', ')] })), serverTools.length > 0 && (_jsxs(Text, { color: colors.tool, children: ["Tools:", ' ', serverTools .map((t) => t.name) .join(', ')] }))] }) }, index)); })] })) })); } export const mcpCommand = { name: 'mcp', description: 'Show connected MCP servers and their tools', handler: (_args, _messages, _metadata) => { const toolManager = getToolManager(); return Promise.resolve(React.createElement(MCP, { key: `mcp-${Date.now()}`, toolManager: toolManager, })); }, }; //# sourceMappingURL=mcp.js.map