|
| 1 | ++++ |
| 2 | +fragment = "content" |
| 3 | +weight = 100 |
| 4 | + |
| 5 | +title = "Model Context Protocol (MCP)" |
| 6 | + |
| 7 | +[sidebar] |
| 8 | + sticky = true |
| 9 | ++++ |
| 10 | + |
| 11 | +The [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) is an open standard that lets AI agents and language models interact with external systems through a uniform interface. |
| 12 | +A GLSP server can optionally act as an MCP server, so that AI clients such as an IDE chat assistant can inspect and edit diagrams through the same interface they use for any other MCP integration. |
| 13 | + |
| 14 | +In practice this lets an assistant answer questions about a diagram, suggest improvements, create or adjust elements from a natural-language request, or check the model for problems, all while the diagram stays open in the GLSP editor. |
| 15 | + |
| 16 | +<small>*Experimental: MCP support is under active development and its configuration may still change. It is currently available for the [Node GLSP server](https://github.com/eclipse-glsp/glsp-server-node) only, with [Java server support](https://github.com/eclipse-glsp/glsp/issues/1672) planned.*</small> |
| 17 | + |
| 18 | +### What it provides |
| 19 | + |
| 20 | +A GLSP MCP server surfaces the active diagrams through the three MCP capability kinds: |
| 21 | + |
| 22 | +* 🛠️ **Tools** to inspect, query, create, modify, delete, validate, and navigate diagram elements. |
| 23 | +* 📦 **Resources** that expose read-only, URI-addressable views of a diagram, such as a rendered image. |
| 24 | +* 💬 **Prompts** that frame common multi-step agent tasks against the diagram. |
| 25 | + |
| 26 | +Each MCP client connects over the standard MCP streamable HTTP transport and gets its own session, guided by a built-in modeling agent persona toward safe use of the tools. |
| 27 | + |
| 28 | +### Enabling MCP |
| 29 | + |
| 30 | +MCP is opt-in and off by default. |
| 31 | +An MCP-aware GLSP client enables it by adding an `mcpServer` configuration to the [initialize request]({{< relref "protocol" >}}) it already sends. |
| 32 | +The standalone workflow example, for instance, passes it through the diagram loader: |
| 33 | + |
| 34 | +```ts |
| 35 | +diagramLoader.load<McpInitializeParameters>({ |
| 36 | + // opt in by adding mcpServer (all fields optional) |
| 37 | + initializeParameters: { mcpServer: { name: 'glsp-workflow', port: 64577 } } |
| 38 | +}); |
| 39 | +``` |
| 40 | + |
| 41 | +An empty `mcpServer: {}` enables MCP with all defaults. |
| 42 | +Its options such as the port, route, and name are documented in the [adopter guide](https://github.com/eclipse-glsp/glsp-server-node/blob/main/packages/server-mcp/README.md). |
| 43 | + |
| 44 | +### Architecture |
| 45 | + |
| 46 | +<p align="center"> |
| 47 | +<img src="mcp-architecture.svg" alt="High-level GLSP MCP architecture" width=700/> |
| 48 | +<br/> |
| 49 | +<b>High-level MCP architecture: the GLSP server starts an MCP server when a client opts in</b> |
| 50 | +</p> |
| 51 | + |
| 52 | +The MCP server runs inside each GLSP server, which is created per connecting application (in the common desktop setup, one per process). |
| 53 | +One GLSP server therefore has one MCP server on one port, and all of that server's diagrams are reached through it. |
| 54 | + |
| 55 | +The MCP server is not started eagerly. |
| 56 | +The GLSP server spawns it the first time a client opts into MCP, and disposes it when the GLSP server shuts down. |
| 57 | +The resolved URL is announced back to the client (and logged on the server's standard output), so the tool platform integration can register it with the MCP client. |
| 58 | +A random free port is used by default, but adopters can pin a fixed port when an external MCP client needs a stable URL. |
| 59 | + |
| 60 | +Besides this Node process model, the MCP server is portable: it can also run fully in the browser inside a Web Worker, so AI-assisted modeling works in pure web deployments of GLSP as well. |
| 61 | + |
| 62 | +### Adapting it to your language |
| 63 | + |
| 64 | +The built-in tools work on any GLSP model, but their default output is deliberately generic. |
| 65 | +A few language-specific adaptations give noticeably better results: |
| 66 | + |
| 67 | +* A custom **model serializer** controls how a diagram is presented to the model. The workflow example renders it as semantically ordered Markdown and drops redundant attributes, which improves comprehension and keeps the context small. |
| 68 | +* A custom **label provider** and **element-types provider** tell the model how elements are labeled and which element types it may create, so the built-in create and modify tools work for your language. |
| 69 | + |
| 70 | +The built-in write tools dispatch standard GLSP [operations]({{< relref "modelOperations" >}}), so they reuse a diagram's existing operation handlers and an assistant's edits follow the same validation and undo or redo as a manual one. |
| 71 | +Adopters therefore rarely need custom tools for editing, but they can add their own tools, resources, and prompts for language-specific actions. |
| 72 | +A tool always returns a human-readable text result and may additionally return a structured payload, so different MCP clients can consume whichever form they support. |
| 73 | + |
| 74 | +The workflow example demonstrates these provider overrides, and the [extension guide](https://github.com/eclipse-glsp/glsp-server-node/blob/main/packages/server-mcp/ARCHITECTURE.md) covers adding custom tools, resources, and prompts. |
| 75 | + |
| 76 | +### Tool platform integration |
| 77 | + |
| 78 | +How the announced MCP server URL reaches the AI client depends on the platform: |
| 79 | + |
| 80 | +* **Eclipse Theia**: the [Theia MCP integration](https://github.com/eclipse-glsp/glsp-theia-integration/tree/master/packages/theia-mcp-integration) registers every GLSP server's MCP endpoint with Theia's AI MCP support automatically, with no extra wiring beyond installing it. |
| 81 | +* **VS Code**: the [VS Code integration](https://github.com/eclipse-glsp/glsp-vscode-integration) provides an MCP server provider that adopters register in their extension and feed with the GLSP initialize result. |
| 82 | +* **Standalone or external clients**: tools such as Claude Desktop or the MCP Inspector connect to the announced URL directly. Pin a fixed port and share it in your setup guide. |
| 83 | + |
| 84 | +### Security |
| 85 | + |
| 86 | +The shipped defaults assume a single trusted local process reaching the server over loopback, which is the typical desktop IDE setup. |
| 87 | +The server binds to loopback only and performs the standard Host and Origin checks to defeat DNS rebinding, but it ships with **no authentication**. |
| 88 | +If an adopter widens the bind beyond loopback without acknowledging the missing authentication, the server refuses to start. Doing so safely requires an external authenticating layer such as a reverse proxy. |
| 89 | +The server is not hardened for hostile multi-tenant or public exposure. |
| 90 | + |
| 91 | +### Further reading |
| 92 | + |
| 93 | +* [server-mcp adopter guide](https://github.com/eclipse-glsp/glsp-server-node/blob/main/packages/server-mcp/README.md): the integration quickstart. |
| 94 | +* [server-mcp architecture and extension guide](https://github.com/eclipse-glsp/glsp-server-node/blob/main/packages/server-mcp/ARCHITECTURE.md): architecture, security model, configuration options, and the extension cookbook. |
| 95 | +* [MCP feature request (issue #1546)](https://github.com/eclipse-glsp/glsp/issues/1546): background and rationale. |
0 commit comments