跪拜 Guibai
← All articles
Frontend · JavaScript · Agent

A Five-Year-Old Intranet App Gets an AI Sidecar via MCP and npm

By 我的刀盾 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Many organizations sit on legacy internal tools that are too costly to rewrite but still gate critical data behind browser logins. This pattern lets an AI agent operate those tools through their existing APIs and authentication, turning a dead-end maintenance burden into automatable infrastructure without opening security holes.

Summary

An old internal web app with near-zero daily users can be given an AI interface without touching its codebase. The approach wraps the app's existing login and file APIs behind an MCP server distributed as a private npm package. An agent launches the server via npx, opens the user's local Chrome to complete a real login, captures the session token into process memory, and then calls the same list and download endpoints the browser would hit. Credentials never touch disk or configuration files, and the server process restart clears them completely. The technique works across Cursor, Claude Desktop, VS Code, and Windsurf because MCP is client-agnostic. The npm package bundles Playwright to drive the local browser, zod for input validation, and the MCP SDK to expose three tools: login_with_browser, list_files, and download_file. A logout tool optionally calls the backend to invalidate the server-side session before clearing memory. The entire setup avoids intranet tunneling, public exposure, or unauthenticated backdoors, keeping the old system's security model intact while letting an agent do the repetitive clicking.

Takeaways
An MCP server packaged as an npm module can be launched with a single npx command from any MCP-compatible client.
Playwright's persistent context with channel: 'chrome' reuses the user's already-installed browser, avoiding Chromium downloads.
Login credentials are extracted from the browser's localStorage, cookies, or intercepted Authorization headers and held only in process memory.
Subsequent API calls carry the captured token and cookie header, hitting the exact same endpoints the web frontend uses.
Logout clears both the server-side session via a backend call and the in-memory credentials, even if the backend call fails.
The npm package pins its version and registry in the MCP config; no API_TOKEN or secret ever appears in mcp.json or Git.
Development mode swaps npx for a local node path, then switches back to npx after publishing to a private registry.
Conclusions

Treating the browser as a credential broker rather than building a separate auth flow preserves the existing security model and avoids the need for API keys or service accounts.

Publishing the MCP server as a private npm package turns a one-off script into a versioned, distributable tool that any team member's agent client can consume with a single config block.

The approach deliberately avoids headless Chromium downloads by relying on the user's local Chrome installation, which sidesteps CI/CD incompatibilities and keeps the setup lightweight for Windows desktops common in enterprise environments.

Clearing credentials on process restart means the agent's access is ephemeral by default; there is no persistent session to leak or rotate, which aligns with zero-trust patterns even inside a legacy system.

Concepts & terms
MCP (Model Context Protocol)
An open protocol that standardizes how AI agents discover and call external tools. An MCP server exposes tools via stdio or HTTP, and any MCP-compatible client can connect to it.
Playwright persistent context
A browser context tied to a user data directory that preserves cookies, localStorage, and extensions across launches. Using channel: 'chrome' connects to the system's existing Chrome rather than downloading a separate Chromium binary.
npx
npm's package runner that can execute a command from an npm package without a prior global install. The -y flag auto-confirms installation prompts, making it suitable for agent-launched processes.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗