Skip to content

Commit b1dc3df

Browse files
committed
Fix all links in MCP_SERVER_ARCHITECTURE.md to use correct relative paths
1 parent 94093c2 commit b1dc3df

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
**MCP Server Architecture**
2+
3+
**Overview**
4+
5+
This document describes the architecture of the Model Control Plane (MCP) server implemented in this repository. The MCP provides a lightweight HTTP front-end that accepts prompts and workflow requests, orchestrates AI clients and local tools (Playwright bridge), and stores short-term context.
6+
7+
**Components**
8+
9+
- **MCP server (Java):** The entry point that binds HTTP endpoints and dispatches requests to handlers. See [../../../../src/main/java/org/k11techlab/framework/ai/mcp/MCPServer.java](../../../../src/main/java/org/k11techlab/framework/ai/mcp/MCPServer.java).
10+
- **Handlers:** Small HttpHandler classes for each endpoint (health, completion, context, generate-page-object, generate-and-run-playwright-test, generate-and-run-selenium-test, correct-code, workflow). See [../../../../src/main/java/org/k11techlab/framework/ai/mcp/handlers/](../../../../src/main/java/org/k11techlab/framework/ai/mcp/handlers/).
11+
- **AI Clients:** Pluggable clients used by handlers to call LLMs or RAG services (RAGEnhancedAIClient, OpenAIClient). These encapsulate prompt formatting, API calls and retry/timeout logic.
12+
- **Playwright bridge (PlaywrightMCPClient):** A process-based JSON-RPC client wrapper that runs `npx @playwright/mcp` and communicates over stdio to control Playwright for browser-driven test execution. See [../../../../src/main/java/org/k11techlab/framework/ai/mcp/util/PlaywrightMCPClient.java](../../../../src/main/java/org/k11techlab/framework/ai/mcp/util/PlaywrightMCPClient.java).
13+
- **Workflows:** Higher-level orchestration (e.g., PlaywrightWorkflow) that generates a test, runs it, and archives logs/reports. See [../../../../src/main/java/org/k11techlab/framework/ai/mcp/workflow/playwright/PlaywrightWorkflow.java](../../../../src/main/java/org/k11techlab/framework/ai/mcp/workflow/playwright/PlaywrightWorkflow.java).
14+
- **Context store (MongoContextStore):** Optional persistence for conversation/context objects using MongoDB. Configured via `config/mcp-config.properties`. See [../../../../src/main/java/org/k11techlab/framework/ai/mcp/store/MongoContextStore.java](../../../../src/main/java/org/k11techlab/framework/ai/mcp/store/MongoContextStore.java).
15+
- **Prompts folder:** [../../../../mcp_prompts/](../../../../mcp_prompts/) holds prompt files referenced by requests (e.g. [../../../../mcp_prompts/k11softwaresolutions/pages/pageobject_creation_prompt_multi.txt](../../../../mcp_prompts/k11softwaresolutions/pages/pageobject_creation_prompt_multi.txt)). The server can accept a `promptFile` reference to load prompts server-side.
16+
17+
**Endpoints (summary)**
18+
19+
- `GET /mcp/health` — simple liveness check handled by HealthHandler.
20+
- `POST /mcp/completion` — textual prompt completion using AI client.
21+
- `POST /mcp/generate-page-object` — accept `{ "promptFile":"<relpath>" }` or text and run the page-object generator.
22+
- `POST /mcp/generate-and-run-playwright-test` — generate Playwright code and run it via the Playwright bridge; archives logs to `mcp_testlog/` and `mcp_testreport/`.
23+
- `POST /mcp/generate-and-run-selenium-test` — generate Selenium (Java/TestNG) test and run via Maven/Surefire.
24+
- `POST /mcp/correct-code` — fix or transform submitted code.
25+
26+
See handlers directory for implementation details: [../../../../src/main/java/org/k11techlab/framework/ai/mcp/handlers/](../../../../src/main/java/org/k11techlab/framework/ai/mcp/handlers/).
27+
28+
**Data & control flow (high-level)**
29+
30+
1. Client sends HTTP request to MCP server endpoint (e.g., generate-page-object).
31+
2. Handler validates input, loads prompt text (inline or from `mcp_prompts/`), and prepares LLM input.
32+
3. Handler invokes an AI client (RAG or direct LLM) to generate code (page object or test).
33+
4. For run requests, the handler either:
34+
- writes generated artifacts to disk and calls the Playwright bridge (PlaywrightMCPClient) which runs Playwright and streams test results; or
35+
- generates Java test code and invokes Maven to run the test (Selenium path).
36+
5. Workflow copies outputs to `mcp_testlog/` and `mcp_testreport/` and returns a response with run metadata.
37+
38+
**Configuration**
39+
40+
- `config/mcp-config.properties` controls port, prompt mappings, classNameBase, log.dir and Mongo connection settings. See [../../../../config/mcp-config.properties](../../../../config/mcp-config.properties).
41+
- Default port observed in the repo is `8090` (property `mcp.port`).
42+
43+
**Runtime requirements**
44+
45+
- Java 17+ / JDK 21 recommended for running the server (project was prepared for Java 21 migration).
46+
- Node.js + Playwright CLI (`npx @playwright/mcp`) for Playwright runs.
47+
- MongoDB if you want persistent context storage (optional; in-memory alternatives may exist).
48+
49+
**Artifacts & logs**
50+
51+
- Generated tests and page objects: [../../../../src/test/java/org/k11techlab/framework_unittests/ai_generated/](../../../../src/test/java/org/k11techlab/framework_unittests/ai_generated/) (example generated test: [../../../../src/test/java/org/k11techlab/framework_unittests/ai_generated/k11softwaresolutions/GeneratedPlaywrightLoginTest.java](../../../../src/test/java/org/k11techlab/framework_unittests/ai_generated/k11softwaresolutions/GeneratedPlaywrightLoginTest.java)).
52+
- Test run logs: `mcp_testlog/`.
53+
- HTML reports: `mcp_testreport/` and `target/surefire-reports/` for Maven-run tests.
54+
55+
**Troubleshooting notes**
56+
57+
- If endpoints return connection errors, ensure the MCP server process is running and listening on the configured port (look for startup message: "MCP Server started on port <port>").
58+
- Playwright runs require `npx` available in PATH and appropriate browser binaries; run `npx playwright install` if required.
59+
- Check `mcp_testlog/` for Playwright bridge logs and `mcp_testreport/` for HTML test reports after a run.
60+
61+
**Where to look in the code**
62+
63+
- Server bootstrap: [../../../../src/main/java/org/k11techlab/framework/ai/mcp/MCPServer.java](../../../../src/main/java/org/k11techlab/framework/ai/mcp/MCPServer.java)
64+
- Handlers: [../../../../src/main/java/org/k11techlab/framework/ai/mcp/handlers/](../../../../src/main/java/org/k11techlab/framework/ai/mcp/handlers/)
65+
- Playwright bridge: [../../../../src/main/java/org/k11techlab/framework/ai/mcp/util/PlaywrightMCPClient.java](../../../../src/main/java/org/k11techlab/framework/ai/mcp/util/PlaywrightMCPClient.java)
66+
- Playwright orchestration: [../../../../src/main/java/org/k11techlab/framework/ai/mcp/workflow/playwright/PlaywrightWorkflow.java](../../../../src/main/java/org/k11techlab/framework/ai/mcp/workflow/playwright/PlaywrightWorkflow.java)
67+
- Prompts: [../../../../mcp_prompts/](../../../../mcp_prompts/) folder (example: [../../../../mcp_prompts/k11softwaresolutions/pages/pageobject_creation_prompt_multi.txt](../../../../mcp_prompts/k11softwaresolutions/pages/pageobject_creation_prompt_multi.txt)).
68+
69+
**Next steps / improvements (suggested)**
70+
71+
- Harden generated interactions with robust waits / fallback actions in generators (addresses flaky selectors like the "login menu not visible" case).
72+
- Add a small systemd/Windows service script or a Dockerfile to run MCP persistently for CI/demo scenarios.
73+
- Add a health-check and readiness probe endpoint that also verifies Playwright and Mongo availability.

0 commit comments

Comments
 (0)