wechat WebMCP
Browser tool configuration for wechat
Tools (3)
insert_article()
Insert content into WeChat Official Account article editor (must be on editor page with action=edit)
Parameters
JavaScript Handler
(params) => {
// New WeChat editor uses multiple ProseMirror instances
const allEditors = document.querySelectorAll('.ProseMirror');
let titleEditor = null;
let contentEditor = null;
// Find title and content editors
allEditors.forEach(editor => {
const placeholder = editor.getAttribute('data-placeholder') || '';
const parentClass = editor.parentElement?.className || '';
if (placeholder.includes('标题')) {
titleEditor = editor;
} else if (parentClass.includes('rich_media_content')) {
// Content editor has parent with rich_media_content class
contentEditor = editor;
}
});
// Fallback: if only 2 ProseMirror editors, use the non-title one as content
if (!contentEditor && allEditors.length === 2 && titleEditor) {
allEditors.forEach(editor => {
if (editor !== titleEditor) contentEditor = editor;
});
}
// Fallback to old selectors
if (!titleEditor) {
titleEditor = document.querySelector('#title') || document.querySelector('[placeholder*="标题"]');
}
if (!contentEditor) {
contentEditor = document.querySelector('.edui-body-container');
}
// Set title if provided
if (params.title && titleEditor) {
if (titleEditor.tagName === 'TEXTAREA' || titleEditor.tagName === 'INPUT') {
titleEditor.value = params.title;
} else {
titleEditor.innerHTML = `<p>${params.title}</p>`;
}
titleEditor.dispatchEvent(new Event('input', { bubbles: true }));
}
// Insert content
if (!contentEditor) {
return { success: false, message: 'Content editor not found. Make sure you are on the article edit page' };
}
contentEditor.focus();
contentEditor.innerHTML = params.content;
contentEditor.dispatchEvent(new Event('input', { bubbles: true }));
return { success: true, message: 'Content inserted into WeChat editor' };
}
navigate_to_draft()
Navigate from WeChat home to draft page
Parameters
No parameters
JavaScript Handler
() => {
// Click 内容管理 menu
const contentMgmt = document.querySelector('[title="内容管理"]');
if (contentMgmt) {
contentMgmt.click();
setTimeout(() => {
const draftLink = Array.from(document.querySelectorAll('a')).find(a => a.textContent.includes('草稿箱'));
if (draftLink) draftLink.click();
}, 800);
return { success: true, message: 'Navigating to draft page...' };
}
return { success: false, message: 'Content management menu not found' };
}
create_new_article()
Click to create new article from draft page
Parameters
No parameters
JavaScript Handler
() => {
const newCreateCard = document.querySelector('.weui-desktop-card_new');
if (newCreateCard) {
newCreateCard.click();
setTimeout(() => {
const writeLink = document.querySelector('li[data-type="0"] a');
if (writeLink) {
writeLink.click();
}
}, 500);
return { success: true, message: 'Opening new article editor...' };
}
return { success: false, message: 'New creation card not found' };
}
WebMCP clients
Use mcp-chrome, or fetch the same tools from the public API in your own browser automation runtime.
How to Use WebMCP
WebMCP tools are designed for browser extensions or automation frameworks. The browser extension matches the current URL against the pattern and executes the JavaScript handler when the tool is invoked.
API Endpoint:
GET /api/webmcp/match?url=https://www.wechat.com/...
Third-party clients can use the same endpoint as mcp-chrome. Execute the returned JavaScript handler in your own browser page context.