A system that automatically generates expressive Model Context Protocol (MCP) implementations for any web application (SaaS or consumer-facing).
Design a system that, given any web application (SaaS or consumer-facing), can automatically generate an expressive Model Control Protocol (MCP) implementation.
This is a fairly hard problem for (at least) three reasons:
-
Behavior tree size: Apps have many buttons and pages. We must traverse at least the important subset of these buttons and pages to establish an application's capabilities.
-
Semantic gap: While links/buttons can be easily identified, it's not clear when these links/buttons correspond to a meaningful tool to expose via the MCP. Similarly, what textual information on the page is relevant for read operations?
-
Under-specified hierarchy: We must infer the object hierarchy. What are the "resources" that the MCP should allow agents to act on? Which tools correspond to which resources?
I break the problem into two separate tasks: (1) define the MCP specification and (2) implement the specification.
-
Python Dependencies (for the test application):
cd test pip3 install -r requirements.txt
-
Node.js Setup:
nvm use 18 npm install
-
Environment Variables:
cp .env.example .env
Then edit
.env
and set the following variables:BROWSERBASE_PROJECT_ID="YOUR_BROWSERBASE_PROJECT_ID" BROWSERBASE_API_KEY="YOUR_BROWSERBASE_API_KEY" OPENAI_API_KEY="THIS_IS_OPTIONAL_WITH_OPENAI_KEY" # SPA Crawler Configuration SPA_CRAWLER_URL="http://localhost:8000" SPA_CRAWLER_USERNAME="[email protected]" SPA_CRAWLER_PASSWORD="password123" SPA_CRAWLER_MAX_DEPTH="1" SPA_CRAWLER_ENV="LOCAL"
By default, the SPA_* environment variables work for the demo app.
You can try a derived MCP for the demo email application:
-
Run the demo app:
cd test python3 app.py
-
In a new terminal in the root directory:
npm run build:mcp npx @modelcontextprotocol/inspector node dist/dynamicMcpServer.js test/exampleMcpConfig.json test/exampleSummaryPageActions.json
-
Try the MCP in the launched browser window
-
Start the demo app:
cd test python3 app.py
-
In the root directory, run the crawler:
npx tsx spaCrawler.ts
-
The resulting output is in
outputMcpConfig.json
andoutputSummaryPageActions.json
-
Use those with the MCP server:
npm run build:mcp node dist/dynamicMcpServer.js outputMcpConfig.json outputSummaryPageActions.json
spaCrawler.ts
- Main crawler that analyzes web applications and generates MCP configurationsdynamicMcpServer.ts
- Dynamic MCP server implementationsharedUtils.ts
- Shared utilities for the projecttest/
- Demo Flask application for testingapp.py
- Simple email application demoexampleMcpConfig.json
- Example MCP configurationexampleSummaryPageActions.json
- Example page action definitions
The system works in two phases:
-
Analysis Phase: The
spaCrawler.ts
analyzes a web application by:- Crawling through pages and identifying interactive elements
- Inferring the application's object hierarchy
- Determining which actions correspond to meaningful MCP tools
- Generating configuration files that define the MCP interface
-
Execution Phase: The
dynamicMcpServer.ts
provides:- A dynamic MCP server that loads configurations at runtime
- Tool execution that translates MCP calls into web application actions
- Real-time interaction with the target web application
npm run build:mcp
npx tsx spaCrawler.ts
npx tsx dynamicMcpServer.ts
npx @modelcontextprotocol/inspector node dist/dynamicMcpServer.js config.json actions.json
See LICENSE.txt for details.