Back to JetBrains

Your Plugin's Second Service: Architecture for Integrations That Grow

JetBrainsNovember 17, 202640m
In a Nutshell

Eugenie evolved a single-plugin architecture into a clean, two-layer system where shared core logic handles model/use-case operations and service-specific extensions manage differences, letting one codebase power four plugins across five code-review services. Each plugin ships its own JAR; build-time token substitution and IDE-service holder maps prevent class-name and key collisions when multiple plugins load. MCP tools are added as annotated suspend functions that call the same use-cases, giving AI agents direct access to the review workflow without extra protocol code.

AI-Generated Notes

These notes were generated by AI and may contain inaccuracies.

Eugenie worked in software development for more than 15 years, with eight years at JetBrains working on IntelliJ IDEA and Upsource, a code review tool. After working on web projects, she started her own plugin in 2019. The idea originated from code reviews she conducted daily as a team leader, finding the Bitbucket web interface painful to use. The plugin began as a simple pull request plugin for Bitbucket Cloud with one plugin and one service.

Today the same codebase shares four plugins for five services with about 7,000 paid seats. Only the first two plugins are paid, while the other two are free. Bitbucket Cloud and Bitbucket Data Center share the same name but are completely different products with different APIs, features, and color schemes. All plugins share one codebase. The presentation covers how the design changed with each new service, why most logic became easy to test, what happens when two plugins from one codebase meet in one IDE, and MCP Tools for AI Agents showing how any plugin can add tools to the IDE's built-in MCP server.

The first request for a second service was Bitbucket Server, now called Bitbucket Data Center. It has its own REST API and features, including the ability to reopen a declined pull request (which Cloud cannot do) while Cloud allows giving a reason when declining. Each server installation can run different versions.

The initial approach split code into a common part and a part for each service. Shared types included code review service instance, pull request, and API client. When products worked differently, the common code asked the service. When a feature existed only in one product, the common code still needed to know about it. For example, Cloud has tasks while server has blocker comments - similar concepts but different implementation details. The common code supported both and asked the service which one it had. This worked but the common code became full of service-specific logic.

GitLab introduced even more differences, particularly around diffs and people. In Bitbucket, comments attach to a single commit or range of commits, but GitLab saves a version on every push (even after forced pushes that may rewrite history), with comments belonging to versions rather than commits. For people, Bitbucket has reviewers with simple status, while GitLab has other roles including assignees and approvals from team members such as code owners.

A new rule was introduced: the shared part holds what makes sense for more than one code review service, even if only one service supports it today. Notifications are now supported for Bitbucket Cloud only but make sense for any code review service. GitLab versions, being very specific, stay in the service-specific part. GitLab's differences needed their own dialogues and panels, and the old theme had no good place for UI.

The old theme cracked in two places. First, GitLab works with models differently, storing versions that shouldn't be added to a shared model. Second, GitLab's dialogues and panels could only go to the service instance, causing it to grow. The theme was moved up from the API to business logic in two steps.

For the model (data in memory that UI shows, like pull request lists, open pull requests, and comments), the shared model got an extension for each service to store service-specific data. Operations moved into use cases - shared code that reads the model, calls the service, and writes results back. Each service has a use case extension for its own part. The shared code stopped calling the API directly; only use case extensions called it. This fixed the first crack, and dialogues and panels gained their own place.

Where services agree, the use case handles work independently. For example, draft deletion happens without calling the service, and removing deleted comments from the model is identical across services. Where services differ, the use case extension handles the work. When resolving a comment, Bitbucket keeps the flag on the first comment of the thread, so its extension updates that one comment. GitLab keeps the flag on every comment in the discussion, so its extension updates all of them.

Services now differ in how they change the model, not only what they send to the server. When Gitee arrived as another one-mode code review service, its proof of concept required no changes to shared code. The architecture split into two layers following clean architecture principles. The IDE layer contains everything built on the IntelliJ platform: actions, UI, settings, extensions like tool windows. Use cases and models went to the core layer.

Every non-trivial behavior goes into the core where tests can easily reach it. The core may use basic IntelliJ classes like project, logger, utility classes, or bundled libraries, but declares interfaces for anything else. This is a convention, not enforced by the build. The IDE layer calls use cases and implements core interfaces. Service-specific protocols like Bitbucket and GitLab REST APIs live in the IDE layer, so the core never sees them. In use case tests, interfaces receive Mockito mocks. A light test project is needed because the core uses projects, using allied features from the platform.

For Bitbucket resolving a comment, the example puts a comment and its reply into the model, runs the use case, and checks two things: the model state and that the API received exactly one call.

Each layer has two interfaces: one for the whole plugin and one for each service. In the Bitbucket plugin with cloud and server services, the Bitbucket plugin extension serves as the entry point registered through a custom extension point. Everything else derives from it: plugin settings, core extensions, and a plugin service extension for each service. Plugin service extensions contain UI that differs between services, such as login dialogs or merge pull request dialogs.

The core declares core extension implemented by the IDE layer. For Bitbucket, this is Bitbucket core extension, providing what the core needs from the IDE like storage, and containing core service extensions for each service. Each gives out that service's model and use case extensions, such as the one resolving comments, and answers questions about the service like whether cloud supports notifications. The IDE layer one creates service-specific dialogues like login and merge dialogs, and renders service-specific Markdown in comments by providing HTML content renderer. Everything specific to Bitbucket Cloud starts from these two classes.

When installing two plugins in one IDE, each plugin has its own class loader, so shared code loads twice and the copies never meet. This is equivalent to several plugins bundling the same library. An alternative approach creates a base plugin with shared code that other plugins depend on, resulting in one copy without clashes. However, version problems arise because users can update the base plugin without other plugins or vice versa, and plugins cannot declare specific version dependencies on the base.

After experimenting with both options, the first approach was chosen: each plugin ships independently, appearing more straightforward for users. The cost involves names, as the IDE finds many things by name globally: IDE services by class names, actions, data keys, tool windows, settings keys. When two plugins use the same data key, GitLab's action can retrieve Bitbucket's object from context - a different class with the same name - causing class cast exceptions because class loaders differ.

Keys created with Key.create don't have this problem because keys with the same name aren't equal. Everything the IDE finds by string needs a plugin prefix. The prefix comes from the build, where each build sets tokens: the prefix, plugin ID, and even terminology like "pull request" since GitLab calls them merge requests. Shared models compile once and pack into every plugin, with the build replacing tokens inside each plugin's JAR after the main build.

In plugin XML, this gives every action its own ID. Values are needed at runtime, so the build writes them into a property file. Shared code loads this file with its own class loader, so each copy finds its plugin's file and gets correct values. IDE services need different handling since their key is the class name and tokens cannot rename classes. Shared code declares no IDE services; instead, each plugin declares a holder containing all shared IDE services in a map from class to instance. Since the holder is a real IDE service, each plugin gets its own coroutine scope disposed when the plugin unloads. This workaround is the simplest approach despite not being elegant.

A fix in shared code requires releasing every plugin. A fix in one plugin's own code requires releasing only that plugin. The major version is shared, and each plugin has its own minor version.

Themes helped unexpectedly with AI agents. MCP Tools for AI Agents became one more client for the core alongside the UI. JetBrains IDEs have a built-in MCP server turned on in settings, setting up agents like Claude Code, Codex, Cursor, Junie, and Copilot. The IDE comes with its own tools allowing agents to find symbols, check files with IDE inspections, or rename with refactoring, plus many other built-in tools. Any plugin can add tools to the same server without implementing the protocol or opening ports.

To add a tool, a dependency on the bundled MCP server plugin is needed, requiring a few lines of XML and a class. With plugin model version 2, the module's XML must declare the MCP server plugin dependency. Each tool is a suspend function with two annotations: name and description. The project comes from the coroutine context. For errors the agent should read, MCP fail is called with a message. The server builds JSON schema from the Kotlin signature, with names and descriptions from annotations and types from Kotlin. Enums give agents closed lists of values. The server adds project path to every tool so agents can specify which open project the call targets.

Nullable types alone don't make parameters optional - default values are needed. Agents sometimes send empty strings instead of omitting parameters, so blank strings are treated like null values. Tools can return strings or serializable classes. Hints tell agents if tools only read, delete, or communicate externally. Long calls should use timeouts or show progress and be made cancelable since agent wait times are unpredictable. When using positions like line or offset, agents sometimes miscount and pass wrong values.

Platform test infrastructure for MCP is internal and unavailable to plugins, so tool logic is tested like other code. Three API considerations emerged: the isEnabled function for turning tools on and off is checked only once at service start, so it can depend on currently opened projects or their state. Router mode is an MCP server setting where agents see a short tool list plus one tool that can run any tool by name. From platform 2026.3, alwaysIncluded keeps tools on the short list. Prompts or resources cannot be added, so descriptions are the only way to guide agents.

Tool names exist in a global namespace. Agents receive one list from the whole IDE including built-in and plugin tools, requiring tool prefixes. With multiple plugins from one codebase, tools can be declared in shared code, or two plugins would offer identical names. The shared base class handles only plumbing: creating MCP use case, running calls, and converting errors to agent messages. Each plugin declares its own tools with unique names, allowing tools to differ slightly. GitLab tools use different naming than Bitbucket tools.

The MCP server has a tool provider API with MCP tools provider class interface for runtime tool declaration. This would allow declaring tools once and adding prefixes dynamically, but requires writing every schema manually instead of generating from Kotlin signatures. Tools are sometimes different anyway. The tool function does minimal work: cleaning up parameters and calling a core use case. It never calls the API itself. The MCP use case works like other use cases with shared parts and service extensions, requiring its own use case because tools must work even when no pull request is open in the UI, plus other differences.

For Bitbucket Cloud adding a comment, the tool handles line miscounting by accepting line text, with the extension rejecting comments if text doesn't match as an additional check. It creates the comment as pending, then the shared part puts the comment into the open pull request model if it exists, showing immediately in the IDE. The use case is tested like others with mock interfaces.

A simple pull request with average computation code containing two bugs was demonstrated. Instead of using the review button, the link was copied and opened in Claude Code terminal. The prompt asked to review the pull request, add comments, and suggest fixes using Bitbucket. The agent first called Bitbucket get pull request tool with ID and repository from the URL, requesting changes, discussions, and commits using the plugin's custom protocol rather than Bitbucket REST API. Next it called Bitbucket get file diff with specific commit hashes and file path. Finding two bugs, it called Bitbucket add comments twice with file path, commit hashes, and line content. Two pending comments were created: one about wrong sign usage, another about missing double typecast.

When asked about using AI-agentic coding to synchronize separate codebases instead of layered abstractions, Eugenie noted she started plugins before the AI era but finds AI agents work well with current abstractions. Most code and new features are now written with AI agents, and reviewing is easier in one codebase than across five. Regarding plugin model version 2 and whether it helps with different module handling for GitHub versus Bitbucket, it primarily concerns optional loading of plugin parts when dependencies exist, useful for MCP server conditional loading and remote development scenarios, not significantly helping with multiple vendor implementations.

Regarding concerns about thousands of MCP tools from marketplace plugins overwhelming agents, router mode helps by showing short lists while allowing name-based discovery. Tool names should be self-describing with prefixes like Bitbucket or GitLab making obvious which tools to use when those services appear in prompts. Encouraging users to disable unused plugins makes sense. An action could create .agent files with guidelines directing to specific tools, already partially implemented with a button starting terminal and inserting prepared prompts, though the API isn't rich enough for all desired functionality.

When evaluating base plugins as an architectural option, several significant drawbacks emerged beyond version compatibility issues. A primary concern is the dependency on a third-party plugin, which creates a poor user experience since users must install multiple plugins rather than a single integrated solution. This approach appears unprofessional and risks users forgetting the purpose of the base plugin or accidentally disabling it.

From a user perspective, installing one plugin is significantly easier than managing multiple dependencies. The base plugin approach creates additional complications for paid plugins, as most of the paid plugin's code would reside in the free base plugin. This structure prevents obfuscation of function names that other plugins call, and makes license verification impossible within the free plugin environment.

Base plugin architectures can work effectively for free plugins that change rarely. These stable plugins can release a single core version and depend on it without encountering version compatibility problems over time.

The presentation highlighted the importance of the MCP server and tools discussion, indicating strong interest in this area and the need for additional educational content on proper implementation and ensuring effective agent interactions.

Keep JetBrains in your library

Save the videos and channels worth coming back to, and find them again in one place.