/**
* Tool definition interface for MCP tools
*/
export interface ToolDefinition {
name: string;
description: string;
inputSchema: {
type: 'object';
properties: Record<string, any>;
required: string[];
};
}
export const webTools: ToolDefinition[] = [
// === Panel Management ===
{
name: 'web_open',
description: 'Open the Web viewer tab in VS Code. Must be called before using other tools.',
inputSchema: { type: 'object', properties: {}, required: [] },
},
{
name: 'web_close',
description: 'Close the Web viewer tab in VS Code.',
inputSchema: { type: 'object', properties: {}, required: [] },
},
// === Navigation & Interaction ===
{
name: 'web_navigate',
description: 'Navigate to a specific route/page.',
inputSchema: {
type: 'object',
properties: {
route: { type: 'string', description: 'Route to navigate (e.g., "home", "about", "#contact")' },
},
required: ['route'],
},
},
{
name: 'web_click',
description: 'Click an element by CSS selector.',
inputSchema: {
type: 'object',
properties: {
selector: { type: 'string', description: 'CSS selector (e.g., "#submit-btn", ".nav-link")' },
},
required: ['selector'],
},
},
{
name: 'web_input',
description: 'Input text into a form field.',
inputSchema: {
type: 'object',
properties: {
selector: { type: 'string', description: 'CSS selector of input element' },
value: { type: 'string', description: 'Text value to input' },
},
required: ['selector', 'value'],
},
},
{
name: 'web_get_state',
description: 'Get current state: URL, title, visible text, forms, links.',
inputSchema: { type: 'object', properties: {}, required: [] },
},
// ============================================================
// THÊM TOOL MỚI TẠI ĐÂY
// ============================================================
{
name: 'web_scroll',
description: 'Scroll page by pixels. Positive = down, negative = up.',
inputSchema: {
type: 'object',
properties: {
y: { type: 'number', description: 'Pixels to scroll (positive=down, negative=up)' },
},
required: ['y'],
},
},
];
// Panel commands (handled by extension, not forwarded to webview)
export const PANEL_COMMANDS = ['web_open', 'web_close'];
// Helper to check if tool is panel command
export function isPanelCommand(toolName: string): boolean {
return PANEL_COMMANDS.includes(toolName);
}
// Get tool command name for HTTP bridge (strip 'web_' prefix)
export function getCommandName(toolName: string): string {
return toolName.replace(/^web_/, '');
}
/**
* Resource definitions for MCP
*/
export const webResources = [
{
uri: 'web://state',
name: 'Web State',
description: 'Current state of the webview',
mimeType: 'application/json',
},
{
uri: 'web://dom',
name: 'Web DOM',
description: 'Current DOM structure',
mimeType: 'text/html',
},
];