Я сегодня играл с BrowserMCP, и мне не удается получить минимальную рабочую версию в Python или Nodejs - то есть что -то, что «перейдет на YouTube и искал« серверы MCP »и нажимать в Enter ..» < /p>
Я правильно получил рабочую версию MCP в курсоре, но для меня это иногда не делает. Я просто хочу что -то, что будет воспроизводить подход курсора к использованию MCP, но программатически.{
"mcpServers": {
"browsermcp": {
"command": "npx",
"args": ["@browsermcp/mcp@latest"]
}
}
}
< /code>
Вот сгенерированный CHATGPT, который я пробовал ранее, но его мусор и не работает: < /p>
const { spawn } = require('child_process');
// You already confirmed this is correct on your system:
const npxPath = 'C:\\nvm4w\\nodejs\\npx.cmd';
// Use full path to cmd.exe for extra reliability
const cmdPath = 'C:\\Windows\\System32\\cmd.exe';
const browserMcp = spawn(cmdPath, ['/c', npxPath, '@browsermcp/mcp@latest'], {
stdio: ['pipe', 'pipe', 'pipe'], // All pipes so you can read/write if needed
windowsVerbatimArguments: true // Sometimes helps on Windows, can omit if not needed
});
// Handle stdout
browserMcp.stdout.on('data', (data) => {
console.log('[browsermcp stdout]:', data.toString());
});
// Handle stderr
browserMcp.stderr.on('data', (data) => {
console.error('[browsermcp stderr]:', data.toString());
});
// Handle process errors (like not found, spawn errors)
browserMcp.on('error', (err) => {
console.error('Failed to start browsermcp process:', err);
process.exit(1);
});
// Handle exit
browserMcp.on('close', (code) => {
console.log(`[browsermcp process exited with code ${code}]`);
});
// Example: Sending a command after a delay (as in your original script)
function sendCommand(command) {
console.log('[Sending to browsermcp]:', JSON.stringify(command));
browserMcp.stdin.write(JSON.stringify(command) + '\n');
}
async function automateBrowser() {
console.log('[Automation starting...]');
await new Promise(resolve => setTimeout(resolve, 8000)); // Wait for MCP to boot
sendCommand({
type: 'tool_code',
tool_name: 'browser_goto',
args: {
url: 'https://youtube.com/'
}
});
await new Promise(resolve => setTimeout(resolve, 10000)); // Wait for page to load
sendCommand({
type: 'tool_code',
tool_name: 'browser_type',
args: {
element: 'textarea[id="prompt-textarea"]',
text: 'generate an image of a dog',
submit: true
}
});
}
// Start automation
automateBrowser();
// Graceful shutdown on Ctrl+C
process.on('SIGINT', () => {
console.log('Ctrl+C detected. Terminating browsermcp process...');
if (browserMcp) {
browserMcp.kill('SIGINT');
}
process.exit();
});
< /code>
Это создало впечатление, что он может сработать, но браузер Chrome ничего не делает ... < /p>
[Sending to browsermcp]: {"type":"tool_code","tool_name":"browser_goto","args":{"url":"https://youtube.com/"}}
[Sending to browsermcp]: {"type":"tool_code","tool_name":"browser_type","args":{"element":"textarea[id=\"prompt-textarea\"]","text":"generate an image of a dog","submit":true}}
Подробнее здесь: https://stackoverflow.com/questions/796 ... mcp-server
Минимальный рабочий пример сервера MCP? ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Минимальный рабочий пример NLopt завершается с ошибкой «RoundoffLimited».
Anonymous » » в форуме Python - 0 Ответы
- 20 Просмотры
-
Последнее сообщение Anonymous
-