import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
import { z } from "zod";
/**
* Login credentials configuration
*/
export const LOGIN_CREDENTIALS = {
username: "admin",
password: "AIWorkshopJuly!25",
targetUrl: "http://localhost"
};
/**
* Tool: perform_login
*
* Performs automated login to the specified URL using predefined credentials.
* This tool is designed to work with the Playwright MCP server for browser automation.
*/
export function registerPerformLoginTool(server: McpServer): void {
server.tool(
"perform_login",
"Performs automated login to http://localhost using predefined credentials (admin/AIWorkshopJuly!25). This tool requires a Playwright MCP server to be running for browser automation.",
{
url: z.string().url().optional().describe("The URL to navigate to for login (defaults to http://localhost)")
},
async ({ url = LOGIN_CREDENTIALS.targetUrl }) => {
try {
// Note: This is a demonstration tool that provides login instructions
// In a real implementation, this would interface with the Playwright MCP server
// to perform actual browser automation
const loginSteps = [
`Navigate to ${url}`,
`Fill username field with: ${LOGIN_CREDENTIALS.username}`,
`Fill password field with: ${LOGIN_CREDENTIALS.password}`,
`Click the login button`,
`Wait for successful login confirmation`
];
const response = {
success: true,
message: "Login tool executed successfully",
steps: loginSteps,
credentials: {
username: LOGIN_CREDENTIALS.username,
target_url: url
},
note: "This tool provides login instructions. To perform actual browser automation, integrate with a running Playwright MCP server."
};
return {
content: [
{
type: "text",
text: `Login Tool Response:
✅ Tool: perform_login
🎯 Target URL: ${url}
👤 Username: ${LOGIN_CREDENTIALS.username}
🔑 Password: [Protected]
📋 Login Steps:
${loginSteps.map((step, index) => `${index + 1}. ${step}`).join('\n')}
💡 Note: This tool is designed to work with the Playwright MCP server for actual browser automation.
To perform real login automation, ensure the Playwright MCP server is running and accessible.
🔧 For browser automation integration, this tool can be extended to:
- Connect to the Playwright MCP server
- Execute browser commands through MCP protocol
- Handle login success/failure scenarios
- Provide detailed feedback on login process`
}
]
};
} catch (error) {
throw new McpError(
ErrorCode.InternalError,
`Login tool failed: ${error instanceof Error ? error.message : String(error)}`
);
}
}
);
}
/**
* Tool: get_login_credentials
*
* Returns the login credentials that will be used for authentication.
* This is useful for verification and debugging purposes.
*/
export function registerGetLoginCredentialsTool(server: McpServer): void {
server.tool(
"get_login_credentials",
"Returns the login credentials that will be used for authentication to http://localhost",
{},
async () => {
return {
content: [
{
type: "text",
text: `Login Credentials:
🎯 Target URL: ${LOGIN_CREDENTIALS.targetUrl}
👤 Username: ${LOGIN_CREDENTIALS.username}
🔑 Password: AIWorkshopJuly!25
ℹ️ These credentials are configured for the OrangeHRM system running on localhost.`
}
]
};
}
);
}
/**
* Tool: test_connection
*
* Tests if the target URL is accessible.
* This is useful for debugging connection issues.
*/
export function registerTestConnectionTool(server: McpServer): void {
server.tool(
"test_connection",
"Tests if the target URL (http://localhost) is accessible",
{},
async () => {
try {
// Basic connectivity test
const response = await fetch(LOGIN_CREDENTIALS.targetUrl, {
method: 'HEAD',
signal: AbortSignal.timeout(5000)
});
return {
content: [
{
type: "text",
text: `Connection Test Results:
🎯 Target URL: ${LOGIN_CREDENTIALS.targetUrl}
✅ Status: ${response.status} ${response.statusText}
🔗 Accessible: Yes
⏱️ Response Time: Available
💡 The target URL is accessible and ready for login operations.`
}
]
};
} catch (error) {
return {
content: [
{
type: "text",
text: `Connection Test Results:
🎯 Target URL: ${LOGIN_CREDENTIALS.targetUrl}
❌ Status: Connection Failed
🔗 Accessible: No
⚠️ Error: ${error instanceof Error ? error.message : String(error)}
💡 Please ensure the target server is running on localhost.`
}
]
};
}
}
);
}
/**
* Tool: navigate_to_pim
*
* Navigates to the PIM (Personal Information Management) page using the left-hand navigation menu.
* This tool assumes the user is already logged in and has access to the navigation menu.
*/
export function registerNavigateToPimTool(server: McpServer): void {
server.tool(
"navigate_to_pim",
"Navigates to the PIM (Personal Information Management) page using the left-hand navigation menu. Assumes user is already logged in.",
{},
async () => {
try {
const navigationSteps = [
"Locate the left-hand navigation menu",
"Find the 'PIM' menu item in the navigation list",
"Click on the 'PIM' link to navigate to the PIM module",
"Wait for the PIM page to load"
];
const response = {
success: true,
message: "PIM navigation tool executed successfully",
steps: navigationSteps,
target_module: "PIM",
expected_url: "/web/index.php/pim/viewPimModule",
note: "This tool provides navigation instructions for the PIM module. Requires user to be logged in first."
};
return {
content: [
{
type: "text",
text: `PIM Navigation Tool Response:
✅ Tool: navigate_to_pim
🎯 Target Module: PIM (Personal Information Management)
🔗 Expected URL: ${LOGIN_CREDENTIALS.targetUrl}/web/index.php/pim/viewPimModule
📋 Navigation Steps:
${navigationSteps.map((step, index) => `${index + 1}. ${step}`).join('\n')}
💡 Note: This tool assumes the user is already logged in and has access to the navigation menu.
The PIM module provides functionality for managing employee personal information, employment details, and related HR data.
🔧 For browser automation integration, this tool can be extended to:
- Verify user is logged in before navigation
- Click the PIM menu item using Playwright
- Wait for page load confirmation
- Handle navigation errors or timeouts
- Provide feedback on successful navigation`
}
]
};
} catch (error) {
throw new McpError(
ErrorCode.InternalError,
`PIM navigation tool failed: ${error instanceof Error ? error.message : String(error)}`
);
}
}
);
}
/**
* Registers all tools with the MCP server
*/
export function registerAllTools(server: McpServer): void {
registerPerformLoginTool(server);
registerGetLoginCredentialsTool(server);
registerTestConnectionTool(server);
registerNavigateToPimTool(server);
}
/**
* Returns an array of all available tool names
*/
export function getAvailableTools(): string[] {
return [
"perform_login",
"get_login_credentials",
"test_connection",
"navigate_to_pim"
];
}